home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / amiiprog.zip / AVKALG.H < prev    next >
C/C++ Source or Header  |  1994-10-27  |  14KB  |  373 lines

  1. //*****************************************************************
  2. //
  3. // Module Name: AvkAlg.h
  4. //
  5. // Description: AVK Video and Audio Microcode Definitions
  6. //
  7. // Status: Version 1 Release 2
  8. //
  9. // Copyright Intel Corp. 1990, 1993
  10. //
  11. // Copyright IBM Corp. 1990, 1993
  12. //
  13. // All Rights Reserved
  14. //
  15. //****************************************************************
  16.  
  17. #ifndef AVKALG_H_INCLUDED          // Ignore multiple includes
  18. #define AVKALG_H_INCLUDED          // Flag file as included
  19.  
  20. // **********************************************************************
  21. // AVSS Frame Format
  22. // **********************************************************************
  23.  
  24. #define AVK_SMALLEST_FRAME_SIZE 16
  25.  
  26. // **************************************************
  27. // Encoded Bitstream Header format
  28. // **************************************************
  29.  
  30. // Hdr: ver | flag | bitslo | bitshi | reserved (2) | height | width
  31. typedef struct {
  32.     U16    CodeAlgVer;    // [ 0 ]    // Algorithm number
  33.     U16    CodeFlag;    // [ 1 ]    // Flag (see below)
  34.     U16    CodeSizeLow;    // [ 2 ]    // Size (see below)
  35.     U16    CodeSizeHigh;    // [ 3 ]
  36.     U32    CodeReserved;    // [ 4 ]    // Write as zero
  37.     U16    CodeYLen;    // [ 6 ]    // Resolution: Y / X order
  38.     U16    CodeXLen;    // [ 7 ]
  39. } AVK_CODE_HDR;
  40.  
  41. #define AVK_CODE_S_LSB  0x02    // LSB always set to 1
  42. #define AVK_CODE_STILL  0x04    // Still: makes no ref to previous image
  43. #define AVK_CODE_PLANE0 0x10    // Color Plane: 2-bit field
  44. #define AVK_CODE_PLANE1 0x20    //    00, 01, 10 <=> Y, v, U
  45. #define AVK_CODE_RESERVED   0xC000    // reserved
  46.  
  47. // CodeSize: Bits, except old RTV
  48. #define AVK_CODE_BYTES(alg, ph)    \
  49.     (( ((((U32) pHdr->CodeSizeHigh) << 16) | pHdr->CodeSizeLow) + 7) / 8)
  50.  
  51. // **********************************************************************
  52. // Audio Microcode
  53. // **********************************************************************
  54.  
  55. // **************************************************
  56. // Special frames: Null (Ignore) & Dummy (from RTV: Time, but no data)
  57.  
  58. // Frame size (bytes) in AVSS frame header
  59. #define AVK_AUD_NULL_FRM_SIZE    0    // Null frame: AVSS Frame header
  60. #define AVK_AUD_DUMMY_FRM_SIZE    8    // Dummy frame: AVSS Frame header
  61.  
  62. // Dummy Frame data: 4-word bitstream header -- INTERNAL AlgNum
  63. #define AVK_AUD_DUMMY_FRM_INIT(pData, AlgNum, SampRate)    {  \
  64.     ((U16 FAR *) pData)[0] = 0;    \
  65.     ((U16 FAR *) pData)[1] = ((AlgNum) << 8) | 0xff;  \
  66.     ((U16 FAR *) pData)[2] = (SampRate);    \
  67.     ((U16 FAR *) pData)[3] = 0;    }
  68.  
  69. // **************************************************
  70. // Audio Algorithms
  71.  
  72. //The following symbols define FAMILIES of audio algorithm microcode
  73. //logic, according to the encoding method:
  74. #define AVK_AUD_ALG_ADPCM4    0    // ADPCM, 4-bit
  75. #define AVK_AUD_ALG_PCM8    1    // PCM, 8-bit
  76.  
  77.  
  78. // ADPCM4 Sample Rates: Samples / Sec
  79. #define AVK_AUD_ALG_ADPCM4_SAMP_HIGH     33075
  80. #define AVK_AUD_ALG_ADPCM4_SAMP_MED     31129    // 124519
  81. #define AVK_AUD_ALG_ADPCM4_SAMP_LOW      8268
  82.  
  83. // PCM8 Sample Rates: Samples / Sec
  84. #define AVK_AUD_ALG_PCM8_SAMP_HIGH     44100
  85. #define AVK_AUD_ALG_PCM8_SAMP_MED     22050
  86. #define AVK_AUD_ALG_PCM8_SAMP_LOW     11025
  87.  
  88. #define AVK_AUD_ALG_MONO    0x1000    // Mono (Flags, can OR)
  89. #define AVK_AUD_ALG_STEREO    0x2000    // Stereo
  90.  
  91. #define AVK_AUD_ALG_PLAYBACK    0x4000    // Playback (Flags, can OR)
  92. #define AVK_AUD_ALG_CAPTURE    0x8000    // Capture
  93.  
  94. #define AVK_AUD_ALG_NUM(alg)    ((alg) & 0x0ff)
  95.  
  96. // macro to derive bits per sample from known algorithm numbers...
  97. #define AVK_AUD_ALG_SAMP_BITS(alg)    \
  98.     (((alg) == AVK_AUD_ALG_ADPCM4) ? 4 :        \
  99.     (((alg) == AVK_AUD_ALG_PCM8)   ? 8 : -1))
  100.  
  101. // audio sample rates BELOW this value permit two audio streams at once...
  102. // The number of SAMPLES PER SECOND maximum, at which two audio streams
  103. // at once can be allowed.
  104. #define AVK_MAX_AUDIO_DUAL  12000
  105.  
  106. // **********************************************************************
  107. // Video Microcode
  108. // **********************************************************************
  109.  
  110. // **************************************************
  111. // Special frames: Null (Ignore) & Dummy (from RTV: Time, but no data)
  112.  
  113. // Frame size (bytes) in AVSS frame header
  114. #define AVK_VID_NULL_FRM_SIZE    0    // Null frame: AVSS Frame header
  115. #define AVK_VID_DUMMY_FRM_SIZE    16    // Dummy frame: AVSS Frame header
  116.  
  117. #define AVK_VID_DUMMY_FRM_CNT    2    // Number of Dummy frames to write
  118.  
  119. // Dummy Frame data: 8-word, 16-byte, 16*8-bit bitstream header
  120. #define AVK_VID_DUMMY_FRM_INIT(pData, AlgNum, xLen, yLen)    {  \
  121.     ((U16 FAR *) pData)[0] = (AlgNum);    \
  122.     ((U16 FAR *) pData)[1] = 0;    \
  123.     ((U16 FAR *) pData)[2] = (AVK_VID_DUMMY_FRM_SIZE * 8);    \
  124.     ((U16 FAR *) pData)[3] = 0;    \
  125.     ((U16 FAR *) pData)[4] = 0;    \
  126.     ((U16 FAR *) pData)[5] = 0;    \
  127.     ((U16 FAR *) pData)[6] = (yLen);    \
  128.     ((U16 FAR *) pData)[7] = (xLen);    }
  129.  
  130. // **************************************************
  131. // Compression / Decompression Algorithms
  132. //   Algorithm Numbers
  133. // Some of these have alternate spellings
  134. // **************************************************
  135.  
  136. // PLV 9-bit Motion Video Algorithms, Decode only
  137. //   Algorithm 5 is backward compatible with version 6 (i.e., use 6 for 5 too)
  138.  
  139. #define AVK_VID_ALG_PLV_10    5    // PLV 1.0,
  140. #define AVK_VID_ALG_PLV_15       6    // PLV 1.5
  141. #define AVK_VID_ALG_PLV_20     20    // PLV 2.0
  142. #define AVK_VID_ALG_PLV_201     21    // PLV 2.0.1
  143.  
  144. // alternates
  145. #define   AVK_PLV_1_0 AVK_VID_ALG_PLV_10
  146. #define   AVK_PLV_1_5 AVK_VID_ALG_PLV_15
  147. #define   AVK_PLV_2_0 AVK_VID_ALG_PLV_20
  148. #define   AVK_PLV_2_01 AVK_VID_ALG_PLV_201
  149.  
  150. // RTV 9-bit Motion Video Algorithms, Decode & Encode
  151.  
  152. #define AVK_VID_ALG_RTV_10    192    // RTV 1.0,  10 fps, 1 Mbit/sec
  153. #define AVK_VID_ALG_RTV_15H    194    // RTV 1.5H, 30 fps, 3 Mbit/sec
  154. #define AVK_VID_ALG_RTV_15    195    // RTV 1.5,  30 fps, 1.6 Mbit/sec
  155. #define AVK_VID_ALG_RTV_20    200    // RTV 2.0, flex data rate
  156. #define AVK_VID_ALG_RTV_21    201    // RTV 2.1, sw decode
  157. #define AVK_VID_ALG_RTV_22    202    // RTV 2.2, data rate arg
  158.  
  159. // alternates
  160. #define   AVK_RTV_1_5 AVK_VID_ALG_RTV_15
  161. #define   AVK_RTV_2_0 AVK_VID_ALG_RTV_20
  162. #define   AVK_RTV_2_1 AVK_VID_ALG_RTV_21
  163. #define   AVK_RTV_2_2 AVK_VID_ALG_RTV_22
  164.  
  165. // 8-bit (9-bit) Planar Lossy Stills Algorithms
  166.  
  167. // PIC 1.0 (9-bit), Lossy YUV-9 stills
  168. #define AVK_VID_ALG_PIC9_10A    128    // Old PIC 1.0, decode only
  169. #define AVK_VID_ALG_PIC9_10    130    // PIC 1.0 for AVK, encode & decode
  170.  
  171. // alternates
  172. #define   AVK_PIC_YUV_9OLD    AVK_VID_ALG_PIC9_10A
  173. #define   AVK_PIC_YUV_9        AVK_VID_ALG_PIC9_10
  174.  
  175. // JPEG Baseline, 9R-7
  176. #define AVK_VID_ALG_JPEG_10    129    // JPEG baseline; 9-bit only for now
  177. // alternates
  178. #define   AVK_JPEG_YUV_9    AVK_VID_ALG_JPEG_10
  179.  
  180. // 16-bit Lossless Stills Algorithms
  181.  
  182. // PIC 1.0 (16-bit), 16-bit lossless
  183. #define AVK_VID_ALG_PIC16_10A      1    // Original PIC 1.0, decode only
  184. #define AVK_VID_ALG_PIC16_10      2    // Improved PIC 1.0, encode & decode
  185.  
  186. // alternates
  187. #define   AVK_PIC_YUV_16OLD    AVK_VID_ALG_PIC16_10A
  188. #define   AVK_PIC_YUV_16    AVK_VID_ALG_PIC16_10
  189.  
  190. // **************************************************
  191. // Compression / Decompression Algorithms
  192. //   Algorithm Arguments
  193. // **************************************************
  194.  
  195. // **************************************************
  196. // PLV 1.0, 9-bit (Alg 5): Decode arguments
  197.  
  198. #define AVK_PLV_10_DECODE_ARGS_SIZE    0
  199. #define AVK_PLV_10_DECODE_WORK_SIZE    (64 * 1024L)
  200.  
  201. // **************************************************
  202. // PLV 1.5, 9-bit (Alg 6): Decode arguments
  203.  
  204. #define AVK_PLV_15_DECODE_ARGS_SIZE    0
  205. #define AVK_PLV_15_DECODE_WORK_SIZE    (64 * 1024L)
  206.  
  207. // **************************************************
  208. // PLV 2.0, 9-bit (Alg 20): Decode arguments
  209.  
  210. #define AVK_PLV_20_DECODE_ARGS_SIZE    0
  211. #define AVK_PLV_20_DECODE_WORK_SIZE    (64 * 1024L)
  212.  
  213. // **************************************************
  214. // RTV 1.5, 9-bit (Alg 195): Decode arguments
  215.  
  216. #define AVK_RTV_15_DECODE_ARGS_SIZE    0
  217. #define AVK_RTV_15_DECODE_WORK_SIZE    0L
  218.  
  219. // **************************************************
  220. // RTV 2.0, 9-bit (Alg 200): Encode arguments
  221.  
  222. #define AVK_RTV_20_ENCODE_ARGS_SIZE    sizeof(AVK_RTV_20_ENCODE_ARGS)
  223. #define AVK_RTV_20_ENCODE_WORK_SIZE    (64 * 1024L)    // full page, aligned
  224. #define AVK_RTV_20_ENCODE_BITS_RATIO    50    // approx % of original
  225.  
  226. #define AVK_RTV_20_ENCODE_ALIGN_ORIG_X    8    // Image alignment, origin
  227. #define AVK_RTV_20_ENCODE_ALIGN_ORIG_Y    8    //   align to multiple
  228. #define AVK_RTV_20_ENCODE_ALIGN_X    16    // Image alignment, size
  229. #define AVK_RTV_20_ENCODE_ALIGN_Y    8    //   align to multiple
  230. #define AVK_RTV_20_ENCODE_MAX_X     256    // Image resolution
  231. #define AVK_RTV_20_ENCODE_MAX_Y     288    //   maximum size
  232.  
  233. #define AVK_RTV_20_ENCODE_DATA_NAME    "ke080200.vsh"    // load in work page
  234.  
  235. typedef struct  AVK_RTV_20_ARGS {
  236.     // Standard Encode Args
  237.     U16    ArgCnt;        // Word count, size of structure (12)
  238.     U16    AlgNum;        // Algorithm number (200)
  239.     U16    xPix, yPix;     // location and size of rectangle to compress
  240.     U16    xLen, yLen;
  241.  
  242.     // Algorithm-specific Encode Args
  243.     U16    StillPeriod;    // how often to force a still
  244.             // (1 = all stills; N = force a still every Nth)
  245.     U16    BytesPerFrame;    // Max bytes/frame (2.2 only)
  246.     U16    LinesPerFrame;    // amount of time available for compression,
  247.             // in (DB) horiz line times (ignored for now)
  248.     U16    Flags;    // See below.
  249.     U16    RelQuant;    // quant value for rel frames (0-7)
  250.                 // (increasing quant increases compression)
  251.     U16    StillQuant;    // quantization for stills (0-7; 0-3 best)
  252. } AVK_RTV_20_ENCODE_ARGS;
  253.  
  254. // alternates
  255. typedef AVK_RTV_20_ENCODE_ARGS    rtv20args;
  256.  
  257. // RTV 2.0 Encode flag bits
  258.  
  259. #define AVK_RTV_20_FLAG_PREFILTER    0x0008    // pre-filter
  260.         // Blurs image to greatly increases compression (about 2X).
  261.         // Essential to achieve CD-ROM rate at 128x240.
  262. #define AVK_RTV_20_FLAG_ASPECT_45    0x0000    // 4:5 aspect ratio
  263. #define AVK_RTV_20_FLAG_ASPECT_25    0x0100    // 2:5 aspect ratio
  264. #define AVK_RTV_20_FLAG_EZ_DECODE    0x0010    // Easier decode
  265.  
  266. // alternates
  267. #define AVK_RTV_20_PREFILTER    AVK_RTV_20_FLAG_PREFILTER
  268. #define AVK_RTV_20_ASPECT_45    AVK_RTV_20_FLAG_ASPECT_45
  269. #define AVK_RTV_20_ASPECT_25    AVK_RTV_20_FLAG_ASPECT_25
  270. #define AVK_RTV_20_EZ_DECODE    AVK_RTV_20_FLAG_EZ_DECODE
  271.  
  272. // **************************************************
  273. // RTV 2.0, 9-bit (Alg 200): Decode arguments
  274.  
  275. #define AVK_RTV_20_DECODE_ARGS_SIZE    0
  276. #define AVK_RTV_20_DECODE_WORK_SIZE    0L
  277.  
  278. // **************************************************
  279. // PIC 1.0, 9-bit Original (Alg 128): Decode arguments
  280.  
  281. #define AVK_PIC9_10A_DECODE_ARGS_SIZE    0
  282. #define AVK_PIC9_10A_DECODE_WORK_SIZE    (32 * 1024L)    // 1/2 page, aligned
  283.  
  284. // **************************************************
  285. // PIC 1.0, 9-bit (Alg 130): Encode arguments
  286.  
  287. #define AVK_PIC9_10_ENCODE_ARGS_SIZE    sizeof(AVK_PIC9_10_ENCODE_ARGS)
  288. #define AVK_PIC9_10_ENCODE_WORK_SIZE    (64 * 1024L)    // full page, aligned
  289. #define AVK_PIC9_10_ENCODE_BITS_RATIO    50    // approx % of original
  290.  
  291. typedef struct {
  292.     // Standard Encode Args
  293.     U16    ArgCnt;        // Word count, size of structure (8)
  294.     U16    AlgNum;        // Algorithm number (130)
  295.     U16    xPix, yPix;     // location and size of rectangle to compress
  296.     U16    xLen, yLen;
  297.  
  298.     // Algorithm-specific Encode Args
  299.     U16    Filtering;    // 0-255, typically 15-20, good 11
  300.     U16    Quantization;    // 0-11, typically 5, good 3
  301. } AVK_PIC9_10_ENCODE_ARGS;
  302.  
  303. typedef AVK_PIC9_10_ENCODE_ARGS    epic9args;
  304.  
  305. // **************************************************
  306. // PIC 1.0, 9-bit (Alg 130): Decode arguments
  307.  
  308. #define AVK_PIC9_10_DECODE_ARGS_SIZE    0
  309. #define AVK_PIC9_10_DECODE_WORK_SIZE    (32 * 1024L)    // 1/2 page, aligned
  310.  
  311. // **************************************************
  312. // JPEG, 9-bit (Alg 129): Encode arguments
  313.  
  314. #define AVK_JPEG_10_ENCODE_ARGS_SIZE    sizeof(AVK_JPEG_10_ENCODE_ARGS)
  315. #define AVK_JPEG_10_ENCODE_QUAN_SIZE    192    // Subtract ArgSize no Quant
  316. #define AVK_JPEG_10_ENCODE_WORK_SIZE    (64 * 1024L)    // full page, aligned
  317. #define AVK_JPEG_10_ENCODE_BITS_RATIO    50    // approx % of original (1/8)
  318.  
  319. typedef struct {
  320.     // Standard Encode Args
  321.     U16    ArgCnt;        // Word count, size of struct (7 or 103)
  322.     U16    AlgNum;        // Algorithm number (129)
  323.     U16    xPix, yPix;     // location and size of rectangle to compress
  324.     U16    xLen, yLen;
  325.  
  326.     // Algorithm-specific Encode Args
  327.     U16    QuanOffset;    // Quantization table offset, bytes
  328.                 // 0 or 14 for (3*64=192 byte table follows)
  329.     char    Quant[192];    // Quantization table (if Offset not 0)
  330. } AVK_JPEG_10_ENCODE_ARGS;
  331.  
  332. typedef AVK_JPEG_10_ENCODE_ARGS    ejpegargs;
  333.  
  334. // **************************************************
  335. // JPEG, 9-bit (Alg 129): Decode arguments
  336.  
  337. #define AVK_JPEG_10_DECODE_ARGS_SIZE    0    // None
  338. #define AVK_JPEG_10_DECODE_WORK_SIZE    (64 * 1024L)    // full page, aligned
  339.  
  340. // **************************************************
  341. // PIC 1.0 A, 16-bit (Alg 1): Decode arguments
  342.  
  343. #define AVK_PIC16_10A_DECODE_ARGS_SIZE    0
  344. #define AVK_PIC16_10A_DECODE_WORK_SIZE    0L
  345.  
  346. // **************************************************
  347. // PIC 1.0, 16-bit (Alg 2): Encode arguments
  348.  
  349. #define AVK_PIC16_10_ENCODE_ARGS_SIZE    sizeof(AVK_PIC16_10_ENCODE_ARGS)
  350. #define AVK_PIC16_10_ENCODE_WORK_SIZE    (10 * 1024L)    // 8K + pad
  351. #define AVK_PIC16_10_ENCODE_BITS_RATIO    50    // approx % of original
  352.  
  353. typedef struct {
  354.     // Standard Encode Args
  355.     U16    ArgCnt;        // Word count, size of structure (6)
  356.     U16    AlgNum;        // Algorithm number (2)
  357.     U16    xPix, yPix;     // location and size of rectangle to compress
  358.     U16    xLen, yLen;
  359.  
  360.     // Algorithm-specific Encode Args
  361.     // (None)
  362. } AVK_PIC16_10_ENCODE_ARGS;
  363.  
  364. typedef AVK_PIC16_10_ENCODE_ARGS    epic16args;
  365.  
  366. // **************************************************
  367. // PIC 1.0, 16-bit (Alg 2): Decode arguments
  368.  
  369. #define AVK_PIC16_10_DECODE_ARGS_SIZE    0
  370. #define AVK_PIC16_10_DECODE_WORK_SIZE    0L
  371.  
  372. #endif       // End of #ifndef to control multiple includes
  373.