tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

YuvStamper.h (2555B)


      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 <cstddef>
      9 #include <cstdint>
     10 
     11 namespace mozilla {
     12 
     13 class 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, uint32_t x = 0,
     20                    uint32_t y = 0) {
     21    YuvStamper stamper(pYData, width, height, stride, x, y,
     22                       (sDigitWidth + sInterDigit) * sPixelSize,
     23                       (sDigitHeight + sInterLine) * sPixelSize);
     24    return stamper.WriteDigits(value);
     25  }
     26 
     27  static bool Encode(uint32_t width, uint32_t height, uint32_t stride,
     28                     unsigned char* pYData, unsigned char* pMsg, size_t msg_len,
     29                     uint32_t x = 0, uint32_t y = 0);
     30 
     31  static bool Decode(uint32_t width, uint32_t height, uint32_t stride,
     32                     unsigned char* pYData, unsigned char* pMsg, size_t msg_len,
     33                     uint32_t x = 0, uint32_t y = 0);
     34 
     35 private:
     36  YuvStamper(unsigned char* pYData, uint32_t width, uint32_t height,
     37             uint32_t stride, uint32_t x, uint32_t y,
     38             unsigned char symbol_width, unsigned char symbol_height);
     39 
     40  bool WriteDigit(unsigned char digit);
     41  void WritePixel(unsigned char* data, uint32_t x, uint32_t y);
     42  uint32_t Capacity();
     43  bool AdvanceCursor();
     44  bool WriteBit(bool one);
     45  bool Write8(unsigned char value);
     46  bool ReadBit(unsigned char& value);
     47  bool Read8(unsigned char& bit);
     48 
     49  const static unsigned char sPixelSize = 3;
     50  const static unsigned char sDigitWidth = 6;
     51  const static unsigned char sDigitHeight = 7;
     52  const static unsigned char sInterDigit = 1;
     53  const static unsigned char sInterLine = 1;
     54  const static uint32_t sBitSize = 4;
     55  const static uint32_t sBitThreshold = 60;
     56  const static unsigned char sYOn = 0x80;
     57  const static unsigned char sYOff = 0;
     58  const static unsigned char sLumaThreshold = 96;
     59  const static unsigned char sLumaMin = 16;
     60  const static unsigned char sLumaMax = 235;
     61 
     62  unsigned char* pYData;
     63  uint32_t mStride;
     64  uint32_t mWidth;
     65  uint32_t mHeight;
     66  unsigned char mSymbolWidth;
     67  unsigned char mSymbolHeight;
     68 
     69  struct Cursor {
     70    Cursor(uint32_t x, uint32_t y) : x(x), y(y) {}
     71    uint32_t x;
     72    uint32_t y;
     73  } mCursor;
     74 };
     75 
     76 }  // namespace mozilla
     77 
     78 #endif