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 "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/gfx/codec/png_codec.h"
9 #include "ui/gfx/size.h"
13 ImagePNGRep::ImagePNGRep()
15 scale_factor(ui::SCALE_FACTOR_NONE
) {
18 ImagePNGRep::ImagePNGRep(const scoped_refptr
<base::RefCountedMemory
>& data
,
19 ui::ScaleFactor data_scale_factor
)
21 scale_factor(data_scale_factor
) {
24 ImagePNGRep::~ImagePNGRep() {
27 gfx::Size
ImagePNGRep::Size() const {
28 // 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 CHECK(raw_data
.get());
32 if (!gfx::PNGCodec::Decode(raw_data
->front(), raw_data
->size(),
34 LOG(ERROR
) << "Unable to decode PNG.";
35 return gfx::Size(0, 0);
37 return gfx::Size(bitmap
.width(), bitmap
.height());