OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/image/image_png_rep.h" | 5 #include "ui/gfx/image/image_png_rep.h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "ui/gfx/codec/png_codec.h" | 9 #include "ui/gfx/codec/png_codec.h" |
9 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
10 | 11 |
11 namespace gfx { | 12 namespace gfx { |
12 | 13 |
13 ImagePNGRep::ImagePNGRep() | 14 ImagePNGRep::ImagePNGRep() |
14 : raw_data(NULL), | 15 : raw_data(NULL), |
15 scale_factor(ui::SCALE_FACTOR_NONE) { | 16 scale(1.0) { |
16 } | 17 } |
17 | 18 |
18 ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data, | 19 ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data, |
19 ui::ScaleFactor data_scale_factor) | 20 float data_scale) |
20 : raw_data(data), | 21 : raw_data(data), |
21 scale_factor(data_scale_factor) { | 22 scale(data_scale) { |
22 } | 23 } |
23 | 24 |
24 ImagePNGRep::~ImagePNGRep() { | 25 ImagePNGRep::~ImagePNGRep() { |
25 } | 26 } |
26 | 27 |
27 gfx::Size ImagePNGRep::Size() const { | 28 gfx::Size ImagePNGRep::Size() const { |
28 // The only way to get the width and height of a raw PNG stream, at least | 29 // The only way to get the width and height of a raw PNG stream, at least |
29 // using the gfx::PNGCodec API, is to decode the whole thing. | 30 // using the gfx::PNGCodec API, is to decode the whole thing. |
30 CHECK(raw_data.get()); | 31 CHECK(raw_data.get()); |
31 SkBitmap bitmap; | 32 SkBitmap bitmap; |
32 if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), | 33 if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), |
33 &bitmap)) { | 34 &bitmap)) { |
34 LOG(ERROR) << "Unable to decode PNG."; | 35 LOG(ERROR) << "Unable to decode PNG."; |
35 return gfx::Size(0, 0); | 36 return gfx::Size(0, 0); |
36 } | 37 } |
37 return gfx::Size(bitmap.width(), bitmap.height()); | 38 return gfx::Size(bitmap.width(), bitmap.height()); |
38 } | 39 } |
39 | 40 |
40 } // namespace gfx | 41 } // namespace gfx |
OLD | NEW |