Changeset 63486 in vbox for trunk/src/VBox/Main/src-all/DisplayResampleImage.cpp
- Timestamp:
- Aug 15, 2016 2:57:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/DisplayResampleImage.cpp
r63459 r63486 16 16 */ 17 17 18 /*19 * Based on gdImageCopyResampled from libgd.20 * Original copyright notice follows:21 22 Portions copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 200723 Pierre-Alain Joye ([email protected]).24 25 Permission has been granted to copy, distribute and modify gd in26 any context without fee, including a commercial application,27 provided that this notice is present in user-accessible supporting28 documentation.29 30 This does not affect your ownership of the derived work itself, and31 the intent is to assure proper credit for the authors of gd, not to32 interfere with your productive use of gd. If you have questions,33 ask. "Derived works" includes all programs that utilize the34 library. Credit must be given in user-accessible documentation.35 36 This software is provided "AS IS." The copyright holders disclaim37 all warranties, either express or implied, including but not38 limited to implied warranties of merchantability and fitness for a39 particular purpose, with respect to this code and accompanying40 documentation.41 */42 43 /*44 *45 * @todo Simplify: Offsets of images are 0,0 => no dstX, dstY, srcX, srcY;46 * Screenshot has no alpha channel => no processing of alpha byte.47 */48 49 18 #include <iprt/types.h> 50 19 51 /* 2.0.10: cast instead of floor() yields 35% performance improvement. 52 Thanks to John Buckman. */ 53 54 #define floor2(exp) ((long) exp) 55 /*#define floor2(exp) floor(exp)*/ 56 57 typedef uint8_t *gdImagePtr; 58 59 DECLINLINE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y, int w) 60 { 61 return *(int32_t *)(im + y * w * 4 + x * 4); 62 } 63 64 DECLINLINE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color, int w) 20 DECLINLINE(void) imageSetPixel (uint8_t *im, int x, int y, int color, int w) 65 21 { 66 22 *(int32_t *)(im + y * w * 4 + x * 4) = color; 67 23 } 68 24 69 #define gdAlphaMax 127 70 #define gdAlphaOpaque 0 71 #define gdAlphaTransparent 127 72 #define gdRedMax 255 73 #define gdGreenMax 255 74 #define gdBlueMax 255 75 #define gdTrueColorGetAlpha(c) (((c) & 0x7F000000) >> 24) 76 #define gdTrueColorGetRed(c) (((c) & 0xFF0000) >> 16) 77 #define gdTrueColorGetGreen(c) (((c) & 0x00FF00) >> 8) 78 #define gdTrueColorGetBlue(c) ((c) & 0x0000FF) 79 #define gdTrueColorAlpha(r, g, b, a) (((a) << 24) + \ 80 ((r) << 16) + \ 81 ((g) << 8) + \ 82 (b)) 83 84 #if 0 /* unused */ 85 void gdImageCopyResampled (uint8_t *dst, 86 uint8_t *src, 87 int dstX, int dstY, 88 int srcX, int srcY, 89 int dstW, int dstH, int srcW, int srcH) 90 { 91 int x, y; 92 double sy1, sy2, sx1, sx2; 93 for (y = dstY; (y < dstY + dstH); y++) 94 { 95 sy1 = ((double) y - (double) dstY) * (double) srcH / (double) dstH; 96 sy2 = ((double) (y + 1) - (double) dstY) * (double) srcH / 97 (double) dstH; 98 for (x = dstX; (x < dstX + dstW); x++) 99 { 100 double sx, sy; 101 double spixels = 0; 102 double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; 103 sx1 = ((double) x - (double) dstX) * (double) srcW / dstW; 104 sx2 = ((double) (x + 1) - (double) dstX) * (double) srcW / dstW; 105 sy = sy1; 106 do 107 { 108 double yportion; 109 if (floor2 (sy) == floor2 (sy1)) 110 { 111 yportion = 1.0 - (sy - (double)floor2 (sy)); 112 if (yportion > sy2 - sy1) 113 { 114 yportion = sy2 - sy1; 115 } 116 sy = (double)floor2 (sy); 117 } 118 else if (sy == floor2 (sy2)) 119 { 120 yportion = sy2 - (double)floor2 (sy2); 121 } 122 else 123 { 124 yportion = 1.0; 125 } 126 sx = sx1; 127 do 128 { 129 double xportion; 130 double pcontribution; 131 int p; 132 if (floor2 (sx) == floor2 (sx1)) 133 { 134 xportion = 1.0 - (sx - (double)floor2 (sx)); 135 if (xportion > sx2 - sx1) 136 { 137 xportion = sx2 - sx1; 138 } 139 sx = (double)floor2 (sx); 140 } 141 else if (sx == floor2 (sx2)) 142 { 143 xportion = sx2 - (double)floor2 (sx2); 144 } 145 else 146 { 147 xportion = 1.0; 148 } 149 pcontribution = xportion * yportion; 150 /* 2.08: previously srcX and srcY were ignored. 151 Andrew Pattison */ 152 p = gdImageGetTrueColorPixel (src, 153 (int) sx + srcX, 154 (int) sy + srcY, srcW); 155 red += gdTrueColorGetRed (p) * pcontribution; 156 green += gdTrueColorGetGreen (p) * pcontribution; 157 blue += gdTrueColorGetBlue (p) * pcontribution; 158 alpha += gdTrueColorGetAlpha (p) * pcontribution; 159 spixels += xportion * yportion; 160 sx += 1.0; 161 } 162 while (sx < sx2); 163 sy += 1.0; 164 } 165 while (sy < sy2); 166 if (spixels != 0.0) 167 { 168 red /= spixels; 169 green /= spixels; 170 blue /= spixels; 171 alpha /= spixels; 172 } 173 /* Clamping to allow for rounding errors above */ 174 if (red > 255.0) 175 { 176 red = 255.0; 177 } 178 if (green > 255.0) 179 { 180 green = 255.0; 181 } 182 if (blue > 255.0) 183 { 184 blue = 255.0; 185 } 186 if (alpha > gdAlphaMax) 187 { 188 alpha = gdAlphaMax; 189 } 190 gdImageSetPixel (dst, 191 x, y, 192 gdTrueColorAlpha ((int) red, 193 (int) green, 194 (int) blue, (int) alpha), dstW); 195 } 196 } 197 } 198 #endif 25 #define trueColorGetAlpha(c) (((c) & 0x7F000000) >> 24) 26 #define trueColorGetRed(c) (((c) & 0xFF0000) >> 16) 27 #define trueColorGetGreen(c) (((c) & 0x00FF00) >> 8) 28 #define trueColorGetBlue(c) ((c) & 0x0000FF) 199 29 200 30 /* Fast integer implementation for 32 bpp bitmap scaling. 201 * Us efixed point values * 16.31 * Using fixed point values * 16. 202 32 */ 203 33 typedef int32_t FIXEDPOINT; … … 209 39 /* For 32 bit source only. */ 210 40 void BitmapScale32 (uint8_t *dst, 211 212 213 214 41 int dstW, int dstH, 42 const uint8_t *src, 43 int iDeltaLine, 44 int srcW, int srcH) 215 45 { 216 46 int x, y; … … 283 113 p = *(uint32_t *)(pu8SrcLine + FIXEDPOINT_TO_INT(sx) * 4); 284 114 /* Color depth specific code end */ 285 red += gdTrueColorGetRed (p) * pcontribution;286 green += gdTrueColorGetGreen (p) * pcontribution;287 blue += gdTrueColorGetBlue (p) * pcontribution;115 red += trueColorGetRed (p) * pcontribution; 116 green += trueColorGetGreen (p) * pcontribution; 117 blue += trueColorGetBlue (p) * pcontribution; 288 118 289 119 sx += INT_TO_FIXEDPOINT(1); … … 312 142 blue = 255; 313 143 } 314 gdImageSetPixel (dst,315 316 317 144 imageSetPixel (dst, 145 x, y, 146 ( ((int) red) << 16) + (((int) green) << 8) + ((int) blue), 147 dstW); 318 148 } 319 149 } 320 150 } 321
Note:
See TracChangeset
for help on using the changeset viewer.