1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/signaling/src/common/YuvStamper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef YUV_STAMPER_H_ 1.9 +#define YUV_STAMPER_H_ 1.10 + 1.11 +#include "nptypes.h" 1.12 + 1.13 +namespace mozilla { 1.14 + 1.15 +class 1.16 +YuvStamper { 1.17 +public: 1.18 + bool WriteDigits(uint32_t value); 1.19 + 1.20 + template<typename T> 1.21 + static bool Write(uint32_t width, uint32_t height, uint32_t stride, 1.22 + unsigned char *pYData, const T& value, 1.23 + uint32_t x=0, uint32_t y=0) 1.24 + { 1.25 + YuvStamper stamper(pYData, width, height, stride, 1.26 + x, y, 1.27 + (sDigitWidth + sInterDigit) * sPixelSize, 1.28 + (sDigitHeight + sInterLine) * sPixelSize); 1.29 + return stamper.WriteDigits(value); 1.30 + } 1.31 + 1.32 + static bool Encode(uint32_t width, uint32_t height, uint32_t stride, 1.33 + unsigned char* pYData, unsigned char* pMsg, size_t msg_len, 1.34 + uint32_t x = 0, uint32_t y = 0); 1.35 + 1.36 + static bool Decode(uint32_t width, uint32_t height, uint32_t stride, 1.37 + unsigned char* pYData, unsigned char* pMsg, size_t msg_len, 1.38 + uint32_t x = 0, uint32_t y = 0); 1.39 + 1.40 + private: 1.41 + YuvStamper(unsigned char* pYData, 1.42 + uint32_t width, uint32_t height, uint32_t stride, 1.43 + uint32_t x, uint32_t y, 1.44 + unsigned char symbol_width, unsigned char symbol_height); 1.45 + 1.46 + bool WriteDigit(unsigned char digit); 1.47 + void WritePixel(unsigned char* data, uint32_t x, uint32_t y); 1.48 + uint32_t Capacity(); 1.49 + bool AdvanceCursor(); 1.50 + bool WriteBit(bool one); 1.51 + bool Write8(unsigned char value); 1.52 + bool ReadBit(unsigned char &value); 1.53 + bool Read8(unsigned char &bit); 1.54 + 1.55 + const static unsigned char sPixelSize = 3; 1.56 + const static unsigned char sDigitWidth = 6; 1.57 + const static unsigned char sDigitHeight = 7; 1.58 + const static unsigned char sInterDigit = 1; 1.59 + const static unsigned char sInterLine = 1; 1.60 + const static uint32_t sBitSize = 4; 1.61 + const static uint32_t sBitThreshold = 60; 1.62 + const static unsigned char sYOn = 0x80; 1.63 + const static unsigned char sYOff = 0; 1.64 + const static unsigned char sLumaThreshold = 96; 1.65 + const static unsigned char sLumaMin = 16; 1.66 + const static unsigned char sLumaMax = 235; 1.67 + 1.68 + unsigned char* pYData; 1.69 + uint32_t mStride; 1.70 + uint32_t mWidth; 1.71 + uint32_t mHeight; 1.72 + unsigned char mSymbolWidth; 1.73 + unsigned char mSymbolHeight; 1.74 + 1.75 + struct Cursor { 1.76 + Cursor(uint32_t x, uint32_t y): 1.77 + x(x), y(y) {} 1.78 + uint32_t x; 1.79 + uint32_t y; 1.80 + } mCursor; 1.81 +}; 1.82 + 1.83 +} 1.84 + 1.85 +#endif 1.86 +