skia2/tools/viewer/ImageSlide.cpp
msarett 50ce1f28ff Add color space xform support to SkJpegCodec (includes F16!)
Also changes SkColorXform to support:
RGBA->RGBA
RGBA->BGRA

Instead of:
RGBA->SkPMColor

TBR=reed@google.com
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2174493002
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot

Committed: https://skia.googlesource.com/skia/+/73d55332e2846dd05e9efdaa2f017bcc3872884b
Review-Url: https://codereview.chromium.org/2174493002
2016-07-29 06:23:33 -07: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.get()));
if (!codec) {
return;
}
fOriginalBitmap.allocPixels(codec->getInfo());
codec->getPixels(codec->getInfo(), fOriginalBitmap.getPixels(), fOriginalBitmap.rowBytes());
SkImageInfo xformedInfo = codec->getInfo().makeColorSpace(
SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named));
fXformedBitmap.allocPixels(xformedInfo);
codec->getPixels(xformedInfo, fXformedBitmap.getPixels(), fXformedBitmap.rowBytes());
}
void ImageSlide::unload() {
fImage.reset(nullptr);
}