blob: 05a419d6d9b1572b858c56745d37cd4c2edd8ccf [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>
27
28using namespace rdr;
29
30namespace rfb {
31
32 class ScaledPixelBuffer {
33 public:
34 ScaledPixelBuffer(U8 *data, int width, int height, int scale);
35 virtual ~ScaledPixelBuffer();
36
37 // Get width, height, number of pixels and scale
38 int width() const { return width_; }
39 int height() const { return height_; }
40 int area() const { return width_ * height_; }
41 int scale() const { return (int)(scale_ratio * 100); }
42
43 // Get rectangle encompassing this buffer
44 // Top-left of rectangle is either at (0,0), or the specified point.
45 Rect getRect() const { return Rect(0, 0, width_, height_); }
46 Rect getRect(const Point& pos) const {
47 return Rect(pos, pos.translate(Point(width_, height_)));
48 }
49
50 // Get the number of pixels per row in the actual pixel buffer data area
51 virtual int getStride() const { return width(); }
52
53 // Get a pointer into the buffer
54 // The pointer is to the top-left pixel of the specified Rect.
55 // The buffer stride (in pixels) is returned.
56 virtual const U8* getPixelsR(const Rect& r, int* stride);
57
58 // Get pixel data for a given part of the buffer
59 // Data is copied into the supplied buffer, with the specified
60 // stride.
61 virtual void getImage(void* imageBuf, const Rect& r, int stride=0);
62
63 // Set the new scale, in percent
64 virtual void setScale(int scale);
65
66 // Scale rect from the source image buffer to the destination buffer
67 // using bilinear interpolation
68 virtual void scaleRect(const Rect& r);
69
70 protected:
71 int width_;
72 int height_;
73 int src_width;
74 int src_height;
75 int bpp;
76 double scale_ratio;
77 U8 *src_data;
78 U8 *data;
79 };
80
81};