2016-06-13 19:26:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ImageSlide.h"
|
|
|
|
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCodec.h"
|
|
|
|
#include "SkColorSpaceXform.h"
|
|
|
|
#include "SkColorSpace.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkData.h"
|
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkMetaData.h"
|
|
|
|
|
|
|
|
ImageSlide::ImageSlide(const SkString& name, const SkString& path) : fPath(path) {
|
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize ImageSlide::getDimensions() const {
|
|
|
|
return fImage ? fImage->dimensions() : SkISize::Make(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSlide::draw(SkCanvas* canvas) {
|
|
|
|
if (canvas->getMetaData().hasBool(kImageColorXformMetaData, true)) {
|
|
|
|
canvas->drawBitmap(fXformedBitmap, 0, 0);
|
|
|
|
} else {
|
|
|
|
// skbug.com/5428
|
|
|
|
// drawImage() and drawBitmap() behave differently in sRGB mode.
|
|
|
|
// canvas->drawImage(fImage.get(), 0, 0);
|
|
|
|
canvas->drawBitmap(fOriginalBitmap, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:52:35 +00:00
|
|
|
void ImageSlide::load(SkScalar, SkScalar) {
|
2016-06-13 19:26:45 +00:00
|
|
|
sk_sp<SkData> encoded = SkData::MakeFromFileName(fPath.c_str());
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
|
2016-07-29 13:23:33 +00:00
|
|
|
if (!codec) {
|
|
|
|
return;
|
2016-06-13 19:26:45 +00:00
|
|
|
}
|
2016-07-29 13:23:33 +00:00
|
|
|
|
|
|
|
fOriginalBitmap.allocPixels(codec->getInfo());
|
|
|
|
codec->getPixels(codec->getInfo(), fOriginalBitmap.getPixels(), fOriginalBitmap.rowBytes());
|
|
|
|
|
|
|
|
SkImageInfo xformedInfo = codec->getInfo().makeColorSpace(
|
2016-10-24 13:24:02 +00:00
|
|
|
SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named));
|
2016-07-29 13:23:33 +00:00
|
|
|
fXformedBitmap.allocPixels(xformedInfo);
|
|
|
|
codec->getPixels(xformedInfo, fXformedBitmap.getPixels(), fXformedBitmap.rowBytes());
|
2016-06-13 19:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImageSlide::unload() {
|
|
|
|
fImage.reset(nullptr);
|
|
|
|
}
|