| 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 25 matching lines...) Expand all Loading... |
| 36 */ | 36 */ |
| 37 SkCodec::Result SkBmpRLECodec::onGetPixels(const SkImageInfo& dstInfo, | 37 SkCodec::Result SkBmpRLECodec::onGetPixels(const SkImageInfo& dstInfo, |
| 38 void* dst, size_t dstRowBytes, | 38 void* dst, size_t dstRowBytes, |
| 39 const Options& opts, | 39 const Options& opts, |
| 40 SkPMColor* inputColorPtr, | 40 SkPMColor* inputColorPtr, |
| 41 int* inputColorCount) { | 41 int* inputColorCount) { |
| 42 if (opts.fSubset) { | 42 if (opts.fSubset) { |
| 43 // Subsets are not supported. | 43 // Subsets are not supported. |
| 44 return kUnimplemented; | 44 return kUnimplemented; |
| 45 } | 45 } |
| 46 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | |
| 47 SkCodecPrintf("Error: scaling not supported.\n"); | |
| 48 return kInvalidScale; | |
| 49 } | |
| 50 if (!conversion_possible(dstInfo, this->getInfo())) { | 46 if (!conversion_possible(dstInfo, this->getInfo())) { |
| 51 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 47 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
| 52 return kInvalidConversion; | 48 return kInvalidConversion; |
| 53 } | 49 } |
| 54 | 50 |
| 55 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); | 51 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); |
| 56 if (kSuccess != result) { | 52 if (kSuccess != result) { |
| 57 return result; | 53 return result; |
| 58 } | 54 } |
| 59 | 55 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // This case should not be reached. We should catch an invalid | 242 // This case should not be reached. We should catch an invalid |
| 247 // color type when we check that the conversion is possible. | 243 // color type when we check that the conversion is possible. |
| 248 SkASSERT(false); | 244 SkASSERT(false); |
| 249 break; | 245 break; |
| 250 } | 246 } |
| 251 } | 247 } |
| 252 } | 248 } |
| 253 | 249 |
| 254 SkCodec::Result SkBmpRLECodec::prepareToDecode(const SkImageInfo& dstInfo, | 250 SkCodec::Result SkBmpRLECodec::prepareToDecode(const SkImageInfo& dstInfo, |
| 255 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { | 251 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
| 252 // Reset fSampleX. If it needs to be a value other than 1, it will get modif
ied by |
| 253 // the sampler. |
| 254 fSampleX = 1; |
| 256 // Create the color table if necessary and prepare the stream for decode | 255 // Create the color table if necessary and prepare the stream for decode |
| 257 // Note that if it is non-NULL, inputColorCount will be modified | 256 // Note that if it is non-NULL, inputColorCount will be modified |
| 258 if (!this->createColorTable(inputColorCount)) { | 257 if (!this->createColorTable(inputColorCount)) { |
| 259 SkCodecPrintf("Error: could not create color table.\n"); | 258 SkCodecPrintf("Error: could not create color table.\n"); |
| 260 return SkCodec::kInvalidInput; | 259 return SkCodec::kInvalidInput; |
| 261 } | 260 } |
| 262 | 261 |
| 263 // Copy the color table to the client if necessary | 262 // Copy the color table to the client if necessary |
| 264 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount)
; | 263 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount)
; |
| 265 | 264 |
| 266 // Initialize a buffer for encoded RLE data | 265 // Initialize a buffer for encoded RLE data |
| 267 if (!this->initializeStreamBuffer()) { | 266 if (!this->initializeStreamBuffer()) { |
| 268 SkCodecPrintf("Error: cannot initialize stream buffer.\n"); | 267 SkCodecPrintf("Error: cannot initialize stream buffer.\n"); |
| 269 return SkCodec::kInvalidConversion; | 268 return SkCodec::kInvalidConversion; |
| 270 } | 269 } |
| 271 | 270 |
| 272 SkScaledCodec::ComputeSampleSize(dstInfo, this->getInfo(), &fSampleX, NULL); | |
| 273 | |
| 274 return SkCodec::kSuccess; | 271 return SkCodec::kSuccess; |
| 275 } | 272 } |
| 276 | 273 |
| 277 /* | 274 /* |
| 278 * Performs the bitmap decoding for RLE input format | 275 * Performs the bitmap decoding for RLE input format |
| 279 * RLE decoding is performed all at once, rather than a one row at a time | 276 * RLE decoding is performed all at once, rather than a one row at a time |
| 280 */ | 277 */ |
| 281 SkCodec::Result SkBmpRLECodec::decodeRows(const SkImageInfo& dstInfo, | 278 SkCodec::Result SkBmpRLECodec::decodeRows(const SkImageInfo& info, |
| 282 void* dst, size_t dstRowBytes, | 279 void* dst, size_t dstRowBytes, |
| 283 const Options& opts) { | 280 const Options& opts) { |
| 284 // Set RLE flags | 281 // Set RLE flags |
| 285 static const uint8_t RLE_ESCAPE = 0; | 282 static const uint8_t RLE_ESCAPE = 0; |
| 286 static const uint8_t RLE_EOL = 0; | 283 static const uint8_t RLE_EOL = 0; |
| 287 static const uint8_t RLE_EOF = 1; | 284 static const uint8_t RLE_EOF = 1; |
| 288 static const uint8_t RLE_DELTA = 2; | 285 static const uint8_t RLE_DELTA = 2; |
| 289 | 286 |
| 290 // Set constant values | 287 // Set constant values |
| 291 const int width = this->getInfo().width(); | 288 const int width = this->getInfo().width(); |
| 292 const int height = dstInfo.height(); | 289 const int height = info.height(); |
| 290 |
| 291 // Account for sampling. |
| 292 SkImageInfo dstInfo = info.makeWH(get_scaled_dimension(width, fSampleX), hei
ght); |
| 293 | 293 |
| 294 // Destination parameters | 294 // Destination parameters |
| 295 int x = 0; | 295 int x = 0; |
| 296 int y = 0; | 296 int y = 0; |
| 297 | 297 |
| 298 // Set the background as transparent. Then, if the RLE code skips pixels, | 298 // Set the background as transparent. Then, if the RLE code skips pixels, |
| 299 // the skipped pixels will be transparent. | 299 // the skipped pixels will be transparent. |
| 300 // Because of the need for transparent pixels, kN32 is the only color | 300 // Because of the need for transparent pixels, kN32 is the only color |
| 301 // type that makes sense for the destination format. | 301 // type that makes sense for the destination format. |
| 302 SkASSERT(kN32_SkColorType == dstInfo.colorType()); | 302 SkASSERT(kN32_SkColorType == dstInfo.colorType()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 459 |
| 460 // Set the indicated number of pixels | 460 // Set the indicated number of pixels |
| 461 for (int which = 0; x < endX; x++) { | 461 for (int which = 0; x < endX; x++) { |
| 462 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]); | 462 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]); |
| 463 which = !which; | 463 which = !which; |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 } | 468 } |
| 469 |
| 470 class SkBmpRLESampler : public SkSampler { |
| 471 public: |
| 472 SkBmpRLESampler(SkBmpRLECodec* codec) |
| 473 : fCodec(codec) |
| 474 { |
| 475 SkASSERT(fCodec); |
| 476 } |
| 477 |
| 478 private: |
| 479 int onSetSampleX(int sampleX) { |
| 480 return fCodec->setSampleX(sampleX); |
| 481 } |
| 482 |
| 483 // Unowned pointer. fCodec will delete this class in its destructor. |
| 484 SkBmpRLECodec* fCodec; |
| 485 }; |
| 486 |
| 487 SkSampler* SkBmpRLECodec::getSampler() { |
| 488 if (!fSampler) { |
| 489 fSampler.reset(new SkBmpRLESampler(this)); |
| 490 } |
| 491 |
| 492 return fSampler; |
| 493 } |
| 494 |
| 495 int SkBmpRLECodec::setSampleX(int sampleX) { |
| 496 fSampleX = sampleX; |
| 497 return get_scaled_dimension(this->getInfo().width(), sampleX); |
| 498 } |
| OLD | NEW |