Move SkImage::encode to SkImage_Codec.cpp.

Chrome depends on SkImage.cpp, but does not include SkImageDecoder,
so having SkImage::encode in SkImage.cpp breaks chromium. Temporarily
fix the problem by moving the implementation into SkImage_Codec.cpp.

The larger fix will be to solve
https://code.google.com/p/skia/issues/detail?id=1275

R=reed@google.com, robertphillips@google.com

Author: scroggo@google.com

Review URL: https://chromiumcodereview.appspot.com/15314004

git-svn-id: http://skia.googlecode.com/svn/trunk@9204 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-05-20 23:57:38 +00:00
parent 73e4d5710b
commit 1f6aed0b1c
3 changed files with 38 additions and 29 deletions

View File

@ -65,6 +65,7 @@
'type': 'executable',
'sources': [
'../tools/skhello.cpp',
'../src/image/SkImage_Codec.cpp',
],
'dependencies': [
'skia_base_libs.gyp:skia_base_libs',

View File

@ -9,7 +9,6 @@
#include "SkImagePriv.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "../images/SkImageEncoder.h"
SK_DEFINE_INST_COUNT(SkImage)
@ -17,10 +16,6 @@ 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;
@ -41,28 +36,4 @@ 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;
}

View File

@ -64,3 +64,40 @@ SkImage* SkImage::NewEncodedData(SkData* data) {
return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height()));
}
///////////////////////////////////////////////////////////////////////////////
// FIXME: Temporarily move this here so chromium can still build until we truly
// fix the core/images dependency issue (https://code.google.com/p/skia/issues/detail?id=1275)
#include "SkImage.h"
#include "../images/SkImageEncoder.h"
static const SkImage_Base* asIB(const SkImage* image) {
return static_cast<const SkImage_Base*>(image);
}
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;
}