/src/compiler/android/jni/ftk/bmpdecoderhelper.h

http://ftk.googlecode.com/ · C++ Header · 123 lines · 78 code · 19 blank · 26 comment · 2 complexity · 47cd72681bc066724c21c149da1bfde3 MD5 · raw file

  1. /*
  2. * Copyright 2007, The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef IMAGE_CODEC_BMPDECODERHELPER_H__
  17. #define IMAGE_CODEC_BMPDECODERHELPER_H__
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // this section is my current "glue" between google3 code and android.
  20. // will be fixed soon
  21. #include "SkTypes.h"
  22. #include <limits.h>
  23. #define DISALLOW_EVIL_CONSTRUCTORS(name)
  24. #define CHECK(predicate) SkASSERT(predicate)
  25. typedef uint8_t uint8;
  26. typedef uint32_t uint32;
  27. template <typename T> class scoped_array {
  28. private:
  29. T* ptr_;
  30. scoped_array(scoped_array const&);
  31. scoped_array& operator=(const scoped_array&);
  32. public:
  33. explicit scoped_array(T* p = 0) : ptr_(p) {}
  34. ~scoped_array() {
  35. delete[] ptr_;
  36. }
  37. void reset(T* p = 0) {
  38. if (p != ptr_) {
  39. delete[] ptr_;
  40. ptr_ = p;
  41. }
  42. }
  43. T& operator[](int i) const {
  44. return ptr_[i];
  45. }
  46. };
  47. ///////////////////////////////////////////////////////////////////////////////
  48. namespace image_codec {
  49. class BmpDecoderCallback {
  50. public:
  51. BmpDecoderCallback() { }
  52. virtual ~BmpDecoderCallback() {}
  53. /**
  54. * This is called once for an image. It is passed the width and height and
  55. * should return the address of a buffer that is large enough to store
  56. * all of the resulting pixels (widht * height * 3 bytes). If it returns NULL,
  57. * then the decoder will abort, but return true, as the caller has received
  58. * valid dimensions.
  59. */
  60. virtual uint8* SetSize(int width, int height) = 0;
  61. private:
  62. DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderCallback);
  63. };
  64. class BmpDecoderHelper {
  65. public:
  66. BmpDecoderHelper() { }
  67. ~BmpDecoderHelper() { }
  68. bool DecodeImage(const char* data,
  69. int len,
  70. int max_pixels,
  71. BmpDecoderCallback* callback);
  72. private:
  73. DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderHelper);
  74. void DoRLEDecode();
  75. void DoStandardDecode();
  76. void PutPixel(int x, int y, uint8 col);
  77. int GetInt();
  78. int GetShort();
  79. uint8 GetByte();
  80. int CalcShiftRight(uint32 mask);
  81. int CalcShiftLeft(uint32 mask);
  82. const uint8* data_;
  83. int pos_;
  84. int len_;
  85. int width_;
  86. int height_;
  87. int bpp_;
  88. int pixelPad_;
  89. int rowPad_;
  90. scoped_array<uint8> colTab_;
  91. uint32 redBits_;
  92. uint32 greenBits_;
  93. uint32 blueBits_;
  94. int redShiftRight_;
  95. int greenShiftRight_;
  96. int blueShiftRight_;
  97. int redShiftLeft_;
  98. int greenShiftLeft_;
  99. int blueShiftLeft_;
  100. uint8* output_;
  101. bool inverted_;
  102. };
  103. } // namespace
  104. #endif