mojo: Fix map of booleans for python bindings.
[chromium-blink-merge.git] / ui / gfx / image / image_png_rep.cc
blob3970d2bcc02e061c2c65e398ab25ce549cf5ac00
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
3 // found in the LICENSE file.
5 #include "ui/gfx/image/image_png_rep.h"
7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/gfx/codec/png_codec.h"
10 #include "ui/gfx/size.h"
12 namespace gfx {
14 ImagePNGRep::ImagePNGRep()
15 : raw_data(NULL),
16 scale(1.0) {
19 ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data,
20 float data_scale)
21 : raw_data(data),
22 scale(data_scale) {
25 ImagePNGRep::~ImagePNGRep() {
28 gfx::Size ImagePNGRep::Size() const {
29 // The only way to get the width and height of a raw PNG stream, at least
30 // using the gfx::PNGCodec API, is to decode the whole thing.
31 CHECK(raw_data.get());
32 SkBitmap bitmap;
33 if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
34 &bitmap)) {
35 LOG(ERROR) << "Unable to decode PNG.";
36 return gfx::Size(0, 0);
38 return gfx::Size(bitmap.width(), bitmap.height());
41 } // namespace gfx