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

Unified Diff: src/images/SkScaledBitmapSampler.h

Issue 1830943002: Revert of Delete SkImageDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@fix-animator
Patch Set: Created 4 years, 9 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 | « src/images/SkJpegUtility.cpp ('k') | src/images/SkScaledBitmapSampler.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkScaledBitmapSampler.h
diff --git a/src/images/SkScaledBitmapSampler.h b/src/images/SkScaledBitmapSampler.h
new file mode 100644
index 0000000000000000000000000000000000000000..198dc07572c0dcf9b920ab08504d16814a4e7ec0
--- /dev/null
+++ b/src/images/SkScaledBitmapSampler.h
@@ -0,0 +1,107 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkScaledBitmapSampler_DEFINED
+#define SkScaledBitmapSampler_DEFINED
+
+#include "SkTypes.h"
+#include "SkColor.h"
+#include "SkImageDecoder.h"
+
+class SkBitmap;
+
+class SkScaledBitmapSampler {
+public:
+ SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize);
+
+ int scaledWidth() const { return fScaledWidth; }
+ int scaledHeight() const { return fScaledHeight; }
+
+ int srcY0() const { return fY0; }
+ int srcDX() const { return fDX; }
+ int srcDY() const { return fDY; }
+
+ enum SrcConfig {
+ kGray, // 1 byte per pixel
+ kIndex, // 1 byte per pixel
+ kRGB, // 3 bytes per pixel
+ kRGBX, // 4 byes per pixel (ignore 4th)
+ kRGBA, // 4 bytes per pixel
+ kRGB_565 // 2 bytes per pixel
+ };
+
+ struct Options {
+ bool fDither;
+ bool fPremultiplyAlpha;
+ bool fSkipZeros;
+ explicit Options(const SkImageDecoder &dec)
+ : fDither(dec.getDitherImage())
+ , fPremultiplyAlpha(!dec.getRequireUnpremultipliedColors())
+ , fSkipZeros(dec.getSkipWritingZeroes())
+ { }
+ };
+
+ // Given a dst bitmap (with pixels already allocated) and a src-config,
+ // prepares iterator to process the src colors and write them into dst.
+ // Returns false if the request cannot be fulfulled.
+ bool begin(SkBitmap* dst, SrcConfig sc, const SkImageDecoder& decoder,
+ const SkPMColor* = nullptr);
+ bool begin(SkBitmap* dst, SrcConfig sc, const Options& opts,
+ const SkPMColor* = nullptr);
+ // call with row of src pixels, for y = 0...scaledHeight-1.
+ // returns true if the row had non-opaque alpha in it
+ bool next(const uint8_t* SK_RESTRICT src);
+
+ // Like next(), but specifies the y value of the source row, so the
+ // rows can come in any order. If the row is not part of the output
+ // sample, it will be skipped. Only sampleInterlaced OR next should
+ // be called for one SkScaledBitmapSampler.
+ bool sampleInterlaced(const uint8_t* SK_RESTRICT src, int srcY);
+
+ typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
+ const uint8_t* SK_RESTRICT src,
+ int width, int deltaSrc, int y,
+ const SkPMColor[]);
+
+private:
+ int fScaledWidth;
+ int fScaledHeight;
+
+ int fX0; // first X coord to sample
+ int fY0; // first Y coord (scanline) to sample
+ int fDX; // step between X samples
+ int fDY; // step between Y samples
+
+#ifdef SK_DEBUG
+ // Keep track of whether the caller is using next or sampleInterlaced.
+ // Only one can be used per sampler.
+ enum SampleMode {
+ kUninitialized_SampleMode,
+ kConsecutive_SampleMode,
+ kInterlaced_SampleMode,
+ };
+
+ SampleMode fSampleMode;
+#endif
+
+ // setup state
+ char* fDstRow; // points into bitmap's pixels
+ size_t fDstRowBytes;
+ int fCurrY; // used for dithering
+ int fSrcPixelSize; // 1, 3, 4
+ RowProc fRowProc;
+
+ // optional reference to the src colors if the src is a palette model
+ const SkPMColor* fCTable;
+
+#ifdef SK_DEBUG
+ // Helper class allowing a test to have access to fRowProc.
+ friend class RowProcTester;
+#endif
+};
+
+#endif
« no previous file with comments | « src/images/SkJpegUtility.cpp ('k') | src/images/SkScaledBitmapSampler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698