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

Unified Diff: src/image/SkImage.cpp

Issue 15002004: add encodeData() to SkImageEncoder, and add encoding to SkImage (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 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 | « include/images/SkImageEncoder.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage.cpp
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 1169459df638d79d9a4262216f531274b139f402..13af631b2a9689815bfec462ac7864252821560a 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -9,6 +9,7 @@
#include "SkImagePriv.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
+#include "../images/SkImageEncoder.h"
SK_DEFINE_INST_COUNT(SkImage)
@@ -16,6 +17,10 @@ static SkImage_Base* asIB(SkImage* image) {
return static_cast<SkImage_Base*>(image);
}
+static const SkImage_Base* asIB(const SkImage* image) {
+ return static_cast<const SkImage_Base*>(image);
+}
+
uint32_t SkImage::NextUniqueID() {
static int32_t gUniqueID;
@@ -35,3 +40,29 @@ void SkImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
GrTexture* SkImage::getTexture() {
return asIB(this)->onGetTexture();
}
+
+static const struct {
+ SkImageEncoder::Type fIE;
+ SkImage::EncodeType fET;
+} gTable[] = {
+ { SkImageEncoder::kBMP_Type, SkImage::kBMP_EncodeType },
+ { SkImageEncoder::kGIF_Type, SkImage::kGIF_EncodeType },
+ { SkImageEncoder::kICO_Type, SkImage::kICO_EncodeType },
+ { SkImageEncoder::kJPEG_Type, SkImage::kJPEG_EncodeType },
+ { SkImageEncoder::kPNG_Type, SkImage::kPNG_EncodeType },
+ { SkImageEncoder::kWBMP_Type, SkImage::kWBMP_EncodeType },
+ { SkImageEncoder::kWEBP_Type, SkImage::kWEBP_EncodeType },
+};
+
+SkData* SkImage::encode(EncodeType et, int quality) const {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gTable); ++i) {
+ if (gTable[i].fET == et) {
+ SkBitmap bm;
+ if (asIB(this)->getROPixels(&bm)) {
+ return SkImageEncoder::EncodeData(bm, gTable[i].fIE, quality);
+ }
+ break;
+ }
+ }
+ return NULL;
+}
« no previous file with comments | « include/images/SkImageEncoder.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698