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

Side by Side Diff: src/codec/SkScaledCodec.cpp

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add SkScanlineOrder enum to SkScanlineDecoder.h Created 5 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkScaledCodec.h" 9 #include "SkScaledCodec.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // than srcWidth or srcHeight. If so, the result of this is dstWidth or dstH eight = 1. 126 // than srcWidth or srcHeight. If so, the result of this is dstWidth or dstH eight = 1.
127 // This functionality allows for tall thin images to still be scaled down by scaling factors. 127 // This functionality allows for tall thin images to still be scaled down by scaling factors.
128 if (*sampleX != *sampleY){ 128 if (*sampleX != *sampleY){
129 if (1 != dstWidth && 1 != dstHeight) { 129 if (1 != dstWidth && 1 != dstHeight) {
130 return false; 130 return false;
131 } 131 }
132 } 132 }
133 return true; 133 return true;
134 } 134 }
135 135
136 static bool is_row_necessary(int srcY, int startY, int sampleY) {
scroggo 2015/08/26 22:40:09 nit: Can you add comments explaining this function
137 if (srcY < startY) {
138 return false;
139 }
140 return ((srcY - startY) % sampleY) == 0;
141 }
142
136 // calculates sampleSize in x and y direction 143 // calculates sampleSize in x and y direction
137 void SkScaledCodec::ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageI nfo& srcInfo, 144 void SkScaledCodec::ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageI nfo& srcInfo,
138 int* sampleXPtr, int* sampleYPtr) { 145 int* sampleXPtr, int* sampleYPtr) {
139 int srcWidth = srcInfo.width(); 146 int srcWidth = srcInfo.width();
140 int dstWidth = dstInfo.width(); 147 int dstWidth = dstInfo.width();
141 int srcHeight = srcInfo.height(); 148 int srcHeight = srcInfo.height();
142 int dstHeight = dstInfo.height(); 149 int dstHeight = dstInfo.height();
143 150
144 int sampleX = srcWidth / dstWidth; 151 int sampleX = srcWidth / dstWidth;
145 int sampleY = srcHeight / dstHeight; 152 int sampleY = srcHeight / dstHeight;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 221
215 SkImageInfo info = requestedInfo; 222 SkImageInfo info = requestedInfo;
216 // use original height as scanlineDecoder does not support y sampling native ly 223 // use original height as scanlineDecoder does not support y sampling native ly
217 info = info.makeWH(requestedInfo.width(), srcHeight); 224 info = info.makeWH(requestedInfo.width(), srcHeight);
218 225
219 // update scanlineDecoder with new info 226 // update scanlineDecoder with new info
220 result = fScanlineDecoder->start(info, &options, ctable, ctableCount); 227 result = fScanlineDecoder->start(info, &options, ctable, ctableCount);
221 if (kSuccess != result) { 228 if (kSuccess != result) {
222 return result; 229 return result;
223 } 230 }
224
225 const bool requiresPostYSampling = fScanlineDecoder->requiresPostYSampling() ;
226 231
227 if (requiresPostYSampling) { 232 switch(fScanlineDecoder->getScanlineOrder()) {
228 SkAutoMalloc storage(srcHeight * rowBytes); 233 case SkScanlineDecoder::kTopDown_SkScanlineOrder: {
229 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); 234 result = fScanlineDecoder->skipScanlines(Y0);
230 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBytes) ;
231 if (kSuccess != result) {
232 return result;
233 }
234 storagePtr += Y0 * rowBytes;
235 for (int y = 0; y < dstHeight; y++) {
236 memcpy(dst, storagePtr, rowBytes);
237 storagePtr += sampleY * rowBytes;
238 dst = SkTAddOffset<void>(dst, rowBytes);
239 }
240 } else {
241 // does not require post y sampling
242 result = fScanlineDecoder->skipScanlines(Y0);
243 if (kSuccess != result) {
244 return result;
245 }
246 for (int y = 0; y < dstHeight; y++) {
247 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes);
248 if (kSuccess != result) { 235 if (kSuccess != result) {
249 return result; 236 return result;
250 } 237 }
251 if (y < dstHeight - 1) { 238 for (int y = 0; y < dstHeight; y++) {
252 result = fScanlineDecoder->skipScanlines(sampleY - 1); 239 result = fScanlineDecoder->getScanlines(dst, 1, rowBytes);
253 if (kSuccess != result) { 240 if (kSuccess != result) {
254 return result; 241 return result;
255 } 242 }
243 if (y < dstHeight - 1) {
244 result = fScanlineDecoder->skipScanlines(sampleY - 1);
245 if (kSuccess != result) {
246 return result;
247 }
248 }
249 dst = SkTAddOffset<void>(dst, rowBytes);
256 } 250 }
257 dst = SkTAddOffset<void>(dst, rowBytes); 251 return kSuccess;
258 } 252 }
253 case SkScanlineDecoder::kOutOfOrder_SkScanlineOrder: {
254 for (int y = 0; y < srcHeight; y++) {
255 int srcY = fScanlineDecoder->getY();
256 if (is_row_necessary(srcY, Y0, sampleY)) {
257 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * (srcY / sa mpleY));
258 result = fScanlineDecoder->getScanlines(dstPtr, 1, rowBytes) ;
259 if (kSuccess != result) {
260 return result;
261 }
262 } else {
263 result = fScanlineDecoder->skipScanlines(1);
264 if (kSuccess != result) {
265 return result;
266 }
267 }
268 }
269 return kSuccess;
270 }
271 case SkScanlineDecoder::kNone_SkScanlineOrder: {
272 SkAutoMalloc storage(srcHeight * rowBytes);
273 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get());
274 result = fScanlineDecoder->getScanlines(storagePtr, srcHeight, rowBy tes);
275 if (kSuccess != result) {
276 return result;
277 }
278 storagePtr += Y0 * rowBytes;
279 for (int y = 0; y < dstHeight; y++) {
280 memcpy(dst, storagePtr, rowBytes);
281 storagePtr += sampleY * rowBytes;
282 dst = SkTAddOffset<void>(dst, rowBytes);
283 }
284 return kSuccess;
285 }
286 default:
287 SkASSERT(false);
288 return kUnimplemented;
259 } 289 }
260 return kSuccess;
261 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698