skia2/tools/viewer/ImageSlide.cpp
Brian Osman 526972ecb5 Rename all color space factories from New* to Make*
Matches our naming convention for all other types - factories that
return sk_sp (or any type that intelligently manages its own
lifetime) are named Make.

Previous factories are still around, assuming
SK_SUPPORT_LEGACY_COLOR_SPACE_FACTORIES is defined. Enable that
define for Android, etc.

See also: https://codereview.chromium.org/2442053002/

BUG=skia:

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3822

Change-Id: Iaea9376490736b494e8ffc820831f052bbe1478d
Reviewed-on: https://skia-review.googlesource.com/3822
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2016-10-24 14:02:27 +00:00

57 lines
1.6 KiB
C++

/*
* 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);
}
}
void ImageSlide::load(SkScalar, SkScalar) {
sk_sp<SkData> encoded = SkData::MakeFromFileName(fPath.c_str());
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
if (!codec) {
return;
}
fOriginalBitmap.allocPixels(codec->getInfo());
codec->getPixels(codec->getInfo(), fOriginalBitmap.getPixels(), fOriginalBitmap.rowBytes());
SkImageInfo xformedInfo = codec->getInfo().makeColorSpace(
SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named));
fXformedBitmap.allocPixels(xformedInfo);
codec->getPixels(xformedInfo, fXformedBitmap.getPixels(), fXformedBitmap.rowBytes());
}
void ImageSlide::unload() {
fImage.reset(nullptr);
}