Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 1516833003: Switch SkAutoMalloc to SkAutoTMalloc to avoid cast (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Go back to patch set 3 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/images/SkImageDecoder_libgif.cpp ('k') | src/images/SkImageDecoder_libpng.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 int srcBytesPerPixel; 489 int srcBytesPerPixel;
490 490
491 if (!get_src_config(cinfo, &sc, &srcBytesPerPixel)) { 491 if (!get_src_config(cinfo, &sc, &srcBytesPerPixel)) {
492 return return_failure(cinfo, *bm, "jpeg colorspace"); 492 return return_failure(cinfo, *bm, "jpeg colorspace");
493 } 493 }
494 494
495 if (!sampler.begin(bm, sc, *this)) { 495 if (!sampler.begin(bm, sc, *this)) {
496 return return_failure(cinfo, *bm, "sampler.begin"); 496 return return_failure(cinfo, *bm, "sampler.begin");
497 } 497 }
498 498
499 SkAutoMalloc srcStorage(cinfo.output_width * srcBytesPerPixel); 499 SkAutoTMalloc<uint8_t> srcStorage(cinfo.output_width * srcBytesPerPixel);
500 uint8_t* srcRow = (uint8_t*)srcStorage.get(); 500 uint8_t* srcRow = srcStorage.get();
501 501
502 // Possibly skip initial rows [sampler.srcY0] 502 // Possibly skip initial rows [sampler.srcY0]
503 if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) { 503 if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) {
504 return return_failure(cinfo, *bm, "skip rows"); 504 return return_failure(cinfo, *bm, "skip rows");
505 } 505 }
506 506
507 // now loop through scanlines until y == bm->height() - 1 507 // now loop through scanlines until y == bm->height() - 1
508 for (int y = 0;; y++) { 508 for (int y = 0;; y++) {
509 JSAMPLE* rowptr = (JSAMPLE*)srcRow; 509 JSAMPLE* rowptr = (JSAMPLE*)srcRow;
510 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1); 510 int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 SkAutoLockPixels alp(bm); 924 SkAutoLockPixels alp(bm);
925 if (nullptr == bm.getPixels()) { 925 if (nullptr == bm.getPixels()) {
926 return false; 926 return false;
927 } 927 }
928 928
929 jpeg_compress_struct cinfo; 929 jpeg_compress_struct cinfo;
930 skjpeg_error_mgr sk_err; 930 skjpeg_error_mgr sk_err;
931 skjpeg_destination_mgr sk_wstream(stream); 931 skjpeg_destination_mgr sk_wstream(stream);
932 932
933 // allocate these before set call setjmp 933 // allocate these before set call setjmp
934 SkAutoMalloc oneRow; 934 SkAutoTMalloc<uint8_t> oneRow;
935 935
936 cinfo.err = jpeg_std_error(&sk_err); 936 cinfo.err = jpeg_std_error(&sk_err);
937 sk_err.error_exit = skjpeg_error_exit; 937 sk_err.error_exit = skjpeg_error_exit;
938 if (setjmp(sk_err.fJmpBuf)) { 938 if (setjmp(sk_err.fJmpBuf)) {
939 return false; 939 return false;
940 } 940 }
941 941
942 // Keep after setjmp or mark volatile. 942 // Keep after setjmp or mark volatile.
943 const WriteScanline writer = ChooseWriter(bm); 943 const WriteScanline writer = ChooseWriter(bm);
944 if (nullptr == writer) { 944 if (nullptr == writer) {
(...skipping 14 matching lines...) Expand all
959 959
960 jpeg_set_defaults(&cinfo); 960 jpeg_set_defaults(&cinfo);
961 jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); 961 jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
962 #ifdef DCT_IFAST_SUPPORTED 962 #ifdef DCT_IFAST_SUPPORTED
963 cinfo.dct_method = JDCT_IFAST; 963 cinfo.dct_method = JDCT_IFAST;
964 #endif 964 #endif
965 965
966 jpeg_start_compress(&cinfo, TRUE); 966 jpeg_start_compress(&cinfo, TRUE);
967 967
968 const int width = bm.width(); 968 const int width = bm.width();
969 uint8_t* oneRowP = (uint8_t*)oneRow.reset(width * 3); 969 uint8_t* oneRowP = oneRow.reset(width * 3);
970 970
971 const SkPMColor* colors = bm.getColorTable() ? bm.getColorTable()->readC olors() : nullptr; 971 const SkPMColor* colors = bm.getColorTable() ? bm.getColorTable()->readC olors() : nullptr;
972 const void* srcRow = bm.getPixels(); 972 const void* srcRow = bm.getPixels();
973 973
974 while (cinfo.next_scanline < cinfo.image_height) { 974 while (cinfo.next_scanline < cinfo.image_height) {
975 JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ 975 JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
976 976
977 writer(oneRowP, srcRow, width, colors); 977 writer(oneRowP, srcRow, width, colors);
978 row_pointer[0] = oneRowP; 978 row_pointer[0] = oneRowP;
979 (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); 979 (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 return SkImageDecoder::kUnknown_Format; 1023 return SkImageDecoder::kUnknown_Format;
1024 } 1024 }
1025 1025
1026 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) { 1026 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1027 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr; 1027 return (SkImageEncoder::kJPEG_Type == t) ? new SkJPEGImageEncoder : nullptr;
1028 } 1028 }
1029 1029
1030 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory); 1030 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1031 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg); 1031 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1032 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory); 1032 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libgif.cpp ('k') | src/images/SkImageDecoder_libpng.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698