OLD | NEW |
1 // Copyright 2014 Google Inc. All Rights Reserved. | 1 // Copyright 2014 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
9 // | 9 // |
10 // WebPPicture tools: alpha handling, etc. | 10 // WebPPicture tools: alpha handling, etc. |
11 // | 11 // |
12 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) |
13 | 13 |
| 14 #include <assert.h> |
| 15 |
14 #include "./vp8enci.h" | 16 #include "./vp8enci.h" |
15 #include "../dsp/yuv.h" | 17 #include "../dsp/yuv.h" |
16 | 18 |
17 static WEBP_INLINE uint32_t MakeARGB32(int r, int g, int b) { | 19 static WEBP_INLINE uint32_t MakeARGB32(int r, int g, int b) { |
18 return (0xff000000u | (r << 16) | (g << 8) | b); | 20 return (0xff000000u | (r << 16) | (g << 8) | b); |
19 } | 21 } |
20 | 22 |
21 //------------------------------------------------------------------------------ | 23 //------------------------------------------------------------------------------ |
22 // Helper: clean up fully transparent area to help compressibility. | 24 // Helper: clean up fully transparent area to help compressibility. |
23 | 25 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 need_reset = 1; | 115 need_reset = 1; |
114 } | 116 } |
115 } | 117 } |
116 } | 118 } |
117 } | 119 } |
118 } | 120 } |
119 | 121 |
120 #undef SIZE | 122 #undef SIZE |
121 #undef SIZE2 | 123 #undef SIZE2 |
122 | 124 |
| 125 void WebPCleanupTransparentAreaLossless(WebPPicture* const pic) { |
| 126 int x, y, w, h; |
| 127 uint32_t* argb; |
| 128 assert(pic != NULL && pic->use_argb); |
| 129 w = pic->width; |
| 130 h = pic->height; |
| 131 argb = pic->argb; |
| 132 |
| 133 for (y = 0; y < h; ++y) { |
| 134 for (x = 0; x < w; ++x) { |
| 135 if ((argb[x] & 0xff000000) == 0) { |
| 136 argb[x] = 0x00000000; |
| 137 } |
| 138 } |
| 139 argb += pic->argb_stride; |
| 140 } |
| 141 } |
| 142 |
123 //------------------------------------------------------------------------------ | 143 //------------------------------------------------------------------------------ |
124 // Blend color and remove transparency info | 144 // Blend color and remove transparency info |
125 | 145 |
126 #define BLEND(V0, V1, ALPHA) \ | 146 #define BLEND(V0, V1, ALPHA) \ |
127 ((((V0) * (255 - (ALPHA)) + (V1) * (ALPHA)) * 0x101) >> 16) | 147 ((((V0) * (255 - (ALPHA)) + (V1) * (ALPHA)) * 0x101) >> 16) |
128 #define BLEND_10BIT(V0, V1, ALPHA) \ | 148 #define BLEND_10BIT(V0, V1, ALPHA) \ |
129 ((((V0) * (1020 - (ALPHA)) + (V1) * (ALPHA)) * 0x101) >> 18) | 149 ((((V0) * (1020 - (ALPHA)) + (V1) * (ALPHA)) * 0x101) >> 18) |
130 | 150 |
131 void WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb) { | 151 void WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb) { |
132 const int red = (background_rgb >> 16) & 0xff; | 152 const int red = (background_rgb >> 16) & 0xff; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 217 } |
198 argb += pic->argb_stride; | 218 argb += pic->argb_stride; |
199 } | 219 } |
200 } | 220 } |
201 } | 221 } |
202 | 222 |
203 #undef BLEND | 223 #undef BLEND |
204 #undef BLEND_10BIT | 224 #undef BLEND_10BIT |
205 | 225 |
206 //------------------------------------------------------------------------------ | 226 //------------------------------------------------------------------------------ |
OLD | NEW |