aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-01-23 05:58:07 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-23 05:58:07 -0800
commitf803da12cff1d9b6148fea319220351efebfd1e0 (patch)
tree12019eaec68c713363ef640ec26cf6beac721299 /include
parenta17241bd0a59efd6c30a007db8f10274b8f80f26 (diff)
add newImage API
BUG=skia:3277 related bug: skbug.com/3276 Review URL: https://codereview.chromium.org/821083002
Diffstat (limited to 'include')
-rw-r--r--include/core/SkFilterQuality.h24
-rw-r--r--include/core/SkImage.h22
-rw-r--r--include/core/SkPaint.h36
3 files changed, 75 insertions, 7 deletions
diff --git a/include/core/SkFilterQuality.h b/include/core/SkFilterQuality.h
new file mode 100644
index 0000000000..db0597e697
--- /dev/null
+++ b/include/core/SkFilterQuality.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkFilterQuality_DEFINED
+#define SkFilterQuality_DEFINED
+
+#include "SkTypes.h"
+
+/**
+ * Controls how much filtering to be done when scaling/transforming complex colors
+ * e.g. images
+ */
+enum SkFilterQuality {
+ kNone_SkFilterQuality, //!< fastest but lowest quality, typically nearest-neighbor
+ kLow_SkFilterQuality, //!< typically bilerp
+ kMedium_SkFilterQuality, //!< typically bilerp + mipmaps for down-scaling
+ kHigh_SkFilterQuality //!< slowest but highest quality, typically bicubic or better
+};
+
+#endif
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 8d65870dc0..b0587b2c3a 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -8,6 +8,7 @@
#ifndef SkImage_DEFINED
#define SkImage_DEFINED
+#include "SkFilterQuality.h"
#include "SkImageInfo.h"
#include "SkImageEncoder.h"
#include "SkRefCnt.h"
@@ -132,6 +133,27 @@ public:
const char* toString(SkString*) const;
+ /**
+ * Return an image that is a rescale of this image (using newWidth, newHeight).
+ *
+ * If subset is NULL, then the entire original image is used as the src for the scaling.
+ * If subset is not NULL, then it specifies subset of src-pixels used for scaling. If
+ * subset extends beyond the bounds of the original image, then NULL is returned.
+ *
+ * Notes:
+ * - newWidth and newHeight must be > 0 or NULL will be returned.
+ *
+ * - it is legal for the returned image to be the same instance as the src image
+ * (if the new dimensions == the src dimensions and subset is NULL or == src dimensions).
+ *
+ * - it is legal for the "scaled" image to have changed its SkAlphaType from unpremul
+ * to premul (as required by the impl). The image should draw (nearly) identically,
+ * since during drawing we will "apply the alpha" to the pixels. Future optimizations
+ * may take away this caveat, preserving unpremul.
+ */
+ SkImage* newImage(int newWidth, int newHeight, const SkIRect* subset = NULL,
+ SkFilterQuality = kNone_SkFilterQuality) const;
+
protected:
SkImage(int width, int height) :
fWidth(width),
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 68220f65c9..fef4319477 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -10,9 +10,13 @@
#include "SkColor.h"
#include "SkDrawLooper.h"
+#include "SkFilterQuality.h"
#include "SkMatrix.h"
#include "SkXfermode.h"
+// TODO: clean up Skia internals so we can remove this and only keep it for clients
+#define SK_SUPPORT_LEGACY_FILTERLEVEL_ENUM
+
class SkAnnotation;
class SkAutoGlyphCache;
class SkColorFilter;
@@ -294,11 +298,12 @@ public:
*/
void setDistanceFieldTextTEMP(bool distanceFieldText);
+#ifdef SK_SUPPORT_LEGACY_FILTERLEVEL_ENUM
enum FilterLevel {
- kNone_FilterLevel,
- kLow_FilterLevel,
- kMedium_FilterLevel,
- kHigh_FilterLevel
+ kNone_FilterLevel = kNone_SkFilterQuality,
+ kLow_FilterLevel = kLow_SkFilterQuality,
+ kMedium_FilterLevel = kMedium_SkFilterQuality,
+ kHigh_FilterLevel = kHigh_SkFilterQuality
};
/**
@@ -306,14 +311,31 @@ public:
* drawing scaled images.
*/
FilterLevel getFilterLevel() const {
- return (FilterLevel)fBitfields.fFilterLevel;
+ return (FilterLevel)this->getFilterQuality();
}
/**
* Set the filter level. This affects the quality (and performance) of
* drawing scaled images.
*/
- void setFilterLevel(FilterLevel);
+ void setFilterLevel(FilterLevel level) {
+ this->setFilterQuality((SkFilterQuality)level);
+ }
+#endif
+
+ /**
+ * Return the filter level. This affects the quality (and performance) of
+ * drawing scaled images.
+ */
+ SkFilterQuality getFilterQuality() const {
+ return (SkFilterQuality)fBitfields.fFilterQuality;
+ }
+
+ /**
+ * Set the filter quality. This affects the quality (and performance) of
+ * drawing scaled images.
+ */
+ void setFilterQuality(SkFilterQuality quality);
/**
* If the predicate is true, set the filterLevel to Low, else set it to
@@ -1040,7 +1062,7 @@ private:
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
- unsigned fFilterLevel : 2;
+ unsigned fFilterQuality : 2;
//unsigned fFreeBits : 2;
} fBitfields;
uint32_t fBitfieldsUInt;