aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-06-22 12:48:26 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-22 12:48:26 -0700
commit871872f3f247f6b699617f6d9ef50ef5da6fbe74 (patch)
tree50358d6f699dd433607d9bc3c29da63e44c5d00f /include
parentc1f56b518218d1caa65d6b7101bebf0d28c02a92 (diff)
change old picture serialization to really handle images
Diffstat (limited to 'include')
-rw-r--r--include/c/sk_image.h2
-rw-r--r--include/c/sk_types.h7
-rw-r--r--include/core/SkImage.h43
-rw-r--r--include/core/SkPicture.h3
-rw-r--r--include/core/SkWriteBuffer.h2
5 files changed, 51 insertions, 6 deletions
diff --git a/include/c/sk_image.h b/include/c/sk_image.h
index 34682c72d3..c9973ac125 100644
--- a/include/c/sk_image.h
+++ b/include/c/sk_image.h
@@ -28,7 +28,7 @@ sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels,
* On success, the encoded data may be processed immediately, or it may be ref()'d for later
* use.
*/
-sk_image_t* sk_image_new_from_data(const sk_data_t* encoded);
+sk_image_t* sk_image_new_from_encoded(const sk_data_t* encoded, const sk_irect_t* subset);
sk_data_t* sk_image_encode(const sk_image_t*);
diff --git a/include/c/sk_types.h b/include/c/sk_types.h
index dc530f374b..00632e0af3 100644
--- a/include/c/sk_types.h
+++ b/include/c/sk_types.h
@@ -68,6 +68,13 @@ typedef struct {
} sk_point_t;
typedef struct {
+ int32_t left;
+ int32_t top;
+ int32_t right;
+ int32_t bottom;
+} sk_irect_t;
+
+typedef struct {
float left;
float top;
float right;
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 9d1c546ef5..062d13afe7 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -65,17 +65,27 @@ public:
* Construct a new SkImage based on the given ImageGenerator.
* This function will always take ownership of the passed
* ImageGenerator. Returns NULL on error.
+ *
+ * If a subset is specified, it must be contained within the generator's bounds.
*/
- static SkImage* NewFromGenerator(SkImageGenerator*);
+ static SkImage* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = NULL);
/**
* Construct a new SkImage based on the specified encoded data. Returns NULL on failure,
* which can mean that the format of the encoded data was not recognized/supported.
*
+ * If a subset is specified, it must be contained within the encoded data's bounds.
+ *
* Regardless of success or failure, the caller is responsible for managing their ownership
* of the data.
*/
- static SkImage* NewFromData(SkData* data);
+ static SkImage* NewFromEncoded(SkData* encoded, const SkIRect* subset = NULL);
+
+#ifdef SK_SUPPORT_LEGACY_IMAGE_NEWFROMDATA
+ static SkImage* NewFromData(SkData* data) {
+ return NewFromEncoded(data, NULL);
+ }
+#endif
/**
* Create a new image from the specified descriptor. Note - the caller is responsible for
@@ -151,6 +161,15 @@ public:
*/
const void* peekPixels(SkImageInfo* info, size_t* rowBytes) const;
+ /**
+ * If the image has direct access to its pixels (i.e. they are in local
+ * RAM) return the (const) address of those pixels, and if not null, return
+ * true, and if pixmap is not NULL, set it to point into the image.
+ *
+ * On failure, return false and ignore the pixmap parameter.
+ */
+ bool peekPixels(SkPixmap* pixmap) const;
+
// DEPRECATED
GrTexture* getTexture() const;
@@ -187,6 +206,8 @@ public:
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
int srcX, int srcY) const;
+ bool readPixels(const SkPixmap& dst, int srcX, int srcY) const;
+
/**
* Encode the image's pixels and return the result as a new SkData, which
* the caller must manage (i.e. call unref() when they are done).
@@ -194,8 +215,22 @@ public:
* If the image type cannot be encoded, or the requested encoder type is
* not supported, this will return NULL.
*/
- SkData* encode(SkImageEncoder::Type t = SkImageEncoder::kPNG_Type,
- int quality = 80) const;
+ SkData* encode(SkImageEncoder::Type, int quality) const;
+
+ SkData* encode() const {
+ return this->encode(SkImageEncoder::kPNG_Type, 100);
+ }
+
+ /**
+ * If the image already has its contents in encoded form (e.g. PNG or JPEG), return a ref
+ * to that data (which the caller must call unref() on). The caller is responsible for calling
+ * unref on the data when they are done.
+ *
+ * If the image does not already has its contents in encoded form, return NULL.
+ *
+ * Note: to force the image to return its contents as encoded data, try calling encode(...).
+ */
+ SkData* refEncoded() const;
/**
* Return a new surface that is compatible with this image's internal representation
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index fe99760f1d..358faf9524 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -175,10 +175,11 @@ private:
// V40: Remove UniqueID serialization from SkImageFilter.
// V41: Added serialization of SkBitmapSource's filterQuality parameter
// V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture?
+ // V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data
// Only SKPs within the min/current picture version range (inclusive) can be read.
static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M39.
- static const uint32_t CURRENT_PICTURE_VERSION = 42;
+ static const uint32_t CURRENT_PICTURE_VERSION = 43;
static_assert(MIN_PICTURE_VERSION <= 41,
"Remove kFontFileName and related code from SkFontDescriptor.cpp.");
diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h
index 39739f2c24..8e4607887d 100644
--- a/include/core/SkWriteBuffer.h
+++ b/include/core/SkWriteBuffer.h
@@ -73,6 +73,7 @@ public:
void writePath(const SkPath& path);
size_t writeStream(SkStream* stream, size_t length);
void writeBitmap(const SkBitmap& bitmap);
+ void writeImage(const SkImage*);
void writeTypeface(SkTypeface* typeface);
void writePaint(const SkPaint& paint) { paint.flatten(*this); }
@@ -106,6 +107,7 @@ public:
* be set to NULL in release and crash in debug.
*/
void setPixelSerializer(SkPixelSerializer*);
+ SkPixelSerializer* getPixelSerializer() const { return fPixelSerializer; }
private:
bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }