strcodec.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. //*@@@+++@@@@******************************************************************
  2. //
  3. // Copyright © Microsoft Corp.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // • Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. // • Redistributions in binary form must reproduce the above copyright notice,
  12. // this list of conditions and the following disclaimer in the documentation
  13. // and/or other materials provided with the distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. // POSSIBILITY OF SUCH DAMAGE.
  26. //
  27. //*@@@---@@@@******************************************************************
  28. #pragma once
  29. #include <stddef.h>
  30. #include "windowsmediaphoto.h"
  31. #include "common.h"
  32. // #include "xplatform_image.h"
  33. // added for Xcode PK universal binary
  34. #ifdef __ppc__
  35. #define _BIG__ENDIAN_
  36. #endif
  37. //================================================================
  38. #ifdef ENABLE_OPTIMIZATIONS
  39. #if defined(WIN32) && !defined(_WIN64)
  40. #define WMP_OPT_SSE2
  41. #define WMP_OPT_CC_ENC
  42. //#define WMP_OPT_TRFM_ENC
  43. //#define WMP_OPT_QT
  44. #define WMP_OPT_CC_DEC
  45. #define WMP_OPT_TRFM_DEC
  46. #define X86OPT_INLINE
  47. #endif
  48. #endif // ENABLE_OPTIMIZATIONS
  49. //================================================================
  50. //#ifdef WIN32
  51. #if defined(WIN32) && !defined(UNDER_CE) // WIN32 seems to be defined always in VS2005 for ARM platform
  52. #define PLATFORM_X86
  53. #include "../x86/x86.h"
  54. #endif
  55. #ifndef UNREFERENCED_PARAMETER
  56. #define UNREFERENCED_PARAMETER(P) { (P) = (P); }
  57. #endif
  58. #ifdef UNDER_CE
  59. #define PLATFORM_WCE
  60. #include "arm.h"
  61. #endif
  62. #ifdef __ANSI__
  63. #define PLATFORM_ANSI
  64. #include "ansi.h"
  65. #endif
  66. //================================================================
  67. #ifdef PLATFORM_ANSI
  68. typedef unsigned long long U64;
  69. #else // PLATFORM_ANSI
  70. typedef unsigned __int64 U64;
  71. #endif // PLATFORM_ANSI
  72. //================================================================
  73. #define MARKERCOUNT (PACKETLENGTH * 2)
  74. // The following macros depend on UINTPTR_T and INTPTR_T being properly defined
  75. // so that they are equal to pointer width. Confirm and fail if our assumptions are wrong.
  76. CT_ASSERT(sizeof(UINTPTR_T) == sizeof(void*), strcodec1);
  77. CT_ASSERT(sizeof(INTPTR_T) == sizeof(void*), strcodec2);
  78. // wrap around pointer, s=pow(2,n), p wraps aligned to s
  79. #define WRAPPTR(p, s) ((void*)((UINTPTR_T)(p) & ~(UINTPTR_T)(s)))
  80. // mask certain bit inside a pointer, simulate wrap around
  81. #define MASKPTR(p, m) ((void*)((UINTPTR_T)(p) & (INTPTR_T)(m)))
  82. // test for more than 1 packet data
  83. #define PACKET1(ps, pc, s) (((INTPTR_T)(ps) ^ (INTPTR_T)(pc)) & ((UINTPTR_T)(s)))
  84. // alternate pointer p between 2 values aligned to s, s=pow(2,n)
  85. //#define ALTPTR(p, s) ((void*)((uintptr_t)(p) ^ (s)))
  86. // align point, s=pow(2,n), p aligns to s
  87. #define ALIGNUP(p, s) ((void*)(((UINTPTR_T)(p) + ((UINTPTR_T)(s) - 1)) & ~((UINTPTR_T)(s) - 1)))
  88. #define ALIGNDOWN(p, s) ((void*)((UINTPTR_T)(p) & ~((UINTPTR_T)(s) - 1)))
  89. //================================================================
  90. // timer support
  91. //================================================================
  92. #define TraceResult(a)
  93. //================================================================
  94. typedef enum tagPacketType
  95. {
  96. PK_NULL = 0,
  97. PK_DC = 1, PK_AD, PK_AC, PK_CP,
  98. PK_MAX,
  99. } PACKETTYPE;
  100. typedef struct tagIOContext
  101. {
  102. U8 P0[PACKETLENGTH]; // packet circular buffer 0
  103. U8 P1[PACKETLENGTH]; // packet circular buffer 1
  104. union
  105. {
  106. U8 P2[PACKETLENGTH];
  107. struct
  108. {
  109. U32 uiShadow; // shadow of P0[0]-P0[3]
  110. U32 uiAccumulator; // 32bit acc as bit field cache
  111. U32 cBitsUsed; // # of bits used of acc, [0,16)
  112. U8* pbPacket; // packet pointer
  113. U8* pbCurrent; // current pointer
  114. struct WMPStream* pWS; // pointer to WMPStream
  115. long offPacket; // byte offset into stream
  116. //ULARGE_INTEGER u64Acc;
  117. //========================================
  118. // index packet, used for packet retrieval
  119. //========================================
  120. U32 cIndex; // current index for index packet
  121. long offIndex; // byte offset into stream for index packet
  122. }State;
  123. }P2Info;
  124. U8 P3[PACKETLENGTH]; // index packet buffer
  125. } IOContext;
  126. typedef struct tagMemReadState
  127. {
  128. U8* pbBuf;
  129. size_t cbBuf;
  130. size_t cbCur;
  131. } MemReadState;
  132. typedef struct tagBitIOInfo
  133. {
  134. U32 uiShadow; // shadow of first 4B of circular buffer
  135. U32 uiAccumulator; // 32bit acc as bit field cache
  136. U32 cBitsUsed; // # of bits used of acc, [0,16)
  137. #ifdef ARMOPT_BITIO
  138. U32 cBitsUnused; // # of bits remain unused in acc, [0,32]
  139. #endif
  140. I32 iMask; // mask used simulate pointer wrap around
  141. U8* pbStart; // start pointer
  142. #ifndef ARMOPT_BITIO
  143. U8* pbCurrent; // current pointer
  144. #else
  145. U32* pbCurrent; // current pointer
  146. #endif
  147. struct WMPStream* pWS; // pointer to WMPStream
  148. size_t offRef; // reference offset on IStream,
  149. // for read, it moves along the stream
  150. // for write, it stays at the attach point
  151. } BitIOInfo;
  152. //================================================================
  153. typedef struct tagCWMIQuantizer {
  154. U8 iIndex;
  155. I32 iQP;
  156. I32 iOffset;
  157. I32 iMan;
  158. I32 iExp;
  159. #if defined(WMP_OPT_QT)
  160. float f1_QP;
  161. double d1_QP;
  162. #endif
  163. } CWMIQuantizer;
  164. /* temporary bridge between old APIs and streaming APIs */
  165. typedef struct tagCWMIMBInfo {
  166. I32 iBlockDC[MAX_CHANNELS][16];
  167. I32 iOrientation;
  168. Int iCBP[MAX_CHANNELS];
  169. Int iDiffCBP[MAX_CHANNELS];
  170. U8 iQIndexLP; // 0 - 15
  171. U8 iQIndexHP; // 0 - 15
  172. } CWMIMBInfo;
  173. struct CWMImageStrCodec;
  174. typedef Int (*ImageDataProc)(struct CWMImageStrCodec*);
  175. /** scan model **/
  176. typedef struct CAdaptiveScan {
  177. U32 uTotal;
  178. U32 uScan;
  179. } CAdaptiveScan;
  180. /** Adaptive context model **/
  181. typedef struct CCodingContext {
  182. BitIOInfo * m_pIODC;
  183. BitIOInfo * m_pIOLP;
  184. BitIOInfo * m_pIOAC;
  185. BitIOInfo * m_pIOFL;
  186. /** adaptive huffman structs **/
  187. CAdaptiveHuffman *m_pAdaptHuffCBPCY;
  188. CAdaptiveHuffman *m_pAdaptHuffCBPCY1;
  189. CAdaptiveHuffman *m_pAHexpt[NUMVLCTABLES];
  190. /** 4x4 zigzag patterns */
  191. CAdaptiveScan m_aScanLowpass[16];
  192. CAdaptiveScan m_aScanHoriz[16];
  193. CAdaptiveScan m_aScanVert[16];
  194. /** Adaptive bit reduction model **/
  195. CAdaptiveModel m_aModelAC;
  196. CAdaptiveModel m_aModelLP;
  197. CAdaptiveModel m_aModelDC;
  198. /** Adaptive lowpass CBP model **/
  199. Int m_iCBPCountZero;
  200. Int m_iCBPCountMax;
  201. /** Adaptive AC CBP model **/
  202. CCBPModel m_aCBPModel;
  203. /** Trim flex bits - externally set **/
  204. Int m_iTrimFlexBits;
  205. Bool m_bInROI; // inside ROI (for region decode and compressed domain cropping)?
  206. } CCodingContext;
  207. // Following stuff used to be in strPredQuant.h
  208. /* circulant buffer for 2 MB rows: current row and previous row */
  209. typedef struct tagCWMIPredInfo {
  210. Int iQPIndex; // QP Index
  211. Int iCBP; // coded block pattern
  212. PixelI iDC; // DC of MB
  213. PixelI iAD[6];
  214. PixelI * piAD; // AC of DC block: [2] 420UV [4] 422UV [6] elsewhere
  215. }CWMIPredInfo;
  216. // the following is used on decode side while reading image info
  217. typedef struct CWMImageStrCodecParameters {
  218. size_t cVersion;
  219. size_t cSubVersion;
  220. COLORFORMAT cfColorFormat; // color format
  221. Bool bRBSwapped; // blue and red shall be swapped in BGR555,565,101010
  222. Bool bAlphaChannel; // alpha channel present
  223. Bool bScaledArith; // lossless mode
  224. Bool bIndexTable; // index table present
  225. Bool bTrimFlexbitsFlag; // trimmed flexbits indicated in packet header
  226. Bool bUseHardTileBoundaries; //default is soft tile boundaries
  227. size_t cNumChannels;
  228. size_t cExtraPixelsTop;
  229. size_t cExtraPixelsLeft;
  230. size_t cExtraPixelsBottom;
  231. size_t cExtraPixelsRight;
  232. Bool bTranscode; // transcoding flag
  233. U32 uQPMode; // 0/1: no dquant/with dquant, first bit for DC, second bit for LP, third bit for HP
  234. U8 uiQPIndexDC[MAX_CHANNELS];
  235. U8 uiQPIndexLP[MAX_CHANNELS];
  236. U8 uiQPIndexHP[MAX_CHANNELS];
  237. }CCoreParameters;
  238. typedef struct CWMITile
  239. {
  240. CWMIQuantizer * pQuantizerDC[MAX_CHANNELS];
  241. CWMIQuantizer * pQuantizerLP[MAX_CHANNELS];
  242. CWMIQuantizer * pQuantizerHP[MAX_CHANNELS];
  243. U8 cNumQPLP;
  244. U8 cNumQPHP;
  245. U8 cBitsLP;
  246. U8 cBitsHP;
  247. Bool bUseDC;
  248. Bool bUseLP;
  249. U8 cChModeDC;
  250. U8 cChModeLP[16];
  251. U8 cChModeHP[16];
  252. } CWMITile;
  253. #ifdef ARMOPT_COLORCONVERSION_C
  254. #include "ARM_InvColorConversion.h"
  255. #endif
  256. struct tagPostProcInfo{
  257. Int iMBDC; // DC of MB
  258. U8 ucMBTexture; // MB texture : 0(flat) 1(horizontal) 2(vertical) 3(bumpy)
  259. Int iBlockDC[4][4]; // DC of block
  260. U8 ucBlockTexture[4][4]; // block texture: 0(flat) 1(horizontal) 2(vertical) 3(bumpy)
  261. };
  262. typedef struct CWMImageStrCodec {
  263. #ifdef ARMOPT_COLORCONVERSION_C
  264. CWMImageStrInvCCParam InvCCParam;
  265. #endif
  266. size_t cbStruct;
  267. CWMImageInfo WMII;
  268. CWMIStrCodecParam WMISCP;
  269. CWMImageBufferInfo WMIBI;
  270. CWMIMBInfo MBInfo;
  271. /** core parameters **/
  272. CCoreParameters m_param;
  273. struct CWMDecoderParameters *m_Dparam; // this is specified thru pointer because the same set of parameters may be used by multiple image planes
  274. U8 cSB;
  275. Bool m_bUVResolutionChange;
  276. Bool bTileExtraction;
  277. BitIOInfo * pIOHeader;
  278. Bool bUseHardTileBoundaries; //default is soft tile boundaries
  279. PixelI * pInterU;
  280. PixelI * pInterV;
  281. //============== tile related info begins here ===========
  282. // index table
  283. size_t *pIndexTable;
  284. // current tile position
  285. size_t cTileRow;
  286. size_t cTileColumn;
  287. // tile boundary
  288. Bool m_bCtxLeft;
  289. Bool m_bCtxTop;
  290. Bool m_bResetRGITotals;
  291. Bool m_bResetContext;
  292. CWMITile * pTile;
  293. // BitIOs
  294. BitIOInfo ** m_ppBitIO;
  295. size_t cNumBitIO;
  296. size_t cHeaderSize;
  297. // coding contexts
  298. struct CCodingContext *m_pCodingContext;
  299. size_t cNumCodingContext;
  300. //============== tile related info ends here ===========
  301. size_t cNumOfQPIndex; // number of QP indexes
  302. U8 cBitsDQUANT; // number of bits to encode DQUANT
  303. size_t cRow; // row for current macro block
  304. size_t cColumn; // column for current macro block
  305. size_t cmbWidth; // macro block/image width
  306. size_t cmbHeight; // macro block/image height
  307. size_t cbChannel; // byte/channel
  308. size_t mbX, mbY;
  309. size_t tileX, tileY;
  310. Bool bVertTileBoundary, bHoriTileBoundary;
  311. Bool bOneMBLeftVertTB, bOneMBRightVertTB; //Macroblock to the left and to the right of tile boundaries
  312. PixelI iPredBefore[2][2];
  313. PixelI iPredAfter[2][2];
  314. //================================
  315. // input data into
  316. // macro block 3 of 2x2 working widow
  317. //================================
  318. ImageDataProc Load;
  319. //ImageDataProc Load2;
  320. ImageDataProc Transform;
  321. ImageDataProc TransformCenter;
  322. //================================
  323. ImageDataProc Quantize;
  324. //ImageDataProc QuantizeLuma;
  325. //ImageDataProc QuantizeChroma;
  326. //================================
  327. // process and store data from
  328. // macro block 0 of 2x2 working window
  329. //================================
  330. ImageDataProc ProcessTopLeft;
  331. ImageDataProc ProcessTop;
  332. ImageDataProc ProcessTopRight;
  333. ImageDataProc ProcessLeft;
  334. ImageDataProc ProcessCenter;
  335. ImageDataProc ProcessRight;
  336. ImageDataProc ProcessBottomLeft;
  337. ImageDataProc ProcessBottom;
  338. ImageDataProc ProcessBottomRight;
  339. //================================
  340. // 2 MB working window for encoder
  341. //================================
  342. PixelI *pPlane[MAX_CHANNELS];
  343. //================================
  344. // 2 rows of MB buffer
  345. //================================
  346. PixelI *a0MBbuffer[MAX_CHANNELS]; // pointer to start of previous MB row
  347. PixelI *a1MBbuffer[MAX_CHANNELS]; // pointer to start of current MB row
  348. PixelI *p0MBbuffer[MAX_CHANNELS]; // working pointer to start of previous row MB
  349. PixelI *p1MBbuffer[MAX_CHANNELS]; // working pointer to start of current row MB
  350. //================================
  351. // downsampling buffer for UV
  352. //================================
  353. PixelI * pResU;
  354. PixelI * pResV;
  355. //================================
  356. // circular buffer for 2 MB rows: current row and previous row
  357. //================================
  358. CWMIPredInfo *PredInfo[MAX_CHANNELS];
  359. CWMIPredInfo *PredInfoPrevRow[MAX_CHANNELS];
  360. CWMIPredInfo *pPredInfoMemory;
  361. struct WMPStream ** ppWStream;
  362. #ifdef _WINDOWS_
  363. TCHAR **ppTempFile;
  364. #else
  365. char **ppTempFile;
  366. #endif
  367. // interleaved alpha support - linked structure for Alpha channel
  368. struct CWMImageStrCodec *m_pNextSC;
  369. Bool m_bSecondary;
  370. //================================
  371. // Perf Timers
  372. //================================
  373. #ifndef DISABLE_PERF_MEASUREMENT
  374. Bool m_fMeasurePerf;
  375. struct PERFTIMERSTATE *m_ptEndToEndPerf; // Measures from Init to Term, including I/O
  376. struct PERFTIMERSTATE *m_ptEncDecPerf; // Measures time spent in ImageStrEncEncode/ImageStrDecDecode, excluding I/O
  377. #endif // DISABLE_PERF_MEASUREMENT
  378. // postproc information for 2 MB rows: 0(previous row) 1(current row)
  379. struct tagPostProcInfo * pPostProcInfo[MAX_CHANNELS][2];
  380. } CWMImageStrCodec;
  381. //================================================================
  382. ERR WMPAlloc(void** ppv, size_t cb);
  383. ERR WMPFree(void** ppv);
  384. //================================================================
  385. Void initMRPtr(CWMImageStrCodec*);
  386. Void advanceMRPtr(CWMImageStrCodec*);
  387. Void swapMRPtr(CWMImageStrCodec*);
  388. Int IDPEmpty(CWMImageStrCodec*);
  389. //================================================================
  390. extern const int dctIndex[3][16];
  391. extern const int blkOffset[16];
  392. extern const int blkOffsetUV[4];
  393. extern const int blkOffsetUV_422[8];
  394. extern const U8 idxCC[16][16];
  395. extern const U8 idxCC_420[8][8];
  396. extern const Char gGDISignature[];
  397. //================================================================
  398. Int allocatePredInfo(CWMImageStrCodec*);
  399. Void freePredInfo(CWMImageStrCodec*);
  400. Void advanceOneMBRow(CWMImageStrCodec*);
  401. //================================================================
  402. // bit I/O
  403. //================================================================
  404. Int allocateBitIOInfo(CWMImageStrCodec*);
  405. Int setBitIOPointers(CWMImageStrCodec* pSC);
  406. #ifndef ARMOPT_BITIO
  407. U32 peekBit16(BitIOInfo* pIO, U32 cBits);
  408. U32 flushBit16(BitIOInfo* pIO, U32 cBits);
  409. U32 getBit16(BitIOInfo* pIO, U32 cBits);
  410. U32 getBool16(BitIOInfo* pIO);
  411. I32 getBit16s(BitIOInfo* pIO, U32 cBits);
  412. U32 getBit32(BitIOInfo* pIO, U32 cBits);
  413. U32 flushToByte(BitIOInfo* pIO);
  414. #endif // ARMOPT_BITIO
  415. Void putBit16z(BitIOInfo* pIO, U32 uiBits, U32 cBits);
  416. Void putBit16(BitIOInfo* pIO, U32 uiBits, U32 cBits);
  417. Void putBit32(BitIOInfo* pIO, U32 uiBits, U32 cBits);
  418. Void fillToByte(BitIOInfo* pIO);
  419. U32 getSizeRead(BitIOInfo* pIO);
  420. U32 getSizeWrite(BitIOInfo* pIO);
  421. U32 getPosRead(BitIOInfo* pIO);
  422. // safe function, solely for the convenience of test code
  423. #ifndef ARMOPT_BITIO
  424. U32 getBit16_S(CWMImageStrCodec* pSC, BitIOInfo* pIO, U32 cBits);
  425. #endif // ARMOPT_BITIO
  426. //================================================================
  427. // packet I/O
  428. //================================================================
  429. ERR attachISRead(BitIOInfo* pIO, struct WMPStream* pWS, CWMImageStrCodec* pSC);
  430. ERR readIS(CWMImageStrCodec* pSC, BitIOInfo* pIO);
  431. ERR detachISRead(CWMImageStrCodec* pSC, BitIOInfo* pIO);
  432. ERR attachISWrite(BitIOInfo* pIO, struct WMPStream* pWS);
  433. ERR writeIS(CWMImageStrCodec* pSC, BitIOInfo* pIO);
  434. ERR detachISWrite(CWMImageStrCodec* pSC, BitIOInfo* pIO);
  435. //================================================================
  436. // post processing for decoder
  437. //================================================================
  438. Int initPostProc(struct tagPostProcInfo * strPostProcInfo[MAX_CHANNELS][2], size_t mbWidth, size_t iNumChannels);
  439. Void termPostProc(struct tagPostProcInfo * strPostProcInfo[MAX_CHANNELS][2], size_t iNumChannels);
  440. Void slideOneMBRow(struct tagPostProcInfo * strPostProcInfo[MAX_CHANNELS][2], size_t iNumChannels, size_t mbWidth, Bool top, Bool bottom);
  441. Void updatePostProcInfo(struct tagPostProcInfo * strPostProcInfo[MAX_CHANNELS][2], PixelI * p, size_t mbX, size_t cc);
  442. Void postProcMB(struct tagPostProcInfo * strPostProcInfo[MAX_CHANNELS][2], PixelI * p0, PixelI * p1, size_t mbX, size_t cc, Int threshold);
  443. Void postProcBlock(struct tagPostProcInfo * strPostProcInfo[MAX_CHANNELS][2], PixelI * p0, PixelI * p1, size_t mbX, size_t cc, Int threshold);
  444. //================================================================
  445. // Simple BitIO access functions
  446. //================================================================
  447. typedef struct tagSimpleBitIO
  448. {
  449. struct WMPStream* pWS;
  450. U32 cbRead;
  451. U8 bAccumulator;
  452. U32 cBitLeft;
  453. } SimpleBitIO;
  454. ERR attach_SB(SimpleBitIO* pSB, struct WMPStream* pWS);
  455. U32 getBit32_SB(SimpleBitIO* pSB, U32 cBits);
  456. Void flushToByte_SB(SimpleBitIO* pSB);
  457. U32 getByteRead_SB(SimpleBitIO* pSB);
  458. ERR detach_SB(SimpleBitIO* pSB);
  459. //----------------------------------------------------------------
  460. EXTERN_C Bool EOSWS_File(struct WMPStream* pWS);
  461. EXTERN_C ERR ReadWS_File(struct WMPStream* pWS, void* pv, size_t cb);
  462. EXTERN_C ERR WriteWS_File(struct WMPStream* pWS, const void* pv, size_t cb);
  463. //EXTERN_C ERR GetLineWS_File(struct WMPStream* pWS, void* pv, size_t cb);
  464. EXTERN_C ERR SetPosWS_File(struct WMPStream* pWS, size_t offPos);
  465. EXTERN_C ERR GetPosWS_File(struct WMPStream* pWS, size_t* poffPos);
  466. //----------------------------------------------------------------
  467. EXTERN_C Bool EOSWS_Memory(struct WMPStream* pWS);
  468. EXTERN_C ERR ReadWS_Memory(struct WMPStream* pWS, void* pv, size_t cb);
  469. EXTERN_C ERR WriteWS_Memory(struct WMPStream* pWS, const void* pv, size_t cb);
  470. //EXTERN_C ERR GetLineWS_Memory(struct WMPStream* pWS, void* pv, size_t cb);
  471. EXTERN_C ERR SetPosWS_Memory(struct WMPStream* pWS, size_t offPos);
  472. EXTERN_C ERR GetPosWS_Memory(struct WMPStream* pWS, size_t* poffPos);
  473. //EXTERN_C ERR GetPtrWS_Memory(struct WMPStream* pWS, size_t align, U8** ppb);
  474. //----------------------------------------------------------------
  475. EXTERN_C Bool EOSWS_List(struct WMPStream* pWS);
  476. EXTERN_C ERR ReadWS_List(struct WMPStream* pWS, void* pv, size_t cb);
  477. EXTERN_C ERR WriteWS_List(struct WMPStream* pWS, const void* pv, size_t cb);
  478. EXTERN_C ERR SetPosWS_List(struct WMPStream* pWS, size_t offPos);
  479. EXTERN_C ERR GetPosWS_List(struct WMPStream* pWS, size_t* poffPos);
  480. EXTERN_C ERR CreateWS_List(struct WMPStream** ppWS);
  481. EXTERN_C ERR CloseWS_List(struct WMPStream** ppWS);
  482. /********************************************************************/
  483. // Stuff related to scale/spatial ordering
  484. typedef struct PacketInfo
  485. {
  486. BAND m_iBand;
  487. size_t m_iSize;
  488. size_t m_iOffset;
  489. struct PacketInfo *m_pNext;
  490. } PacketInfo;
  491. /********************************************************************/
  492. /********************************************************************/
  493. const static Int blkIdxByRow[4][4] = {{0, 1, 4, 5}, {2, 3, 6, 7}, {8, 9, 12, 13}, {10, 11, 14, 15}};
  494. const static Int blkIdxByColumn[4][4] = {{0, 2, 8, 10}, {1, 3, 9, 11},{4, 6, 12, 14},{5, 7, 13, 15}};
  495. Int getACPredMode(CWMIMBInfo *, COLORFORMAT);
  496. Int getDCACPredMode(CWMImageStrCodec *, size_t);
  497. Void updatePredInfo(CWMImageStrCodec* pSC, CWMIMBInfo *, size_t, COLORFORMAT);
  498. Int AllocateCodingContextDec(struct CWMImageStrCodec *pSC, Int iNumContexts);
  499. Void ResetCodingContext(CCodingContext *pContext);
  500. Void getTilePos(CWMImageStrCodec* pSC, size_t mbX, size_t mbY);
  501. Void InitZigzagScan(CCodingContext * pSC);
  502. Int checkImageBuffer(CWMImageStrCodec *, size_t, size_t);
  503. //U32 log2(U32);
  504. //DQUANT stuff
  505. EXTERN_C Void remapQP(CWMIQuantizer *, I32, Bool);
  506. Int allocateTileInfo(CWMImageStrCodec *);
  507. Void freeTileInfo(CWMImageStrCodec *);
  508. Int allocateQuantizer(CWMIQuantizer * pQuantizer[MAX_CHANNELS], size_t, size_t);
  509. Void freeQuantizer(CWMIQuantizer * pQuantizer[MAX_CHANNELS]);
  510. Void setUniformQuantizer(CWMImageStrCodec *, size_t);
  511. Void useDCQuantizer(CWMImageStrCodec *, size_t);
  512. Void useLPQuantizer(CWMImageStrCodec *, size_t, size_t);
  513. Void formatQuantizer(CWMIQuantizer * pQuantizer[MAX_CHANNELS], U8, size_t, size_t, Bool, Bool);
  514. U8 dquantBits(U8);
  515. #ifdef ARMOPT_BITIO
  516. #define peekBit16 peekBits
  517. #define flushBit16 flushBits
  518. #define getBit16 getBits
  519. #define getBit32 getBits
  520. #define getBit16s getBitsS
  521. #define getBool16(pIO) getBits(pIO, 1)
  522. U32 peekBits(BitIOInfo* pIO, U32 cBits);
  523. void flushBits(BitIOInfo* pIO, U32 cBits);
  524. U32 getBits(BitIOInfo* pIO, U32 cBits);
  525. U32 getBitsS(BitIOInfo* pIO, U32 cBits);
  526. void flushToByte(BitIOInfo* pIO);
  527. #endif // ARMOPT_BITIO
  528. /*************************************************************************
  529. Bitio defines
  530. *************************************************************************/
  531. #define PEEKBIT16(pIO, cBits) \
  532. assert(0 <= (I32)cBits && cBits <= 16);\
  533. return (pIO->uiAccumulator >> (32 - cBits/* - pIO->cBitsUsed*/));
  534. #define FLUSHBIT16(pIO, cBits) \
  535. assert(0 <= (I32)cBits && cBits <= 16);\
  536. assert((pIO->iMask & 1) == 0);\
  537. pIO->cBitsUsed += cBits;\
  538. pIO->pbCurrent = MASKPTR(pIO->pbCurrent + ((pIO->cBitsUsed >> 3)/* & 2*/), pIO->iMask);\
  539. pIO->cBitsUsed &= 16 - 1;\
  540. pIO->uiAccumulator = LOAD16(pIO->pbCurrent) << pIO->cBitsUsed;\
  541. return 0;
  542. // pIO->uiAccumulator = LOAD16(pIO->pbCurrent) & ((U32)(-1) >> pIO->cBitsUsed);\
  543. void OutputPerfTimerReport(CWMImageStrCodec *pState);