diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-01-06 20:16:26 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-01-06 20:16:26 +0000 |
commit | b08eb2b3bce45411494fe00258e4c91248ccd15e (patch) | |
tree | b20617e02fa260e8b09114a72bee7f2ade789323 | |
parent | 092590b88dd87d2fca87d38b2003068ffef37f2f (diff) |
separate image encode and decode
remove obsolete build-flag for encode
git-svn-id: http://skia.googlecode.com/svn/trunk@56 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkPreConfig.h | 6 | ||||
-rw-r--r-- | include/images/SkImageDecoder.h | 32 | ||||
-rw-r--r-- | include/images/SkImageEncoder.h | 36 | ||||
-rw-r--r-- | samplecode/SampleApp.cpp | 4 | ||||
-rw-r--r-- | samplecode/SampleEncode.cpp | 4 | ||||
-rw-r--r-- | samplecode/SampleRegion.cpp | 22 | ||||
-rw-r--r-- | src/animator/SkSnapshot.cpp | 3 | ||||
-rw-r--r-- | src/animator/SkSnapshot.h | 3 | ||||
-rw-r--r-- | src/images/SkImageDecoder.cpp | 33 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libjpeg.cpp | 5 | ||||
-rw-r--r-- | src/images/SkImageDecoder_libpng.cpp | 4 | ||||
-rw-r--r-- | src/images/SkImageEncoder.cpp | 48 | ||||
-rw-r--r-- | src/ports/SkImageDecoder_CG.cpp | 4 | ||||
-rw-r--r-- | src/ports/SkImageDecoder_Factory.cpp | 19 | ||||
-rw-r--r-- | src/ports/SkImageDecoder_empty.cpp | 3 | ||||
-rw-r--r-- | src/ports/SkImageEncoder_Factory.cpp | 32 | ||||
-rw-r--r-- | src/xml/SkJSDisplayable.cpp | 4 | ||||
-rw-r--r-- | xcode/maccore/maccore.xcodeproj/project.pbxproj | 4 |
18 files changed, 127 insertions, 139 deletions
diff --git a/include/core/SkPreConfig.h b/include/core/SkPreConfig.h index 04f1987738..b8c91b2ad6 100644 --- a/include/core/SkPreConfig.h +++ b/include/core/SkPreConfig.h @@ -96,12 +96,6 @@ ////////////////////////////////////////////////////////////////////// // Conditional features based on build target -#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) - #ifndef SK_BUILD_NO_IMAGE_ENCODE - #define SK_SUPPORT_IMAGE_ENCODE - #endif -#endif - #ifdef SK_BUILD_FOR_SYMBIAN #define SK_USE_RUNTIME_GLOBALS #endif diff --git a/include/images/SkImageDecoder.h b/include/images/SkImageDecoder.h index 4a18cab594..5b91c51fdd 100644 --- a/include/images/SkImageDecoder.h +++ b/include/images/SkImageDecoder.h @@ -266,36 +266,4 @@ private: SkImageDecoder& operator=(const SkImageDecoder&); }; -#ifdef SK_SUPPORT_IMAGE_ENCODE - -class SkWStream; - -class SkImageEncoder { -public: - enum Type { - kJPEG_Type, - kPNG_Type - }; - static SkImageEncoder* Create(Type); - - virtual ~SkImageEncoder(); - - /* Quality ranges from 0..100 */ - - bool encodeFile(const char file[], const SkBitmap&, int quality = 80); - bool encodeStream(SkWStream*, const SkBitmap&, int quality = 80); - - static bool EncodeFile(const char file[], const SkBitmap&, Type, - int quality = 80); - static bool EncodeStream(SkWStream*, const SkBitmap&, Type, - int quality = 80); - -protected: - virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0; -}; - -#endif /* SK_SUPPORT_IMAGE_ENCODE */ - -/////////////////////////////////////////////////////////////////////// - #endif diff --git a/include/images/SkImageEncoder.h b/include/images/SkImageEncoder.h new file mode 100644 index 0000000000..94989c0843 --- /dev/null +++ b/include/images/SkImageEncoder.h @@ -0,0 +1,36 @@ +#ifndef SkImageEncoder_DEFINED +#define SkImageEncoder_DEFINED + +#include "SkTypes.h" + +class SkBitmap; +class SkWStream; + +class SkImageEncoder { +public: + enum Type { + kJPEG_Type, + kPNG_Type + }; + static SkImageEncoder* Create(Type); + + virtual ~SkImageEncoder(); + + /* Quality ranges from 0..100 */ + enum { + kDefaultQuality = 80 + }; + + bool encodeFile(const char file[], const SkBitmap&, int quality); + bool encodeStream(SkWStream*, const SkBitmap&, int quality); + + static bool EncodeFile(const char file[], const SkBitmap&, Type, + int quality); + static bool EncodeStream(SkWStream*, const SkBitmap&, Type, + int quality); + +protected: + virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0; +}; + +#endif diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index df0723f3e1..0d2bbbc23b 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -2,7 +2,7 @@ #include "SkDevice.h" #include "SkGLCanvas.h" #include "SkGraphics.h" -#include "SkImageDecoder.h" +#include "SkImageEncoder.h" #include "SkPaint.h" #include "SkPicture.h" #include "SkStream.h" @@ -438,7 +438,7 @@ bool SampleWindow::onHandleChar(SkUnichar uni) { cleanup_for_filename(&name); name.append(".png"); if (SkImageEncoder::EncodeFile(name.c_str(), this->getBitmap(), - SkImageEncoder::kPNG_Type)) { + SkImageEncoder::kPNG_Type, 100)) { SkDebugf("Created %s\n", name.c_str()); } return true; diff --git a/samplecode/SampleEncode.cpp b/samplecode/SampleEncode.cpp index e36ab429ec..e4197bf0c7 100644 --- a/samplecode/SampleEncode.cpp +++ b/samplecode/SampleEncode.cpp @@ -3,7 +3,7 @@ #include "SkCanvas.h" #include "SkGradientShader.h" #include "SkGraphics.h" -#include "SkImageDecoder.h" +#include "SkImageEncoder.h" #include "SkPath.h" #include "SkPorterDuff.h" #include "SkRegion.h" @@ -129,7 +129,7 @@ public: remove(path.c_str()); SkImageEncoder* codec = SkImageEncoder::Create(gTypes[j]); - if (!codec->encodeFile(path.c_str(), fBitmaps[i])) { + if (!codec->encodeFile(path.c_str(), fBitmaps[i], 100)) { SkDebugf("------ failed to encode %s\n", path.c_str()); remove(path.c_str()); // remove any partial file } diff --git a/samplecode/SampleRegion.cpp b/samplecode/SampleRegion.cpp index 8958c82d88..d3fe062bf2 100644 --- a/samplecode/SampleRegion.cpp +++ b/samplecode/SampleRegion.cpp @@ -279,28 +279,6 @@ protected: canvas->translate(SkIntToScalar(200), 0); } - - if (false) - { - SkBitmap bitmap; - - bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); - bitmap.allocPixels(); - bitmap.eraseColor(0); - - SkCanvas canvas(bitmap); - SkPaint paint; - SkRect r; - - paint.setAntiAlias(true); - paint.setARGB(0xFF, 0xFF, 0, 0xFF); - r.set(0, 0, SkIntToScalar(100), SkIntToScalar(100)); - canvas.drawOval(r, paint); - - SkImageEncoder* en = SkImageEncoder::Create(SkImageEncoder::kPNG_Type); - en->encodeFile("testfile.png", bitmap); - delete en; - } } virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) diff --git a/src/animator/SkSnapshot.cpp b/src/animator/SkSnapshot.cpp index b65c517b73..0043ca5bd5 100644 --- a/src/animator/SkSnapshot.cpp +++ b/src/animator/SkSnapshot.cpp @@ -17,8 +17,6 @@ #include "SkTypes.h" -#ifdef SK_SUPPORT_IMAGE_ENCODE - #include "SkSnapshot.h" #include "SkAnimateMaker.h" #include "SkCanvas.h" @@ -71,4 +69,3 @@ bool SkSnapshot::draw(SkAnimateMaker& maker) { return false; } -#endif diff --git a/src/animator/SkSnapshot.h b/src/animator/SkSnapshot.h index c459fbbcef..7392edc3d8 100644 --- a/src/animator/SkSnapshot.h +++ b/src/animator/SkSnapshot.h @@ -18,8 +18,6 @@ #ifndef SkSnapShot_DEFINED #define SkSnapShot_DEFINED -#ifdef SK_SUPPORT_IMAGE_ENCODE - #include "SkDrawable.h" #include "SkImageDecoder.h" #include "SkMemberInfo.h" @@ -37,6 +35,5 @@ class SkSnapshot: public SkDrawable { int fSeqVal; }; -#endif // SK_SUPPORT_IMAGE_ENCODE #endif // SkSnapShot_DEFINED diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index 18b52d689c..2d477ef4aa 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -155,36 +155,3 @@ bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm, return success; } -/////////////////////////////////////////////////////////////////////////////// - -#ifdef SK_SUPPORT_IMAGE_ENCODE - -SkImageEncoder::~SkImageEncoder() {} - -bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm, - int quality) { - quality = SkMin32(100, SkMax32(0, quality)); - return this->onEncode(stream, bm, quality); -} - -bool SkImageEncoder::encodeFile(const char file[], const SkBitmap& bm, - int quality) { - quality = SkMin32(100, SkMax32(0, quality)); - SkFILEWStream stream(file); - return this->onEncode(&stream, bm, quality); -} - -bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, - int quality) { - SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); - return enc.get() && enc.get()->encodeFile(file, bm, quality); -} - -bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t, - int quality) { - SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); - return enc.get() && enc.get()->encodeStream(stream, bm, quality); -} - -#endif - diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp index 492de2374f..51339971ac 100644 --- a/src/images/SkImageDecoder_libjpeg.cpp +++ b/src/images/SkImageDecoder_libjpeg.cpp @@ -15,6 +15,7 @@ */ #include "SkImageDecoder.h" +#include "SkImageEncoder.h" #include "SkColorPriv.h" #include "SkDither.h" #include "SkScaledBitmapSampler.h" @@ -501,8 +502,6 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, /////////////////////////////////////////////////////////////////////////////// -#ifdef SK_SUPPORT_IMAGE_ENCODE - #include "SkColorPriv.h" // taken from jcolor.c in libjpeg @@ -795,8 +794,6 @@ SkImageEncoder* SkImageEncoder_JPEG_Factory() { return SkNEW(SkJPEGImageEncoder); } -#endif /* SK_SUPPORT_IMAGE_ENCODE */ - ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 862ebf1d98..1371ecc77d 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -16,6 +16,7 @@ */ #include "SkImageDecoder.h" +#include "SkImageEncoder.h" #include "SkColor.h" #include "SkColorPriv.h" #include "SkDither.h" @@ -443,8 +444,6 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap, /////////////////////////////////////////////////////////////////////////////// -#ifdef SK_SUPPORT_IMAGE_ENCODE - #include "SkColorPriv.h" #include "SkUnPreMultiply.h" @@ -792,4 +791,3 @@ SkImageEncoder* SkImageEncoder_PNG_Factory() { return SkNEW(SkPNGImageEncoder); } -#endif /* SK_SUPPORT_IMAGE_ENCODE */ diff --git a/src/images/SkImageEncoder.cpp b/src/images/SkImageEncoder.cpp new file mode 100644 index 0000000000..d3599059d9 --- /dev/null +++ b/src/images/SkImageEncoder.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SkImageEncoder.h" +#include "SkBitmap.h" +#include "SkStream.h" +#include "SkTemplates.h" + +SkImageEncoder::~SkImageEncoder() {} + +bool SkImageEncoder::encodeStream(SkWStream* stream, const SkBitmap& bm, + int quality) { + quality = SkMin32(100, SkMax32(0, quality)); + return this->onEncode(stream, bm, quality); +} + +bool SkImageEncoder::encodeFile(const char file[], const SkBitmap& bm, + int quality) { + quality = SkMin32(100, SkMax32(0, quality)); + SkFILEWStream stream(file); + return this->onEncode(&stream, bm, quality); +} + +bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, + int quality) { + SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); + return enc.get() && enc.get()->encodeFile(file, bm, quality); +} + +bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t, + int quality) { + SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t)); + return enc.get() && enc.get()->encodeStream(stream, bm, quality); +} + diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp index 74ff11285f..5594eac91a 100644 --- a/src/ports/SkImageDecoder_CG.cpp +++ b/src/ports/SkImageDecoder_CG.cpp @@ -15,6 +15,7 @@ #include <Carbon/Carbon.h> #include "SkImageDecoder.h" +#include "SkImageEncoder.h" #include "SkMovie.h" #include "SkStream.h" #include "SkTemplates.h" @@ -105,8 +106,6 @@ SkMovie* SkMovie::DecodeStream(SkStream* stream) { ///////////////////////////////////////////////////////////////////////// -#ifdef SK_SUPPORT_IMAGE_ENCODE - static size_t consumer_put(void* info, const void* buffer, size_t count) { SkWStream* stream = reinterpret_cast<SkWStream*>(info); return stream->write(buffer, count) ? count : 0; @@ -195,4 +194,3 @@ SkImageEncoder* SkImageEncoder::Create(Type t) { return SkNEW_ARGS(SkImageEncoder_CG, (t)); } -#endif diff --git a/src/ports/SkImageDecoder_Factory.cpp b/src/ports/SkImageDecoder_Factory.cpp index d0053cfac0..5c45a43ec5 100644 --- a/src/ports/SkImageDecoder_Factory.cpp +++ b/src/ports/SkImageDecoder_Factory.cpp @@ -83,22 +83,3 @@ SkMovie* SkMovie::DecodeStream(SkStream* stream) { return NULL; } -///////////////////////////////////////////////////////////////////////// - -#ifdef SK_SUPPORT_IMAGE_ENCODE - -extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); -extern SkImageEncoder* SkImageEncoder_PNG_Factory(); - -SkImageEncoder* SkImageEncoder::Create(Type t) { - switch (t) { - case kJPEG_Type: - return SkImageEncoder_JPEG_Factory(); - case kPNG_Type: - return SkImageEncoder_PNG_Factory(); - default: - return NULL; - } -} - -#endif diff --git a/src/ports/SkImageDecoder_empty.cpp b/src/ports/SkImageDecoder_empty.cpp index 45eb346115..740af7dbb2 100644 --- a/src/ports/SkImageDecoder_empty.cpp +++ b/src/ports/SkImageDecoder_empty.cpp @@ -89,8 +89,6 @@ SkMovie* SkMovie::DecodeStream(SkStream* stream) { ///////////////////////////////////////////////////////////////////////// -#ifdef SK_SUPPORT_IMAGE_ENCODE - extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); extern SkImageEncoder* SkImageEncoder_PNG_Factory(); @@ -107,4 +105,3 @@ SkImageEncoder* SkImageEncoder::Create(Type t) { } } -#endif diff --git a/src/ports/SkImageEncoder_Factory.cpp b/src/ports/SkImageEncoder_Factory.cpp new file mode 100644 index 0000000000..cdd7c0409f --- /dev/null +++ b/src/ports/SkImageEncoder_Factory.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2009, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SkImageEncoder.h" + +extern SkImageEncoder* SkImageEncoder_JPEG_Factory(); +extern SkImageEncoder* SkImageEncoder_PNG_Factory(); + +SkImageEncoder* SkImageEncoder::Create(Type t) { + switch (t) { + case kJPEG_Type: + return SkImageEncoder_JPEG_Factory(); + case kPNG_Type: + return SkImageEncoder_PNG_Factory(); + default: + return NULL; + } +} + diff --git a/src/xml/SkJSDisplayable.cpp b/src/xml/SkJSDisplayable.cpp index d52a7c98f0..848b9f97dd 100644 --- a/src/xml/SkJSDisplayable.cpp +++ b/src/xml/SkJSDisplayable.cpp @@ -179,9 +179,7 @@ JS_INIT(Sk, Set) JS_INIT(Sk, Skew) // JS_INIT(Sk, 3D_Camera) // JS_INIT(Sk, 3D_Patch) -#ifdef SK_SUPPORT_IMAGE_ENCODE JS_INIT(Sk, Snapshot) -#endif // JS_INIT(SkDraw, Stroke) JS_INIT(Sk, Text) JS_INIT(Sk, TextOnPath) @@ -451,9 +449,7 @@ void SkJS::InitializeDisplayables(const SkBitmap& bitmap, JSContext *cx, JSObjec SkewInit(cx, obj, proto); // 3D_CameraInit(cx, obj, proto); // 3D_PatchInit(cx, obj, proto); - #ifdef SK_SUPPORT_IMAGE_ENCODE SnapshotInit(cx, obj, proto); - #endif // StrokeInit(cx, obj, proto); TextInit(cx, obj, proto); TextOnPathInit(cx, obj, proto); diff --git a/xcode/maccore/maccore.xcodeproj/project.pbxproj b/xcode/maccore/maccore.xcodeproj/project.pbxproj index 30bf7683f2..4b84b4375f 100644 --- a/xcode/maccore/maccore.xcodeproj/project.pbxproj +++ b/xcode/maccore/maccore.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 001EA8910F13F2CE00900BA9 /* SkImageEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 001EA8900F13F2CE00900BA9 /* SkImageEncoder.cpp */; }; 002884A50EFAB5DE0083E387 /* SkOSFile_stdio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 002884A20EFAB5DE0083E387 /* SkOSFile_stdio.cpp */; }; 002884A60EFAB5DE0083E387 /* SkThread_pthread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 002884A30EFAB5DE0083E387 /* SkThread_pthread.cpp */; }; 002884A70EFAB5DE0083E387 /* SkTime_Unix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 002884A40EFAB5DE0083E387 /* SkTime_Unix.cpp */; }; @@ -18,6 +19,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 001EA8900F13F2CE00900BA9 /* SkImageEncoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkImageEncoder.cpp; path = ../../src/images/SkImageEncoder.cpp; sourceTree = SOURCE_ROOT; }; 002884A20EFAB5DE0083E387 /* SkOSFile_stdio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkOSFile_stdio.cpp; path = ../../src/ports/SkOSFile_stdio.cpp; sourceTree = SOURCE_ROOT; }; 002884A30EFAB5DE0083E387 /* SkThread_pthread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkThread_pthread.cpp; path = ../../src/ports/SkThread_pthread.cpp; sourceTree = SOURCE_ROOT; }; 002884A40EFAB5DE0083E387 /* SkTime_Unix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkTime_Unix.cpp; path = ../../src/ports/SkTime_Unix.cpp; sourceTree = SOURCE_ROOT; }; @@ -74,6 +76,7 @@ 27739F280F11405800F233EA /* Images */ = { isa = PBXGroup; children = ( + 001EA8900F13F2CE00900BA9 /* SkImageEncoder.cpp */, 27739F2E0F11409100F233EA /* SkImageDecoder_CG.cpp */, 27739F2C0F11408100F233EA /* SkImageDecoder.cpp */, 27739F2A0F11407000F233EA /* SkCreateCGImageRef.cpp */, @@ -148,6 +151,7 @@ 27739F2B0F11407000F233EA /* SkCreateCGImageRef.cpp in Sources */, 27739F2D0F11408100F233EA /* SkImageDecoder.cpp in Sources */, 27739F2F0F11409100F233EA /* SkImageDecoder_CG.cpp in Sources */, + 001EA8910F13F2CE00900BA9 /* SkImageEncoder.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |