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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkSwizzler.h" | 10 #include "SkSwizzler.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 for (i = 0; i < bytesInRow; i++) { | 36 for (i = 0; i < bytesInRow; i++) { |
| 37 U8CPU currByte = src[i]; | 37 U8CPU currByte = src[i]; |
| 38 for (int j = 0; j < 8; j++) { | 38 for (int j = 0; j < 8; j++) { |
| 39 dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_B LACK; | 39 dst[j] = ((currByte >> (7 - j)) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_B LACK; |
| 40 } | 40 } |
| 41 dst += 8; | 41 dst += 8; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Finish the remaining bits | 44 // Finish the remaining bits |
| 45 width &= 7; | 45 width &= 7; |
| 46 U8CPU currByte = src[i]; | 46 if (width > 0) { |
|
msarett
2015/08/05 20:39:08
This reads out of bounds memory when width is a mu
| |
| 47 for (int j = 0; j < width; j++) { | 47 U8CPU currByte = src[i]; |
| 48 dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; | 48 for (int j = 0; j < width; j++) { |
| 49 currByte <<= 1; | 49 dst[j] = ((currByte >> 7) & 1) ? GRAYSCALE_WHITE : GRAYSCALE_BLACK; |
| 50 currByte <<= 1; | |
| 51 } | |
| 50 } | 52 } |
| 51 return SkSwizzler::kOpaque_ResultAlpha; | 53 return SkSwizzler::kOpaque_ResultAlpha; |
| 52 } | 54 } |
| 53 | 55 |
| 54 #undef GRAYSCALE_BLACK | 56 #undef GRAYSCALE_BLACK |
| 55 #undef GRAYSCALE_WHITE | 57 #undef GRAYSCALE_WHITE |
| 56 | 58 |
| 57 static SkSwizzler::ResultAlpha swizzle_bit_to_index( | 59 static SkSwizzler::ResultAlpha swizzle_bit_to_index( |
| 58 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 60 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 59 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { | 61 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
| 60 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 62 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 61 | 63 |
| 62 // Determine how many full bytes are in the row | 64 // Determine how many full bytes are in the row |
| 63 int bytesInRow = width >> 3; | 65 int bytesInRow = width >> 3; |
| 64 int i; | 66 int i; |
| 65 for (i = 0; i < bytesInRow; i++) { | 67 for (i = 0; i < bytesInRow; i++) { |
| 66 U8CPU currByte = src[i]; | 68 U8CPU currByte = src[i]; |
| 67 for (int j = 0; j < 8; j++) { | 69 for (int j = 0; j < 8; j++) { |
| 68 dst[j] = (currByte >> (7 - j)) & 1; | 70 dst[j] = (currByte >> (7 - j)) & 1; |
| 69 } | 71 } |
| 70 dst += 8; | 72 dst += 8; |
| 71 } | 73 } |
| 72 | 74 |
| 73 // Finish the remaining bits | 75 // Finish the remaining bits |
| 74 width &= 7; | 76 width &= 7; |
| 75 U8CPU currByte = src[i]; | 77 if (width > 0) { |
| 76 for (int j = 0; j < width; j++) { | 78 U8CPU currByte = src[i]; |
| 77 dst[j] = ((currByte >> 7) & 1); | 79 for (int j = 0; j < width; j++) { |
| 78 currByte <<= 1; | 80 dst[j] = ((currByte >> 7) & 1); |
| 81 currByte <<= 1; | |
| 82 } | |
| 79 } | 83 } |
| 80 return SkSwizzler::kOpaque_ResultAlpha; | 84 return SkSwizzler::kOpaque_ResultAlpha; |
| 81 } | 85 } |
| 82 | 86 |
| 83 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( | 87 static SkSwizzler::ResultAlpha swizzle_bit_to_n32( |
| 84 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 88 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 85 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { | 89 int /*bitsPerPixel*/, const SkPMColor* /*ctable*/) { |
| 86 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; | 90 SkPMColor* SK_RESTRICT dst = (SkPMColor*) dstRow; |
| 87 | 91 |
| 88 // Determine how many full bytes are in the row | 92 // Determine how many full bytes are in the row |
| 89 int bytesInRow = width >> 3; | 93 int bytesInRow = width >> 3; |
| 90 int i; | 94 int i; |
| 91 for (i = 0; i < bytesInRow; i++) { | 95 for (i = 0; i < bytesInRow; i++) { |
| 92 U8CPU currByte = src[i]; | 96 U8CPU currByte = src[i]; |
| 93 for (int j = 0; j < 8; j++) { | 97 for (int j = 0; j < 8; j++) { |
| 94 dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK ; | 98 dst[j] = ((currByte >> (7 - j)) & 1) ? SK_ColorWHITE : SK_ColorBLACK ; |
| 95 } | 99 } |
| 96 dst += 8; | 100 dst += 8; |
| 97 } | 101 } |
| 98 | 102 |
| 99 // Finish the remaining bits | 103 // Finish the remaining bits |
| 100 width &= 7; | 104 width &= 7; |
| 101 U8CPU currByte = src[i]; | 105 if (width > 0) { |
| 102 for (int j = 0; j < width; j++) { | 106 U8CPU currByte = src[i]; |
| 103 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | 107 for (int j = 0; j < width; j++) { |
| 104 currByte <<= 1; | 108 dst[j] = ((currByte >> 7) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| 109 currByte <<= 1; | |
| 110 } | |
| 105 } | 111 } |
| 106 return SkSwizzler::kOpaque_ResultAlpha; | 112 return SkSwizzler::kOpaque_ResultAlpha; |
| 107 } | 113 } |
| 108 | 114 |
| 109 // kIndex1, kIndex2, kIndex4 | 115 // kIndex1, kIndex2, kIndex4 |
| 110 | 116 |
| 111 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( | 117 static SkSwizzler::ResultAlpha swizzle_small_index_to_index( |
| 112 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, | 118 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int width, |
| 113 int bitsPerPixel, const SkPMColor ctable[]) { | 119 int bitsPerPixel, const SkPMColor ctable[]) { |
| 114 | 120 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 // bits of SK_ColorBLACK are identical to the 565 representation | 586 // bits of SK_ColorBLACK are identical to the 565 representation |
| 581 // for black. | 587 // for black. |
| 582 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 588 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); |
| 583 break; | 589 break; |
| 584 default: | 590 default: |
| 585 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 591 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| 586 SkASSERT(false); | 592 SkASSERT(false); |
| 587 break; | 593 break; |
| 588 } | 594 } |
| 589 } | 595 } |
| OLD | NEW |