| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "ui/gfx/codec/jpeg_codec.h" | 5 #include "ui/gfx/codec/jpeg_codec.h" | 
|  | 6 #include "ui/gfx/codec/codec_priv.h" | 
| 6 | 7 | 
| 7 #include <setjmp.h> | 8 #include <setjmp.h> | 
| 8 | 9 | 
| 9 #include <memory> | 10 #include <memory> | 
| 10 | 11 | 
| 11 #include "base/logging.h" | 12 #include "base/logging.h" | 
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" | 
| 13 #include "third_party/skia/include/core/SkColorPriv.h" | 14 #include "third_party/skia/include/core/SkColorPriv.h" | 
| 14 #include "third_party/skia/include/core/SkStream.h" |  | 
| 15 #include "third_party/skia/include/encode/SkJpegEncoder.h" | 15 #include "third_party/skia/include/encode/SkJpegEncoder.h" | 
| 16 | 16 | 
| 17 extern "C" { | 17 extern "C" { | 
| 18 #if defined(USE_SYSTEM_LIBJPEG) | 18 #if defined(USE_SYSTEM_LIBJPEG) | 
| 19 #include <jpeglib.h> | 19 #include <jpeglib.h> | 
| 20 #elif defined(USE_LIBJPEG_TURBO) | 20 #elif defined(USE_LIBJPEG_TURBO) | 
| 21 #include "third_party/libjpeg_turbo/jpeglib.h" | 21 #include "third_party/libjpeg_turbo/jpeglib.h" | 
| 22 #else | 22 #else | 
| 23 #include "third_party/libjpeg/jpeglib.h" | 23 #include "third_party/libjpeg/jpeglib.h" | 
| 24 #endif | 24 #endif | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 40   CoderErrorMgr *err = reinterpret_cast<CoderErrorMgr*>(cinfo->err); | 40   CoderErrorMgr *err = reinterpret_cast<CoderErrorMgr*>(cinfo->err); | 
| 41 | 41 | 
| 42   // Return control to the setjmp point. | 42   // Return control to the setjmp point. | 
| 43   longjmp(err->setjmp_buffer, false); | 43   longjmp(err->setjmp_buffer, false); | 
| 44 } | 44 } | 
| 45 | 45 | 
| 46 }  // namespace | 46 }  // namespace | 
| 47 | 47 | 
| 48 // Encoder --------------------------------------------------------------------- | 48 // Encoder --------------------------------------------------------------------- | 
| 49 | 49 | 
| 50 namespace { |  | 
| 51 |  | 
| 52 class VectorWStream : public SkWStream { |  | 
| 53  public: |  | 
| 54   VectorWStream(std::vector<unsigned char>* dst) : dst_(dst) { |  | 
| 55     DCHECK(dst_); |  | 
| 56     DCHECK_EQ(0UL, dst_->size()); |  | 
| 57   } |  | 
| 58 |  | 
| 59   bool write(const void* buffer, size_t size) override { |  | 
| 60     const unsigned char* ptr = reinterpret_cast<const unsigned char*>(buffer); |  | 
| 61     dst_->insert(dst_->end(), ptr, ptr + size); |  | 
| 62     return true; |  | 
| 63   } |  | 
| 64 |  | 
| 65   size_t bytesWritten() const override { return dst_->size(); } |  | 
| 66 |  | 
| 67  private: |  | 
| 68   // Does not have ownership. |  | 
| 69   std::vector<unsigned char>* dst_; |  | 
| 70 }; |  | 
| 71 }; |  | 
| 72 |  | 
| 73 bool JPEGCodec::Encode(const SkPixmap& src, | 50 bool JPEGCodec::Encode(const SkPixmap& src, | 
| 74                        int quality, | 51                        int quality, | 
| 75                        std::vector<unsigned char>* output) { | 52                        std::vector<unsigned char>* output) { | 
| 76   output->clear(); | 53   output->clear(); | 
| 77   VectorWStream dst(output); | 54   VectorWStream dst(output); | 
| 78 | 55 | 
| 79   SkJpegEncoder::Options options; | 56   SkJpegEncoder::Options options; | 
| 80   options.fQuality = quality; | 57   options.fQuality = quality; | 
| 81   return SkJpegEncoder::Encode(&dst, src, options); | 58   return SkJpegEncoder::Encode(&dst, src, options); | 
| 82 } | 59 } | 
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 308   int data_length = w * h * 4; | 285   int data_length = w * h * 4; | 
| 309 | 286 | 
| 310   std::unique_ptr<SkBitmap> bitmap(new SkBitmap()); | 287   std::unique_ptr<SkBitmap> bitmap(new SkBitmap()); | 
| 311   bitmap->allocN32Pixels(w, h); | 288   bitmap->allocN32Pixels(w, h); | 
| 312   memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); | 289   memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); | 
| 313 | 290 | 
| 314   return bitmap; | 291   return bitmap; | 
| 315 } | 292 } | 
| 316 | 293 | 
| 317 }  // namespace gfx | 294 }  // namespace gfx | 
| OLD | NEW | 
|---|