| 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" |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 } | 596 } |
| 597 } | 597 } |
| 598 #endif | 598 #endif |
| 599 | 599 |
| 600 jpeg_finish_decompress(&cinfo); | 600 jpeg_finish_decompress(&cinfo); |
| 601 jpeg_destroy_decompress(&cinfo); | 601 jpeg_destroy_decompress(&cinfo); |
| 602 return true; | 602 return true; |
| 603 } | 603 } |
| 604 | 604 |
| 605 // static | 605 // static |
| 606 SkBitmap* JPEGCodec::Decode(const unsigned char* input, size_t input_size) { | 606 std::unique_ptr<SkBitmap> JPEGCodec::Decode(const unsigned char* input, |
| 607 size_t input_size) { |
| 607 int w, h; | 608 int w, h; |
| 608 std::vector<unsigned char> data_vector; | 609 std::vector<unsigned char> data_vector; |
| 609 if (!Decode(input, input_size, FORMAT_SkBitmap, &data_vector, &w, &h)) | 610 if (!Decode(input, input_size, FORMAT_SkBitmap, &data_vector, &w, &h)) |
| 610 return NULL; | 611 return nullptr; |
| 611 | 612 |
| 612 // Skia only handles 32 bit images. | 613 // Skia only handles 32 bit images. |
| 613 int data_length = w * h * 4; | 614 int data_length = w * h * 4; |
| 614 | 615 |
| 615 SkBitmap* bitmap = new SkBitmap(); | 616 std::unique_ptr<SkBitmap> bitmap(new SkBitmap()); |
| 616 bitmap->allocN32Pixels(w, h); | 617 bitmap->allocN32Pixels(w, h); |
| 617 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); | 618 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); |
| 618 | 619 |
| 619 return bitmap; | 620 return bitmap; |
| 620 } | 621 } |
| 621 | 622 |
| 622 } // namespace gfx | 623 } // namespace gfx |
| OLD | NEW |