1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "Decompressor.h"
#ifdef __MINGW32__
#ifdef __STRICT_ANSI__
#undef __STRICT_ANSI__
#endif
#include <fcntl.h>
#endif
#include <stdio.h>
static size_t STDIOReadFunction(void *context,uint8_t *buffer,size_t length) { return fread(buffer,1,length,(FILE *)context); }
int main(int argc,const char **argv)
{
FILE *file=stdin;
if(argc==2) if(!(file=fopen(argv[1],"rb"))) return 1;
#ifdef __MINGW32__
setmode(fileno(file),O_BINARY);
#endif
WinZipJPEGDecompressor *decompressor=AllocWinZipJPEGDecompressor(STDIOReadFunction,file);
if(!decompressor)
{
fprintf(stderr,"Failed to allocate decompressor.\n");
return 1;
}
int error;
error=ReadWinZipJPEGHeader(decompressor);
if(error)
{
fprintf(stderr,"Error %d while trying to read header.\n",error);
return 1;
}
for(;;)
{
error=ReadNextWinZipJPEGBundle(decompressor);
if(error)
{
fprintf(stderr,"Error %d while trying to read next bundle.\n",error);
return 1;
}
//printf("%d bytes of metadata.\n",WinZipJPEGBundleMetadataLength(decompressor));
fwrite(WinZipJPEGBundleMetadataBytes(decompressor),
1,WinZipJPEGBundleMetadataLength(decompressor),stdout);
if(IsFinalWinZipJPEGBundle(decompressor)) break;
while(AreMoreWinZipJPEGSlicesAvailable(decompressor))
{
error=ReadNextWinZipJPEGSlice(decompressor);
if(error)
{
fprintf(stderr,"Error %d while trying to read next slice.\n",error);
return 1;
}
uint8_t buffer[1024];
while(AreMoreWinZipJPEGBytesAvailable(decompressor))
{
size_t actual=EncodeWinZipJPEGBlocksToBuffer(decompressor,buffer,sizeof(buffer));
fwrite(buffer,1,actual,stdout);
}
}
}
FreeWinZipJPEGDecompressor(decompressor);
return 0;
}
|