| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 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 // functions for sample output. | 10 // functions for sample output. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 WebPRGBABuffer* const buf = &output->u.RGBA; | 49 WebPRGBABuffer* const buf = &output->u.RGBA; |
| 50 uint8_t* const dst = buf->rgba + io->mb_y * buf->stride; | 50 uint8_t* const dst = buf->rgba + io->mb_y * buf->stride; |
| 51 WebPSamplerProcessPlane(io->y, io->y_stride, | 51 WebPSamplerProcessPlane(io->y, io->y_stride, |
| 52 io->u, io->v, io->uv_stride, | 52 io->u, io->v, io->uv_stride, |
| 53 dst, buf->stride, io->mb_w, io->mb_h, | 53 dst, buf->stride, io->mb_w, io->mb_h, |
| 54 WebPSamplers[output->colorspace]); | 54 WebPSamplers[output->colorspace]); |
| 55 return io->mb_h; | 55 return io->mb_h; |
| 56 } | 56 } |
| 57 | 57 |
| 58 //------------------------------------------------------------------------------ | 58 //------------------------------------------------------------------------------ |
| 59 // YUV444 -> RGB conversion | |
| 60 | |
| 61 #if 0 // TODO(skal): this is for future rescaling. | |
| 62 static int EmitRGB(const VP8Io* const io, WebPDecParams* const p) { | |
| 63 WebPDecBuffer* output = p->output; | |
| 64 const WebPRGBABuffer* const buf = &output->u.RGBA; | |
| 65 uint8_t* dst = buf->rgba + io->mb_y * buf->stride; | |
| 66 const uint8_t* y_src = io->y; | |
| 67 const uint8_t* u_src = io->u; | |
| 68 const uint8_t* v_src = io->v; | |
| 69 const WebPYUV444Converter convert = WebPYUV444Converters[output->colorspace]; | |
| 70 const int mb_w = io->mb_w; | |
| 71 const int last = io->mb_h; | |
| 72 int j; | |
| 73 for (j = 0; j < last; ++j) { | |
| 74 convert(y_src, u_src, v_src, dst, mb_w); | |
| 75 y_src += io->y_stride; | |
| 76 u_src += io->uv_stride; | |
| 77 v_src += io->uv_stride; | |
| 78 dst += buf->stride; | |
| 79 } | |
| 80 return io->mb_h; | |
| 81 } | |
| 82 #endif | |
| 83 | |
| 84 //------------------------------------------------------------------------------ | |
| 85 // Fancy upsampling | 59 // Fancy upsampling |
| 86 | 60 |
| 87 #ifdef FANCY_UPSAMPLING | 61 #ifdef FANCY_UPSAMPLING |
| 88 static int EmitFancyRGB(const VP8Io* const io, WebPDecParams* const p) { | 62 static int EmitFancyRGB(const VP8Io* const io, WebPDecParams* const p) { |
| 89 int num_lines_out = io->mb_h; // a priori guess | 63 int num_lines_out = io->mb_h; // a priori guess |
| 90 const WebPRGBABuffer* const buf = &p->output->u.RGBA; | 64 const WebPRGBABuffer* const buf = &p->output->u.RGBA; |
| 91 uint8_t* dst = buf->rgba + io->mb_y * buf->stride; | 65 uint8_t* dst = buf->rgba + io->mb_y * buf->stride; |
| 92 WebPUpsampleLinePairFunc upsample = WebPUpsamplers[p->output->colorspace]; | 66 WebPUpsampleLinePairFunc upsample = WebPUpsamplers[p->output->colorspace]; |
| 93 const uint8_t* cur_y = io->y; | 67 const uint8_t* cur_y = io->y; |
| 94 const uint8_t* cur_u = io->u; | 68 const uint8_t* cur_u = io->u; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 dst + buf->stride, NULL, mb_w); | 112 dst + buf->stride, NULL, mb_w); |
| 139 } | 113 } |
| 140 } | 114 } |
| 141 return num_lines_out; | 115 return num_lines_out; |
| 142 } | 116 } |
| 143 | 117 |
| 144 #endif /* FANCY_UPSAMPLING */ | 118 #endif /* FANCY_UPSAMPLING */ |
| 145 | 119 |
| 146 //------------------------------------------------------------------------------ | 120 //------------------------------------------------------------------------------ |
| 147 | 121 |
| 148 static int EmitAlphaYUV(const VP8Io* const io, WebPDecParams* const p) { | 122 static int EmitAlphaYUV(const VP8Io* const io, WebPDecParams* const p, |
| 123 int expected_num_lines_out) { |
| 149 const uint8_t* alpha = io->a; | 124 const uint8_t* alpha = io->a; |
| 150 const WebPYUVABuffer* const buf = &p->output->u.YUVA; | 125 const WebPYUVABuffer* const buf = &p->output->u.YUVA; |
| 151 const int mb_w = io->mb_w; | 126 const int mb_w = io->mb_w; |
| 152 const int mb_h = io->mb_h; | 127 const int mb_h = io->mb_h; |
| 153 uint8_t* dst = buf->a + io->mb_y * buf->a_stride; | 128 uint8_t* dst = buf->a + io->mb_y * buf->a_stride; |
| 154 int j; | 129 int j; |
| 155 | 130 (void)expected_num_lines_out; |
| 131 assert(expected_num_lines_out == mb_h); |
| 156 if (alpha != NULL) { | 132 if (alpha != NULL) { |
| 157 for (j = 0; j < mb_h; ++j) { | 133 for (j = 0; j < mb_h; ++j) { |
| 158 memcpy(dst, alpha, mb_w * sizeof(*dst)); | 134 memcpy(dst, alpha, mb_w * sizeof(*dst)); |
| 159 alpha += io->width; | 135 alpha += io->width; |
| 160 dst += buf->a_stride; | 136 dst += buf->a_stride; |
| 161 } | 137 } |
| 162 } else if (buf->a != NULL) { | 138 } else if (buf->a != NULL) { |
| 163 // the user requested alpha, but there is none, set it to opaque. | 139 // the user requested alpha, but there is none, set it to opaque. |
| 164 for (j = 0; j < mb_h; ++j) { | 140 for (j = 0; j < mb_h; ++j) { |
| 165 memset(dst, 0xff, mb_w * sizeof(*dst)); | 141 memset(dst, 0xff, mb_w * sizeof(*dst)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 188 *alpha -= io->width; | 164 *alpha -= io->width; |
| 189 } | 165 } |
| 190 if (io->crop_top + io->mb_y + io->mb_h == io->crop_bottom) { | 166 if (io->crop_top + io->mb_y + io->mb_h == io->crop_bottom) { |
| 191 // If it's the very last call, we process all the remaining rows! | 167 // If it's the very last call, we process all the remaining rows! |
| 192 *num_rows = io->crop_bottom - io->crop_top - start_y; | 168 *num_rows = io->crop_bottom - io->crop_top - start_y; |
| 193 } | 169 } |
| 194 } | 170 } |
| 195 return start_y; | 171 return start_y; |
| 196 } | 172 } |
| 197 | 173 |
| 198 static int EmitAlphaRGB(const VP8Io* const io, WebPDecParams* const p) { | 174 static int EmitAlphaRGB(const VP8Io* const io, WebPDecParams* const p, |
| 175 int expected_num_lines_out) { |
| 199 const uint8_t* alpha = io->a; | 176 const uint8_t* alpha = io->a; |
| 200 if (alpha != NULL) { | 177 if (alpha != NULL) { |
| 201 const int mb_w = io->mb_w; | 178 const int mb_w = io->mb_w; |
| 202 const WEBP_CSP_MODE colorspace = p->output->colorspace; | 179 const WEBP_CSP_MODE colorspace = p->output->colorspace; |
| 203 const int alpha_first = | 180 const int alpha_first = |
| 204 (colorspace == MODE_ARGB || colorspace == MODE_Argb); | 181 (colorspace == MODE_ARGB || colorspace == MODE_Argb); |
| 205 const WebPRGBABuffer* const buf = &p->output->u.RGBA; | 182 const WebPRGBABuffer* const buf = &p->output->u.RGBA; |
| 206 int num_rows; | 183 int num_rows; |
| 207 const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows); | 184 const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows); |
| 208 uint8_t* const base_rgba = buf->rgba + start_y * buf->stride; | 185 uint8_t* const base_rgba = buf->rgba + start_y * buf->stride; |
| 209 uint8_t* dst = base_rgba + (alpha_first ? 0 : 3); | 186 uint8_t* const dst = base_rgba + (alpha_first ? 0 : 3); |
| 210 uint32_t alpha_mask = 0xff; | 187 const int has_alpha = WebPDispatchAlpha(alpha, io->width, mb_w, |
| 211 int i, j; | 188 num_rows, dst, buf->stride); |
| 212 | 189 (void)expected_num_lines_out; |
| 213 for (j = 0; j < num_rows; ++j) { | 190 assert(expected_num_lines_out == num_rows); |
| 214 for (i = 0; i < mb_w; ++i) { | 191 // has_alpha is true if there's non-trivial alpha to premultiply with. |
| 215 const uint32_t alpha_value = alpha[i]; | 192 if (has_alpha && WebPIsPremultipliedMode(colorspace)) { |
| 216 dst[4 * i] = alpha_value; | |
| 217 alpha_mask &= alpha_value; | |
| 218 } | |
| 219 alpha += io->width; | |
| 220 dst += buf->stride; | |
| 221 } | |
| 222 // alpha_mask is < 0xff if there's non-trivial alpha to premultiply with. | |
| 223 if (alpha_mask != 0xff && WebPIsPremultipliedMode(colorspace)) { | |
| 224 WebPApplyAlphaMultiply(base_rgba, alpha_first, | 193 WebPApplyAlphaMultiply(base_rgba, alpha_first, |
| 225 mb_w, num_rows, buf->stride); | 194 mb_w, num_rows, buf->stride); |
| 226 } | 195 } |
| 227 } | 196 } |
| 228 return 0; | 197 return 0; |
| 229 } | 198 } |
| 230 | 199 |
| 231 static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p) { | 200 static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p, |
| 201 int expected_num_lines_out) { |
| 232 const uint8_t* alpha = io->a; | 202 const uint8_t* alpha = io->a; |
| 233 if (alpha != NULL) { | 203 if (alpha != NULL) { |
| 234 const int mb_w = io->mb_w; | 204 const int mb_w = io->mb_w; |
| 235 const WEBP_CSP_MODE colorspace = p->output->colorspace; | 205 const WEBP_CSP_MODE colorspace = p->output->colorspace; |
| 236 const WebPRGBABuffer* const buf = &p->output->u.RGBA; | 206 const WebPRGBABuffer* const buf = &p->output->u.RGBA; |
| 237 int num_rows; | 207 int num_rows; |
| 238 const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows); | 208 const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows); |
| 239 uint8_t* const base_rgba = buf->rgba + start_y * buf->stride; | 209 uint8_t* const base_rgba = buf->rgba + start_y * buf->stride; |
| 240 #ifdef WEBP_SWAP_16BIT_CSP | 210 #ifdef WEBP_SWAP_16BIT_CSP |
| 241 uint8_t* alpha_dst = base_rgba; | 211 uint8_t* alpha_dst = base_rgba; |
| 242 #else | 212 #else |
| 243 uint8_t* alpha_dst = base_rgba + 1; | 213 uint8_t* alpha_dst = base_rgba + 1; |
| 244 #endif | 214 #endif |
| 245 uint32_t alpha_mask = 0x0f; | 215 uint32_t alpha_mask = 0x0f; |
| 246 int i, j; | 216 int i, j; |
| 247 | |
| 248 for (j = 0; j < num_rows; ++j) { | 217 for (j = 0; j < num_rows; ++j) { |
| 249 for (i = 0; i < mb_w; ++i) { | 218 for (i = 0; i < mb_w; ++i) { |
| 250 // Fill in the alpha value (converted to 4 bits). | 219 // Fill in the alpha value (converted to 4 bits). |
| 251 const uint32_t alpha_value = alpha[i] >> 4; | 220 const uint32_t alpha_value = alpha[i] >> 4; |
| 252 alpha_dst[2 * i] = (alpha_dst[2 * i] & 0xf0) | alpha_value; | 221 alpha_dst[2 * i] = (alpha_dst[2 * i] & 0xf0) | alpha_value; |
| 253 alpha_mask &= alpha_value; | 222 alpha_mask &= alpha_value; |
| 254 } | 223 } |
| 255 alpha += io->width; | 224 alpha += io->width; |
| 256 alpha_dst += buf->stride; | 225 alpha_dst += buf->stride; |
| 257 } | 226 } |
| 227 (void)expected_num_lines_out; |
| 228 assert(expected_num_lines_out == num_rows); |
| 258 if (alpha_mask != 0x0f && WebPIsPremultipliedMode(colorspace)) { | 229 if (alpha_mask != 0x0f && WebPIsPremultipliedMode(colorspace)) { |
| 259 WebPApplyAlphaMultiply4444(base_rgba, mb_w, num_rows, buf->stride); | 230 WebPApplyAlphaMultiply4444(base_rgba, mb_w, num_rows, buf->stride); |
| 260 } | 231 } |
| 261 } | 232 } |
| 262 return 0; | 233 return 0; |
| 263 } | 234 } |
| 264 | 235 |
| 265 //------------------------------------------------------------------------------ | 236 //------------------------------------------------------------------------------ |
| 266 // YUV rescaling (no final RGB conversion needed) | 237 // YUV rescaling (no final RGB conversion needed) |
| 267 | 238 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 289 // But we need to cast the const away, though. | 260 // But we need to cast the const away, though. |
| 290 WebPMultRows((uint8_t*)io->y, io->y_stride, | 261 WebPMultRows((uint8_t*)io->y, io->y_stride, |
| 291 io->a, io->width, io->mb_w, mb_h, 0); | 262 io->a, io->width, io->mb_w, mb_h, 0); |
| 292 } | 263 } |
| 293 num_lines_out = Rescale(io->y, io->y_stride, mb_h, scaler); | 264 num_lines_out = Rescale(io->y, io->y_stride, mb_h, scaler); |
| 294 Rescale(io->u, io->uv_stride, uv_mb_h, &p->scaler_u); | 265 Rescale(io->u, io->uv_stride, uv_mb_h, &p->scaler_u); |
| 295 Rescale(io->v, io->uv_stride, uv_mb_h, &p->scaler_v); | 266 Rescale(io->v, io->uv_stride, uv_mb_h, &p->scaler_v); |
| 296 return num_lines_out; | 267 return num_lines_out; |
| 297 } | 268 } |
| 298 | 269 |
| 299 static int EmitRescaledAlphaYUV(const VP8Io* const io, WebPDecParams* const p) { | 270 static int EmitRescaledAlphaYUV(const VP8Io* const io, WebPDecParams* const p, |
| 271 int expected_num_lines_out) { |
| 300 if (io->a != NULL) { | 272 if (io->a != NULL) { |
| 301 const WebPYUVABuffer* const buf = &p->output->u.YUVA; | 273 const WebPYUVABuffer* const buf = &p->output->u.YUVA; |
| 302 uint8_t* dst_y = buf->y + p->last_y * buf->y_stride; | 274 uint8_t* dst_y = buf->y + p->last_y * buf->y_stride; |
| 303 const uint8_t* src_a = buf->a + p->last_y * buf->a_stride; | 275 const uint8_t* src_a = buf->a + p->last_y * buf->a_stride; |
| 304 const int num_lines_out = Rescale(io->a, io->width, io->mb_h, &p->scaler_a); | 276 const int num_lines_out = Rescale(io->a, io->width, io->mb_h, &p->scaler_a); |
| 277 (void)expected_num_lines_out; |
| 278 assert(expected_num_lines_out == num_lines_out); |
| 305 if (num_lines_out > 0) { // unmultiply the Y | 279 if (num_lines_out > 0) { // unmultiply the Y |
| 306 WebPMultRows(dst_y, buf->y_stride, src_a, buf->a_stride, | 280 WebPMultRows(dst_y, buf->y_stride, src_a, buf->a_stride, |
| 307 p->scaler_a.dst_width, num_lines_out, 1); | 281 p->scaler_a.dst_width, num_lines_out, 1); |
| 308 } | 282 } |
| 309 } | 283 } |
| 310 return 0; | 284 return 0; |
| 311 } | 285 } |
| 312 | 286 |
| 313 static int InitYUVRescaler(const VP8Io* const io, WebPDecParams* const p) { | 287 static int InitYUVRescaler(const VP8Io* const io, WebPDecParams* const p) { |
| 314 const int has_alpha = WebPIsAlphaMode(p->output->colorspace); | 288 const int has_alpha = WebPIsAlphaMode(p->output->colorspace); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 return 1; | 328 return 1; |
| 355 } | 329 } |
| 356 | 330 |
| 357 //------------------------------------------------------------------------------ | 331 //------------------------------------------------------------------------------ |
| 358 // RGBA rescaling | 332 // RGBA rescaling |
| 359 | 333 |
| 360 static int ExportRGB(WebPDecParams* const p, int y_pos) { | 334 static int ExportRGB(WebPDecParams* const p, int y_pos) { |
| 361 const WebPYUV444Converter convert = | 335 const WebPYUV444Converter convert = |
| 362 WebPYUV444Converters[p->output->colorspace]; | 336 WebPYUV444Converters[p->output->colorspace]; |
| 363 const WebPRGBABuffer* const buf = &p->output->u.RGBA; | 337 const WebPRGBABuffer* const buf = &p->output->u.RGBA; |
| 364 uint8_t* dst = buf->rgba + (p->last_y + y_pos) * buf->stride; | 338 uint8_t* dst = buf->rgba + y_pos * buf->stride; |
| 365 int num_lines_out = 0; | 339 int num_lines_out = 0; |
| 366 // For RGB rescaling, because of the YUV420, current scan position | 340 // For RGB rescaling, because of the YUV420, current scan position |
| 367 // U/V can be +1/-1 line from the Y one. Hence the double test. | 341 // U/V can be +1/-1 line from the Y one. Hence the double test. |
| 368 while (WebPRescalerHasPendingOutput(&p->scaler_y) && | 342 while (WebPRescalerHasPendingOutput(&p->scaler_y) && |
| 369 WebPRescalerHasPendingOutput(&p->scaler_u)) { | 343 WebPRescalerHasPendingOutput(&p->scaler_u)) { |
| 370 assert(p->last_y + y_pos + num_lines_out < p->output->height); | 344 assert(y_pos + num_lines_out < p->output->height); |
| 371 assert(p->scaler_u.y_accum == p->scaler_v.y_accum); | 345 assert(p->scaler_u.y_accum == p->scaler_v.y_accum); |
| 372 WebPRescalerExportRow(&p->scaler_y); | 346 WebPRescalerExportRow(&p->scaler_y); |
| 373 WebPRescalerExportRow(&p->scaler_u); | 347 WebPRescalerExportRow(&p->scaler_u); |
| 374 WebPRescalerExportRow(&p->scaler_v); | 348 WebPRescalerExportRow(&p->scaler_v); |
| 375 convert(p->scaler_y.dst, p->scaler_u.dst, p->scaler_v.dst, | 349 convert(p->scaler_y.dst, p->scaler_u.dst, p->scaler_v.dst, |
| 376 dst, p->scaler_y.dst_width); | 350 dst, p->scaler_y.dst_width); |
| 377 dst += buf->stride; | 351 dst += buf->stride; |
| 378 ++num_lines_out; | 352 ++num_lines_out; |
| 379 } | 353 } |
| 380 return num_lines_out; | 354 return num_lines_out; |
| 381 } | 355 } |
| 382 | 356 |
| 383 static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) { | 357 static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) { |
| 384 const int mb_h = io->mb_h; | 358 const int mb_h = io->mb_h; |
| 385 const int uv_mb_h = (mb_h + 1) >> 1; | 359 const int uv_mb_h = (mb_h + 1) >> 1; |
| 386 int j = 0, uv_j = 0; | 360 int j = 0, uv_j = 0; |
| 387 int num_lines_out = 0; | 361 int num_lines_out = 0; |
| 388 while (j < mb_h) { | 362 while (j < mb_h) { |
| 389 const int y_lines_in = | 363 const int y_lines_in = |
| 390 WebPRescalerImport(&p->scaler_y, mb_h - j, | 364 WebPRescalerImport(&p->scaler_y, mb_h - j, |
| 391 io->y + j * io->y_stride, io->y_stride); | 365 io->y + j * io->y_stride, io->y_stride); |
| 392 const int u_lines_in = | |
| 393 WebPRescalerImport(&p->scaler_u, uv_mb_h - uv_j, | |
| 394 io->u + uv_j * io->uv_stride, io->uv_stride); | |
| 395 const int v_lines_in = | |
| 396 WebPRescalerImport(&p->scaler_v, uv_mb_h - uv_j, | |
| 397 io->v + uv_j * io->uv_stride, io->uv_stride); | |
| 398 (void)v_lines_in; // remove a gcc warning | |
| 399 assert(u_lines_in == v_lines_in); | |
| 400 j += y_lines_in; | 366 j += y_lines_in; |
| 401 uv_j += u_lines_in; | 367 if (WebPRescaleNeededLines(&p->scaler_u, uv_mb_h - uv_j)) { |
| 402 num_lines_out += ExportRGB(p, num_lines_out); | 368 const int u_lines_in = |
| 369 WebPRescalerImport(&p->scaler_u, uv_mb_h - uv_j, |
| 370 io->u + uv_j * io->uv_stride, io->uv_stride); |
| 371 const int v_lines_in = |
| 372 WebPRescalerImport(&p->scaler_v, uv_mb_h - uv_j, |
| 373 io->v + uv_j * io->uv_stride, io->uv_stride); |
| 374 (void)v_lines_in; // remove a gcc warning |
| 375 assert(u_lines_in == v_lines_in); |
| 376 uv_j += u_lines_in; |
| 377 } |
| 378 num_lines_out += ExportRGB(p, p->last_y + num_lines_out); |
| 403 } | 379 } |
| 404 return num_lines_out; | 380 return num_lines_out; |
| 405 } | 381 } |
| 406 | 382 |
| 407 static int ExportAlpha(WebPDecParams* const p, int y_pos) { | 383 static int ExportAlpha(WebPDecParams* const p, int y_pos, int max_lines_out) { |
| 408 const WebPRGBABuffer* const buf = &p->output->u.RGBA; | 384 const WebPRGBABuffer* const buf = &p->output->u.RGBA; |
| 409 uint8_t* const base_rgba = buf->rgba + (p->last_y + y_pos) * buf->stride; | 385 uint8_t* const base_rgba = buf->rgba + y_pos * buf->stride; |
| 410 const WEBP_CSP_MODE colorspace = p->output->colorspace; | 386 const WEBP_CSP_MODE colorspace = p->output->colorspace; |
| 411 const int alpha_first = | 387 const int alpha_first = |
| 412 (colorspace == MODE_ARGB || colorspace == MODE_Argb); | 388 (colorspace == MODE_ARGB || colorspace == MODE_Argb); |
| 413 uint8_t* dst = base_rgba + (alpha_first ? 0 : 3); | 389 uint8_t* dst = base_rgba + (alpha_first ? 0 : 3); |
| 414 int num_lines_out = 0; | 390 int num_lines_out = 0; |
| 415 const int is_premult_alpha = WebPIsPremultipliedMode(colorspace); | 391 const int is_premult_alpha = WebPIsPremultipliedMode(colorspace); |
| 416 uint32_t alpha_mask = 0xff; | 392 uint32_t non_opaque = 0; |
| 417 const int width = p->scaler_a.dst_width; | 393 const int width = p->scaler_a.dst_width; |
| 418 | 394 |
| 419 while (WebPRescalerHasPendingOutput(&p->scaler_a)) { | 395 while (WebPRescalerHasPendingOutput(&p->scaler_a) && |
| 420 int i; | 396 num_lines_out < max_lines_out) { |
| 421 assert(p->last_y + y_pos + num_lines_out < p->output->height); | 397 assert(y_pos + num_lines_out < p->output->height); |
| 422 WebPRescalerExportRow(&p->scaler_a); | 398 WebPRescalerExportRow(&p->scaler_a); |
| 423 for (i = 0; i < width; ++i) { | 399 non_opaque |= WebPDispatchAlpha(p->scaler_a.dst, 0, width, 1, dst, 0); |
| 424 const uint32_t alpha_value = p->scaler_a.dst[i]; | |
| 425 dst[4 * i] = alpha_value; | |
| 426 alpha_mask &= alpha_value; | |
| 427 } | |
| 428 dst += buf->stride; | 400 dst += buf->stride; |
| 429 ++num_lines_out; | 401 ++num_lines_out; |
| 430 } | 402 } |
| 431 if (is_premult_alpha && alpha_mask != 0xff) { | 403 if (is_premult_alpha && non_opaque) { |
| 432 WebPApplyAlphaMultiply(base_rgba, alpha_first, | 404 WebPApplyAlphaMultiply(base_rgba, alpha_first, |
| 433 width, num_lines_out, buf->stride); | 405 width, num_lines_out, buf->stride); |
| 434 } | 406 } |
| 435 return num_lines_out; | 407 return num_lines_out; |
| 436 } | 408 } |
| 437 | 409 |
| 438 static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos) { | 410 static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos, |
| 411 int max_lines_out) { |
| 439 const WebPRGBABuffer* const buf = &p->output->u.RGBA; | 412 const WebPRGBABuffer* const buf = &p->output->u.RGBA; |
| 440 uint8_t* const base_rgba = buf->rgba + (p->last_y + y_pos) * buf->stride; | 413 uint8_t* const base_rgba = buf->rgba + y_pos * buf->stride; |
| 441 #ifdef WEBP_SWAP_16BIT_CSP | 414 #ifdef WEBP_SWAP_16BIT_CSP |
| 442 uint8_t* alpha_dst = base_rgba; | 415 uint8_t* alpha_dst = base_rgba; |
| 443 #else | 416 #else |
| 444 uint8_t* alpha_dst = base_rgba + 1; | 417 uint8_t* alpha_dst = base_rgba + 1; |
| 445 #endif | 418 #endif |
| 446 int num_lines_out = 0; | 419 int num_lines_out = 0; |
| 447 const WEBP_CSP_MODE colorspace = p->output->colorspace; | 420 const WEBP_CSP_MODE colorspace = p->output->colorspace; |
| 448 const int width = p->scaler_a.dst_width; | 421 const int width = p->scaler_a.dst_width; |
| 449 const int is_premult_alpha = WebPIsPremultipliedMode(colorspace); | 422 const int is_premult_alpha = WebPIsPremultipliedMode(colorspace); |
| 450 uint32_t alpha_mask = 0x0f; | 423 uint32_t alpha_mask = 0x0f; |
| 451 | 424 |
| 452 while (WebPRescalerHasPendingOutput(&p->scaler_a)) { | 425 while (WebPRescalerHasPendingOutput(&p->scaler_a) && |
| 426 num_lines_out < max_lines_out) { |
| 453 int i; | 427 int i; |
| 454 assert(p->last_y + y_pos + num_lines_out < p->output->height); | 428 assert(y_pos + num_lines_out < p->output->height); |
| 455 WebPRescalerExportRow(&p->scaler_a); | 429 WebPRescalerExportRow(&p->scaler_a); |
| 456 for (i = 0; i < width; ++i) { | 430 for (i = 0; i < width; ++i) { |
| 457 // Fill in the alpha value (converted to 4 bits). | 431 // Fill in the alpha value (converted to 4 bits). |
| 458 const uint32_t alpha_value = p->scaler_a.dst[i] >> 4; | 432 const uint32_t alpha_value = p->scaler_a.dst[i] >> 4; |
| 459 alpha_dst[2 * i] = (alpha_dst[2 * i] & 0xf0) | alpha_value; | 433 alpha_dst[2 * i] = (alpha_dst[2 * i] & 0xf0) | alpha_value; |
| 460 alpha_mask &= alpha_value; | 434 alpha_mask &= alpha_value; |
| 461 } | 435 } |
| 462 alpha_dst += buf->stride; | 436 alpha_dst += buf->stride; |
| 463 ++num_lines_out; | 437 ++num_lines_out; |
| 464 } | 438 } |
| 465 if (is_premult_alpha && alpha_mask != 0x0f) { | 439 if (is_premult_alpha && alpha_mask != 0x0f) { |
| 466 WebPApplyAlphaMultiply4444(base_rgba, width, num_lines_out, buf->stride); | 440 WebPApplyAlphaMultiply4444(base_rgba, width, num_lines_out, buf->stride); |
| 467 } | 441 } |
| 468 return num_lines_out; | 442 return num_lines_out; |
| 469 } | 443 } |
| 470 | 444 |
| 471 static int EmitRescaledAlphaRGB(const VP8Io* const io, WebPDecParams* const p) { | 445 static int EmitRescaledAlphaRGB(const VP8Io* const io, WebPDecParams* const p, |
| 446 int expected_num_out_lines) { |
| 472 if (io->a != NULL) { | 447 if (io->a != NULL) { |
| 473 WebPRescaler* const scaler = &p->scaler_a; | 448 WebPRescaler* const scaler = &p->scaler_a; |
| 474 int j = 0; | 449 int lines_left = expected_num_out_lines; |
| 475 int pos = 0; | 450 const int y_end = p->last_y + lines_left; |
| 476 while (j < io->mb_h) { | 451 while (lines_left > 0) { |
| 477 j += WebPRescalerImport(scaler, io->mb_h - j, | 452 const int row_offset = scaler->src_y - io->mb_y; |
| 478 io->a + j * io->width, io->width); | 453 WebPRescalerImport(scaler, io->mb_h + io->mb_y - scaler->src_y, |
| 479 pos += p->emit_alpha_row(p, pos); | 454 io->a + row_offset * io->width, io->width); |
| 455 lines_left -= p->emit_alpha_row(p, y_end - lines_left, lines_left); |
| 480 } | 456 } |
| 481 } | 457 } |
| 482 return 0; | 458 return 0; |
| 483 } | 459 } |
| 484 | 460 |
| 485 static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) { | 461 static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) { |
| 486 const int has_alpha = WebPIsAlphaMode(p->output->colorspace); | 462 const int has_alpha = WebPIsAlphaMode(p->output->colorspace); |
| 487 const int out_width = io->scaled_width; | 463 const int out_width = io->scaled_width; |
| 488 const int out_height = io->scaled_height; | 464 const int out_height = io->scaled_height; |
| 489 const int uv_in_width = (io->mb_w + 1) >> 1; | 465 const int uv_in_width = (io->mb_w + 1) >> 1; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 509 WebPRescalerInit(&p->scaler_y, io->mb_w, io->mb_h, | 485 WebPRescalerInit(&p->scaler_y, io->mb_w, io->mb_h, |
| 510 tmp + 0 * out_width, out_width, out_height, 0, 1, | 486 tmp + 0 * out_width, out_width, out_height, 0, 1, |
| 511 work + 0 * work_size); | 487 work + 0 * work_size); |
| 512 WebPRescalerInit(&p->scaler_u, uv_in_width, uv_in_height, | 488 WebPRescalerInit(&p->scaler_u, uv_in_width, uv_in_height, |
| 513 tmp + 1 * out_width, out_width, out_height, 0, 1, | 489 tmp + 1 * out_width, out_width, out_height, 0, 1, |
| 514 work + 1 * work_size); | 490 work + 1 * work_size); |
| 515 WebPRescalerInit(&p->scaler_v, uv_in_width, uv_in_height, | 491 WebPRescalerInit(&p->scaler_v, uv_in_width, uv_in_height, |
| 516 tmp + 2 * out_width, out_width, out_height, 0, 1, | 492 tmp + 2 * out_width, out_width, out_height, 0, 1, |
| 517 work + 2 * work_size); | 493 work + 2 * work_size); |
| 518 p->emit = EmitRescaledRGB; | 494 p->emit = EmitRescaledRGB; |
| 495 WebPInitYUV444Converters(); |
| 519 | 496 |
| 520 if (has_alpha) { | 497 if (has_alpha) { |
| 521 WebPRescalerInit(&p->scaler_a, io->mb_w, io->mb_h, | 498 WebPRescalerInit(&p->scaler_a, io->mb_w, io->mb_h, |
| 522 tmp + 3 * out_width, out_width, out_height, 0, 1, | 499 tmp + 3 * out_width, out_width, out_height, 0, 1, |
| 523 work + 3 * work_size); | 500 work + 3 * work_size); |
| 524 p->emit_alpha = EmitRescaledAlphaRGB; | 501 p->emit_alpha = EmitRescaledAlphaRGB; |
| 525 if (p->output->colorspace == MODE_RGBA_4444 || | 502 if (p->output->colorspace == MODE_RGBA_4444 || |
| 526 p->output->colorspace == MODE_rgbA_4444) { | 503 p->output->colorspace == MODE_rgbA_4444) { |
| 527 p->emit_alpha_row = ExportAlphaRGBA4444; | 504 p->emit_alpha_row = ExportAlphaRGBA4444; |
| 528 } else { | 505 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 552 if (is_alpha && WebPIsPremultipliedMode(colorspace)) { | 529 if (is_alpha && WebPIsPremultipliedMode(colorspace)) { |
| 553 WebPInitUpsamplers(); | 530 WebPInitUpsamplers(); |
| 554 } | 531 } |
| 555 if (io->use_scaling) { | 532 if (io->use_scaling) { |
| 556 const int ok = is_rgb ? InitRGBRescaler(io, p) : InitYUVRescaler(io, p); | 533 const int ok = is_rgb ? InitRGBRescaler(io, p) : InitYUVRescaler(io, p); |
| 557 if (!ok) { | 534 if (!ok) { |
| 558 return 0; // memory error | 535 return 0; // memory error |
| 559 } | 536 } |
| 560 } else { | 537 } else { |
| 561 if (is_rgb) { | 538 if (is_rgb) { |
| 539 WebPInitSamplers(); |
| 562 p->emit = EmitSampledRGB; // default | 540 p->emit = EmitSampledRGB; // default |
| 563 if (io->fancy_upsampling) { | 541 if (io->fancy_upsampling) { |
| 564 #ifdef FANCY_UPSAMPLING | 542 #ifdef FANCY_UPSAMPLING |
| 565 const int uv_width = (io->mb_w + 1) >> 1; | 543 const int uv_width = (io->mb_w + 1) >> 1; |
| 566 p->memory = WebPSafeMalloc(1ULL, (size_t)(io->mb_w + 2 * uv_width)); | 544 p->memory = WebPSafeMalloc(1ULL, (size_t)(io->mb_w + 2 * uv_width)); |
| 567 if (p->memory == NULL) { | 545 if (p->memory == NULL) { |
| 568 return 0; // memory error. | 546 return 0; // memory error. |
| 569 } | 547 } |
| 570 p->tmp_y = (uint8_t*)p->memory; | 548 p->tmp_y = (uint8_t*)p->memory; |
| 571 p->tmp_u = p->tmp_y + io->mb_w; | 549 p->tmp_u = p->tmp_y + io->mb_w; |
| 572 p->tmp_v = p->tmp_u + uv_width; | 550 p->tmp_v = p->tmp_u + uv_width; |
| 573 p->emit = EmitFancyRGB; | 551 p->emit = EmitFancyRGB; |
| 574 WebPInitUpsamplers(); | 552 WebPInitUpsamplers(); |
| 575 #endif | 553 #endif |
| 576 } else { | |
| 577 WebPInitSamplers(); | |
| 578 } | 554 } |
| 579 } else { | 555 } else { |
| 580 p->emit = EmitYUV; | 556 p->emit = EmitYUV; |
| 581 } | 557 } |
| 582 if (is_alpha) { // need transparency output | 558 if (is_alpha) { // need transparency output |
| 583 p->emit_alpha = | 559 p->emit_alpha = |
| 584 (colorspace == MODE_RGBA_4444 || colorspace == MODE_rgbA_4444) ? | 560 (colorspace == MODE_RGBA_4444 || colorspace == MODE_rgbA_4444) ? |
| 585 EmitAlphaRGBA4444 | 561 EmitAlphaRGBA4444 |
| 586 : is_rgb ? EmitAlphaRGB | 562 : is_rgb ? EmitAlphaRGB |
| 587 : EmitAlphaYUV; | 563 : EmitAlphaYUV; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 604 const int mb_w = io->mb_w; | 580 const int mb_w = io->mb_w; |
| 605 const int mb_h = io->mb_h; | 581 const int mb_h = io->mb_h; |
| 606 int num_lines_out; | 582 int num_lines_out; |
| 607 assert(!(io->mb_y & 1)); | 583 assert(!(io->mb_y & 1)); |
| 608 | 584 |
| 609 if (mb_w <= 0 || mb_h <= 0) { | 585 if (mb_w <= 0 || mb_h <= 0) { |
| 610 return 0; | 586 return 0; |
| 611 } | 587 } |
| 612 num_lines_out = p->emit(io, p); | 588 num_lines_out = p->emit(io, p); |
| 613 if (p->emit_alpha != NULL) { | 589 if (p->emit_alpha != NULL) { |
| 614 p->emit_alpha(io, p); | 590 p->emit_alpha(io, p, num_lines_out); |
| 615 } | 591 } |
| 616 p->last_y += num_lines_out; | 592 p->last_y += num_lines_out; |
| 617 return 1; | 593 return 1; |
| 618 } | 594 } |
| 619 | 595 |
| 620 //------------------------------------------------------------------------------ | 596 //------------------------------------------------------------------------------ |
| 621 | 597 |
| 622 static void CustomTeardown(const VP8Io* io) { | 598 static void CustomTeardown(const VP8Io* io) { |
| 623 WebPDecParams* const p = (WebPDecParams*)io->opaque; | 599 WebPDecParams* const p = (WebPDecParams*)io->opaque; |
| 624 WebPSafeFree(p->memory); | 600 WebPSafeFree(p->memory); |
| 625 p->memory = NULL; | 601 p->memory = NULL; |
| 626 } | 602 } |
| 627 | 603 |
| 628 //------------------------------------------------------------------------------ | 604 //------------------------------------------------------------------------------ |
| 629 // Main entry point | 605 // Main entry point |
| 630 | 606 |
| 631 void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io) { | 607 void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io) { |
| 632 io->put = CustomPut; | 608 io->put = CustomPut; |
| 633 io->setup = CustomSetup; | 609 io->setup = CustomSetup; |
| 634 io->teardown = CustomTeardown; | 610 io->teardown = CustomTeardown; |
| 635 io->opaque = params; | 611 io->opaque = params; |
| 636 } | 612 } |
| 637 | 613 |
| 638 //------------------------------------------------------------------------------ | 614 //------------------------------------------------------------------------------ |
| OLD | NEW |