Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
#include <stdlib.h></stdlib.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define BLOCKROWS 3
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#define NEXT2(x) (((x) + 1) & -2)  // uguale o successivo (pad)
Shinya Kitaoka 120a6e
#define NEXT4(x) (((x) + 3) & -4)  // uguale o successivo multiplo di 4	(pad)
Shinya Kitaoka 120a6e
#define FIXDPI(x) ((x) / 65536.)   // fixedpt
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef long psdByte;
Toshihiro Shimizu 890ddd
typedef unsigned short psdUint16;
Toshihiro Shimizu 890ddd
typedef long psdPixel;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
enum { RAWDATA, RLECOMP, ZIPWITHOUTPREDICTION, ZIPWITHPREDICTION };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct TPSDChannelInfo {
Shinya Kitaoka 120a6e
  int id;                         // channel id
Shinya Kitaoka 120a6e
  int comptype;                   // channel's compression type
Shinya Kitaoka 120a6e
  psdPixel rows, cols, rowbytes;  // computed by dochannel()
Shinya Kitaoka 120a6e
  // FIXME: need depth??
Shinya Kitaoka 120a6e
  psdByte length;   // channel byte count in file
Shinya Kitaoka 120a6e
  psdByte filepos;  // file offset of channel data (AFTER compression type)
Shinya Kitaoka 120a6e
  psdByte *rowpos;  // row data file positions (RLE ONLY)
Shinya Kitaoka 120a6e
  unsigned char *unzipdata;  // uncompressed data (ZIP ONLY)
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int unpackrow(unsigned char *out, unsigned char *in, psdPixel outlen,
Shinya Kitaoka 120a6e
              psdPixel inlen);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void readrow(FILE *psd, TPSDChannelInfo *chan, psdPixel rowIndex,
Shinya Kitaoka 120a6e
             unsigned char *inbuffer, unsigned char *outbuffer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void skipBlock(FILE *f);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void *mymalloc(long n);
Toshihiro Shimizu 890ddd
unsigned read2UBytes(FILE *f);
Toshihiro Shimizu 890ddd
int read2Bytes(FILE *f);
Toshihiro Shimizu 890ddd
long read4Bytes(FILE *f);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int psdUnzipWithoutPrediction(unsigned char *src_buf, int src_len,
Shinya Kitaoka 120a6e
                              unsigned char *dst_buf, int dst_len);
Toshihiro Shimizu 890ddd
int psdUnzipWithPrediction(unsigned char *src_buf, int src_len,
Shinya Kitaoka 120a6e
                           unsigned char *dst_buf, int dst_len, int row_size,
Shinya Kitaoka 120a6e
                           int color_depth);