Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "platform/graphics/ImageBufferClient.h" | 43 #include "platform/graphics/ImageBufferClient.h" |
| 44 #include "platform/graphics/RecordingImageBufferSurface.h" | 44 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 45 #include "platform/graphics/StaticBitmapImage.h" | 45 #include "platform/graphics/StaticBitmapImage.h" |
| 46 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 46 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 47 #include "platform/graphics/gpu/DrawingBuffer.h" | 47 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 48 #include "platform/graphics/gpu/Extensions3DUtil.h" | 48 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 49 #include "platform/graphics/paint/PaintImage.h" | 49 #include "platform/graphics/paint/PaintImage.h" |
| 50 #include "platform/graphics/paint/PaintRecord.h" | 50 #include "platform/graphics/paint/PaintRecord.h" |
| 51 #include "platform/graphics/skia/SkiaUtils.h" | 51 #include "platform/graphics/skia/SkiaUtils.h" |
| 52 #include "platform/image-encoders/ImageEncoder.h" | 52 #include "platform/image-encoders/ImageEncoder.h" |
| 53 #include "platform/image-encoders/PNGImageEncoder.h" | |
| 54 #include "platform/image-encoders/WEBPImageEncoder.h" | |
| 55 #include "platform/network/mime/MIMETypeRegistry.h" | 53 #include "platform/network/mime/MIMETypeRegistry.h" |
| 56 #include "platform/wtf/CheckedNumeric.h" | 54 #include "platform/wtf/CheckedNumeric.h" |
| 57 #include "platform/wtf/MathExtras.h" | 55 #include "platform/wtf/MathExtras.h" |
| 58 #include "platform/wtf/PtrUtil.h" | 56 #include "platform/wtf/PtrUtil.h" |
| 59 #include "platform/wtf/Vector.h" | 57 #include "platform/wtf/Vector.h" |
| 60 #include "platform/wtf/text/Base64.h" | 58 #include "platform/wtf/text/Base64.h" |
| 61 #include "platform/wtf/text/WTFString.h" | 59 #include "platform/wtf/text/WTFString.h" |
| 62 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" | 60 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" |
| 63 #include "public/platform/Platform.h" | 61 #include "public/platform/Platform.h" |
| 64 #include "public/platform/WebGraphicsContext3DProvider.h" | 62 #include "public/platform/WebGraphicsContext3DProvider.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 } | 537 } |
| 540 | 538 |
| 541 void ImageBuffer::SetNeedsCompositingUpdate() { | 539 void ImageBuffer::SetNeedsCompositingUpdate() { |
| 542 if (client_) | 540 if (client_) |
| 543 client_->SetNeedsCompositingUpdate(); | 541 client_->SetNeedsCompositingUpdate(); |
| 544 } | 542 } |
| 545 | 543 |
| 546 bool ImageDataBuffer::EncodeImage(const String& mime_type, | 544 bool ImageDataBuffer::EncodeImage(const String& mime_type, |
| 547 const double& quality, | 545 const double& quality, |
| 548 Vector<unsigned char>* encoded_image) const { | 546 Vector<unsigned char>* encoded_image) const { |
| 547 SkImageInfo info = | |
| 548 SkImageInfo::Make(Width(), Height(), kRGBA_8888_SkColorType, | |
|
scroggo_chromium
2017/05/22 13:35:04
It seems weird to me that the color type and alpha
msarett1
2017/05/22 15:33:56
Yeah that seems to be part of the implicit contrac
| |
| 549 kUnpremul_SkAlphaType, nullptr); | |
| 550 size_t rowBytes = Width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); | |
|
scroggo_chromium
2017/05/22 13:35:04
Should this be info.minRowBytes?
Also, nit: Could
msarett1
2017/05/22 15:33:56
Yeah, that's better.
| |
| 551 SkPixmap src(info, Pixels(), rowBytes); | |
|
scroggo_chromium
2017/05/22 13:35:04
This kind of seems like it should be in the constr
msarett1
2017/05/22 15:33:56
I agree. This could/should just be two methods.
| |
| 552 | |
| 549 if (mime_type == "image/jpeg") { | 553 if (mime_type == "image/jpeg") { |
| 550 SkImageInfo info = | |
| 551 SkImageInfo::Make(Width(), Height(), kRGBA_8888_SkColorType, | |
| 552 kUnpremul_SkAlphaType, nullptr); | |
| 553 size_t rowBytes = | |
| 554 Width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); | |
| 555 SkPixmap src(info, Pixels(), rowBytes); | |
| 556 | |
| 557 SkJpegEncoder::Options options; | 554 SkJpegEncoder::Options options; |
| 558 options.fQuality = ImageEncoder::ComputeJpegQuality(quality); | 555 options.fQuality = ImageEncoder::ComputeJpegQuality(quality); |
| 559 options.fAlphaOption = SkJpegEncoder::AlphaOption::kBlendOnBlack; | 556 options.fAlphaOption = SkJpegEncoder::AlphaOption::kBlendOnBlack; |
| 560 options.fBlendBehavior = SkTransferFunctionBehavior::kIgnore; | 557 options.fBlendBehavior = SkTransferFunctionBehavior::kIgnore; |
| 561 if (options.fQuality == 100) { | 558 if (options.fQuality == 100) { |
| 562 options.fDownsample = SkJpegEncoder::Downsample::k444; | 559 options.fDownsample = SkJpegEncoder::Downsample::k444; |
| 563 } | 560 } |
| 564 return ImageEncoder::Encode(encoded_image, src, options); | 561 return ImageEncoder::Encode(encoded_image, src, options); |
| 565 } | 562 } |
| 566 | 563 |
| 567 if (mime_type == "image/webp") { | 564 if (mime_type == "image/webp") { |
| 568 int compression_quality = WEBPImageEncoder::kDefaultCompressionQuality; | 565 SkWebpEncoder::Options options = ImageEncoder::ComputeWebpOptions( |
| 569 if (quality >= 0.0 && quality <= 1.0) | 566 quality, SkTransferFunctionBehavior::kIgnore); |
| 570 compression_quality = static_cast<int>(quality * 100 + 0.5); | 567 return ImageEncoder::Encode(encoded_image, src, options); |
| 571 return WEBPImageEncoder::Encode(*this, compression_quality, encoded_image); | |
| 572 } | 568 } |
| 573 | 569 |
| 574 DCHECK_EQ(mime_type, "image/png"); | 570 DCHECK_EQ(mime_type, "image/png"); |
| 575 return PNGImageEncoder::Encode(*this, encoded_image); | 571 SkPngEncoder::Options options; |
| 572 options.fFilterFlags = SkPngEncoder::FilterFlag::kSub; | |
| 573 options.fZLibLevel = 3; | |
| 574 options.fUnpremulBehavior = SkTransferFunctionBehavior::kIgnore; | |
| 575 return ImageEncoder::Encode(encoded_image, src, options); | |
| 576 } | 576 } |
| 577 | 577 |
| 578 String ImageDataBuffer::ToDataURL(const String& mime_type, | 578 String ImageDataBuffer::ToDataURL(const String& mime_type, |
| 579 const double& quality) const { | 579 const double& quality) const { |
| 580 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); | 580 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); |
| 581 | 581 |
| 582 Vector<unsigned char> result; | 582 Vector<unsigned char> result; |
| 583 if (!EncodeImage(mime_type, quality, &result)) | 583 if (!EncodeImage(mime_type, quality, &result)) |
| 584 return "data:,"; | 584 return "data:,"; |
| 585 | 585 |
| 586 return "data:" + mime_type + ";base64," + Base64Encode(result); | 586 return "data:" + mime_type + ";base64," + Base64Encode(result); |
| 587 } | 587 } |
| 588 | 588 |
| 589 } // namespace blink | 589 } // namespace blink |
| OLD | NEW |