Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 | 470 |
| 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) { |
|
msarett
2015/08/11 22:35:03
Turns out this is reachable and we have a test now
| |
| 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 // This line should be unreachable, since we require that |
|
scroggo
2015/08/12 14:14:30
nit: this line is reachable - it just shouldn't be
msarett
2015/08/12 15:01:24
Haha yep. Fixing the comment.
| |
| 497 return false; | 498 // RLE Bmps have a valid number of totalBytes, and Icos skip |
| 498 } | 499 // the header that contains totalBytes. |
| 500 SkASSERT(!inIco); | |
|
msarett
2015/08/11 22:35:03
I discovered that this is unreachable when trying
| |
| 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 Loading... | |
| 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 } |
| OLD | NEW |