michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef YUV_STAMPER_H_ michael@0: #define YUV_STAMPER_H_ michael@0: michael@0: #include "nptypes.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class michael@0: YuvStamper { michael@0: public: michael@0: bool WriteDigits(uint32_t value); michael@0: michael@0: template michael@0: static bool Write(uint32_t width, uint32_t height, uint32_t stride, michael@0: unsigned char *pYData, const T& value, michael@0: uint32_t x=0, uint32_t y=0) michael@0: { michael@0: YuvStamper stamper(pYData, width, height, stride, michael@0: x, y, michael@0: (sDigitWidth + sInterDigit) * sPixelSize, michael@0: (sDigitHeight + sInterLine) * sPixelSize); michael@0: return stamper.WriteDigits(value); michael@0: } michael@0: michael@0: static bool Encode(uint32_t width, uint32_t height, uint32_t stride, michael@0: unsigned char* pYData, unsigned char* pMsg, size_t msg_len, michael@0: uint32_t x = 0, uint32_t y = 0); michael@0: michael@0: static bool Decode(uint32_t width, uint32_t height, uint32_t stride, michael@0: unsigned char* pYData, unsigned char* pMsg, size_t msg_len, michael@0: uint32_t x = 0, uint32_t y = 0); michael@0: michael@0: private: michael@0: YuvStamper(unsigned char* pYData, michael@0: uint32_t width, uint32_t height, uint32_t stride, michael@0: uint32_t x, uint32_t y, michael@0: unsigned char symbol_width, unsigned char symbol_height); michael@0: michael@0: bool WriteDigit(unsigned char digit); michael@0: void WritePixel(unsigned char* data, uint32_t x, uint32_t y); michael@0: uint32_t Capacity(); michael@0: bool AdvanceCursor(); michael@0: bool WriteBit(bool one); michael@0: bool Write8(unsigned char value); michael@0: bool ReadBit(unsigned char &value); michael@0: bool Read8(unsigned char &bit); michael@0: michael@0: const static unsigned char sPixelSize = 3; michael@0: const static unsigned char sDigitWidth = 6; michael@0: const static unsigned char sDigitHeight = 7; michael@0: const static unsigned char sInterDigit = 1; michael@0: const static unsigned char sInterLine = 1; michael@0: const static uint32_t sBitSize = 4; michael@0: const static uint32_t sBitThreshold = 60; michael@0: const static unsigned char sYOn = 0x80; michael@0: const static unsigned char sYOff = 0; michael@0: const static unsigned char sLumaThreshold = 96; michael@0: const static unsigned char sLumaMin = 16; michael@0: const static unsigned char sLumaMax = 235; michael@0: michael@0: unsigned char* pYData; michael@0: uint32_t mStride; michael@0: uint32_t mWidth; michael@0: uint32_t mHeight; michael@0: unsigned char mSymbolWidth; michael@0: unsigned char mSymbolHeight; michael@0: michael@0: struct Cursor { michael@0: Cursor(uint32_t x, uint32_t y): michael@0: x(x), y(y) {} michael@0: uint32_t x; michael@0: uint32_t y; michael@0: } mCursor; michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif michael@0: