gfx/skia/trunk/src/images/bmpdecoderhelper.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/images/bmpdecoderhelper.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2007 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef IMAGE_CODEC_BMPDECODERHELPER_H__
    1.14 +#define IMAGE_CODEC_BMPDECODERHELPER_H__
    1.15 +
    1.16 +///////////////////////////////////////////////////////////////////////////////
    1.17 +// this section is my current "glue" between google3 code and android.
    1.18 +// will be fixed soon
    1.19 +
    1.20 +#include "SkTypes.h"
    1.21 +#include <limits.h>
    1.22 +#define DISALLOW_EVIL_CONSTRUCTORS(name)
    1.23 +#define CHECK(predicate)  SkASSERT(predicate)
    1.24 +typedef uint8_t uint8;
    1.25 +typedef uint32_t uint32;
    1.26 +
    1.27 +template <typename T> class scoped_array {
    1.28 +private:
    1.29 +  T* ptr_;
    1.30 +  scoped_array(scoped_array const&);
    1.31 +  scoped_array& operator=(const scoped_array&);
    1.32 +
    1.33 +public:
    1.34 +  explicit scoped_array(T* p = 0) : ptr_(p) {}
    1.35 +  ~scoped_array() {
    1.36 +    delete[] ptr_;
    1.37 +  }
    1.38 +
    1.39 +  void reset(T* p = 0) {
    1.40 +    if (p != ptr_) {
    1.41 +      delete[] ptr_;
    1.42 +      ptr_ = p;
    1.43 +    }
    1.44 +  }
    1.45 +
    1.46 +  T& operator[](int i) const {
    1.47 +    return ptr_[i];
    1.48 +  }
    1.49 +};
    1.50 +
    1.51 +///////////////////////////////////////////////////////////////////////////////
    1.52 +
    1.53 +namespace image_codec {
    1.54 +
    1.55 +class BmpDecoderCallback {
    1.56 + public:
    1.57 +  BmpDecoderCallback() { }
    1.58 +  virtual ~BmpDecoderCallback() {}
    1.59 +
    1.60 +  /**
    1.61 +   * This is called once for an image. It is passed the width and height and
    1.62 +   * should return the address of a buffer that is large enough to store
    1.63 +   * all of the resulting pixels (widht * height * 3 bytes). If it returns NULL,
    1.64 +   * then the decoder will abort, but return true, as the caller has received
    1.65 +   * valid dimensions.
    1.66 +   */
    1.67 +  virtual uint8* SetSize(int width, int height) = 0;
    1.68 +
    1.69 + private:
    1.70 +  DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderCallback);
    1.71 +};
    1.72 +
    1.73 +class BmpDecoderHelper {
    1.74 + public:
    1.75 +  BmpDecoderHelper() { }
    1.76 +  ~BmpDecoderHelper() { }
    1.77 +  bool DecodeImage(const char* data,
    1.78 +                   size_t len,
    1.79 +                   int max_pixels,
    1.80 +                   BmpDecoderCallback* callback);
    1.81 +
    1.82 + private:
    1.83 +  DISALLOW_EVIL_CONSTRUCTORS(BmpDecoderHelper);
    1.84 +
    1.85 +  void DoRLEDecode();
    1.86 +  void DoStandardDecode();
    1.87 +  void PutPixel(int x, int y, uint8 col);
    1.88 +
    1.89 +  int GetInt();
    1.90 +  int GetShort();
    1.91 +  uint8 GetByte();
    1.92 +  int CalcShiftRight(uint32 mask);
    1.93 +  int CalcShiftLeft(uint32 mask);
    1.94 +
    1.95 +  const uint8* data_;
    1.96 +  size_t pos_;
    1.97 +  size_t len_;
    1.98 +  int width_;
    1.99 +  int height_;
   1.100 +  int bpp_;
   1.101 +  int pixelPad_;
   1.102 +  int rowPad_;
   1.103 +  scoped_array<uint8> colTab_;
   1.104 +  uint32 redBits_;
   1.105 +  uint32 greenBits_;
   1.106 +  uint32 blueBits_;
   1.107 +  int redShiftRight_;
   1.108 +  int greenShiftRight_;
   1.109 +  int blueShiftRight_;
   1.110 +  int redShiftLeft_;
   1.111 +  int greenShiftLeft_;
   1.112 +  int blueShiftLeft_;
   1.113 +  uint8* output_;
   1.114 +  bool inverted_;
   1.115 +};
   1.116 +
   1.117 +} // namespace
   1.118 +
   1.119 +#endif

mercurial