diff options
author | Derek Sollenberger <djsollen@google.com> | 2012-01-18 08:56:56 -0500 |
---|---|---|
committer | Derek Sollenberger <derek@android.com> | 2012-02-06 14:14:40 -0500 |
commit | 1cab2921ab279367f8206cdadc9259d12e603548 (patch) | |
tree | 2852f9dc2481f639122e18fc7831ae6ca43d6d5a /src/images | |
parent | d7176fd5571bc9878d3cdac8696eaa35ec170d9d (diff) | |
download | external_skia-1cab2921ab279367f8206cdadc9259d12e603548.zip external_skia-1cab2921ab279367f8206cdadc9259d12e603548.tar.gz external_skia-1cab2921ab279367f8206cdadc9259d12e603548.tar.bz2 |
Skia merge (revision 3022)
This CL has companion changes to account for API updates in...
(1) frameworks/base
(2) external/webkit
Change-Id: Ibb989e76e8bd24313849f9631dbef42cdef9eb7d
Diffstat (limited to 'src/images')
28 files changed, 204 insertions, 677 deletions
diff --git a/src/images/SkBitmap_RLEPixels.h b/src/images/SkBitmap_RLEPixels.h index c83bc69..dfe83a2 100644 --- a/src/images/SkBitmap_RLEPixels.h +++ b/src/images/SkBitmap_RLEPixels.h @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #ifndef SkBitmap_RLEPixels_DEFINED #define SkBitmap_RLEPixels_DEFINED diff --git a/src/images/SkCreateRLEPixelRef.cpp b/src/images/SkCreateRLEPixelRef.cpp index a3bf5bc..44652be 100644 --- a/src/images/SkCreateRLEPixelRef.cpp +++ b/src/images/SkCreateRLEPixelRef.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkChunkAlloc.h" #include "SkPackBits.h" #include "SkBitmap.h" diff --git a/src/images/SkFDStream.cpp b/src/images/SkFDStream.cpp index db4a51a..e1e214a 100644 --- a/src/images/SkFDStream.cpp +++ b/src/images/SkFDStream.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkStream.h" #include <unistd.h> diff --git a/src/images/SkFlipPixelRef.cpp b/src/images/SkFlipPixelRef.cpp index 39e1a12..e81c83c 100644 --- a/src/images/SkFlipPixelRef.cpp +++ b/src/images/SkFlipPixelRef.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkFlipPixelRef.h" #include "SkFlattenable.h" #include "SkRegion.h" @@ -74,8 +81,7 @@ SkPixelRef* SkFlipPixelRef::Create(SkFlattenableReadBuffer& buffer) { return SkNEW_ARGS(SkFlipPixelRef, (buffer)); } -static SkPixelRef::Registrar reg("SkFlipPixelRef", - SkFlipPixelRef::Create); +SK_DEFINE_PIXEL_REF_REGISTRAR(SkFlipPixelRef) /////////////////////////////////////////////////////////////////////////////// diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index 4a790d5..ee0d6cc 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -1,19 +1,11 @@ -/* libs/graphics/images/SkImageDecoder.cpp -** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkImageDecoder.h" #include "SkBitmap.h" @@ -234,8 +226,8 @@ bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, if (stream.isValid()) { if (SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format)) { bm->pixelRef()->setURI(file); + return true; } - return true; } return false; } diff --git a/src/images/SkImageDecoder_Factory.cpp b/src/images/SkImageDecoder_Factory.cpp index e5ff395..f3cb120 100644 --- a/src/images/SkImageDecoder_Factory.cpp +++ b/src/images/SkImageDecoder_Factory.cpp @@ -1,19 +1,11 @@ -/* libs/graphics/ports/SkImageDecoder_Factory.cpp -** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkImageDecoder.h" #include "SkMovie.h" diff --git a/src/images/SkImageDecoder_fpdfemb.cpp b/src/images/SkImageDecoder_fpdfemb.cpp deleted file mode 100644 index 7f37e3d..0000000 --- a/src/images/SkImageDecoder_fpdfemb.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright 2007, 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 "SkImageDecoder.h" -#include "SkScaledBitmapSampler.h" -#include "SkStream.h" -#include "SkColorPriv.h" -#include "SkTDArray.h" - -#include "fpdfemb.h" - -class SkFPDFEMBImageDecoder : public SkImageDecoder { -public: - SkFPDFEMBImageDecoder() {} - - virtual Format getFormat() const { - return kBMP_Format; - } - -protected: - virtual bool onDecode(SkStream* stream, SkBitmap* bm, - SkBitmap::Config pref, Mode mode); - -private: - bool render(FPDFEMB_PAGE page, const FPDFEMB_RECT& bounds, SkBitmap* bm, - SkBitmap::Config prefConfig, SkImageDecoder::Mode mode); -}; - -SkImageDecoder* SkImageDecoder_FPDFEMB_Factory(SkStream*); -SkImageDecoder* SkImageDecoder_FPDFEMB_Factory(SkStream* stream) { - static const char kPDFSig[] = { '%', 'P', 'D', 'F' }; - - size_t len = stream->getLength(); - char buffer[sizeof(kPDFSig)]; - - SkDebugf("---- SkImageDecoder_FPDFEMB_Factory len=%d\n", len); - - if (len != 12683) { return NULL; } - - if (len > sizeof(kPDFSig) && - stream->read(buffer, sizeof(kPDFSig)) == sizeof(kPDFSig) && - !memcmp(buffer, kPDFSig, sizeof(kPDFSig))) { - return SkNEW(SkFPDFEMBImageDecoder); - } - return NULL; -} - -/////////////////////////////////////////////////////////////////////////////// - -extern "C" { - static void* pdf_alloc(FPDFEMB_MEMMGR* pMgr, unsigned int size) { - void* addr = sk_malloc_throw(size); - // SkDebugf("---- pdf_alloc %d %p\n", size, addr); - return addr; - } - - static void* pdf_alloc_nl(FPDFEMB_MEMMGR* pMgr, unsigned int size) { - void* addr = sk_malloc_flags(size, 0); - // SkDebugf("---- pdf_alloc_nl %d %p\n", size, addr); - return addr; - } - - static void* pdf_realloc(FPDFEMB_MEMMGR*, void* addr, unsigned int size) { - void* newaddr = sk_realloc_throw(addr, size); - // SkDebugf("---- pdf_realloc %p %d %p\n", addr, size, newaddr); - return newaddr; - } - - static void pdf_free(FPDFEMB_MEMMGR* pMgr, void* pointer) { - // SkDebugf("---- pdf_free %p\n", pointer); - sk_free(pointer); - } - - void FX_OUTPUT_LOG_FUNC(const char* format, ...) { - SkDebugf("---- LOG_FUNC %s\n", format); - } - - static unsigned int file_getsize(FPDFEMB_FILE_ACCESS* file) { - SkStream* stream = (SkStream*)file->user; - return stream->getLength(); - } - - static FPDFEMB_RESULT file_readblock(FPDFEMB_FILE_ACCESS* file, void* dst, - unsigned int offset, unsigned int size) { - SkStream* stream = (SkStream*)file->user; -// SkDebugf("---- readblock %p %p %d %d\n", stream, dst, offset, size); - if (!stream->rewind()) { - SkDebugf("---- rewind failed\n"); - return FPDFERR_ERROR; - } - if (stream->skip(offset) != offset) { - SkDebugf("---- skip failed\n"); - return FPDFERR_ERROR; - } - if (stream->read(dst, size) != size) { - SkDebugf("---- read failed\n"); - return FPDFERR_ERROR; - } - return FPDFERR_SUCCESS; - } - - static void pdf_oom_handler(void* memory, int size) { - SkDebugf("======== pdf OOM %p %d\n", memory, size); - } -} - -static inline int PDF2Pixels(int x) { return x / 100; } -static inline SkScalar PDF2Scalar(int x) { - return SkScalarMulDiv(SK_Scalar1, x, 100); -} - -bool SkFPDFEMBImageDecoder::render(FPDFEMB_PAGE page, const FPDFEMB_RECT& bounds, SkBitmap* bm, - SkBitmap::Config prefConfig, SkImageDecoder::Mode mode) { - int width = PDF2Pixels(bounds.right - bounds.left); - int height = PDF2Pixels(bounds.top - bounds.bottom); - - SkDebugf("----- bitmap size [%d %d], mode=%d\n", width, height, mode); - bm->setConfig(SkBitmap::kARGB_8888_Config, width, height); - if (SkImageDecoder::kDecodeBounds_Mode == mode) { - return true; - } - - // USE THE CODEC TO ALLOCATE THE PIXELS!!!! - if (!this->allocPixelRef(bm, NULL)) { - SkDebugf("----- failed to alloc pixels\n"); - return false; - } - - bm->eraseColor(0); - - FPDFEMB_RESULT result; - FPDFEMB_BITMAP dib; - - result = FPDFEMB_CreateDIB(width, height, FPDFDIB_BGRA, bm->getPixels(), - bm->rowBytes(), &dib); - SkDebugf("---- createdib %d\n", result); - - result = FPDFEMB_StartRender(dib, page, 0, 0, width, height, 0, 0, NULL, NULL); - SkDebugf("---- render %d\n", result); - - result = FPDFEMB_DestroyDIB(dib); - SkDebugf("---- destroydib %d\n", result); - - SkPMColor* dst = bm->getAddr32(0, 0); - const uint8_t* src = (uint8_t*)dst; - int n = bm->getSize() >> 2; - for (int i = 0; i < n; i++) { - int b = *src++; - int g = *src++; - int r = *src++; - int a = *src++; - *dst++ = SkPackARGB32(a, r, g, b); - } - - return true; -} - -#define USE_FIXED_MEM (4 * 1024 * 1024) - -bool SkFPDFEMBImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, - SkBitmap::Config prefConfig, Mode mode) { - - FPDFEMB_RESULT result; -#ifdef USE_FIXED_MEM - SkAutoMalloc storage(USE_FIXED_MEM); - result = FPDFEMB_InitFixedMemory(storage.get(), USE_FIXED_MEM, - pdf_oom_handler); -#else - FPDFEMB_MEMMGR memmgr; - memmgr.Alloc = pdf_alloc; - memmgr.AllocNL = pdf_alloc_nl; - memmgr.Realloc = pdf_realloc; - memmgr.Free = pdf_free; - - result = FPDFEMB_Init(&memmgr); -#endif - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory init %d, streamLen = %d\n", result, stream->getLength()); - - FPDFEMB_FILE_ACCESS file; - file.GetSize = file_getsize; - file.ReadBlock = file_readblock; - file.user = stream; - - FPDFEMB_DOCUMENT document; - result = FPDFEMB_StartLoadDocument(&file, NULL, &document, NULL); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory open %d %p\n", result, document); - - int pageCount = FPDFEMB_GetPageCount(document); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory pageCount %d\n", pageCount); - - if (pageCount > 0) { - FPDFEMB_PAGE page; - result = FPDFEMB_LoadPage(document, 0, &page); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory load page %d\n", result); - - int width, height; - result = FPDFEMB_GetPageSize(page, &width, &height); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory page size %d [%d %d]\n", result, width, height); - - FPDFEMB_RECT rect; - result = FPDFEMB_GetPageBBox(page, &rect); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory page rect %d [%d %d %d %d]\n", result, - rect.left, rect.top, rect.right, rect.bottom); - - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory begin page parse...\n"); - result = FPDFEMB_StartParse(page, false, NULL); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory page parse %d\n", result); - - if (0 == result) { - this->render(page, rect, bm, prefConfig, mode); - } - - result = FPDFEMB_ClosePage(page); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory close page %d\n", result); - } - - result = FPDFEMB_CloseDocument(document); - SkDebugf("----- SkImageDecoder_FPDFEMB_Factory close %d\n", result); - - // FPDFEMB_Exit(); - - return true; -} diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp index 30bfbdb..b5e49e8 100644 --- a/src/images/SkImageDecoder_libbmp.cpp +++ b/src/images/SkImageDecoder_libbmp.cpp @@ -1,18 +1,11 @@ + /* - * Copyright 2007, 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 + * Copyright 2007 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "bmpdecoderhelper.h" #include "SkImageDecoder.h" diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp index 75a9ee0..7a451a0 100644 --- a/src/images/SkImageDecoder_libgif.cpp +++ b/src/images/SkImageDecoder_libgif.cpp @@ -1,19 +1,11 @@ -/* libs/graphics/images/SkImageDecoder_libgif.cpp -** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkImageDecoder.h" #include "SkColor.h" diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp index 45d863a..bb6bc95 100644 --- a/src/images/SkImageDecoder_libico.cpp +++ b/src/images/SkImageDecoder_libico.cpp @@ -1,19 +1,11 @@ -/* libs/graphics/images/SkImageDecoder_libico.cpp -** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkImageDecoder.h" #include "SkStream.h" @@ -32,6 +24,11 @@ protected: virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode); }; +SkImageDecoder* SkCreateICOImageDecoder(); +SkImageDecoder* SkCreateICOImageDecoder() { + return new SkICOImageDecoder; +} + ///////////////////////////////////////////////////////////////////////////////////////// //read bytes starting from the begin-th index in the buffer diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp index 89ee9eb..8d87450 100644 --- a/src/images/SkImageDecoder_libjpeg.cpp +++ b/src/images/SkImageDecoder_libjpeg.cpp @@ -1,19 +1,12 @@ + /* - * Copyright 2007, 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 + * Copyright 2007 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "SkImageDecoder.h" #include "SkImageEncoder.h" #include "SkJpegUtility.h" @@ -32,7 +25,7 @@ extern "C" { #include "jerror.h" } -#ifdef ANDROID +#ifdef SK_BUILD_FOR_ANDROID #include <cutils/properties.h> // Key to lookup the size of memory buffer set in system property @@ -122,7 +115,7 @@ private: jpeg_decompress_struct* cinfo_ptr; }; -#ifdef ANDROID +#ifdef SK_BUILD_FOR_ANDROID /* Check if the memory cap property is set. If so, use the memory size for jpeg decode. */ @@ -218,7 +211,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { jpeg_create_decompress(&cinfo); autoClean.set(&cinfo); -#ifdef ANDROID +#ifdef SK_BUILD_FOR_ANDROID overwrite_mem_buffer_size(&cinfo); #endif @@ -421,7 +414,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { return return_false(cinfo, *bm, "sampler.begin"); } - uint8_t* srcRow = (uint8_t*)srcStorage.alloc(cinfo.output_width * 4); + uint8_t* srcRow = (uint8_t*)srcStorage.reset(cinfo.output_width * 4); // Possibly skip initial rows [sampler.srcY0] if (!skip_src_rows(&cinfo, srcRow, sampler.srcY0())) { @@ -491,7 +484,7 @@ bool SkJPEGImageDecoder::onBuildTileIndex(SkStream* stream, cinfo->do_fancy_upsampling = 0; cinfo->do_block_smoothing = 0; -#ifdef ANDROID +#ifdef SK_BUILD_FOR_ANDROID overwrite_mem_buffer_size(cinfo); #endif @@ -516,7 +509,7 @@ bool SkJPEGImageDecoder::onBuildTileIndex(SkStream* stream, // Init decoder to image decode mode jpeg_create_decompress(cinfo); -#ifdef ANDROID +#ifdef SK_BUILD_FOR_ANDROID overwrite_mem_buffer_size(cinfo); #endif @@ -669,7 +662,7 @@ bool SkJPEGImageDecoder::onDecodeRegion(SkBitmap* bm, SkIRect region) { return return_false(*cinfo, *bitmap, "sampler.begin"); } - uint8_t* srcRow = (uint8_t*)srcStorage.alloc(width * 4); + uint8_t* srcRow = (uint8_t*)srcStorage.reset(width * 4); // Possibly skip initial rows [sampler.srcY0] if (!skip_src_rows_tile(cinfo, index->index, srcRow, sampler.srcY0())) { @@ -919,7 +912,7 @@ protected: jpeg_start_compress(&cinfo, TRUE); const int width = bm.width(); - uint8_t* oneRowP = (uint8_t*)oneRow.alloc(width * 3); + uint8_t* oneRowP = (uint8_t*)oneRow.reset(width * 3); const SkPMColor* colors = ctLocker.lockColors(bm); const void* srcRow = bm.getPixels(); diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 5cd86f7..138c28c 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -1,19 +1,11 @@ -/* libs/graphics/images/SkImageDecoder_libpng.cpp -** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkImageDecoder.h" #include "SkImageEncoder.h" @@ -1006,6 +998,11 @@ static inline int pack_palette(SkColorTable* ctable, class SkPNGImageEncoder : public SkImageEncoder { protected: virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality); +private: + bool doEncode(SkWStream* stream, const SkBitmap& bm, + const bool& hasAlpha, int colorType, + int bitDepth, SkBitmap::Config config, + png_color_8& sig_bit); }; bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, @@ -1068,6 +1065,15 @@ bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, bitDepth = computeBitDepth(ctable->count()); } + return doEncode(stream, bitmap, hasAlpha, colorType, + bitDepth, config, sig_bit); +} + +bool SkPNGImageEncoder::doEncode(SkWStream* stream, const SkBitmap& bitmap, + const bool& hasAlpha, int colorType, + int bitDepth, SkBitmap::Config config, + png_color_8& sig_bit) { + png_structp png_ptr; png_infop info_ptr; diff --git a/src/images/SkImageDecoder_libpvjpeg.cpp b/src/images/SkImageDecoder_libpvjpeg.cpp deleted file mode 100644 index b98763e..0000000 --- a/src/images/SkImageDecoder_libpvjpeg.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#include "SkImageDecoder.h" -#include "SkColor.h" -#include "SkColorPriv.h" -#include "SkDither.h" -#include "SkMath.h" -#include "SkStream.h" -#include "SkTemplates.h" -#include "SkUtils.h" - -extern void ValidateHeap(); - -class SkPVJPEGImageDecoder : public SkImageDecoder { -protected: - virtual bool onDecode(SkStream* stream, SkBitmap* bm, - SkBitmap::Config pref, Mode); - -private: - enum { - STORAGE_SIZE = 8 * 1024 - }; - char fStorage[STORAGE_SIZE]; -}; - -SkImageDecoder* SkImageDecoder_PVJPEG_Factory(SkStream* stream) -{ - return SkNEW(SkPVJPEGImageDecoder); -} - -#include "pvjpgdecoderinterface.h" -#include "pvjpgdecoder_factory.h" - -class AutoPVDelete { -public: - AutoPVDelete(PVJpgDecoderInterface* codec) : fCodec(codec) {} - ~AutoPVDelete() { - fCodec->Reset(); - PVJpgDecoderFactory::DeletePVJpgDecoder(fCodec); - } -private: - PVJpgDecoderInterface* fCodec; -}; - -class MyObserver : public MPVJpegDecObserver { -public: - MyObserver() : fCount(0) {} - ~MyObserver() { - if (fCount != 0) { - SkDebugf("--- pvjpeg left %d allocations\n", fCount); - } - } - - virtual void allocateBuffer(uint8* &buffer, int32 buffersize) { - ++fCount; - // we double the allocation to work around bug when height is odd - buffer = (uint8*)sk_malloc_throw(buffersize << 1); - SkDebugf("--- pvjpeg alloc [%d] %d addr=%p\n", fCount, buffersize, buffer); - } - - virtual void deallocateBuffer(uint8 *buffer) { - SkDebugf("--- pvjpeg free [%d] addr=%p\n", fCount, buffer); - --fCount; - sk_free(buffer); - } - -private: - int fCount; -}; - -static void check_status(TPvJpgDecStatus status) { - if (TPVJPGDEC_SUCCESS != status) { - SkDEBUGF(("--- pvjpeg status %d\n", status)); - } -} - -static bool getFrame(PVJpgDecoderInterface* codec, SkBitmap* bitmap, - SkBitmap::Config prefConfig, SkImageDecoder::Mode mode) { - TPvJpgDecInfo info; - TPvJpgDecStatus status = codec->GetInfo(&info); - if (status != TPVJPGDEC_SUCCESS) - return false; - - int width = info.iWidth[0]; - int height = info.iHeight[0]; - - bitmap->setConfig(SkBitmap::kRGB_565_Config, width, height); - bitmap->setIsOpaque(true); - - if (SkImageDecoder::kDecodeBounds_Mode == mode) { - return true; - } - - SkASSERT(info.iNumComponent == 3); - - TPvJpgDecOutputFmt format; - format.iColorFormat = TPV_COLORFMT_RGB16; - format.iCropped.topLeftX = 0; - format.iCropped.topLeftY = 0; - format.iCropped.bottomRightX = width - 1; - format.iCropped.bottomRightY = height - 1; - format.iOutputPitch = bitmap->rowBytes() >> 1; - status = codec->SetOutput(&format); - if (status != TPVJPGDEC_SUCCESS) { - SkDebugf("--- PV SetOutput failed %d\n", status); - return false; - } - - TPvJpgDecFrame frame; - uint8* ptrs[3]; - int32 widths[3], heights[3]; - sk_bzero(ptrs, sizeof(ptrs)); - frame.ptr = ptrs; - frame.iWidth = widths; - frame.iHeight = heights; - - status = codec->GetFrame(&frame); - if (status != TPVJPGDEC_SUCCESS) { - SkDebugf("--- PV GetFrame failed %d\n", status); - return false; - } - - bitmap->allocPixels(); - memcpy(bitmap->getPixels(), ptrs[0], bitmap->getSize()); - return true; -} - -class OsclCleanupper { -public: - OsclCleanupper() { - OsclBase::Init(); - OsclErrorTrap::Init(); - OsclMem::Init(); - } - ~OsclCleanupper() { - OsclMem::Cleanup(); - OsclErrorTrap::Cleanup(); - OsclBase::Cleanup(); - } -}; - -bool SkPVJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, - SkBitmap::Config prefConfig, Mode mode) -{ - // do I need this guy? - OsclCleanupper oc; - - PVJpgDecoderInterface* codec = PVJpgDecoderFactory::CreatePVJpgDecoder(); - TPvJpgDecStatus status = codec->Init(); - check_status(status); - - MyObserver observer; // must create before autopvdelete - AutoPVDelete ad(codec); - - status = codec->SetObserver(&observer); - check_status(status); - - char* storage = fStorage; - int32 bytesInStorage = 0; - for (;;) - { - int32 bytesRead = stream->read(storage + bytesInStorage, - STORAGE_SIZE - bytesInStorage); - if (bytesRead <= 0) { - SkDEBUGF(("SkPVJPEGImageDecoder: stream read returned %d\n", bytesRead)); - return false; - } - - // update bytesInStorage to account for the read() - bytesInStorage += bytesRead; - SkASSERT(bytesInStorage <= STORAGE_SIZE); - - // now call Decode to eat some of the bytes - int32 consumed = bytesInStorage; - status = codec->Decode((uint8*)storage, &consumed); - - SkASSERT(bytesInStorage >= consumed); - bytesInStorage -= consumed; - // now bytesInStorage is the remaining unread bytes - if (bytesInStorage > 0) { // slide the leftovers to the beginning - SkASSERT(storage == fStorage); - SkASSERT(consumed >= 0 && bytesInStorage >= 0); - SkASSERT((size_t)(consumed + bytesInStorage) <= sizeof(fStorage)); - SkASSERT(sizeof(fStorage) == STORAGE_SIZE); - // SkDebugf("-- memmov srcOffset=%d, numBytes=%d\n", consumed, bytesInStorage); - memmove(storage, storage + consumed, bytesInStorage); - } - - switch (status) { - case TPVJPGDEC_SUCCESS: - SkDEBUGF(("SkPVJPEGImageDecoder::Decode returned success?\n");) - return false; - case TPVJPGDEC_FRAME_READY: - case TPVJPGDEC_DONE: - return getFrame(codec, decodedBitmap, prefConfig, mode); - case TPVJPGDEC_FAIL: - case TPVJPGDEC_INVALID_MEMORY: - case TPVJPGDEC_INVALID_PARAMS: - case TPVJPGDEC_NO_IMAGE_DATA: - SkDEBUGF(("SkPVJPEGImageDecoder: failed to decode err=%d\n", status);) - return false; - case TPVJPGDEC_WAITING_FOR_INPUT: - break; // loop around and eat more from the stream - } - } - return false; -} - diff --git a/src/images/SkImageDecoder_wbmp.cpp b/src/images/SkImageDecoder_wbmp.cpp index 6d63ca9..a7d910f 100644 --- a/src/images/SkImageDecoder_wbmp.cpp +++ b/src/images/SkImageDecoder_wbmp.cpp @@ -1,18 +1,11 @@ -/** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkImageDecoder.h" #include "SkColor.h" diff --git a/src/images/SkImageEncoder.cpp b/src/images/SkImageEncoder.cpp index d359905..e05a28c 100644 --- a/src/images/SkImageEncoder.cpp +++ b/src/images/SkImageEncoder.cpp @@ -1,19 +1,12 @@ + /* - * 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 + * Copyright 2009 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "SkImageEncoder.h" #include "SkBitmap.h" #include "SkStream.h" diff --git a/src/images/SkImageEncoder_Factory.cpp b/src/images/SkImageEncoder_Factory.cpp index 0bb4d1a..2bd1113 100644 --- a/src/images/SkImageEncoder_Factory.cpp +++ b/src/images/SkImageEncoder_Factory.cpp @@ -1,25 +1,19 @@ + /* - * 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 + * Copyright 2009 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "SkImageEncoder.h" #include "SkTRegistry.h" typedef SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> EncodeReg; -template EncodeReg* EncodeReg::gHead; +// Can't use the typedef here because of complex C++ corner cases +template EncodeReg* SkTRegistry<SkImageEncoder*, SkImageEncoder::Type>::gHead; #ifdef SK_ENABLE_LIBPNG extern SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type); @@ -41,4 +35,3 @@ SkImageEncoder* SkImageEncoder::Create(Type t) { #endif return NULL; } - diff --git a/src/images/SkImageRef.cpp b/src/images/SkImageRef.cpp index 7d2d416..2d53f7e 100644 --- a/src/images/SkImageRef.cpp +++ b/src/images/SkImageRef.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkImageRef.h" #include "SkBitmap.h" #include "SkFlattenable.h" diff --git a/src/images/SkImageRefPool.cpp b/src/images/SkImageRefPool.cpp index e322507..bfa933e 100644 --- a/src/images/SkImageRefPool.cpp +++ b/src/images/SkImageRefPool.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkImageRefPool.h" #include "SkImageRef.h" #include "SkThread.h" diff --git a/src/images/SkImageRefPool.h b/src/images/SkImageRefPool.h index b2eb7b3..d29b8db 100644 --- a/src/images/SkImageRefPool.h +++ b/src/images/SkImageRefPool.h @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #ifndef SkImageRefPool_DEFINED #define SkImageRefPool_DEFINED diff --git a/src/images/SkImageRef_GlobalPool.cpp b/src/images/SkImageRef_GlobalPool.cpp index 1f44a84..6ea42c1 100644 --- a/src/images/SkImageRef_GlobalPool.cpp +++ b/src/images/SkImageRef_GlobalPool.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkImageRef_GlobalPool.h" #include "SkImageRefPool.h" #include "SkThread.h" @@ -50,8 +57,7 @@ SkPixelRef* SkImageRef_GlobalPool::Create(SkFlattenableReadBuffer& buffer) { return SkNEW_ARGS(SkImageRef_GlobalPool, (buffer)); } -static SkPixelRef::Registrar reg("SkImageRef_GlobalPool", - SkImageRef_GlobalPool::Create); +SK_DEFINE_PIXEL_REF_REGISTRAR(SkImageRef_GlobalPool) /////////////////////////////////////////////////////////////////////////////// // global imagerefpool wrappers diff --git a/src/images/SkJpegUtility.cpp b/src/images/SkJpegUtility.cpp index a2fe9a8..aa5237f 100644 --- a/src/images/SkJpegUtility.cpp +++ b/src/images/SkJpegUtility.cpp @@ -1,19 +1,12 @@ + /* - * Copyright (C) 2010 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 + * Copyright 2010 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "SkJpegUtility.h" ///////////////////////////////////////////////////////////////////// diff --git a/src/images/SkMovie.cpp b/src/images/SkMovie.cpp index 7186ed5..81820a5 100644 --- a/src/images/SkMovie.cpp +++ b/src/images/SkMovie.cpp @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkMovie.h" #include "SkCanvas.h" #include "SkPaint.h" diff --git a/src/images/SkMovie_gif.cpp b/src/images/SkMovie_gif.cpp index 0a85c2d..91d3591 100644 --- a/src/images/SkMovie_gif.cpp +++ b/src/images/SkMovie_gif.cpp @@ -1,19 +1,11 @@ -/* libs/graphics/images/SkImageDecoder_libgif.cpp -** -** Copyright 2006, 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. -*/ + +/* + * Copyright 2006 The Android Open Source Project + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "SkMovie.h" #include "SkColor.h" @@ -245,7 +237,7 @@ static void drawFrame(SkBitmap* bm, const SavedImage* frame, const ColorMapObjec } if (cmap == NULL || cmap->ColorCount != (1 << cmap->BitsPerPixel)) { - SkASSERT(!"bad colortable setup"); + SkDEBUGFAIL("bad colortable setup"); return; } diff --git a/src/images/SkPageFlipper.cpp b/src/images/SkPageFlipper.cpp index 526ba09..8e51e63 100644 --- a/src/images/SkPageFlipper.cpp +++ b/src/images/SkPageFlipper.cpp @@ -1,19 +1,12 @@ + /* - * Copyright (C) 2008 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 + * Copyright 2008 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "SkPageFlipper.h" SkPageFlipper::SkPageFlipper() { diff --git a/src/images/SkScaledBitmapSampler.cpp b/src/images/SkScaledBitmapSampler.cpp index 32b78ef..1af433d 100644 --- a/src/images/SkScaledBitmapSampler.cpp +++ b/src/images/SkScaledBitmapSampler.cpp @@ -1,19 +1,12 @@ + /* - * Copyright 2007, 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 + * Copyright 2007 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #include "SkScaledBitmapSampler.h" #include "SkBitmap.h" #include "SkColorPriv.h" diff --git a/src/images/SkScaledBitmapSampler.h b/src/images/SkScaledBitmapSampler.h index 43f1669..8a735df 100644 --- a/src/images/SkScaledBitmapSampler.h +++ b/src/images/SkScaledBitmapSampler.h @@ -1,3 +1,10 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #ifndef SkScaledBitmapSampler_DEFINED #define SkScaledBitmapSampler_DEFINED diff --git a/src/images/bmpdecoderhelper.cpp b/src/images/bmpdecoderhelper.cpp index acabf44..7749664 100644 --- a/src/images/bmpdecoderhelper.cpp +++ b/src/images/bmpdecoderhelper.cpp @@ -1,18 +1,11 @@ + /* - * Copyright 2007, 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 + * Copyright 2007 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + // Author: cevans@google.com (Chris Evans) #include "bmpdecoderhelper.h" diff --git a/src/images/bmpdecoderhelper.h b/src/images/bmpdecoderhelper.h index 07f0ae5..f3324ee 100644 --- a/src/images/bmpdecoderhelper.h +++ b/src/images/bmpdecoderhelper.h @@ -1,19 +1,12 @@ + /* - * Copyright 2007, 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 + * Copyright 2007 The Android Open Source Project * - * 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. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + #ifndef IMAGE_CODEC_BMPDECODERHELPER_H__ #define IMAGE_CODEC_BMPDECODERHELPER_H__ |