Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +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 | |
Peter Åstrand | b49cd1b | 2008-12-09 13:39:24 +0000 | [diff] [blame] | 25 | #ifndef __RFB_SCALEDPIXELBUFFER_H__ |
| 26 | #define __RFB_SCALEDPIXELBUFFER_H__ |
| 27 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 28 | #include <rdr/types.h> |
george82 | f98083a | 2006-05-29 13:52:55 +0000 | [diff] [blame] | 29 | #include <rdr/Exception.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 30 | #include <rfb/Rect.h> |
Constantin Kaplinsky | 1ae2eb0 | 2006-05-26 05:24:24 +0000 | [diff] [blame] | 31 | #include <rfb/PixelFormat.h> |
george82 | 4ff6675 | 2006-11-20 15:55:05 +0000 | [diff] [blame] | 32 | #include <rfb/ScaleFilters.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 33 | |
| 34 | using namespace rdr; |
| 35 | |
| 36 | namespace rfb { |
| 37 | |
george82 | f98083a | 2006-05-29 13:52:55 +0000 | [diff] [blame] | 38 | struct UnsupportedPixelFormatException : public Exception { |
| 39 | UnsupportedPixelFormatException(const char* s="Now supported only true colour pixel data in the scaling mode.") |
| 40 | : Exception(s) {} |
| 41 | }; |
| 42 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 43 | class ScaledPixelBuffer { |
| 44 | public: |
Constantin Kaplinsky | 1ae2eb0 | 2006-05-26 05:24:24 +0000 | [diff] [blame] | 45 | ScaledPixelBuffer(U8 **data, int width, int height, int scale, PixelFormat pf); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | ScaledPixelBuffer(); |
| 47 | virtual ~ScaledPixelBuffer(); |
| 48 | |
| 49 | // Get width, height, number of pixels and scale |
| 50 | int width() const { return scaled_width; } |
| 51 | int height() const { return scaled_height; } |
george82 | b85a0d6 | 2006-07-23 07:09:35 +0000 | [diff] [blame] | 52 | int getSrcWidth() const { return src_width; } |
| 53 | int getSrcHeight() const { return src_height; } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 54 | int area() const { return scaled_width * scaled_height; } |
george82 | 2446ed0 | 2007-03-10 08:55:35 +0000 | [diff] [blame] | 55 | int getScale() const { return scale; } |
| 56 | double getScaleRatioX() const { return scale_ratio_x; } |
| 57 | double getScaleRatioY() const { return scale_ratio_y; } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 58 | |
george82 | 4ff6675 | 2006-11-20 15:55:05 +0000 | [diff] [blame] | 59 | // Pixel manipulation routines |
| 60 | inline U32 getSourcePixel(int x, int y); |
george82 | 4ff6675 | 2006-11-20 15:55:05 +0000 | [diff] [blame] | 61 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | // Get rectangle encompassing this buffer |
| 63 | // Top-left of rectangle is either at (0,0), or the specified point. |
| 64 | Rect getRect() const { return Rect(0, 0, scaled_width, scaled_height); } |
| 65 | Rect getRect(const Point& pos) const { |
| 66 | return Rect(pos, pos.translate(Point(scaled_width, scaled_height))); |
| 67 | } |
| 68 | |
| 69 | // Set the new source buffer and its parameters |
| 70 | void setSourceBuffer(U8 **src_data, int w, int h); |
| 71 | |
george82 | 4ff6675 | 2006-11-20 15:55:05 +0000 | [diff] [blame] | 72 | void setScaledBuffer(U8 **scaled_data_) { |
| 73 | scaled_data = scaled_data_; |
| 74 | }; |
| 75 | |
Constantin Kaplinsky | 1ae2eb0 | 2006-05-26 05:24:24 +0000 | [diff] [blame] | 76 | // Set the new pixel format |
| 77 | void setPF(const PixelFormat &pf); |
| 78 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | // Set the new scale, in percent |
george82 | 2446ed0 | 2007-03-10 08:55:35 +0000 | [diff] [blame] | 80 | virtual void setScale(int scale); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 81 | |
george82 | c4eb626 | 2007-03-20 10:54:38 +0000 | [diff] [blame] | 82 | // Set/get the scale method |
| 83 | virtual void setScaleFilter(unsigned int scaleFilterID); |
| 84 | unsigned int getScaleFilterID() const { return scaleFilterID; } |
| 85 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 86 | // Scale rect from the source image buffer to the destination buffer |
george82 | ea974d7 | 2006-11-26 11:21:02 +0000 | [diff] [blame] | 87 | // using the current interpolation method |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 88 | virtual void scaleRect(const Rect& r); |
| 89 | |
| 90 | // Calculate the scaled image rectangle which depend on the source |
| 91 | // image rectangle. |
Peter Åstrand | b49cd1b | 2008-12-09 13:39:24 +0000 | [diff] [blame] | 92 | Rect calculateScaleBoundary(const Rect& r); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 93 | |
| 94 | protected: |
| 95 | |
| 96 | // Calculate the scaled buffer size depending on the source buffer |
| 97 | // parameters (width, height, pixel format) |
george82 | 4ff6675 | 2006-11-20 15:55:05 +0000 | [diff] [blame] | 98 | virtual void calculateScaledBufferSize(); |
| 99 | |
| 100 | // Free the weight tabs for x and y |
| 101 | virtual void freeWeightTabs(); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 102 | |
george82 | 3a1982e | 2007-11-04 07:35:51 +0000 | [diff] [blame] | 103 | // Recreates the row accumulators. |
| 104 | virtual void recreateRowAccum(); |
| 105 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 106 | |
| 107 | int src_width; |
| 108 | int src_height; |
| 109 | int scaled_width; |
| 110 | int scaled_height; |
george82 | 2446ed0 | 2007-03-10 08:55:35 +0000 | [diff] [blame] | 111 | int scale; |
| 112 | double scale_ratio_x; |
| 113 | double scale_ratio_y; |
Constantin Kaplinsky | 1ae2eb0 | 2006-05-26 05:24:24 +0000 | [diff] [blame] | 114 | PixelFormat pf; |
george82 | 4ff6675 | 2006-11-20 15:55:05 +0000 | [diff] [blame] | 115 | unsigned int scaleFilterID; |
| 116 | ScaleFilters scaleFilters; |
| 117 | SFilterWeightTab *xWeightTabs; |
| 118 | SFilterWeightTab *yWeightTabs; |
george82 | 3a1982e | 2007-11-04 07:35:51 +0000 | [diff] [blame] | 119 | int *raccum; |
| 120 | int *gaccum; |
| 121 | int *baccum; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 122 | U8 **src_data; |
george82 | df9f31c | 2006-09-16 11:06:07 +0000 | [diff] [blame] | 123 | U8 **scaled_data; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | }; |
Peter Åstrand | b49cd1b | 2008-12-09 13:39:24 +0000 | [diff] [blame] | 127 | |
| 128 | #endif |