blob: e6c15b8eb2376bc3d3e809f3205211740f64cc32 [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
43 if (src_buffer) {
44 delete src_buffer;
45 src_buffer = 0;
46 }
47 if (scale_ != 100) {
48 scaling = true;
49 src_buffer = new ManagedPixelBuffer(format, src_width, src_height);
50 src_data = &(src_buffer->data);
51 } else {
52 scaling = false;
53 }
54 ScaledPixelBuffer::setScale(scale_);
55}
56
57void ScaledDIBSectionBuffer::setPF(const PixelFormat &pf) {
58 if (scaling) src_buffer->setPF(pf);
59 DIBSectionBuffer::setPF(pf);
60 scaled_data = data;
61}
62
63void ScaledDIBSectionBuffer::setSize(int src_width_, int src_height_) {
64 src_width = src_width_;
65 src_height = src_height_;
66 if (scaling) {
67 src_buffer->setSize(src_width, src_height);
68 }
69 calculateScaledBufferSize();
70 recreateScaledBuffer();
71 scaled_data = data;
72}
73
74void ScaledDIBSectionBuffer::recreateScaledBuffer() {
75 width_ = scaled_width;
76 height_ = scaled_height;
77 DIBSectionBuffer::recreateBuffer();
78 scaled_data = data;
79}
80
81void ScaledDIBSectionBuffer::fillRect(const Rect &dest, Pixel pix) {
82 if (scaling) {
83 src_buffer->fillRect(dest, pix);
84 scaleRect(dest);
85 } else {
86 DIBSectionBuffer::fillRect(dest, pix);
87 }
88}
89
90void ScaledDIBSectionBuffer::imageRect(const Rect &dest, const void* pixels, int stride) {
91 if (scaling) {
92 src_buffer->imageRect(dest, pixels, stride);
93 scaleRect(dest);
94 } else {
95 DIBSectionBuffer::imageRect(dest, pixels, stride);
96 }
97}
98
99void ScaledDIBSectionBuffer::copyRect(const Rect &dest, const Point &move_by_delta) {
100 if (scaling) {
101 src_buffer->copyRect(dest, move_by_delta);
102 scaleRect(dest);
103 } else {
104 DIBSectionBuffer::copyRect(dest, move_by_delta);
105 }
106}
107
108void ScaledDIBSectionBuffer::maskRect(const Rect& r, const void* pixels, const void* mask_) {
109 if (scaling) {
110 src_buffer->maskRect(r, pixels, mask_);
111 scaleRect(r);
112 } else {
113 DIBSectionBuffer::maskRect(r, pixels, mask_);
114 }
115}
116
117void ScaledDIBSectionBuffer::maskRect(const Rect& r, Pixel pixel, const void* mask_) {
118 if (scaling) {
119 src_buffer->maskRect(r, pixel, mask_);
120 scaleRect(r);
121 } else {
122 DIBSectionBuffer::maskRect(r, pixel, mask_);
123 }
124}