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

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

Issue 1273853004: Fix bmp RLE "bug" and add invalid image test to CodexTest (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments 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
« no previous file with comments | « resources/invalid_images/mask-bmp-ico.ico ('k') | src/codec/SkBmpRLECodec.h » ('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 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 "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkBmpMaskCodec.h" 9 #include "SkBmpMaskCodec.h"
10 #include "SkBmpRLECodec.h" 10 #include "SkBmpRLECodec.h"
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // Return the codec 471 // Return the codec
472 switch (inputFormat) { 472 switch (inputFormat) {
473 case kStandard_BmpInputFormat: 473 case kStandard_BmpInputFormat:
474 *codecOut = SkNEW_ARGS(SkBmpStandardCodec, (imageInfo, stream, 474 *codecOut = SkNEW_ARGS(SkBmpStandardCodec, (imageInfo, stream,
475 bitsPerPixel, numColors, bytesPerColor, 475 bitsPerPixel, numColors, bytesPerColor,
476 offset - bytesRead, rowOrder, inIco)); 476 offset - bytesRead, rowOrder, inIco));
477 return true; 477 return true;
478 case kBitMask_BmpInputFormat: 478 case kBitMask_BmpInputFormat:
479 // Bmp-in-Ico must be standard mode 479 // Bmp-in-Ico must be standard mode
480 if (inIco) { 480 if (inIco) {
481 SkCodecPrintf("Error: Icos may not use bit mask format.\n");
481 return false; 482 return false;
482 } 483 }
483 // Skip to the start of the pixel array. 484 // Skip to the start of the pixel array.
484 // We can do this here because there is no color table to read 485 // We can do this here because there is no color table to read
485 // in bit mask mode. 486 // in bit mask mode.
486 if (stream->skip(offset - bytesRead) != offset - bytesRead) { 487 if (stream->skip(offset - bytesRead) != offset - bytesRead) {
487 SkCodecPrintf("Error: unable to skip to image data.\n"); 488 SkCodecPrintf("Error: unable to skip to image data.\n");
488 return false; 489 return false;
489 } 490 }
490 491
491 *codecOut = SkNEW_ARGS(SkBmpMaskCodec, (imageInfo, stream, 492 *codecOut = SkNEW_ARGS(SkBmpMaskCodec, (imageInfo, stream,
492 bitsPerPixel, masks.detach(), rowOrder)); 493 bitsPerPixel, masks.detach(), rowOrder));
493 return true; 494 return true;
494 case kRLE_BmpInputFormat: 495 case kRLE_BmpInputFormat:
495 // Bmp-in-Ico must be standard mode 496 // Bmp-in-Ico must be standard mode
496 if (inIco) { 497 // When inIco is true, this line cannot be reached, since we
497 return false; 498 // require that RLE Bmps have a valid number of totalBytes, and
498 } 499 // Icos skip the header that contains totalBytes.
500 SkASSERT(!inIco);
499 *codecOut = SkNEW_ARGS(SkBmpRLECodec, ( 501 *codecOut = SkNEW_ARGS(SkBmpRLECodec, (
500 imageInfo, stream, bitsPerPixel, numColors, 502 imageInfo, stream, bitsPerPixel, numColors,
501 bytesPerColor, offset - bytesRead, rowOrder, RLEBytes)); 503 bytesPerColor, offset - bytesRead, rowOrder, RLEBytes));
502 return true; 504 return true;
503 default: 505 default:
504 SkASSERT(false); 506 SkASSERT(false);
505 return false; 507 return false;
506 } 508 }
507 } 509 }
508 510
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 */ 559 */
558 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const { 560 void* SkBmpCodec::getDstStartRow(void* dst, size_t dstRowBytes, int32_t y) const {
559 return (kTopDown_RowOrder == fRowOrder) ? SkTAddOffset<void*>(dst, y * dstRo wBytes) : dst; 561 return (kTopDown_RowOrder == fRowOrder) ? SkTAddOffset<void*>(dst, y * dstRo wBytes) : dst;
560 } 562 }
561 563
562 /* 564 /*
563 * Compute the number of colors in the color table 565 * Compute the number of colors in the color table
564 */ 566 */
565 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { 567 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) {
566 // Zero is a default for maxColors 568 // Zero is a default for maxColors
567 // Also set fNumColors to maxColors when it is too large 569 // Also set numColors to maxColors when it is too large
568 uint32_t maxColors = 1 << fBitsPerPixel; 570 uint32_t maxColors = 1 << fBitsPerPixel;
569 if (numColors == 0 || numColors >= maxColors) { 571 if (numColors == 0 || numColors >= maxColors) {
570 return maxColors; 572 return maxColors;
571 } 573 }
572 return numColors; 574 return numColors;
573 } 575 }
OLDNEW
« no previous file with comments | « resources/invalid_images/mask-bmp-ico.ico ('k') | src/codec/SkBmpRLECodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698