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 "SkBmpRLECodec.h" | 8 #include "SkBmpRLECodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 fRLEBytes = remainingBytes + additionalBytes; | 194 fRLEBytes = remainingBytes + additionalBytes; |
195 return fRLEBytes; | 195 return fRLEBytes; |
196 } | 196 } |
197 | 197 |
198 /* | 198 /* |
199 * Set an RLE pixel using the color table | 199 * Set an RLE pixel using the color table |
200 */ | 200 */ |
201 void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes, | 201 void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes, |
202 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, | 202 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, |
203 uint8_t index) { | 203 uint8_t index) { |
204 if (is_coord_necessary(x, fSampleX, dstInfo.width())) { | 204 if (dst && is_coord_necessary(x, fSampleX, dstInfo.width())) { |
205 // Set the row | 205 // Set the row |
206 uint32_t row = this->getDstRow(y, dstInfo.height()); | 206 uint32_t row = this->getDstRow(y, dstInfo.height()); |
207 | 207 |
208 // Set the pixel based on destination color type | 208 // Set the pixel based on destination color type |
209 const int dstX = get_dst_coord(x, fSampleX); | 209 const int dstX = get_dst_coord(x, fSampleX); |
210 switch (dstInfo.colorType()) { | 210 switch (dstInfo.colorType()) { |
211 case kN32_SkColorType: { | 211 case kN32_SkColorType: { |
212 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst
RowBytes); | 212 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst
RowBytes); |
213 dstRow[dstX] = fColorTable->operator[](index); | 213 dstRow[dstX] = fColorTable->operator[](index); |
214 break; | 214 break; |
(...skipping 12 matching lines...) Expand all Loading... |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 /* | 230 /* |
231 * Set an RLE pixel from R, G, B values | 231 * Set an RLE pixel from R, G, B values |
232 */ | 232 */ |
233 void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes, | 233 void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes, |
234 const SkImageInfo& dstInfo, uint32_t x, | 234 const SkImageInfo& dstInfo, uint32_t x, |
235 uint32_t y, uint8_t red, uint8_t green, | 235 uint32_t y, uint8_t red, uint8_t green, |
236 uint8_t blue) { | 236 uint8_t blue) { |
237 if (is_coord_necessary(x, fSampleX, dstInfo.width())) { | 237 if (dst && is_coord_necessary(x, fSampleX, dstInfo.width())) { |
238 // Set the row | 238 // Set the row |
239 uint32_t row = this->getDstRow(y, dstInfo.height()); | 239 uint32_t row = this->getDstRow(y, dstInfo.height()); |
240 | 240 |
241 // Set the pixel based on destination color type | 241 // Set the pixel based on destination color type |
242 const int dstX = get_dst_coord(x, fSampleX); | 242 const int dstX = get_dst_coord(x, fSampleX); |
243 switch (dstInfo.colorType()) { | 243 switch (dstInfo.colorType()) { |
244 case kN32_SkColorType: { | 244 case kN32_SkColorType: { |
245 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst
RowBytes); | 245 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dst
RowBytes); |
246 dstRow[dstX] = SkPackARGB32NoCheck(0xFF, red, green, blue); | 246 dstRow[dstX] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
247 break; | 247 break; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 int height = info.height(); | 309 int height = info.height(); |
310 | 310 |
311 // Account for sampling. | 311 // Account for sampling. |
312 SkImageInfo dstInfo = info.makeWH(get_scaled_dimension(width, fSampleX), hei
ght); | 312 SkImageInfo dstInfo = info.makeWH(get_scaled_dimension(width, fSampleX), hei
ght); |
313 | 313 |
314 // Set the background as transparent. Then, if the RLE code skips pixels, | 314 // Set the background as transparent. Then, if the RLE code skips pixels, |
315 // the skipped pixels will be transparent. | 315 // the skipped pixels will be transparent. |
316 // Because of the need for transparent pixels, kN32 is the only color | 316 // Because of the need for transparent pixels, kN32 is the only color |
317 // type that makes sense for the destination format. | 317 // type that makes sense for the destination format. |
318 SkASSERT(kN32_SkColorType == dstInfo.colorType()); | 318 SkASSERT(kN32_SkColorType == dstInfo.colorType()); |
319 SkSampler::Fill(dstInfo, dst, dstRowBytes, SK_ColorTRANSPARENT, opts.fZeroIn
itialized); | 319 if (dst) { |
| 320 SkSampler::Fill(dstInfo, dst, dstRowBytes, SK_ColorTRANSPARENT, opts.fZe
roInitialized); |
| 321 } |
320 | 322 |
321 // Adjust the height and the dst if the previous call to decodeRows() left u
s | 323 // Adjust the height and the dst if the previous call to decodeRows() left u
s |
322 // with lines that need to be skipped. | 324 // with lines that need to be skipped. |
323 if (height > fLinesToSkip) { | 325 if (height > fLinesToSkip) { |
324 height -= fLinesToSkip; | 326 height -= fLinesToSkip; |
325 dst = SkTAddOffset<void>(dst, fLinesToSkip * dstRowBytes); | 327 dst = SkTAddOffset<void>(dst, fLinesToSkip * dstRowBytes); |
326 fLinesToSkip = 0; | 328 fLinesToSkip = 0; |
327 } else { | 329 } else { |
328 fLinesToSkip -= height; | 330 fLinesToSkip -= height; |
329 return height; | 331 return height; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 // Set the indicated number of pixels | 495 // Set the indicated number of pixels |
494 for (int which = 0; x < endX; x++) { | 496 for (int which = 0; x < endX; x++) { |
495 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]); | 497 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]); |
496 which = !which; | 498 which = !which; |
497 } | 499 } |
498 } | 500 } |
499 } | 501 } |
500 } | 502 } |
501 } | 503 } |
502 | 504 |
| 505 bool SkBmpRLECodec::skipRows(int count) { |
| 506 const SkImageInfo rowInfo = SkImageInfo::Make(this->getInfo().width(), count
, kN32_SkColorType, |
| 507 kUnpremul_SkAlphaType); |
| 508 |
| 509 return count == this->decodeRows(rowInfo, nullptr, 0, this->options()); |
| 510 } |
| 511 |
503 // FIXME: Make SkBmpRLECodec have no knowledge of sampling. | 512 // FIXME: Make SkBmpRLECodec have no knowledge of sampling. |
504 // Or it should do all sampling natively. | 513 // Or it should do all sampling natively. |
505 // It currently is a hybrid that needs to know what SkScaledCodec is doin
g. | 514 // It currently is a hybrid that needs to know what SkScaledCodec is doin
g. |
506 class SkBmpRLESampler : public SkSampler { | 515 class SkBmpRLESampler : public SkSampler { |
507 public: | 516 public: |
508 SkBmpRLESampler(SkBmpRLECodec* codec) | 517 SkBmpRLESampler(SkBmpRLECodec* codec) |
509 : fCodec(codec) | 518 : fCodec(codec) |
510 { | 519 { |
511 SkASSERT(fCodec); | 520 SkASSERT(fCodec); |
512 } | 521 } |
(...skipping 17 matching lines...) Expand all Loading... |
530 fSampler.reset(new SkBmpRLESampler(this)); | 539 fSampler.reset(new SkBmpRLESampler(this)); |
531 } | 540 } |
532 | 541 |
533 return fSampler; | 542 return fSampler; |
534 } | 543 } |
535 | 544 |
536 int SkBmpRLECodec::setSampleX(int sampleX){ | 545 int SkBmpRLECodec::setSampleX(int sampleX){ |
537 fSampleX = sampleX; | 546 fSampleX = sampleX; |
538 return get_scaled_dimension(this->getInfo().width(), sampleX); | 547 return get_scaled_dimension(this->getInfo().width(), sampleX); |
539 } | 548 } |
OLD | NEW |