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