aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images/SkScaledBitmapSampler.h
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-01 17:27:15 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-01 17:27:15 +0000
commit8d2392487cd97e68c0a71da9fd5d2b42ecac5ec8 (patch)
treee7133b74f371352488ce900f9371bc68977ee1ea /src/images/SkScaledBitmapSampler.h
parent3702b2587cb18021d8efdd001ab3c9085f0ac51a (diff)
Add an option on SkImageDecoder to skip writing 0s.
Only implemented for PNG. Add a getter and setter, and sets the default to false in the constructor. Also copies the setting in copyFieldsToOther. Fix an indpendent bug where fDitherImage was not being copied in copyFieldsToOther. In SkScaledBitmapSampler::begin, consolidate the settings passed in by passing a const reference to the decoder. The decoder can be referenced for its settings of dither, unpremultiplied, and now skipping writing zeroes. Update callers to use the new API. In png decoder, rather than passing around a pointer to an initial read of getDitherImage, and potentially changing it, look at the field on the decoder itself, and modify it directly. This is a change in behavior - now if that same decoder is used to decode a different image, the dither setting has changed. I think this is okay because A) the typical use case is to use a new decoder for each decode, B) we do not make any promises that a decode does not change the decoder and C) it makes the code in SkScaledBitmapSampler much cleaner. In SkScaledBitmapScampler, add new row procs for skipping zeroes. Now that choosing the row proc has five dimensions (src config, dst config, dither, skip writing zeroes, unpremultiplied), use a new method: each src/dst combination has a function for choosing the right proc depending on the decoder. SkScaledBitmapScampler::RowProc is now public for convenience. Remove Sample_Gray_D8888_Unpremul, which is effectively no different from Sample_Gray_D8888. In cases where unpremultiplied was trivial, such as 565 and when sampling from gray, decoding may now succeed. Add a benchmark (currently disabled) for comparing the speed of skipping writing zeroes versus not skipping. For this particular image, which is mostly transparent pixels, normal decoding took about 3.6 milliseconds, while skipping zeroes in the decode took only about 2.5 milliseconds (this is on a Nexus 4). Presumably it would be slower on an image with a small amount of transparency, but there will be no slowdown for an image which reports that it has no transparency. In SkImageRef_ashmem, always skip writing zeroes, since ashmem memory is guaranteed to be initialized to 0. Add a flag to skip writing zeroes in skimage. Add a regression test for choosing the rowproc to ensure I did not change any behavior accidentally. BUG=skia:1661 R=reed@google.com Review URL: https://codereview.chromium.org/24269006 git-svn-id: http://skia.googlecode.com/svn/trunk@11558 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images/SkScaledBitmapSampler.h')
-rw-r--r--src/images/SkScaledBitmapSampler.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/images/SkScaledBitmapSampler.h b/src/images/SkScaledBitmapSampler.h
index 6477db2178..a293fe7ebb 100644
--- a/src/images/SkScaledBitmapSampler.h
+++ b/src/images/SkScaledBitmapSampler.h
@@ -10,6 +10,7 @@
#include "SkTypes.h"
#include "SkColor.h"
+#include "SkImageDecoder.h"
class SkBitmap;
@@ -35,12 +36,17 @@ public:
// 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, bool doDither,
- const SkPMColor* = NULL, bool requireUnPremul = false);
+ bool begin(SkBitmap* dst, SrcConfig sc, const SkImageDecoder& decoder,
+ const SkPMColor* = NULL);
// 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);
+ 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;
@@ -50,11 +56,6 @@ private:
int fDX; // step between X samples
int fDY; // step between Y samples
- typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
- const uint8_t* SK_RESTRICT src,
- int width, int deltaSrc, int y,
- const SkPMColor[]);
-
// setup state
char* fDstRow; // points into bitmap's pixels
size_t fDstRowBytes;
@@ -64,6 +65,11 @@ private:
// 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