#include "ui/gfx/image/image_png_rep.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/size.h"
namespace gfx {
ImagePNGRep::ImagePNGRep() = default;
ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data,
float data_scale)
: raw_data(data),
scale(data_scale) {
}
ImagePNGRep::ImagePNGRep(const ImagePNGRep& other) = default;
ImagePNGRep::~ImagePNGRep() {
}
gfx::Size ImagePNGRep::Size() const {
CHECK(raw_data.get());
SkBitmap bitmap = gfx::PNGCodec::Decode(*raw_data);
if (bitmap.isNull()) {
LOG(ERROR) << "Unable to decode PNG.";
return gfx::Size(0, 0);
}
return gfx::Size(bitmap.width(), bitmap.height());
}
}