michael@0: michael@0: /* michael@0: * Copyright 2007 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef IMAGE_CODEC_BMPDECODERHELPER_H__ michael@0: #define IMAGE_CODEC_BMPDECODERHELPER_H__ michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: // this section is my current "glue" between google3 code and android. michael@0: // will be fixed soon michael@0: michael@0: #include "SkTypes.h" michael@0: #include michael@0: #define DISALLOW_EVIL_CONSTRUCTORS(name) michael@0: #define CHECK(predicate) SkASSERT(predicate) michael@0: typedef uint8_t uint8; michael@0: typedef uint32_t uint32; michael@0: michael@0: template class scoped_array { michael@0: private: michael@0: T* ptr_; michael@0: scoped_array(scoped_array const&); michael@0: scoped_array& operator=(const scoped_array&); michael@0: michael@0: public: michael@0: explicit scoped_array(T* p = 0) : ptr_(p) {} michael@0: ~scoped_array() { michael@0: delete[] ptr_; michael@0: } michael@0: michael@0: void reset(T* p = 0) { michael@0: if (p != ptr_) { michael@0: delete[] ptr_; michael@0: ptr_ = p; michael@0: } michael@0: } michael@0: michael@0: T& operator[](int i) const { michael@0: return ptr_[i]; michael@0: } michael@0: }; michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: namespace image_codec { michael@0: michael@0: class BmpDecoderCallback { michael@0: public: michael@0: BmpDecoderCallback() { } michael@0: virtual ~BmpDecoderCallback() {} michael@0: michael@0: /** michael@0: * This is called once for an image. It is passed the width and height and michael@0: * should return the address of a buffer that is large enough to store michael@0: * all of the resulting pixels (widht * height * 3 bytes). If it returns NULL, michael@0: * then the decoder will abort, but return true, as the caller has received michael@0: * valid dimensions. michael@0: */ michael@0: virtual uint8* SetSize(int width, int height) = 0; michael@0: michael@0: private: michael@0: DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderCallback); michael@0: }; michael@0: michael@0: class BmpDecoderHelper { michael@0: public: michael@0: BmpDecoderHelper() { } michael@0: ~BmpDecoderHelper() { } michael@0: bool DecodeImage(const char* data, michael@0: size_t len, michael@0: int max_pixels, michael@0: BmpDecoderCallback* callback); michael@0: michael@0: private: michael@0: DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderHelper); michael@0: michael@0: void DoRLEDecode(); michael@0: void DoStandardDecode(); michael@0: void PutPixel(int x, int y, uint8 col); michael@0: michael@0: int GetInt(); michael@0: int GetShort(); michael@0: uint8 GetByte(); michael@0: int CalcShiftRight(uint32 mask); michael@0: int CalcShiftLeft(uint32 mask); michael@0: michael@0: const uint8* data_; michael@0: size_t pos_; michael@0: size_t len_; michael@0: int width_; michael@0: int height_; michael@0: int bpp_; michael@0: int pixelPad_; michael@0: int rowPad_; michael@0: scoped_array colTab_; michael@0: uint32 redBits_; michael@0: uint32 greenBits_; michael@0: uint32 blueBits_; michael@0: int redShiftRight_; michael@0: int greenShiftRight_; michael@0: int blueShiftRight_; michael@0: int redShiftLeft_; michael@0: int greenShiftLeft_; michael@0: int blueShiftLeft_; michael@0: uint8* output_; michael@0: bool inverted_; michael@0: }; michael@0: michael@0: } // namespace michael@0: michael@0: #endif