github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/rawp/librawp/include/rawp.h (about) 1 // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #ifndef RAWP_H_ 6 #define RAWP_H_ 7 8 #include <stdint.h> 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 // header size 15 static const int kRawPHeaderSize = 24; 16 17 // magic 18 static const char* kRawPSig = "RawP"; 19 static const uint32_t kRawPMagic = 0x1BF2380A; 20 21 // data type 22 static const uint8_t kRawPDataType_UInt = 1; 23 static const uint8_t kRawPDataType_Int = 2; 24 static const uint8_t kRawPDataType_Float = 3; 25 26 // RawP Image Spec (Little Endian), 24Bytes. 27 typedef struct RawPHeader { 28 char Sig[4]; // 4Bytes, RawP 29 uint32_t Magic; // 4Bytes, 0x1BF2380A 30 uint16_t Width; // 2Bytes, image Width 31 uint16_t Height; // 2Bytes, image Height 32 uint8_t Channels; // 1Bytes, 1=Gray, 3=RGB, 4=RGBA 33 uint8_t Depth; // 1Bytes, 8/16/32/64 bits 34 uint8_t DataType; // 1Bytes, 1=Uint, 2=Int, 3=Float 35 uint8_t UseSnappy; // 1Bytes, 0=disabled, 1=enabled (RawPHeader.Data) 36 uint32_t DataSize; // 4Bytes, image data size (RawPHeader.Data) 37 uint32_t DataCheckSum; // 4Bytes, CRC32(RawPHeader.Data[RawPHeader.DataSize]) 38 uint8_t* Data; // ?Bytes, image data (RawPHeader.DataSize) 39 } RawPHeader; 40 41 typedef struct RawPEncodeOptions { 42 uint8_t UseSnappy; // 0=disabled, 1=enabled (RawPHeader.Data) 43 } RawPEncodeOptions; 44 45 typedef struct RawPEncodeContext { 46 RawPHeader Header; 47 uint8_t* Pix; 48 uint32_t MaxEncodedLength; 49 } RawPEncodeContext; 50 51 int rawpDecodeHeader( 52 const uint8_t* data, int data_size, 53 RawPHeader* hdr 54 ); 55 56 int rawpDecode( 57 const uint8_t* data, int data_size, 58 uint8_t* output, int output_size, 59 RawPHeader* hdr 60 ); 61 62 int rawpEncodeInit( 63 const uint8_t* pix, int width, int height, 64 int channels, int depth, int data_type, 65 const RawPEncodeOptions* opt, 66 RawPEncodeContext* ctx 67 ); 68 69 size_t rawpEncode( 70 RawPEncodeContext* ctx, 71 uint8_t* output 72 ); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 #endif // RAWP_H_