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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp

Issue 1460523002: GIF decoding to Index8, unit tests and misusing unit test as benchmark (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Skia:onGetColorType related implementation. Fix part of Leon's review comments. 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, 65 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
66 SkPMColor ctable[], int* ctableCount) 66 SkPMColor ctable[], int* ctableCount)
67 { 67 {
68 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "index", static_c ast<int>(m_frameIndex)); 68 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "index", static_c ast<int>(m_frameIndex));
69 69
70 // Implementation doesn't support scaling yet so make sure we're not given a different size. 70 // Implementation doesn't support scaling yet so make sure we're not given a different size.
71 if (info.width() != getInfo().width() || info.height() != getInfo().height() ) 71 if (info.width() != getInfo().width() || info.height() != getInfo().height() )
72 return false; 72 return false;
73 73
74 if (info.colorType() != getInfo().colorType()) { 74 // if colorType declared in getInfo() fails, Skia would fetch N32 version
75 if (info.colorType() != getInfo().colorType() && info.colorType() != kN32_Sk ColorType) {
75 // ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaTyp e after sniffing the encoded data, so if we see a request 76 // ImageFrame may have changed the owning SkBitmap to kOpaque_SkAlphaTyp e after sniffing the encoded data, so if we see a request
76 // for opaque, that is ok even if our initial alphatype was not opaque. 77 // for opaque, that is ok even if our initial alphatype was not opaque.
77 return false; 78 return false;
78 } 79 }
79 80
80 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); 81 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId);
81 bool decoded = m_frameGenerator->decodeAndScale(getInfo(), m_frameIndex, pix els, rowBytes); 82 bool decoded = m_frameGenerator->decodeAndScale(info, m_frameIndex, pixels, rowBytes, ctable, ctableCount);
82 PlatformInstrumentation::didDecodeLazyPixelRef(); 83 PlatformInstrumentation::didDecodeLazyPixelRef();
83 84
84 return decoded; 85 return decoded;
85 } 86 }
86 87
87 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace) 88 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace)
88 { 89 {
89 if (!RuntimeEnabledFeatures::decodeToYUVEnabled()) 90 if (!RuntimeEnabledFeatures::decodeToYUVEnabled())
90 return false; 91 return false;
91 92
(...skipping 17 matching lines...) Expand all
109 // we only need the size, it doesn't really matter about premul or not, or g amma settings. 110 // we only need the size, it doesn't really matter about premul or not, or g amma settings.
110 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); 111 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied);
111 if (!decoder) 112 if (!decoder)
112 return 0; 113 return 0;
113 114
114 decoder->setData(buffer.get(), true); 115 decoder->setData(buffer.get(), true);
115 if (!decoder->isSizeAvailable()) 116 if (!decoder->isSizeAvailable())
116 return 0; 117 return 0;
117 118
118 const IntSize size = decoder->size(); 119 const IntSize size = decoder->size();
119 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); 120 const SkImageInfo info = decoder->canDecodeTo(0, ImageFrame::Index8)
121 ? SkImageInfo::Make(size.width(), size.height(), kIndex_8_SkColorType, k Premul_SkAlphaType)
122 : SkImageInfo::MakeN32Premul(size.width(), size.height());
120 123
121 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false); 124 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false);
122 if (!frame) 125 if (!frame)
123 return 0; 126 return 0;
124 127
125 return new DecodingImageGenerator(frame, info, 0); 128 return new DecodingImageGenerator(frame, info, 0);
126 } 129 }
127 130
131 SkColorType DecodingImageGenerator::onGetColorType()
132 {
133 // GIFDecoder: generator info is Index8 when constructed. but after download ing data this could
134 // change - it could turn out that some frames can be decoded only to N32.
135 if (m_frameGenerator->canDecodeTo(m_frameIndex, kIndex_8_SkColorType))
136 return kIndex_8_SkColorType;
137 return kN32_SkColorType;
138 }
139
128 } // namespace blink 140 } // namespace blink
129 141
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698