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