1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_ 8 #define CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_ 9 10 #include <memory> 11 12 #include "core/fxcodec/jbig2/JBig2_Define.h" 13 #include "core/fxcrt/maybe_owned.h" 14 15 struct FX_RECT; 16 17 enum JBig2ComposeOp { 18 JBIG2_COMPOSE_OR = 0, 19 JBIG2_COMPOSE_AND = 1, 20 JBIG2_COMPOSE_XOR = 2, 21 JBIG2_COMPOSE_XNOR = 3, 22 JBIG2_COMPOSE_REPLACE = 4 23 }; 24 25 class CJBig2_Image { 26 public: 27 CJBig2_Image(int32_t w, int32_t h); 28 CJBig2_Image(int32_t w, int32_t h, int32_t stride, uint8_t* pBuf); 29 CJBig2_Image(const CJBig2_Image& im); 30 ~CJBig2_Image(); 31 width()32 int32_t width() const { return m_nWidth; } height()33 int32_t height() const { return m_nHeight; } stride()34 int32_t stride() const { return m_nStride; } data()35 uint8_t* data() const { return m_pData.Get(); } 36 37 int getPixel(int32_t x, int32_t y) const; 38 int32_t setPixel(int32_t x, int32_t y, int bVal); 39 40 void copyLine(int32_t hTo, int32_t hFrom); 41 void fill(bool v); 42 43 bool composeTo(CJBig2_Image* pDst, int32_t x, int32_t y, JBig2ComposeOp op); 44 bool composeTo(CJBig2_Image* pDst, 45 int32_t x, 46 int32_t y, 47 JBig2ComposeOp op, 48 const FX_RECT* pSrcRect); 49 50 bool composeTo_opt2(CJBig2_Image* pDst, 51 int32_t x, 52 int32_t y, 53 JBig2ComposeOp op); 54 bool composeTo_opt2(CJBig2_Image* pDst, 55 int32_t x, 56 int32_t y, 57 JBig2ComposeOp op, 58 const FX_RECT* pSrcRect); 59 60 bool composeFrom(int32_t x, int32_t y, CJBig2_Image* pSrc, JBig2ComposeOp op); 61 bool composeFrom(int32_t x, 62 int32_t y, 63 CJBig2_Image* pSrc, 64 JBig2ComposeOp op, 65 const FX_RECT* pSrcRect); 66 67 std::unique_ptr<CJBig2_Image> subImage(int32_t x, 68 int32_t y, 69 int32_t w, 70 int32_t h); 71 void expand(int32_t h, bool v); 72 73 74 private: 75 MaybeOwned<uint8_t, FxFreeDeleter> m_pData; 76 int32_t m_nWidth; // 1-bit pixels 77 int32_t m_nHeight; // lines 78 int32_t m_nStride; // bytes 79 }; 80 81 #endif // CORE_FXCODEC_JBIG2_JBIG2_IMAGE_H_ 82