Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: tools/viewer/ImageSlide.cpp

Issue 2058753002: Display JPGs in Viewer with Split Screen and ColorSpaceXform (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Unmerge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/viewer/ImageSlide.h ('k') | tools/viewer/Viewer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/viewer/ImageSlide.cpp
diff --git a/tools/viewer/ImageSlide.cpp b/tools/viewer/ImageSlide.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4a03185733fa0b0fde40763075ffd1640cf999f2
--- /dev/null
+++ b/tools/viewer/ImageSlide.cpp
@@ -0,0 +1,58 @@
+/*
+* 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() {
+ sk_sp<SkData> encoded = SkData::MakeFromFileName(fPath.c_str());
+ fImage = SkImage::MakeFromEncoded(encoded);
+ fImage->asLegacyBitmap(&fOriginalBitmap, SkImage::kRO_LegacyBitmapMode);
+
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get()));
+ sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace());
+ sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named);
+ std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, dstSpace);
+ fOriginalBitmap.deepCopyTo(&fXformedBitmap);
+ uint32_t* row = (uint32_t*) fXformedBitmap.getPixels();
+ for (int y = 0; y < fXformedBitmap.height(); y++) {
+ xform->xform_RGBA_8888(row, row, fXformedBitmap.width());
+ row = SkTAddOffset<uint32_t>(row, fXformedBitmap.rowBytes());
+ }
+ fXformedBitmap.notifyPixelsChanged(); // This is needed for the deepCopy
+}
+
+void ImageSlide::unload() {
+ fImage.reset(nullptr);
+}
« no previous file with comments | « tools/viewer/ImageSlide.h ('k') | tools/viewer/Viewer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698