OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/image-encoders/ImageEncoder.h" |
| 6 |
| 7 namespace blink { |
| 8 |
| 9 bool ImageEncoder::Encode(Vector<unsigned char>* dst, |
| 10 const SkPixmap& src, |
| 11 const SkJpegEncoder::Options& options) { |
| 12 VectorWStream dst_stream(dst); |
| 13 return SkJpegEncoder::Encode(&dst_stream, src, options); |
| 14 } |
| 15 |
| 16 bool ImageEncoder::Encode(Vector<unsigned char>* dst, |
| 17 const SkPixmap& src, |
| 18 const SkPngEncoder::Options& options) { |
| 19 VectorWStream dst_stream(dst); |
| 20 return SkPngEncoder::Encode(&dst_stream, src, options); |
| 21 } |
| 22 |
| 23 std::unique_ptr<ImageEncoder> ImageEncoder::Create( |
| 24 Vector<unsigned char>* dst, |
| 25 const SkPixmap& src, |
| 26 const SkJpegEncoder::Options& options) { |
| 27 std::unique_ptr<ImageEncoder> image_encoder(new ImageEncoder(dst)); |
| 28 image_encoder->encoder_ = |
| 29 SkJpegEncoder::Make(&image_encoder->dst_, src, options); |
| 30 if (!image_encoder->encoder_) { |
| 31 return nullptr; |
| 32 } |
| 33 |
| 34 return image_encoder; |
| 35 } |
| 36 |
| 37 std::unique_ptr<ImageEncoder> ImageEncoder::Create( |
| 38 Vector<unsigned char>* dst, |
| 39 const SkPixmap& src, |
| 40 const SkPngEncoder::Options& options) { |
| 41 std::unique_ptr<ImageEncoder> image_encoder(new ImageEncoder(dst)); |
| 42 image_encoder->encoder_ = |
| 43 SkPngEncoder::Make(&image_encoder->dst_, src, options); |
| 44 if (!image_encoder->encoder_) { |
| 45 return nullptr; |
| 46 } |
| 47 |
| 48 return image_encoder; |
| 49 } |
| 50 |
| 51 int ImageEncoder::ComputeJpegQuality(double quality) { |
| 52 int compression_quality = 92; // Default value |
| 53 if (quality >= 0.0 && quality <= 1.0) |
| 54 compression_quality = static_cast<int>(quality * 100 + 0.5); |
| 55 return compression_quality; |
| 56 } |
| 57 }; |
OLD | NEW |