media/webrtc/signaling/src/common/YuvStamper.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 #ifndef YUV_STAMPER_H_
     6 #define YUV_STAMPER_H_
     8 #include "nptypes.h"
    10 namespace mozilla {
    12 class
    13 YuvStamper {
    14 public:
    15   bool WriteDigits(uint32_t value);
    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   }
    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);
    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);
    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);
    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);
    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;
    65   unsigned char* pYData;
    66   uint32_t mStride;
    67   uint32_t mWidth;
    68   uint32_t mHeight;
    69   unsigned char mSymbolWidth;
    70   unsigned char mSymbolHeight;
    72   struct Cursor {
    73     Cursor(uint32_t x, uint32_t y):
    74       x(x), y(y) {}
    75     uint32_t x;
    76     uint32_t y;
    77   } mCursor;
    78 };
    80 }
    82 #endif

mercurial