blob: d69f0ac18fabcff1ba9a3957b7340d8a782a0709 [file] [log] [blame]
george82f891ccd2005-12-03 07:30:51 +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>
26#include <rfb/Rect.h>
george822dc01bc2006-05-24 09:58:37 +000027#include <rfb/PixelFormat.h>
george82f891ccd2005-12-03 07:30:51 +000028
29using namespace rdr;
30
31namespace rfb {
32
33 class ScaledPixelBuffer {
34 public:
george822dc01bc2006-05-24 09:58:37 +000035 ScaledPixelBuffer(U8 **data, int width, int height, int scale, PixelFormat pf);
george8204a91b92006-02-12 05:59:58 +000036 ScaledPixelBuffer();
george82f891ccd2005-12-03 07:30:51 +000037 virtual ~ScaledPixelBuffer();
38
39 // Get width, height, number of pixels and scale
george8201117ec2006-02-12 11:03:48 +000040 int width() const { return scaled_width; }
41 int height() const { return scaled_height; }
42 int area() const { return scaled_width * scaled_height; }
george826b974db2006-04-05 15:02:36 +000043 int getScale() const { return scale; }
george82f891ccd2005-12-03 07:30:51 +000044
45 // Get rectangle encompassing this buffer
46 // Top-left of rectangle is either at (0,0), or the specified point.
george8201117ec2006-02-12 11:03:48 +000047 Rect getRect() const { return Rect(0, 0, scaled_width, scaled_height); }
george82f891ccd2005-12-03 07:30:51 +000048 Rect getRect(const Point& pos) const {
george8201117ec2006-02-12 11:03:48 +000049 return Rect(pos, pos.translate(Point(scaled_width, scaled_height)));
george82f891ccd2005-12-03 07:30:51 +000050 }
51
george82c5b39732006-04-05 15:25:14 +000052 // Set the new source buffer and its parameters
53 void setSourceBuffer(U8 **src_data, int w, int h);
54
george822dc01bc2006-05-24 09:58:37 +000055 // Set the new pixel format
56 void setPF(const PixelFormat &pf);
57
george82f891ccd2005-12-03 07:30:51 +000058 // Set the new scale, in percent
59 virtual void setScale(int scale);
60
61 // Scale rect from the source image buffer to the destination buffer
62 // using bilinear interpolation
63 virtual void scaleRect(const Rect& r);
64
george821d78bd32006-03-27 15:10:43 +000065 // Calculate the scaled image rectangle which depend on the source
66 // image rectangle.
67 inline Rect calculateScaleBoundary(const Rect& r);
68
george82f891ccd2005-12-03 07:30:51 +000069 protected:
george82fea770d2006-04-05 15:33:50 +000070
71 // Calculate the scaled buffer size depending on the source buffer
72 // parameters (width, height, pixel format)
73 void calculateScaledBufferSize();
74
george8297e5c232006-02-12 11:28:53 +000075
george82f891ccd2005-12-03 07:30:51 +000076 int src_width;
77 int src_height;
george8201117ec2006-02-12 11:03:48 +000078 int scaled_width;
79 int scaled_height;
george822dc01bc2006-05-24 09:58:37 +000080 PixelFormat pf;
george826b974db2006-04-05 15:02:36 +000081 int scale;
george82f891ccd2005-12-03 07:30:51 +000082 double scale_ratio;
george82461e4b32006-02-12 07:58:02 +000083 U8 **src_data;
george8271273472006-02-12 06:44:18 +000084 U8 *scaled_data;
george82f891ccd2005-12-03 07:30:51 +000085 };
86
87};