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

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

Issue 338493005: stop using SkBitmap::Config (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months 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_libpng.cpp ('k') | src/images/SkImageEncoder_argb.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 2010, The Android Open Source Project 2 * Copyright 2010, The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 // This guy exists just to aid in debugging, as it allows debuggers to just 163 // This guy exists just to aid in debugging, as it allows debuggers to just
164 // set a break-point in one place to see all error exists. 164 // set a break-point in one place to see all error exists.
165 static bool return_false(const SkBitmap& bm, const char msg[]) { 165 static bool return_false(const SkBitmap& bm, const char msg[]) {
166 SkDEBUGF(("libwebp error %s [%d %d]", msg, bm.width(), bm.height())); 166 SkDEBUGF(("libwebp error %s [%d %d]", msg, bm.width(), bm.height()));
167 return false; // must always return false 167 return false; // must always return false
168 } 168 }
169 169
170 static WEBP_CSP_MODE webp_decode_mode(const SkBitmap* decodedBitmap, bool premul tiply) { 170 static WEBP_CSP_MODE webp_decode_mode(const SkBitmap* decodedBitmap, bool premul tiply) {
171 WEBP_CSP_MODE mode = MODE_LAST; 171 WEBP_CSP_MODE mode = MODE_LAST;
172 SkBitmap::Config config = decodedBitmap->config(); 172 const SkColorType ct = decodedBitmap->colorType();
173 173
174 if (config == SkBitmap::kARGB_8888_Config) { 174 if (ct == kN32_SkColorType) {
175 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 175 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
176 mode = premultiply ? MODE_bgrA : MODE_BGRA; 176 mode = premultiply ? MODE_bgrA : MODE_BGRA;
177 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 177 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
178 mode = premultiply ? MODE_rgbA : MODE_RGBA; 178 mode = premultiply ? MODE_rgbA : MODE_RGBA;
179 #else 179 #else
180 #error "Skia uses BGRA or RGBA byte order" 180 #error "Skia uses BGRA or RGBA byte order"
181 #endif 181 #endif
182 } else if (config == SkBitmap::kARGB_4444_Config) { 182 } else if (ct == kARGB_4444_SkColorType) {
183 mode = premultiply ? MODE_rgbA_4444 : MODE_RGBA_4444; 183 mode = premultiply ? MODE_rgbA_4444 : MODE_RGBA_4444;
184 } else if (config == SkBitmap::kRGB_565_Config) { 184 } else if (ct == kRGB_565_SkColorType) {
185 mode = MODE_RGB_565; 185 mode = MODE_RGB_565;
186 } 186 }
187 SkASSERT(MODE_LAST != mode); 187 SkASSERT(MODE_LAST != mode);
188 return mode; 188 return mode;
189 } 189 }
190 190
191 // Incremental WebP image decoding. Reads input buffer of 64K size iteratively 191 // Incremental WebP image decoding. Reads input buffer of 64K size iteratively
192 // and decodes this block to appropriate color-space as per config object. 192 // and decodes this block to appropriate color-space as per config object.
193 static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) { 193 static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) {
194 WebPIDecoder* idec = WebPIDecode(NULL, 0, config); 194 WebPIDecoder* idec = WebPIDecode(NULL, 0, config);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 *height = origHeight; 325 *height = origHeight;
326 326
327 SkRefCnt_SafeAssign(this->fInputStream, stream); 327 SkRefCnt_SafeAssign(this->fInputStream, stream);
328 this->fOrigWidth = origWidth; 328 this->fOrigWidth = origWidth;
329 this->fOrigHeight = origHeight; 329 this->fOrigHeight = origHeight;
330 this->fHasAlpha = hasAlpha; 330 this->fHasAlpha = hasAlpha;
331 331
332 return true; 332 return true;
333 } 333 }
334 334
335 static bool is_config_compatible(const SkBitmap& bitmap) { 335 static bool is_config_compatible(const SkBitmap& bitmap) {
scroggo 2014/06/16 14:50:32 is_colortype_compatible*
336 SkBitmap::Config config = bitmap.config(); 336 const SkColorType ct = bitmap.colorType();
337 return config == SkBitmap::kARGB_4444_Config || 337 return ct == kARGB_4444_SkColorType || ct == kRGB_565_SkColorType || ct == k N32_SkColorType;
338 config == SkBitmap::kRGB_565_Config ||
339 config == SkBitmap::kARGB_8888_Config;
340 } 338 }
341 339
342 bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap, 340 bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap,
343 const SkIRect& region) { 341 const SkIRect& region) {
344 SkIRect rect = SkIRect::MakeWH(fOrigWidth, fOrigHeight); 342 SkIRect rect = SkIRect::MakeWH(fOrigWidth, fOrigHeight);
345 343
346 if (!rect.intersect(region)) { 344 if (!rect.intersect(region)) {
347 // If the requested region is entirely outsides the image, return false 345 // If the requested region is entirely outsides the image, return false
348 return false; 346 return false;
349 } 347 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 const uint8_t* SK_RESTRICT src = (const uint8_t*)in; 547 const uint8_t* SK_RESTRICT src = (const uint8_t*)in;
550 for (int i = 0; i < width; ++i) { 548 for (int i = 0; i < width; ++i) {
551 const uint32_t c = ctable[*src++]; 549 const uint32_t c = ctable[*src++];
552 rgb[0] = SkGetPackedR32(c); 550 rgb[0] = SkGetPackedR32(c);
553 rgb[1] = SkGetPackedG32(c); 551 rgb[1] = SkGetPackedG32(c);
554 rgb[2] = SkGetPackedB32(c); 552 rgb[2] = SkGetPackedB32(c);
555 rgb += 3; 553 rgb += 3;
556 } 554 }
557 } 555 }
558 556
559 static ScanlineImporter ChooseImporter(const SkBitmap::Config& config, 557 static ScanlineImporter ChooseImporter(SkColorType ct, bool hasAlpha, int* bpp ) {
scroggo 2014/06/16 14:50:32 nit: double spaces between type and name are no lo
560 bool hasAlpha, 558 switch (ct) {
561 int* bpp) { 559 case kN32_SkColorType:
562 switch (config) {
563 case SkBitmap::kARGB_8888_Config:
564 if (hasAlpha) { 560 if (hasAlpha) {
565 *bpp = 4; 561 *bpp = 4;
566 return ARGB_8888_To_RGBA; 562 return ARGB_8888_To_RGBA;
567 } else { 563 } else {
568 *bpp = 3; 564 *bpp = 3;
569 return ARGB_8888_To_RGB; 565 return ARGB_8888_To_RGB;
570 } 566 }
571 case SkBitmap::kARGB_4444_Config: 567 case kARGB_4444_SkColorType:
572 if (hasAlpha) { 568 if (hasAlpha) {
573 *bpp = 4; 569 *bpp = 4;
574 return ARGB_4444_To_RGBA; 570 return ARGB_4444_To_RGBA;
575 } else { 571 } else {
576 *bpp = 3; 572 *bpp = 3;
577 return ARGB_4444_To_RGB; 573 return ARGB_4444_To_RGB;
578 } 574 }
579 case SkBitmap::kRGB_565_Config: 575 case kRGB_565_SkColorType:
580 *bpp = 3; 576 *bpp = 3;
581 return RGB_565_To_RGB; 577 return RGB_565_To_RGB;
582 case SkBitmap::kIndex8_Config: 578 case kIndex_8_SkColorType:
583 *bpp = 3; 579 *bpp = 3;
584 return Index8_To_RGB; 580 return Index8_To_RGB;
585 default: 581 default:
586 return NULL; 582 return NULL;
587 } 583 }
588 } 584 }
589 585
590 static int stream_writer(const uint8_t* data, size_t data_size, 586 static int stream_writer(const uint8_t* data, size_t data_size,
591 const WebPPicture* const picture) { 587 const WebPPicture* const picture) {
592 SkWStream* const stream = (SkWStream*)picture->custom_ptr; 588 SkWStream* const stream = (SkWStream*)picture->custom_ptr;
593 return stream->write(data, data_size) ? 1 : 0; 589 return stream->write(data, data_size) ? 1 : 0;
594 } 590 }
595 591
596 class SkWEBPImageEncoder : public SkImageEncoder { 592 class SkWEBPImageEncoder : public SkImageEncoder {
597 protected: 593 protected:
598 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK _OVERRIDE; 594 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) SK _OVERRIDE;
599 595
600 private: 596 private:
601 typedef SkImageEncoder INHERITED; 597 typedef SkImageEncoder INHERITED;
602 }; 598 };
603 599
604 bool SkWEBPImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bm, 600 bool SkWEBPImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bm,
605 int quality) { 601 int quality) {
606 const SkBitmap::Config config = bm.config();
607 const bool hasAlpha = !bm.isOpaque(); 602 const bool hasAlpha = !bm.isOpaque();
608 int bpp = -1; 603 int bpp = -1;
609 const ScanlineImporter scanline_import = ChooseImporter(config, hasAlpha, 604 const ScanlineImporter scanline_import = ChooseImporter(bm.colorType(), hasA lpha, &bpp);
610 &bpp);
611 if (NULL == scanline_import) { 605 if (NULL == scanline_import) {
612 return false; 606 return false;
613 } 607 }
614 if (-1 == bpp) { 608 if (-1 == bpp) {
615 return false; 609 return false;
616 } 610 }
617 611
618 SkAutoLockPixels alp(bm); 612 SkAutoLockPixels alp(bm);
619 SkAutoLockColors ctLocker; 613 SkAutoLockColors ctLocker;
620 if (NULL == bm.getPixels()) { 614 if (NULL == bm.getPixels()) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return SkImageDecoder::kUnknown_Format; 677 return SkImageDecoder::kUnknown_Format;
684 } 678 }
685 679
686 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { 680 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) {
687 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L; 681 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L;
688 } 682 }
689 683
690 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); 684 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory);
691 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); 685 static SkImageDecoder_FormatReg gFormatReg(get_format_webp);
692 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); 686 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libpng.cpp ('k') | src/images/SkImageEncoder_argb.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698