blob: 8af6957919db75074c4c2733bef47ad218202f47 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2005 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
19// -=- ScaledPixelBuffer.h
20//
21// The ScaledPixelBuffer class allows to scale the image data
22// from the source buffer to destination buffer using bilinear
23// interpolation.
24
25#include <rdr/types.h>
george82f98083a2006-05-29 13:52:55 +000026#include <rdr/Exception.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000027#include <rfb/Rect.h>
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000028#include <rfb/PixelFormat.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029
30using namespace rdr;
31
32namespace rfb {
33
george82f98083a2006-05-29 13:52:55 +000034 struct UnsupportedPixelFormatException : public Exception {
35 UnsupportedPixelFormatException(const char* s="Now supported only true colour pixel data in the scaling mode.")
36 : Exception(s) {}
37 };
38
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039 class ScaledPixelBuffer {
40 public:
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000041 ScaledPixelBuffer(U8 **data, int width, int height, int scale, PixelFormat pf);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042 ScaledPixelBuffer();
43 virtual ~ScaledPixelBuffer();
44
45 // Get width, height, number of pixels and scale
46 int width() const { return scaled_width; }
47 int height() const { return scaled_height; }
48 int area() const { return scaled_width * scaled_height; }
49 int getScale() const { return scale; }
50
51 // Get rectangle encompassing this buffer
52 // Top-left of rectangle is either at (0,0), or the specified point.
53 Rect getRect() const { return Rect(0, 0, scaled_width, scaled_height); }
54 Rect getRect(const Point& pos) const {
55 return Rect(pos, pos.translate(Point(scaled_width, scaled_height)));
56 }
57
58 // Set the new source buffer and its parameters
59 void setSourceBuffer(U8 **src_data, int w, int h);
60
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000061 // Set the new pixel format
62 void setPF(const PixelFormat &pf);
63
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000064 // Set the new scale, in percent
65 virtual void setScale(int scale);
66
67 // Scale rect from the source image buffer to the destination buffer
68 // using bilinear interpolation
69 virtual void scaleRect(const Rect& r);
70
71 // Calculate the scaled image rectangle which depend on the source
72 // image rectangle.
73 inline Rect calculateScaleBoundary(const Rect& r);
74
75 protected:
76
77 // Calculate the scaled buffer size depending on the source buffer
78 // parameters (width, height, pixel format)
79 void calculateScaledBufferSize();
80
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000081
82 int src_width;
83 int src_height;
84 int scaled_width;
85 int scaled_height;
Constantin Kaplinsky1ae2eb02006-05-26 05:24:24 +000086 PixelFormat pf;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000087 int scale;
88 double scale_ratio;
89 U8 **src_data;
90 U8 *scaled_data;
91 };
92
93};