int main(int argc,char *argv[]) { msgqueue_param_t *msgqueue; int infd, outfd; Byte8_t jptlen, j2klen; struct stat sb; Byte_t *jptstream, *j2kstream; if( argc < 3){ fprintf( stderr, "Too few arguments:\n"); fprintf( stderr, " - input jpt file\n"); fprintf( stderr, " - output j2k file\n"); return -1; } if(( infd = open( argv[1], O_RDONLY)) == -1){ fprintf( stderr, "file %s not exist\n", argv[1]); return -1; } if( fstat( infd, &sb) == -1){ fprintf( stderr, "input file stream is broken\n"); return -1; } jptlen = (Byte8_t)sb.st_size; jptstream = (Byte_t *)malloc( jptlen); if( read( infd, jptstream, jptlen) != jptlen){ fprintf( stderr, "file reading error\n"); free( jptstream); return -1; } close(infd); msgqueue = gene_msgqueue( true, NULL); parse_stream( jptstream, jptlen, 0, msgqueue); //print_msgqueue( msgqueue); j2kstream = recons_j2k( msgqueue, jptstream, msgqueue->first->csn, 0, &j2klen); delete_msgqueue( &msgqueue); free( jptstream); if(( outfd = open( argv[2], O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){ fprintf( stderr, "file %s open error\n", argv[2]); return -1; } if( write( outfd, j2kstream, j2klen) != j2klen) fprintf( stderr, "j2k file write error\n"); free( j2kstream); close(outfd); return 0; }
Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox) { Byte_t *pnmstream; Byte_t *j2kstream; // j2k or jp2 codestream Byte8_t j2klen; j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); pnmstream = j2k_to_pnm( j2kstream, j2klen, ihdrbox); free( j2kstream); return pnmstream; }
void OPJ_CALLCONV decode_jpip( jpip_dec_param_t *dec) { parse_JPIPstream( dec->jpipstream, dec->jpiplen, 0, dec->msgqueue); if( dec->metadatalist){ /* JP2 encoding*/ parse_metamsg( dec->msgqueue, dec->jpipstream, dec->jpiplen, dec->metadatalist); dec->ihdrbox = gene_ihdrbox( dec->metadatalist, dec->jpipstream); dec->jp2kstream = recons_jp2( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, &dec->jp2klen); } else /* J2k encoding */ /* Notice: arguments fw, fh need to be set for LRCP, PCRL, CPRL*/ dec->jp2kstream = recons_j2k( dec->msgqueue, dec->jpipstream, dec->msgqueue->first->csn, 0, 0, &dec->jp2klen); }
Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox) { Byte_t *pnmstream; Byte_t *j2kstream; /* j2k or jp2 codestream */ Byte8_t j2klen; FILE *fp; const char j2kfname[] = "tmp.j2k"; j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); fp = fopen( j2kfname, "w+b"); fwrite( j2kstream, j2klen, 1, fp); free( j2kstream); fseek( fp, 0, SEEK_SET); pnmstream = j2k_to_pnm( fp, ihdrbox); fclose( fp); remove( j2kfname); return pnmstream; }
Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox) { Byte_t *pnmstream; Byte_t *j2kstream; /* j2k or jp2 codestream */ Byte8_t j2klen; size_t retlen; FILE *fp; const char j2kfname[] = "tmp.j2k"; fp = fopen( j2kfname, "w+b"); if( !fp ) { return NULL; } j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); if( !j2kstream ) { fclose(fp); remove( j2kfname); return NULL; } retlen = fwrite( j2kstream, 1, j2klen, fp); opj_free( j2kstream); fclose(fp); if( retlen != j2klen ) { remove( j2kfname); return NULL; } pnmstream = j2k_to_pnm( j2kfname, ihdrbox); remove( j2kfname); return pnmstream; }