180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2007 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef IMAGE_CODEC_BMPDECODERHELPER_H__ 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define IMAGE_CODEC_BMPDECODERHELPER_H__ 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/////////////////////////////////////////////////////////////////////////////// 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// this section is my current "glue" between google3 code and android. 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru// will be fixed soon 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypes.h" 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include <limits.h> 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define DISALLOW_EVIL_CONSTRUCTORS(name) 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define CHECK(predicate) SkASSERT(predicate) 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutypedef uint8_t uint8; 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutypedef uint32_t uint32; 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutemplate <typename T> class scoped_array { 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru T* ptr_; 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scoped_array(scoped_array const&); 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scoped_array& operator=(const scoped_array&); 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru explicit scoped_array(T* p = 0) : ptr_(p) {} 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ~scoped_array() { 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru delete[] ptr_; 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void reset(T* p = 0) { 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (p != ptr_) { 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru delete[] ptr_; 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ptr_ = p; 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru T& operator[](int i) const { 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return ptr_[i]; 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/////////////////////////////////////////////////////////////////////////////// 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querunamespace image_codec { 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass BmpDecoderCallback { 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru BmpDecoderCallback() { } 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual ~BmpDecoderCallback() {} 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * This is called once for an image. It is passed the width and height and 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * should return the address of a buffer that is large enough to store 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * all of the resulting pixels (widht * height * 3 bytes). If it returns NULL, 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * then the decoder will abort, but return true, as the caller has received 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * valid dimensions. 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual uint8* SetSize(int width, int height) = 0; 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderCallback); 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass BmpDecoderHelper { 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru BmpDecoderHelper() { } 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ~BmpDecoderHelper() { } 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool DecodeImage(const char* data, 75910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger size_t len, 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int max_pixels, 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru BmpDecoderCallback* callback); 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderHelper); 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void DoRLEDecode(); 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void DoStandardDecode(); 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void PutPixel(int x, int y, uint8 col); 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int GetInt(); 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int GetShort(); 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint8 GetByte(); 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int CalcShiftRight(uint32 mask); 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int CalcShiftLeft(uint32 mask); 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const uint8* data_; 93910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger size_t pos_; 94910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger size_t len_; 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int width_; 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int height_; 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int bpp_; 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int pixelPad_; 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int rowPad_; 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru scoped_array<uint8> colTab_; 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint32 redBits_; 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint32 greenBits_; 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint32 blueBits_; 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int redShiftRight_; 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int greenShiftRight_; 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int blueShiftRight_; 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int redShiftLeft_; 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int greenShiftLeft_; 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int blueShiftLeft_; 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint8* output_; 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool inverted_; 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} // namespace 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 117