Chromium Code Reviews| 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 | 6 |
| 7 #include <setjmp.h> | 7 #include <setjmp.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "third_party/skia/include/core/SkColorPriv.h" | 12 #include "third_party/skia/include/core/SkColorPriv.h" |
| 13 | 13 |
| 14 extern "C" { | 14 extern "C" { |
| 15 #if defined(USE_SYSTEM_LIBJPEG) | 15 #if defined(USE_SYSTEM_LIBJPEG) && !defined(OS_CHROMEOS) |
|
Elliot Glaysher
2014/09/16 18:01:57
I don't believe that chromeos ever uses USE_SYSTEM
| |
| 16 #include <jpeglib.h> | 16 #include <jpeglib.h> |
| 17 #elif defined(USE_LIBJPEG_TURBO) | 17 #elif defined(USE_LIBJPEG_TURBO) && !defined(OS_CHROMEOS) |
| 18 #include "third_party/libjpeg_turbo/jpeglib.h" | 18 #include "third_party/libjpeg_turbo/jpeglib.h" |
| 19 #else | 19 #else |
| 20 #include "third_party/libjpeg/jpeglib.h" | 20 #include "third_party/libjpeg/jpeglib.h" |
| 21 #endif | 21 #endif |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace gfx { | 24 namespace gfx { |
| 25 | 25 |
| 26 // Encoder/decoder shared stuff ------------------------------------------------ | 26 // Encoder/decoder shared stuff ------------------------------------------------ |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // used to pass error info through the JPEG library | 30 // used to pass error info through the JPEG library |
| 31 struct CoderErrorMgr { | 31 struct CoderErrorMgr { |
| 32 jpeg_error_mgr pub; | 32 jpeg_error_mgr pub; |
| 33 jmp_buf setjmp_buffer; | 33 jmp_buf setjmp_buffer; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 void ErrorExit(jpeg_common_struct* cinfo) { | 36 void ErrorExit(jpeg_common_struct* cinfo) { |
| 37 CoderErrorMgr *err = reinterpret_cast<CoderErrorMgr*>(cinfo->err); | 37 CoderErrorMgr *err = reinterpret_cast<CoderErrorMgr*>(cinfo->err); |
| 38 | 38 |
| 39 // Return control to the setjmp point. | 39 // Return control to the setjmp point. |
| 40 longjmp(err->setjmp_buffer, false); | 40 longjmp(err->setjmp_buffer, false); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // This method helps identify at run time which library chromium is using. | 45 // This method helps identify at run time which library chromium is using. |
| 46 JPEGCodec::LibraryVariant JPEGCodec::JpegLibraryVariant() { | 46 JPEGCodec::LibraryVariant JPEGCodec::JpegLibraryVariant() { |
| 47 #if defined(USE_SYSTEM_LIBJPEG) | 47 #if defined(USE_SYSTEM_LIBJPEG) && !defined(OS_CHROMEOS) |
| 48 return SYSTEM_LIBJPEG; | 48 return SYSTEM_LIBJPEG; |
| 49 #elif defined(USE_LIBJPEG_TURBO) | 49 #elif defined(USE_LIBJPEG_TURBO) && !defined(OS_CHROMEOS) |
| 50 return LIBJPEG_TURBO; | 50 return LIBJPEG_TURBO; |
| 51 #else | 51 #else |
| 52 return IJG_LIBJPEG; | 52 return IJG_LIBJPEG; |
| 53 #endif | 53 #endif |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Encoder --------------------------------------------------------------------- | 56 // Encoder --------------------------------------------------------------------- |
| 57 // | 57 // |
| 58 // This code is based on nsJPEGEncoder from Mozilla. | 58 // This code is based on nsJPEGEncoder from Mozilla. |
| 59 // Copyright 2005 Google Inc. (Brett Wilson, contributor) | 59 // Copyright 2005 Google Inc. (Brett Wilson, contributor) |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 int data_length = w * h * 4; | 613 int data_length = w * h * 4; |
| 614 | 614 |
| 615 SkBitmap* bitmap = new SkBitmap(); | 615 SkBitmap* bitmap = new SkBitmap(); |
| 616 bitmap->allocN32Pixels(w, h); | 616 bitmap->allocN32Pixels(w, h); |
| 617 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); | 617 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); |
| 618 | 618 |
| 619 return bitmap; | 619 return bitmap; |
| 620 } | 620 } |
| 621 | 621 |
| 622 } // namespace gfx | 622 } // namespace gfx |
| OLD | NEW |