Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
| 10 #include "SkImageEncoder.h" | 10 #include "SkImageEncoder.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 if (1 != row_count) { | 277 if (1 != row_count) { |
| 278 return false; | 278 return false; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 return true; | 281 return true; |
| 282 } | 282 } |
| 283 #endif | 283 #endif |
| 284 | 284 |
| 285 // This guy exists just to aid in debugging, as it allows debuggers to just | 285 // This guy exists just to aid in debugging, as it allows debuggers to just |
| 286 // set a break-point in one place to see all error exists. | 286 // set a break-point in one place to see all error exists. |
| 287 static bool return_false(const jpeg_decompress_struct& cinfo, | 287 static void error_message(const jpeg_decompress_struct& cinfo, |
| 288 const SkBitmap& bm, const char msg[]) { | 288 const SkBitmap& bm, const char msg[]) { |
| 289 #ifdef SK_DEBUG | 289 #if defined(SK_DEBUG) && defined(SK_DEBUG_JPEG_ERRORS) |
|
scroggo
2013/09/24 23:01:07
Like I said in the bug, I think this is a bad idea
| |
| 290 SkDebugf("libjpeg error %d <%s> from %s [%d %d]\n", cinfo.err->msg_code, | 290 SkDebugf("libjpeg error %d <%s> from %s [%d %d]\n", cinfo.err->msg_code, |
| 291 cinfo.err->jpeg_message_table[cinfo.err->msg_code], msg, | 291 cinfo.err->jpeg_message_table[cinfo.err->msg_code], msg, |
| 292 bm.width(), bm.height()); | 292 bm.width(), bm.height()); |
| 293 #endif | 293 #endif |
| 294 } | |
| 295 | |
| 296 | |
| 297 static bool return_false(const jpeg_decompress_struct& cinfo, | |
| 298 const SkBitmap& bm, const char msg[]) { | |
| 299 error_message(cinfo, bm, msg); | |
| 294 return false; // must always return false | 300 return false; // must always return false |
| 295 } | 301 } |
| 296 | 302 |
| 297 // Convert a scanline of CMYK samples to RGBX in place. Note that this | 303 // Convert a scanline of CMYK samples to RGBX in place. Note that this |
| 298 // method moves the "scanline" pointer in its processing | 304 // method moves the "scanline" pointer in its processing |
| 299 static void convert_CMYK_to_RGB(uint8_t* scanline, unsigned int width) { | 305 static void convert_CMYK_to_RGB(uint8_t* scanline, unsigned int width) { |
| 300 // At this point we've received CMYK pixels from libjpeg. We | 306 // At this point we've received CMYK pixels from libjpeg. We |
| 301 // perform a crude conversion to RGB (based on the formulae | 307 // perform a crude conversion to RGB (based on the formulae |
| 302 // from easyrgb.com): | 308 // from easyrgb.com): |
| 303 // CMYK -> CMY | 309 // CMYK -> CMY |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 cinfo.out_color_space == JCS_RGB_565))) | 554 cinfo.out_color_space == JCS_RGB_565))) |
| 549 { | 555 { |
| 550 JSAMPLE* rowptr = (JSAMPLE*)bm->getPixels(); | 556 JSAMPLE* rowptr = (JSAMPLE*)bm->getPixels(); |
| 551 INT32 const bpr = bm->rowBytes(); | 557 INT32 const bpr = bm->rowBytes(); |
| 552 | 558 |
| 553 while (cinfo.output_scanline < cinfo.output_height) { | 559 while (cinfo.output_scanline < cinfo.output_height) { |
| 554 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); | 560 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); |
| 555 // if row_count == 0, then we didn't get a scanline, so abort. | 561 // if row_count == 0, then we didn't get a scanline, so abort. |
| 556 // if we supported partial images, we might return true in this case | 562 // if we supported partial images, we might return true in this case |
| 557 if (0 == row_count) { | 563 if (0 == row_count) { |
| 558 return return_false(cinfo, *bm, "read_scanlines"); | 564 error_message(cinfo, *bm, "read_scanlines"); |
|
scroggo
2013/09/24 23:01:07
I think this should not print an error message at
| |
| 565 return true; | |
|
scroggo
2013/09/24 23:01:07
Since we never initialized the memory, won't this
| |
| 559 } | 566 } |
| 560 if (this->shouldCancelDecode()) { | 567 if (this->shouldCancelDecode()) { |
| 561 return return_false(cinfo, *bm, "shouldCancelDecode"); | 568 return return_false(cinfo, *bm, "shouldCancelDecode"); |
| 562 } | 569 } |
| 563 rowptr += bpr; | 570 rowptr += bpr; |
| 564 } | 571 } |
| 565 jpeg_finish_decompress(&cinfo); | 572 jpeg_finish_decompress(&cinfo); |
| 566 return true; | 573 return true; |
| 567 } | 574 } |
| 568 #endif | 575 #endif |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 598 // Possibly skip initial rows [sampler.srcY0] | 605 // Possibly skip initial rows [sampler.srcY0] |
| 599 if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) { | 606 if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) { |
| 600 return return_false(cinfo, *bm, "skip rows"); | 607 return return_false(cinfo, *bm, "skip rows"); |
| 601 } | 608 } |
| 602 | 609 |
| 603 // now loop through scanlines until y == bm->height() - 1 | 610 // now loop through scanlines until y == bm->height() - 1 |
| 604 for (int y = 0;; y++) { | 611 for (int y = 0;; y++) { |
| 605 JSAMPLE* rowptr = (JSAMPLE*)srcRow; | 612 JSAMPLE* rowptr = (JSAMPLE*)srcRow; |
| 606 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); | 613 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); |
| 607 if (0 == row_count) { | 614 if (0 == row_count) { |
| 608 return return_false(cinfo, *bm, "read_scanlines"); | 615 error_message(cinfo, *bm, "read_scanlines"); |
| 616 return true; | |
| 609 } | 617 } |
| 610 if (this->shouldCancelDecode()) { | 618 if (this->shouldCancelDecode()) { |
| 611 return return_false(cinfo, *bm, "shouldCancelDecode"); | 619 return return_false(cinfo, *bm, "shouldCancelDecode"); |
| 612 } | 620 } |
| 613 | 621 |
| 614 if (JCS_CMYK == cinfo.out_color_space) { | 622 if (JCS_CMYK == cinfo.out_color_space) { |
| 615 convert_CMYK_to_RGB(srcRow, cinfo.output_width); | 623 convert_CMYK_to_RGB(srcRow, cinfo.output_width); |
| 616 } | 624 } |
| 617 | 625 |
| 618 sampler.next(srcRow); | 626 sampler.next(srcRow); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 INT32 const bpr = bitmap.rowBytes(); | 788 INT32 const bpr = bitmap.rowBytes(); |
| 781 int rowTotalCount = 0; | 789 int rowTotalCount = 0; |
| 782 | 790 |
| 783 while (rowTotalCount < height) { | 791 while (rowTotalCount < height) { |
| 784 int rowCount = jpeg_read_tile_scanline(cinfo, | 792 int rowCount = jpeg_read_tile_scanline(cinfo, |
| 785 fImageIndex->huffmanIndex(), | 793 fImageIndex->huffmanIndex(), |
| 786 &rowptr); | 794 &rowptr); |
| 787 // if row_count == 0, then we didn't get a scanline, so abort. | 795 // if row_count == 0, then we didn't get a scanline, so abort. |
| 788 // if we supported partial images, we might return true in this case | 796 // if we supported partial images, we might return true in this case |
| 789 if (0 == rowCount) { | 797 if (0 == rowCount) { |
| 790 return return_false(*cinfo, bitmap, "read_scanlines"); | 798 error_message(*cinfo, bitmap, "read_scanlines"); |
| 799 return true; | |
| 791 } | 800 } |
| 792 if (this->shouldCancelDecode()) { | 801 if (this->shouldCancelDecode()) { |
| 793 return return_false(*cinfo, bitmap, "shouldCancelDecode"); | 802 return return_false(*cinfo, bitmap, "shouldCancelDecode"); |
| 794 } | 803 } |
| 795 rowTotalCount += rowCount; | 804 rowTotalCount += rowCount; |
| 796 rowptr += bpr; | 805 rowptr += bpr; |
| 797 } | 806 } |
| 798 | 807 |
| 799 if (swapOnly) { | 808 if (swapOnly) { |
| 800 bm->swap(bitmap); | 809 bm->swap(bitmap); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 // Possibly skip initial rows [sampler.srcY0] | 846 // Possibly skip initial rows [sampler.srcY0] |
| 838 if (!skip_src_rows_tile(cinfo, fImageIndex->huffmanIndex(), srcRow, sampler. srcY0())) { | 847 if (!skip_src_rows_tile(cinfo, fImageIndex->huffmanIndex(), srcRow, sampler. srcY0())) { |
| 839 return return_false(*cinfo, bitmap, "skip rows"); | 848 return return_false(*cinfo, bitmap, "skip rows"); |
| 840 } | 849 } |
| 841 | 850 |
| 842 // now loop through scanlines until y == bitmap->height() - 1 | 851 // now loop through scanlines until y == bitmap->height() - 1 |
| 843 for (int y = 0;; y++) { | 852 for (int y = 0;; y++) { |
| 844 JSAMPLE* rowptr = (JSAMPLE*)srcRow; | 853 JSAMPLE* rowptr = (JSAMPLE*)srcRow; |
| 845 int row_count = jpeg_read_tile_scanline(cinfo, fImageIndex->huffmanIndex (), &rowptr); | 854 int row_count = jpeg_read_tile_scanline(cinfo, fImageIndex->huffmanIndex (), &rowptr); |
| 846 if (0 == row_count) { | 855 if (0 == row_count) { |
| 847 return return_false(*cinfo, bitmap, "read_scanlines"); | 856 error_message(*cinfo, bitmap, "read_scanlines"); |
| 857 return true; | |
| 848 } | 858 } |
| 849 if (this->shouldCancelDecode()) { | 859 if (this->shouldCancelDecode()) { |
| 850 return return_false(*cinfo, bitmap, "shouldCancelDecode"); | 860 return return_false(*cinfo, bitmap, "shouldCancelDecode"); |
| 851 } | 861 } |
| 852 | 862 |
| 853 if (JCS_CMYK == cinfo->out_color_space) { | 863 if (JCS_CMYK == cinfo->out_color_space) { |
| 854 convert_CMYK_to_RGB(srcRow, width); | 864 convert_CMYK_to_RGB(srcRow, width); |
| 855 } | 865 } |
| 856 | 866 |
| 857 sampler.next(srcRow); | 867 sampler.next(srcRow); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 } | 1161 } |
| 1152 | 1162 |
| 1153 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { | 1163 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { |
| 1154 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; | 1164 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; |
| 1155 } | 1165 } |
| 1156 | 1166 |
| 1157 | 1167 |
| 1158 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); | 1168 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); |
| 1159 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); | 1169 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); |
| 1160 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); | 1170 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); |
| OLD | NEW |