george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 1 | /* 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 | |
| 28 | using namespace rdr; |
| 29 | |
| 30 | namespace rfb { |
| 31 | |
| 32 | class ScaledPixelBuffer { |
| 33 | public: |
george82 | 461e4b3 | 2006-02-12 07:58:02 +0000 | [diff] [blame] | 34 | ScaledPixelBuffer(U8 **data, int width, int height, int scale); |
george82 | 04a91b9 | 2006-02-12 05:59:58 +0000 | [diff] [blame] | 35 | ScaledPixelBuffer(); |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 36 | virtual ~ScaledPixelBuffer(); |
| 37 | |
| 38 | // Get width, height, number of pixels and scale |
george82 | 01117ec | 2006-02-12 11:03:48 +0000 | [diff] [blame] | 39 | int width() const { return scaled_width; } |
| 40 | int height() const { return scaled_height; } |
| 41 | int area() const { return scaled_width * scaled_height; } |
george82 | 6b974db | 2006-04-05 15:02:36 +0000 | [diff] [blame] | 42 | int getScale() const { return scale; } |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 43 | |
| 44 | // Get rectangle encompassing this buffer |
| 45 | // Top-left of rectangle is either at (0,0), or the specified point. |
george82 | 01117ec | 2006-02-12 11:03:48 +0000 | [diff] [blame] | 46 | Rect getRect() const { return Rect(0, 0, scaled_width, scaled_height); } |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 47 | Rect getRect(const Point& pos) const { |
george82 | 01117ec | 2006-02-12 11:03:48 +0000 | [diff] [blame] | 48 | return Rect(pos, pos.translate(Point(scaled_width, scaled_height))); |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 49 | } |
| 50 | |
george82 | c5b3973 | 2006-04-05 15:25:14 +0000 | [diff] [blame] | 51 | // Set the new source buffer and its parameters |
| 52 | void setSourceBuffer(U8 **src_data, int w, int h); |
| 53 | |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 54 | // Set the new scale, in percent |
| 55 | virtual void setScale(int scale); |
| 56 | |
| 57 | // Scale rect from the source image buffer to the destination buffer |
| 58 | // using bilinear interpolation |
| 59 | virtual void scaleRect(const Rect& r); |
| 60 | |
george82 | 1d78bd3 | 2006-03-27 15:10:43 +0000 | [diff] [blame] | 61 | // Calculate the scaled image rectangle which depend on the source |
| 62 | // image rectangle. |
| 63 | inline Rect calculateScaleBoundary(const Rect& r); |
| 64 | |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 65 | protected: |
george82 | fea770d | 2006-04-05 15:33:50 +0000 | [diff] [blame] | 66 | |
| 67 | // Calculate the scaled buffer size depending on the source buffer |
| 68 | // parameters (width, height, pixel format) |
| 69 | void calculateScaledBufferSize(); |
| 70 | |
| 71 | // Recreate the scaled pixel buffer |
george82 | 97e5c23 | 2006-02-12 11:28:53 +0000 | [diff] [blame] | 72 | virtual void recreateScaledBuffer(); |
| 73 | |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 74 | int src_width; |
| 75 | int src_height; |
george82 | 01117ec | 2006-02-12 11:03:48 +0000 | [diff] [blame] | 76 | int scaled_width; |
| 77 | int scaled_height; |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 78 | int bpp; |
george82 | 6b974db | 2006-04-05 15:02:36 +0000 | [diff] [blame] | 79 | int scale; |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 80 | double scale_ratio; |
george82 | 461e4b3 | 2006-02-12 07:58:02 +0000 | [diff] [blame] | 81 | U8 **src_data; |
george82 | 7127347 | 2006-02-12 06:44:18 +0000 | [diff] [blame] | 82 | U8 *scaled_data; |
george82 | f891ccd | 2005-12-03 07:30:51 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | }; |