blob: 7f14cceb09e7894561f81127b126f9c60f783560 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2006 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 *
18 * TightVNC distribution homepage on the Web: http://www.tightvnc.com/
19 *
20 */
21
22// -=- ScaledDIBSectionBuffer.cxx
23
24#include <math.h>
25
26#include <rfb_win32/ScaledDIBSectionBuffer.h>
27
28using namespace rfb;
29using namespace win32;
30
31ScaledDIBSectionBuffer::ScaledDIBSectionBuffer(HWND window)
32 : src_buffer(0), scaling(false), DIBSectionBuffer(window) {
33 scaled_data = data;
34}
35
36ScaledDIBSectionBuffer::~ScaledDIBSectionBuffer() {
37 if (src_buffer) delete src_buffer;
38}
39
40void ScaledDIBSectionBuffer::setScale(int scale_) {
41 if (scale_ == getScale()) return;
42
george822ac935e2006-05-29 13:57:39 +000043 if (format.depth != 24) throw rfb::UnsupportedPixelFormatException();
44
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000045 if (scale_ != 100) {
46 scaling = true;
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000047 if (!src_buffer) {
48 src_buffer = new ManagedPixelBuffer(format, src_width, src_height);
49 src_data = &(src_buffer->data);
george82e89d47f2006-05-27 12:31:08 +000050 memcpy(src_buffer->data, data, area() * (getPF().bpp/8));
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000051 }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000052 } else {
53 scaling = false;
54 }
55 ScaledPixelBuffer::setScale(scale_);
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000056 recreateScaledBuffer();
george82e89d47f2006-05-27 12:31:08 +000057 if (scaling) {
58 scaleRect(Rect(0, 0, src_width, src_height));
59 } else {
60 memcpy(data, src_buffer->data, src_buffer->area() * (src_buffer->getPF().bpp/8));
61 if (src_buffer) {
62 delete src_buffer;
63 src_buffer = 0;
64 src_data = 0;
65 }
66 }
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000067}
68
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000069void ScaledDIBSectionBuffer::setPF(const PixelFormat &pf_) {
70 if (scaling) {
71 ScaledPixelBuffer::setPF(pf_);
72 src_buffer->setPF(pf_);
73 }
74 DIBSectionBuffer::setPF(pf_);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000075 scaled_data = data;
76}
77
78void ScaledDIBSectionBuffer::setSize(int src_width_, int src_height_) {
79 src_width = src_width_;
80 src_height = src_height_;
81 if (scaling) {
82 src_buffer->setSize(src_width, src_height);
83 }
84 calculateScaledBufferSize();
85 recreateScaledBuffer();
86 scaled_data = data;
87}
88
89void ScaledDIBSectionBuffer::recreateScaledBuffer() {
90 width_ = scaled_width;
91 height_ = scaled_height;
92 DIBSectionBuffer::recreateBuffer();
93 scaled_data = data;
94}
95
96void ScaledDIBSectionBuffer::fillRect(const Rect &dest, Pixel pix) {
97 if (scaling) {
98 src_buffer->fillRect(dest, pix);
99 scaleRect(dest);
100 } else {
101 DIBSectionBuffer::fillRect(dest, pix);
102 }
103}
104
105void ScaledDIBSectionBuffer::imageRect(const Rect &dest, const void* pixels, int stride) {
106 if (scaling) {
107 src_buffer->imageRect(dest, pixels, stride);
108 scaleRect(dest);
109 } else {
110 DIBSectionBuffer::imageRect(dest, pixels, stride);
111 }
112}
113
114void ScaledDIBSectionBuffer::copyRect(const Rect &dest, const Point &move_by_delta) {
115 if (scaling) {
116 src_buffer->copyRect(dest, move_by_delta);
117 scaleRect(dest);
118 } else {
119 DIBSectionBuffer::copyRect(dest, move_by_delta);
120 }
121}
122
123void ScaledDIBSectionBuffer::maskRect(const Rect& r, const void* pixels, const void* mask_) {
124 if (scaling) {
125 src_buffer->maskRect(r, pixels, mask_);
126 scaleRect(r);
127 } else {
128 DIBSectionBuffer::maskRect(r, pixels, mask_);
129 }
130}
131
132void ScaledDIBSectionBuffer::maskRect(const Rect& r, Pixel pixel, const void* mask_) {
133 if (scaling) {
134 src_buffer->maskRect(r, pixel, mask_);
135 scaleRect(r);
136 } else {
137 DIBSectionBuffer::maskRect(r, pixel, mask_);
138 }
139}