aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-10-16 18:56:57 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-16 18:57:02 +0000
commit82269abfec798621c8dbbc6bd48996c0b2686f41 (patch)
tree4cbc683affe8e898a8973e8edd76187d3d32ba0e /src/codec
parent354ec36bad4f504286916e72b1e1a4eefde2efc2 (diff)
Revert "Revert "apply codec origin in generator""
This reverts commit 363dd988a55c2ed3fa92e2368c1c889101425734. Reason for revert: pdfium fix landed Original change's description: > Revert "apply codec origin in generator" > > This reverts commit fa15877f487333bec876e7315cf584c0d598d098. > > Reason for revert: Appears to break PDFium. > > Original change's description: > > apply codec origin in generator > > > > Bug: skia: > > Change-Id: I383dacb49b1e3c88467ccdbf3288764bb1bbf01a > > Reviewed-on: https://skia-review.googlesource.com/58600 > > Reviewed-by: Leon Scroggins <scroggo@google.com> > > Commit-Queue: Mike Reed <reed@google.com> > > TBR=scroggo@google.com,reed@google.com > > Change-Id: Id97137d6ec39ca638c941928bae6510814b1c499 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/60041 > Reviewed-by: Ben Wagner <benjaminwagner@google.com> > Commit-Queue: Ben Wagner <benjaminwagner@google.com> TBR=benjaminwagner@google.com,scroggo@google.com,reed@google.com Change-Id: I1b54a6e6e6cbda07f346ffbbc4977f9db705abcd No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/60320 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/SkCodecImageGenerator.cpp74
1 files changed, 66 insertions, 8 deletions
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index e6ca2122ea..e8d7d3038a 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -5,8 +5,41 @@
* found in the LICENSE file.
*/
+#include "SkAutoPixmapStorage.h"
#include "SkCodecImageGenerator.h"
#include "SkMakeUnique.h"
+#include "SkPixmapPriv.h"
+
+#define kMirrorX SkPixmapPriv::kMirrorX
+#define kMirrorY SkPixmapPriv::kMirrorY
+#define kSwapXY SkPixmapPriv::kSwapXY
+
+const uint8_t gOrientationFlags[] = {
+ 0, // kTopLeft_Origin
+ kMirrorX, // kTopRight_Origin
+ kMirrorX | kMirrorY, // kBottomRight_Origin
+ kMirrorY, // kBottomLeft_Origin
+ kSwapXY, // kLeftTop_Origin
+ kMirrorX | kSwapXY, // kRightTop_Origin
+ kMirrorX | kMirrorY | kSwapXY, // kRightBottom_Origin
+ kMirrorY | kSwapXY, // kLeftBottom_Origin
+};
+
+SkPixmapPriv::OrientFlags SkPixmapPriv::OriginToOrient(SkCodec::Origin o) {
+ unsigned io = static_cast<int>(o) - 1;
+ SkASSERT(io < SK_ARRAY_COUNT(gOrientationFlags));
+ return static_cast<SkPixmapPriv::OrientFlags>(gOrientationFlags[io]);
+}
+
+static bool should_swap_width_height(SkCodec::Origin o) {
+ return SkToBool(SkPixmapPriv::OriginToOrient(o) & kSwapXY);
+}
+
+static SkImageInfo swap_width_height(SkImageInfo info) {
+ return info.makeWH(info.height(), info.width());
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
std::unique_ptr<SkImageGenerator> SkCodecImageGenerator::MakeFromEncodedCodec(sk_sp<SkData> data) {
auto codec = SkCodec::MakeFromData(data);
@@ -17,16 +50,19 @@ std::unique_ptr<SkImageGenerator> SkCodecImageGenerator::MakeFromEncodedCodec(sk
return std::unique_ptr<SkImageGenerator>(new SkCodecImageGenerator(std::move(codec), data));
}
-static SkImageInfo adjust_info(const SkImageInfo& info) {
- SkImageInfo newInfo = info;
+static SkImageInfo adjust_info(SkCodec* codec) {
+ SkImageInfo info = codec->getInfo();
if (kUnpremul_SkAlphaType == info.alphaType()) {
- newInfo = newInfo.makeAlphaType(kPremul_SkAlphaType);
+ info = info.makeAlphaType(kPremul_SkAlphaType);
}
- return newInfo;
+ if (should_swap_width_height(codec->getOrigin())) {
+ info = swap_width_height(info);
+ }
+ return info;
}
SkCodecImageGenerator::SkCodecImageGenerator(std::unique_ptr<SkCodec> codec, sk_sp<SkData> data)
- : INHERITED(adjust_info(codec->getInfo()))
+ : INHERITED(adjust_info(codec.get()))
, fCodec(std::move(codec))
, fData(std::move(data))
{}
@@ -35,13 +71,35 @@ SkData* SkCodecImageGenerator::onRefEncodedData() {
return SkRef(fData.get());
}
-bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
- const Options& opts) {
+bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* requestPixels,
+ size_t requestRowBytes, const Options& opts) {
+ const SkCodec::Origin origin = fCodec->getOrigin();
+ const SkPixmap request(requestInfo, requestPixels, requestRowBytes);
+ const SkPixmap* codecMap = &request;
+ SkAutoPixmapStorage storage; // used if we have to post-orient the output from the codec
+
+ if (origin != SkCodec::kTopLeft_Origin) {
+ SkImageInfo info = requestInfo;
+ if (should_swap_width_height(origin)) {
+ info = swap_width_height(info);
+ }
+ // need a tmp buffer to receive the pixels, so we can post-orient them
+ if (!storage.tryAlloc(info)) {
+ return false;
+ }
+ codecMap = &storage;
+ }
+
SkCodec::Options codecOpts;
codecOpts.fPremulBehavior = opts.fBehavior;
- SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, &codecOpts);
+ SkCodec::Result result = fCodec->getPixels(*codecMap, &codecOpts);
switch (result) {
case SkCodec::kSuccess:
+ if (codecMap != &request) {
+ return SkPixmapPriv::Orient(request, *codecMap,
+ SkPixmapPriv::OriginToOrient(origin));
+ }
+ // fall through
case SkCodec::kIncompleteInput:
case SkCodec::kErrorInInput:
return true;