/* Copyright (C) 2002 Sony Computer Entertainment America */
/*        All Rights Reserved.  SCEA Confidential         */

#ifndef SCEIMAGE_IPU_H
#define SCEIMAGE_IPU_H

// Every compressed IPU frame from EyeToy has a 16 byte header
#include <libipu.h>

#define IPU_HDR_STRING 0x6d757069 // hex equivalent to 'ipum'
typedef struct {
  unsigned int ipu_identifier; // always IPU_HDR_STRING
  int bytesize;
  unsigned short width;
  unsigned short height;
  char compression_level;
  char unused;
  unsigned short num_frames; // always 1
} ipu_bitstream_header;


// jpeg header.  Always 623 bytes.  Only variables are X,Y,
#define JFIF_HDR_STRING 0x4a46494600 // hex equivalent to "JFIF"
typedef struct {
  unsigned char SOI[2]; // 0xffd8
  unsigned char APP0[2]; // 0xffe0
  unsigned char La0[2]; // 0x0010
  unsigned char jfif_identifier[5]; // always JFIF_HDR_STRING
  unsigned char Unit; // 0x01
  unsigned char version[2]; // 0x0101
  unsigned char hpixd[2]; // 0
  unsigned char vpixd[2];  // 0
  //  unsigned char thumb_h; // 0
  //  unsigned char thumb_v; // 0
  unsigned short bytesize;
  unsigned char DQT_Y[2]; // ffdb
  unsigned char Lq_Y[2]; // 0x0043
  unsigned char PqTq0; // 0x00
  unsigned char dqt_y[64];
  unsigned char DQT_C[2]; // ffdb
  unsigned char Lq_C[2]; // 0x0043
  unsigned char PqTq1; // 0x00
  unsigned char dqt_c[64];
  unsigned char DHT0[2]; // 0xffc4
  unsigned char Lh0[2]; // 0x001f
  unsigned char TcTh0; // 0x00
  unsigned char huff_y_dc[28];
  unsigned char DHT1[2]; // 0xffc4
  unsigned char Lh1[2]; // 0x00b5
  unsigned char TcTh1; // 0x10
  unsigned char huff_y_ac[178];
  unsigned char DHT2[2]; // 0xffc4
  unsigned char Lh2[2]; // 0x001f
  unsigned char TcTh2; // 0x01
  unsigned char huff_c_dc[28];
  unsigned char DHT3[2]; // 0xffc4
  unsigned char Lh3[2]; // 0x00b5
  unsigned char TcTh3; // 0x11
  unsigned char huff_c_ac[178];
  unsigned char SOF0[2]; // 0xffc0
  unsigned char Lf0[2]; // 0x0011
  unsigned char P; // 0x08
  unsigned char Y[2]; // image height
  unsigned char X[2]; // image width
  unsigned char Nf; // 0x03
  unsigned char C1; // 0x01
  unsigned char H1V1; // 0x22 for 411, 0x21 for 422
  unsigned char Tq0; // 0x00
  unsigned char C2; // 0x02
  unsigned char H2V2; // 0x11
  unsigned char Tq1; // 0x01
  unsigned char C3; // 0x03
  unsigned char H3V3; // 0x11
  unsigned char Tq2; // 0x01
  unsigned char SOS[2]; // 0xffda
  unsigned char Ls[2]; // 0x000c
  unsigned char Ns;  // 0x03
  unsigned char Cs1;  // 0x01
  unsigned char Td1Ta1;  // 0x00
  unsigned char Cs2;  // 0x02
  unsigned char Td2Ta2;  // 0x11
  unsigned char Cs3;  // 0x03
  unsigned char Td3Ta3;  // 0x11
  unsigned char Ss; // 0x00
  unsigned char Se; // 0x3f
  unsigned char AhAl; // 0x00
} jpeg_bitstream_header;


void ipu_decompressRGB(ipu_bitstream_header *ipu_bitstream, void* ipu_output, sceImage* rgb);
void ipu_decompressYCbCr(ipu_bitstream_header *ipu_bitstream, void* ipu_output, sceImage*y, sceImage*cr, sceImage*cb);
void ipu_decompressYCbCr111(ipu_bitstream_header *ipu_bitstream, void* ipu_output, sceImage*y, sceImage*cr, sceImage*cb);
void ipu_decompressCbCr(ipu_bitstream_header *ipu_bitstream, void* ipu_output, sceImage*cr, sceImage*cb);
void ipu_decompressY(ipu_bitstream_header *ipu_bitstream, void* ipu_output, sceImage*y);
void ipu_decompressRGB(ipu_bitstream_header *ipu_bitstream, void* ipu_output, sceImage* r, sceImage*g, sceImage*b);

#endif

