OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, The Android Open Source Project | 2 * Copyright 2010, The Android Open Source Project |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
5 * you may not use this file except in compliance with the License. | 5 * you may not use this file except in compliance with the License. |
6 * You may obtain a copy of the License at | 6 * You may obtain a copy of the License at |
7 * | 7 * |
8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
9 * | 9 * |
10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 config->options.crop_left = region.fLeft; | 263 config->options.crop_left = region.fLeft; |
264 config->options.crop_top = region.fTop; | 264 config->options.crop_top = region.fTop; |
265 config->options.crop_width = region.width(); | 265 config->options.crop_width = region.width(); |
266 config->options.crop_height = region.height(); | 266 config->options.crop_height = region.height(); |
267 | 267 |
268 return true; | 268 return true; |
269 } | 269 } |
270 | 270 |
271 bool SkWEBPImageDecoder::setDecodeConfig(SkBitmap* decodedBitmap, | 271 bool SkWEBPImageDecoder::setDecodeConfig(SkBitmap* decodedBitmap, |
272 int width, int height) { | 272 int width, int height) { |
273 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, fHasAlpha); | 273 SkBitmap::Config config = this->getPrefConfig(k32Bit_SrcDepth, SkToBool(fHas
Alpha)); |
274 | 274 |
275 // YUV converter supports output in RGB565, RGBA4444 and RGBA8888 formats. | 275 // YUV converter supports output in RGB565, RGBA4444 and RGBA8888 formats. |
276 if (fHasAlpha) { | 276 if (fHasAlpha) { |
277 if (config != SkBitmap::kARGB_4444_Config) { | 277 if (config != SkBitmap::kARGB_4444_Config) { |
278 config = SkBitmap::kARGB_8888_Config; | 278 config = SkBitmap::kARGB_8888_Config; |
279 } | 279 } |
280 } else { | 280 } else { |
281 if (config != SkBitmap::kRGB_565_Config && | 281 if (config != SkBitmap::kRGB_565_Config && |
282 config != SkBitmap::kARGB_4444_Config) { | 282 config != SkBitmap::kARGB_4444_Config) { |
283 config = SkBitmap::kARGB_8888_Config; | 283 config = SkBitmap::kARGB_8888_Config; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return false; | 530 return false; |
531 } | 531 } |
532 | 532 |
533 SkAutoLockPixels alp(bm); | 533 SkAutoLockPixels alp(bm); |
534 SkAutoLockColors ctLocker; | 534 SkAutoLockColors ctLocker; |
535 if (NULL == bm.getPixels()) { | 535 if (NULL == bm.getPixels()) { |
536 return false; | 536 return false; |
537 } | 537 } |
538 | 538 |
539 WebPConfig webp_config; | 539 WebPConfig webp_config; |
540 if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, quality)) { | 540 if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, (float) quality)) { |
541 return false; | 541 return false; |
542 } | 542 } |
543 | 543 |
544 WebPPicture pic; | 544 WebPPicture pic; |
545 WebPPictureInit(&pic); | 545 WebPPictureInit(&pic); |
546 pic.width = bm.width(); | 546 pic.width = bm.width(); |
547 pic.height = bm.height(); | 547 pic.height = bm.height(); |
548 pic.writer = stream_writer; | 548 pic.writer = stream_writer; |
549 pic.custom_ptr = (void*)stream; | 549 pic.custom_ptr = (void*)stream; |
550 | 550 |
551 const SkPMColor* colors = ctLocker.lockColors(bm); | 551 const SkPMColor* colors = ctLocker.lockColors(bm); |
552 const uint8_t* src = (uint8_t*)bm.getPixels(); | 552 const uint8_t* src = (uint8_t*)bm.getPixels(); |
553 const int rgbStride = pic.width * 3; | 553 const int rgbStride = pic.width * 3; |
554 | 554 |
555 // Import (for each scanline) the bit-map image (in appropriate color-space) | 555 // Import (for each scanline) the bit-map image (in appropriate color-space) |
556 // to RGB color space. | 556 // to RGB color space. |
557 uint8_t* rgb = new uint8_t[rgbStride * pic.height]; | 557 uint8_t* rgb = new uint8_t[rgbStride * pic.height]; |
558 for (int y = 0; y < pic.height; ++y) { | 558 for (int y = 0; y < pic.height; ++y) { |
559 scanline_import(src + y * bm.rowBytes(), rgb + y * rgbStride, | 559 scanline_import(src + y * bm.rowBytes(), rgb + y * rgbStride, |
560 pic.width, colors); | 560 pic.width, colors); |
561 } | 561 } |
562 | 562 |
563 bool ok = WebPPictureImportRGB(&pic, rgb, rgbStride); | 563 bool ok = (bool) WebPPictureImportRGB(&pic, rgb, rgbStride); |
564 delete[] rgb; | 564 delete[] rgb; |
565 | 565 |
566 ok = ok && WebPEncode(&webp_config, &pic); | 566 ok = ok && WebPEncode(&webp_config, &pic); |
567 WebPPictureFree(&pic); | 567 WebPPictureFree(&pic); |
568 | 568 |
569 return ok; | 569 return ok; |
570 } | 570 } |
571 | 571 |
572 | 572 |
573 /////////////////////////////////////////////////////////////////////////////// | 573 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 12 matching lines...) Expand all Loading... |
586 // Magic matches, call decoder | 586 // Magic matches, call decoder |
587 return SkNEW(SkWEBPImageDecoder); | 587 return SkNEW(SkWEBPImageDecoder); |
588 } | 588 } |
589 | 589 |
590 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 590 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
591 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 591 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
592 } | 592 } |
593 | 593 |
594 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); | 594 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); |
595 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); | 595 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact
ory); |
OLD | NEW |