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

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

Issue 719213008: SkColorTable locking serves no purpose anymore. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: oops Created 6 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_libjpeg.cpp ('k') | src/images/SkImageDecoder_libwebp.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 2006 The Android Open Source Project 2 * Copyright 2006 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 #include "SkImageDecoder.h" 8 #include "SkImageDecoder.h"
9 #include "SkImageEncoder.h" 9 #include "SkImageEncoder.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } else if (hasAlpha) { 406 } else if (hasAlpha) {
407 sc = SkScaledBitmapSampler::kRGBA; 407 sc = SkScaledBitmapSampler::kRGBA;
408 } else { 408 } else {
409 sc = SkScaledBitmapSampler::kRGBX; 409 sc = SkScaledBitmapSampler::kRGBX;
410 } 410 }
411 411
412 /* We have to pass the colortable explicitly, since we may have one 412 /* We have to pass the colortable explicitly, since we may have one
413 even if our decodedBitmap doesn't, due to the request that we 413 even if our decodedBitmap doesn't, due to the request that we
414 upscale png's palette to a direct model 414 upscale png's palette to a direct model
415 */ 415 */
416 SkAutoLockColors ctLock(colorTable); 416 const SkPMColor* colors = colorTable ? colorTable->readColors() : NULL;
417 if (!sampler.begin(decodedBitmap, sc, *this, ctLock.colors())) { 417 if (!sampler.begin(decodedBitmap, sc, *this, colors)) {
418 return kFailure; 418 return kFailure;
419 } 419 }
420 const int height = decodedBitmap->height(); 420 const int height = decodedBitmap->height();
421 421
422 if (number_passes > 1) { 422 if (number_passes > 1) {
423 SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel); 423 SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel);
424 uint8_t* base = (uint8_t*)storage.get(); 424 uint8_t* base = (uint8_t*)storage.get();
425 size_t rowBytes = origWidth * srcBytesPerPixel; 425 size_t rowBytes = origWidth * srcBytesPerPixel;
426 426
427 for (int i = 0; i < number_passes; i++) { 427 for (int i = 0; i < number_passes; i++) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 } else if (hasAlpha) { 887 } else if (hasAlpha) {
888 sc = SkScaledBitmapSampler::kRGBA; 888 sc = SkScaledBitmapSampler::kRGBA;
889 } else { 889 } else {
890 sc = SkScaledBitmapSampler::kRGBX; 890 sc = SkScaledBitmapSampler::kRGBX;
891 } 891 }
892 892
893 /* We have to pass the colortable explicitly, since we may have one 893 /* We have to pass the colortable explicitly, since we may have one
894 even if our decodedBitmap doesn't, due to the request that we 894 even if our decodedBitmap doesn't, due to the request that we
895 upscale png's palette to a direct model 895 upscale png's palette to a direct model
896 */ 896 */
897 SkAutoLockColors ctLock(colorTable); 897 const SkPMColor* colors = colorTable ? colorTable->readColors() : NULL;
898 if (!sampler.begin(&decodedBitmap, sc, *this, ctLock.colors())) { 898 if (!sampler.begin(&decodedBitmap, sc, *this, colors)) {
899 return false; 899 return false;
900 } 900 }
901 const int height = decodedBitmap.height(); 901 const int height = decodedBitmap.height();
902 902
903 if (number_passes > 1) { 903 if (number_passes > 1) {
904 SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel); 904 SkAutoMalloc storage(origWidth * origHeight * srcBytesPerPixel);
905 uint8_t* base = (uint8_t*)storage.get(); 905 uint8_t* base = (uint8_t*)storage.get();
906 size_t rb = origWidth * srcBytesPerPixel; 906 size_t rb = origWidth * srcBytesPerPixel;
907 907
908 for (int i = 0; i < number_passes; i++) { 908 for (int i = 0; i < number_passes; i++) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 /* Pack palette[] with the corresponding colors, and if hasAlpha is true, also 1040 /* Pack palette[] with the corresponding colors, and if hasAlpha is true, also
1041 pack trans[] and return the number of trans[] entries written. If hasAlpha 1041 pack trans[] and return the number of trans[] entries written. If hasAlpha
1042 is false, the return value will always be 0. 1042 is false, the return value will always be 0.
1043 1043
1044 Note: this routine takes care of unpremultiplying the RGB values when we 1044 Note: this routine takes care of unpremultiplying the RGB values when we
1045 have alpha in the colortable, since png doesn't support premul colors 1045 have alpha in the colortable, since png doesn't support premul colors
1046 */ 1046 */
1047 static inline int pack_palette(SkColorTable* ctable, 1047 static inline int pack_palette(SkColorTable* ctable,
1048 png_color* SK_RESTRICT palette, 1048 png_color* SK_RESTRICT palette,
1049 png_byte* SK_RESTRICT trans, bool hasAlpha) { 1049 png_byte* SK_RESTRICT trans, bool hasAlpha) {
1050 SkAutoLockColors alc(ctable); 1050 const SkPMColor* SK_RESTRICT colors = ctable ? ctable->readColors() : NULL;
1051 const SkPMColor* SK_RESTRICT colors = alc.colors();
1052 const int ctCount = ctable->count(); 1051 const int ctCount = ctable->count();
1053 int i, num_trans = 0; 1052 int i, num_trans = 0;
1054 1053
1055 if (hasAlpha) { 1054 if (hasAlpha) {
1056 /* first see if we have some number of fully opaque at the end of the 1055 /* first see if we have some number of fully opaque at the end of the
1057 ctable. PNG allows num_trans < num_palette, but all of the trans 1056 ctable. PNG allows num_trans < num_palette, but all of the trans
1058 entries must come first in the palette. If I was smarter, I'd 1057 entries must come first in the palette. If I was smarter, I'd
1059 reorder the indices and ctable so that all non-opaque colors came 1058 reorder the indices and ctable so that all non-opaque colors came
1060 first in the palette. But, since that would slow down the encode, 1059 first in the palette. But, since that would slow down the encode,
1061 I'm leaving the indices and ctable order as is, and just looking 1060 I'm leaving the indices and ctable order as is, and just looking
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 return SkImageDecoder::kUnknown_Format; 1275 return SkImageDecoder::kUnknown_Format;
1277 } 1276 }
1278 1277
1279 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { 1278 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) {
1280 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; 1279 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL;
1281 } 1280 }
1282 1281
1283 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); 1282 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory);
1284 static SkImageDecoder_FormatReg gFormatReg(get_format_png); 1283 static SkImageDecoder_FormatReg gFormatReg(get_format_png);
1285 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); 1284 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libjpeg.cpp ('k') | src/images/SkImageDecoder_libwebp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698