Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef YUV_STAMPER_H_ |
michael@0 | 6 | #define YUV_STAMPER_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "nptypes.h" |
michael@0 | 9 | |
michael@0 | 10 | namespace mozilla { |
michael@0 | 11 | |
michael@0 | 12 | class |
michael@0 | 13 | YuvStamper { |
michael@0 | 14 | public: |
michael@0 | 15 | bool WriteDigits(uint32_t value); |
michael@0 | 16 | |
michael@0 | 17 | template<typename T> |
michael@0 | 18 | static bool Write(uint32_t width, uint32_t height, uint32_t stride, |
michael@0 | 19 | unsigned char *pYData, const T& value, |
michael@0 | 20 | uint32_t x=0, uint32_t y=0) |
michael@0 | 21 | { |
michael@0 | 22 | YuvStamper stamper(pYData, width, height, stride, |
michael@0 | 23 | x, y, |
michael@0 | 24 | (sDigitWidth + sInterDigit) * sPixelSize, |
michael@0 | 25 | (sDigitHeight + sInterLine) * sPixelSize); |
michael@0 | 26 | return stamper.WriteDigits(value); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | static bool Encode(uint32_t width, uint32_t height, uint32_t stride, |
michael@0 | 30 | unsigned char* pYData, unsigned char* pMsg, size_t msg_len, |
michael@0 | 31 | uint32_t x = 0, uint32_t y = 0); |
michael@0 | 32 | |
michael@0 | 33 | static bool Decode(uint32_t width, uint32_t height, uint32_t stride, |
michael@0 | 34 | unsigned char* pYData, unsigned char* pMsg, size_t msg_len, |
michael@0 | 35 | uint32_t x = 0, uint32_t y = 0); |
michael@0 | 36 | |
michael@0 | 37 | private: |
michael@0 | 38 | YuvStamper(unsigned char* pYData, |
michael@0 | 39 | uint32_t width, uint32_t height, uint32_t stride, |
michael@0 | 40 | uint32_t x, uint32_t y, |
michael@0 | 41 | unsigned char symbol_width, unsigned char symbol_height); |
michael@0 | 42 | |
michael@0 | 43 | bool WriteDigit(unsigned char digit); |
michael@0 | 44 | void WritePixel(unsigned char* data, uint32_t x, uint32_t y); |
michael@0 | 45 | uint32_t Capacity(); |
michael@0 | 46 | bool AdvanceCursor(); |
michael@0 | 47 | bool WriteBit(bool one); |
michael@0 | 48 | bool Write8(unsigned char value); |
michael@0 | 49 | bool ReadBit(unsigned char &value); |
michael@0 | 50 | bool Read8(unsigned char &bit); |
michael@0 | 51 | |
michael@0 | 52 | const static unsigned char sPixelSize = 3; |
michael@0 | 53 | const static unsigned char sDigitWidth = 6; |
michael@0 | 54 | const static unsigned char sDigitHeight = 7; |
michael@0 | 55 | const static unsigned char sInterDigit = 1; |
michael@0 | 56 | const static unsigned char sInterLine = 1; |
michael@0 | 57 | const static uint32_t sBitSize = 4; |
michael@0 | 58 | const static uint32_t sBitThreshold = 60; |
michael@0 | 59 | const static unsigned char sYOn = 0x80; |
michael@0 | 60 | const static unsigned char sYOff = 0; |
michael@0 | 61 | const static unsigned char sLumaThreshold = 96; |
michael@0 | 62 | const static unsigned char sLumaMin = 16; |
michael@0 | 63 | const static unsigned char sLumaMax = 235; |
michael@0 | 64 | |
michael@0 | 65 | unsigned char* pYData; |
michael@0 | 66 | uint32_t mStride; |
michael@0 | 67 | uint32_t mWidth; |
michael@0 | 68 | uint32_t mHeight; |
michael@0 | 69 | unsigned char mSymbolWidth; |
michael@0 | 70 | unsigned char mSymbolHeight; |
michael@0 | 71 | |
michael@0 | 72 | struct Cursor { |
michael@0 | 73 | Cursor(uint32_t x, uint32_t y): |
michael@0 | 74 | x(x), y(y) {} |
michael@0 | 75 | uint32_t x; |
michael@0 | 76 | uint32_t y; |
michael@0 | 77 | } mCursor; |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | #endif |
michael@0 | 83 |