OLD | NEW |
1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 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 // main entry for the decoder | 10 // main entry for the decoder |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 //------------------------------------------------------------------------------ | 383 //------------------------------------------------------------------------------ |
384 // Scaling. | 384 // Scaling. |
385 | 385 |
386 static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) { | 386 static int AllocateAndInitRescaler(VP8LDecoder* const dec, VP8Io* const io) { |
387 const int num_channels = 4; | 387 const int num_channels = 4; |
388 const int in_width = io->mb_w; | 388 const int in_width = io->mb_w; |
389 const int out_width = io->scaled_width; | 389 const int out_width = io->scaled_width; |
390 const int in_height = io->mb_h; | 390 const int in_height = io->mb_h; |
391 const int out_height = io->scaled_height; | 391 const int out_height = io->scaled_height; |
392 const uint64_t work_size = 2 * num_channels * (uint64_t)out_width; | 392 const uint64_t work_size = 2 * num_channels * (uint64_t)out_width; |
393 int32_t* work; // Rescaler work area. | 393 rescaler_t* work; // Rescaler work area. |
394 const uint64_t scaled_data_size = num_channels * (uint64_t)out_width; | 394 const uint64_t scaled_data_size = (uint64_t)out_width; |
395 uint32_t* scaled_data; // Temporary storage for scaled BGRA data. | 395 uint32_t* scaled_data; // Temporary storage for scaled BGRA data. |
396 const uint64_t memory_size = sizeof(*dec->rescaler) + | 396 const uint64_t memory_size = sizeof(*dec->rescaler) + |
397 work_size * sizeof(*work) + | 397 work_size * sizeof(*work) + |
398 scaled_data_size * sizeof(*scaled_data); | 398 scaled_data_size * sizeof(*scaled_data); |
399 uint8_t* memory = (uint8_t*)WebPSafeCalloc(memory_size, sizeof(*memory)); | 399 uint8_t* memory = (uint8_t*)WebPSafeMalloc(memory_size, sizeof(*memory)); |
400 if (memory == NULL) { | 400 if (memory == NULL) { |
401 dec->status_ = VP8_STATUS_OUT_OF_MEMORY; | 401 dec->status_ = VP8_STATUS_OUT_OF_MEMORY; |
402 return 0; | 402 return 0; |
403 } | 403 } |
404 assert(dec->rescaler_memory == NULL); | 404 assert(dec->rescaler_memory == NULL); |
405 dec->rescaler_memory = memory; | 405 dec->rescaler_memory = memory; |
406 | 406 |
407 dec->rescaler = (WebPRescaler*)memory; | 407 dec->rescaler = (WebPRescaler*)memory; |
408 memory += sizeof(*dec->rescaler); | 408 memory += sizeof(*dec->rescaler); |
409 work = (int32_t*)memory; | 409 work = (rescaler_t*)memory; |
410 memory += work_size * sizeof(*work); | 410 memory += work_size * sizeof(*work); |
411 scaled_data = (uint32_t*)memory; | 411 scaled_data = (uint32_t*)memory; |
412 | 412 |
413 WebPRescalerInit(dec->rescaler, in_width, in_height, (uint8_t*)scaled_data, | 413 WebPRescalerInit(dec->rescaler, in_width, in_height, (uint8_t*)scaled_data, |
414 out_width, out_height, 0, num_channels, | 414 out_width, out_height, 0, num_channels, work); |
415 in_width, out_width, in_height, out_height, work); | |
416 return 1; | 415 return 1; |
417 } | 416 } |
418 | 417 |
419 //------------------------------------------------------------------------------ | 418 //------------------------------------------------------------------------------ |
420 // Export to ARGB | 419 // Export to ARGB |
421 | 420 |
422 // We have special "export" function since we need to convert from BGRA | 421 // We have special "export" function since we need to convert from BGRA |
423 static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace, | 422 static int Export(WebPRescaler* const rescaler, WEBP_CSP_MODE colorspace, |
424 int rgba_stride, uint8_t* const rgba) { | 423 int rgba_stride, uint8_t* const rgba) { |
425 uint32_t* const src = (uint32_t*)rescaler->dst; | 424 uint32_t* const src = (uint32_t*)rescaler->dst; |
426 const int dst_width = rescaler->dst_width; | 425 const int dst_width = rescaler->dst_width; |
427 int num_lines_out = 0; | 426 int num_lines_out = 0; |
428 while (WebPRescalerHasPendingOutput(rescaler)) { | 427 while (WebPRescalerHasPendingOutput(rescaler)) { |
429 uint8_t* const dst = rgba + num_lines_out * rgba_stride; | 428 uint8_t* const dst = rgba + num_lines_out * rgba_stride; |
430 WebPRescalerExportRow(rescaler, 0); | 429 WebPRescalerExportRow(rescaler); |
431 WebPMultARGBRow(src, dst_width, 1); | 430 WebPMultARGBRow(src, dst_width, 1); |
432 VP8LConvertFromBGRA(src, dst_width, colorspace, dst); | 431 VP8LConvertFromBGRA(src, dst_width, colorspace, dst); |
433 ++num_lines_out; | 432 ++num_lines_out; |
434 } | 433 } |
435 return num_lines_out; | 434 return num_lines_out; |
436 } | 435 } |
437 | 436 |
438 // Emit scaled rows. | 437 // Emit scaled rows. |
439 static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec, | 438 static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec, |
440 uint8_t* in, int in_stride, int mb_h, | 439 uint8_t* in, int in_stride, int mb_h, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 for (i = 0; i < width; ++i) a[i] = (src[i] >> 24); | 537 for (i = 0; i < width; ++i) a[i] = (src[i] >> 24); |
539 } | 538 } |
540 } | 539 } |
541 | 540 |
542 static int ExportYUVA(const VP8LDecoder* const dec, int y_pos) { | 541 static int ExportYUVA(const VP8LDecoder* const dec, int y_pos) { |
543 WebPRescaler* const rescaler = dec->rescaler; | 542 WebPRescaler* const rescaler = dec->rescaler; |
544 uint32_t* const src = (uint32_t*)rescaler->dst; | 543 uint32_t* const src = (uint32_t*)rescaler->dst; |
545 const int dst_width = rescaler->dst_width; | 544 const int dst_width = rescaler->dst_width; |
546 int num_lines_out = 0; | 545 int num_lines_out = 0; |
547 while (WebPRescalerHasPendingOutput(rescaler)) { | 546 while (WebPRescalerHasPendingOutput(rescaler)) { |
548 WebPRescalerExportRow(rescaler, 0); | 547 WebPRescalerExportRow(rescaler); |
549 WebPMultARGBRow(src, dst_width, 1); | 548 WebPMultARGBRow(src, dst_width, 1); |
550 ConvertToYUVA(src, dst_width, y_pos, dec->output_); | 549 ConvertToYUVA(src, dst_width, y_pos, dec->output_); |
551 ++y_pos; | 550 ++y_pos; |
552 ++num_lines_out; | 551 ++num_lines_out; |
553 } | 552 } |
554 return num_lines_out; | 553 return num_lines_out; |
555 } | 554 } |
556 | 555 |
557 static int EmitRescaledRowsYUVA(const VP8LDecoder* const dec, | 556 static int EmitRescaledRowsYUVA(const VP8LDecoder* const dec, |
558 uint8_t* in, int in_stride, int mb_h) { | 557 uint8_t* in, int in_stride, int mb_h) { |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 VP8LClear(dec); | 1394 VP8LClear(dec); |
1396 return 1; | 1395 return 1; |
1397 | 1396 |
1398 Err: | 1397 Err: |
1399 VP8LClear(dec); | 1398 VP8LClear(dec); |
1400 assert(dec->status_ != VP8_STATUS_OK); | 1399 assert(dec->status_ != VP8_STATUS_OK); |
1401 return 0; | 1400 return 0; |
1402 } | 1401 } |
1403 | 1402 |
1404 //------------------------------------------------------------------------------ | 1403 //------------------------------------------------------------------------------ |
OLD | NEW |