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

Unified Diff: src/codec/SkCodecPriv.h

Issue 1287423002: Scanline decoding for bmp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows errors Created 5 years, 4 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/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodec_libgif.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodecPriv.h
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
index 9a28cfdda1690df3268b02198930bd8db2144135..726074195daf23d787c0187520baa9a4a97e1e86 100644
--- a/src/codec/SkCodecPriv.h
+++ b/src/codec/SkCodecPriv.h
@@ -30,6 +30,45 @@
#define COMPUTE_RESULT_ALPHA \
SkSwizzler::GetResult(zeroAlpha, maxAlpha);
+/*
+ * Returns the first coordinate that we will keep during a scaled decode.
+ * The output can be interpreted as an x-coordinate or a y-coordinate.
+ *
+ * This does not need to be called and is not called when sampleFactor == 1.
+ */
+static int get_start_coord(int sampleFactor) { return sampleFactor / 2; };
+
+/*
+ * Given a coordinate in the original image, this returns the corresponding
+ * coordinate in the scaled image. This function is meaningless if
+ * IsCoordNecessary returns false.
+ * The output can be interpreted as an x-coordinate or a y-coordinate.
+ *
+ * This does not need to be called and is not called when sampleFactor == 1.
+ */
+static int get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sampleFactor; };
+
+/*
+ * When scaling, we will discard certain y-coordinates (rows) and
+ * x-coordinates (columns). This function returns true if we should keep the
+ * coordinate and false otherwise.
+ * The inputs may be x-coordinates or y-coordinates.
+ *
+ * This does not need to be called and is not called when sampleFactor == 1.
+ */
+static bool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) {
+ // Get the first coordinate that we want to keep
+ int startCoord = get_start_coord(sampleFactor);
+
+ // Return false on edge cases
+ if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaledDim) {
+ return false;
+ }
+
+ // Every sampleFactor rows are necessary
+ return ((srcCoord - startCoord) % sampleFactor) == 0;
+}
+
static inline bool valid_alpha(SkAlphaType dstAlpha, SkAlphaType srcAlpha) {
// Check for supported alpha types
if (srcAlpha != dstAlpha) {
@@ -132,6 +171,23 @@ static inline size_t compute_row_bytes(int width, uint32_t bitsPerPixel) {
}
/*
+ * On incomplete images, get the color to fill with
+ */
+static inline SkPMColor get_fill_color_or_index(SkAlphaType alphaType) {
+ // This condition works properly for all supported output color types.
+ // kIndex8: The low 8-bits of both possible return values is 0, which is
+ // our desired default index.
+ // kGray8: The low 8-bits of both possible return values is 0, which is
+ // black, our desired fill value.
+ // kRGB565: The low 16-bits of both possible return values is 0, which is
+ // black, our desired fill value.
+ // kN32: Return black for opaque images and transparent for non-opaque
+ // images.
+ return kOpaque_SkAlphaType == alphaType ?
+ SK_ColorBLACK : SK_ColorTRANSPARENT;
+}
+
+/*
* Get a byte from a buffer
* This method is unsafe, the caller is responsible for performing a check
*/
« no previous file with comments | « src/codec/SkBmpStandardCodec.cpp ('k') | src/codec/SkCodec_libgif.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698