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

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

Issue 1321433002: Add subsetting to SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-scan
Patch Set: Created 5 years, 2 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 "SkBmpRLECodec.h" 8 #include "SkBmpRLECodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 fRLEBytes = remainingBytes + additionalBytes; 193 fRLEBytes = remainingBytes + additionalBytes;
194 return fRLEBytes; 194 return fRLEBytes;
195 } 195 }
196 196
197 /* 197 /*
198 * Set an RLE pixel using the color table 198 * Set an RLE pixel using the color table
199 */ 199 */
200 void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes, 200 void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes,
201 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, 201 const SkImageInfo& dstInfo, uint32_t x, uint32_t y,
202 uint8_t index) { 202 uint8_t index) {
203 if (is_coord_necessary(x, fSampleX, dstInfo.width())) { 203 if (is_coord_necessary(x, fSampleX, this->subsetWidth(), this->subsetLeft()) ) {
204 // Set the row 204 // Set the row
205 uint32_t row = this->getDstRow(y, dstInfo.height()); 205 uint32_t row = this->getDstRow(y, dstInfo.height());
206 206
207 // Set the pixel based on destination color type 207 // Set the pixel based on destination color type
208 const int dstX = get_dst_coord(x, fSampleX); 208 const int dstX = get_dst_coord(x, fSampleX);
209 switch (dstInfo.colorType()) { 209 switch (dstInfo.colorType()) {
210 case kN32_SkColorType: { 210 case kN32_SkColorType: {
211 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst RowBytes); 211 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst RowBytes);
212 dstRow[dstX] = fColorTable->operator[](index); 212 dstRow[dstX] = fColorTable->operator[](index);
213 break; 213 break;
(...skipping 12 matching lines...) Expand all
226 } 226 }
227 } 227 }
228 228
229 /* 229 /*
230 * Set an RLE pixel from R, G, B values 230 * Set an RLE pixel from R, G, B values
231 */ 231 */
232 void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes, 232 void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes,
233 const SkImageInfo& dstInfo, uint32_t x, 233 const SkImageInfo& dstInfo, uint32_t x,
234 uint32_t y, uint8_t red, uint8_t green, 234 uint32_t y, uint8_t red, uint8_t green,
235 uint8_t blue) { 235 uint8_t blue) {
236 if (is_coord_necessary(x, fSampleX, dstInfo.width())) { 236 if (is_coord_necessary(x, fSampleX, this->subsetWidth(), this->subsetLeft()) ) {
237 // Set the row 237 // Set the row
238 uint32_t row = this->getDstRow(y, dstInfo.height()); 238 uint32_t row = this->getDstRow(y, dstInfo.height());
239 239
240 // Set the pixel based on destination color type 240 // Set the pixel based on destination color type
241 const int dstX = get_dst_coord(x, fSampleX); 241 const int dstX = get_dst_coord(x, fSampleX);
242 switch (dstInfo.colorType()) { 242 switch (dstInfo.colorType()) {
243 case kN32_SkColorType: { 243 case kN32_SkColorType: {
244 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst RowBytes); 244 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst RowBytes);
245 dstRow[dstX] = SkPackARGB32NoCheck(0xFF, red, green, blue); 245 dstRow[dstX] = SkPackARGB32NoCheck(0xFF, red, green, blue);
246 break; 246 break;
(...skipping 23 matching lines...) Expand all
270 270
271 // Copy the color table to the client if necessary 271 // Copy the color table to the client if necessary
272 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ; 272 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ;
273 273
274 // Initialize a buffer for encoded RLE data 274 // Initialize a buffer for encoded RLE data
275 if (!this->initializeStreamBuffer()) { 275 if (!this->initializeStreamBuffer()) {
276 SkCodecPrintf("Error: cannot initialize stream buffer.\n"); 276 SkCodecPrintf("Error: cannot initialize stream buffer.\n");
277 return SkCodec::kInvalidConversion; 277 return SkCodec::kInvalidConversion;
278 } 278 }
279 279
280 SkScaledCodec::ComputeSampleSize(dstInfo, this->getInfo(), &fSampleX, NULL); 280 SkScaledCodec::ComputeSampleSize(dstInfo.dimensions(), this->getInfo().dimen sions(), &fSampleX,
281 nullptr);
281 282
282 return SkCodec::kSuccess; 283 return SkCodec::kSuccess;
283 } 284 }
284 285
285 /* 286 /*
286 * Performs the bitmap decoding for RLE input format 287 * Performs the bitmap decoding for RLE input format
287 * RLE decoding is performed all at once, rather than a one row at a time 288 * RLE decoding is performed all at once, rather than a one row at a time
288 */ 289 */
289 int SkBmpRLECodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstR owBytes, 290 int SkBmpRLECodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstR owBytes,
290 const Options& opts) { 291 const Options& opts) {
291 // Set RLE flags 292 // Set RLE flags
292 static const uint8_t RLE_ESCAPE = 0; 293 static const uint8_t RLE_ESCAPE = 0;
293 static const uint8_t RLE_EOL = 0; 294 static const uint8_t RLE_EOL = 0;
294 static const uint8_t RLE_EOF = 1; 295 static const uint8_t RLE_EOF = 1;
295 static const uint8_t RLE_DELTA = 2; 296 static const uint8_t RLE_DELTA = 2;
296 297
297 // Set constant values 298 // Set constant values
298 const int width = this->getInfo().width(); 299 const int width = this->getInfo().width();
299 const int height = dstInfo.height(); 300 const int height = dstInfo.height();
300 301
301 // Destination parameters 302 // Destination parameters
302 int x = 0; 303 int x = 0;
303 int y = 0; 304 int y = 0;
304 305
305 // Set the background as transparent. Then, if the RLE code skips pixels, 306 // Set the background as transparent. Then, if the RLE code skips pixels,
306 // the skipped pixels will be transparent. 307 // the skipped pixels will be transparent.
307 // Because of the need for transparent pixels, kN32 is the only color 308 // Because of the need for transparent pixels, kN32 is the only color
308 // type that makes sense for the destination format. 309 // type that makes sense for the destination format.
309 SkASSERT(kN32_SkColorType == dstInfo.colorType()); 310 SkASSERT(kN32_SkColorType == dstInfo.colorType());
310 SkSwizzler::Fill(dst, dstInfo, dstRowBytes, SK_ColorTRANSPARENT, opts.fZeroI nitialized); 311 SkSwizzler::Fill(dst, dstInfo.makeWH(this->subsetWidth(), height), dstRowByt es,
312 SK_ColorTRANSPARENT, opts.fZeroInitialized);
311 313
312 while (true) { 314 while (true) {
313 // If we have reached a row that is beyond the requested height, we have 315 // If we have reached a row that is beyond the requested height, we have
314 // succeeded. 316 // succeeded.
315 if (y >= height) { 317 if (y >= height) {
316 // It would be better to check for the EOF marker before indicating 318 // It would be better to check for the EOF marker before indicating
317 // success, but we may be performing a scanline decode, which 319 // success, but we may be performing a scanline decode, which
318 // would require us to stop before decoding the full height. 320 // would require us to stop before decoding the full height.
319 return height; 321 return height;
320 } 322 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 467
466 // Set the indicated number of pixels 468 // Set the indicated number of pixels
467 for (int which = 0; x < endX; x++) { 469 for (int which = 0; x < endX; x++) {
468 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]); 470 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]);
469 which = !which; 471 which = !which;
470 } 472 }
471 } 473 }
472 } 474 }
473 } 475 }
474 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698