static void init_jasper( void ) { pthread_mutex_lock( &jasper_lock ); if (++jasper_refs == 1) { jas_image_fmtops_t fmtops; int fmtid = 0; fmtops.decode = jp2_decode; fmtops.encode = jp2_encode; fmtops.validate = jp2_validate; jas_image_addfmt(fmtid, "jp2", "jp2", "JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops); ++fmtid; fmtops.decode = jpc_decode; fmtops.encode = jpc_encode; fmtops.validate = jpc_validate; jas_image_addfmt(fmtid, "jpc", "jpc", "JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)", &fmtops); ++fmtid; } pthread_mutex_unlock( &jasper_lock ); }
int main(int argc, char **argv) { int fmtid = 0; jas_image_fmtops_t fmtops; fmtops.decode = jp2_decode; fmtops.encode = NULL; fmtops.validate = jp2_validate; jas_image_addfmt(fmtid, "jp2", "jp2", "JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops); ++fmtid; fmtops.decode = NULL; fmtops.encode = bmp_encode; fmtops.validate = NULL; jas_image_addfmt(fmtid, "bmp", "bmp", "Microsoft Bitmap (BMP)", &fmtops); ++fmtid; jas_stream_t *in = jas_stream_fdopen(STDIN_FILENO, "rb"); assert(in != NULL); jas_stream_t *out = jas_stream_fdopen(STDOUT_FILENO, "w+b"); assert(out != NULL); jas_image_t *image = jas_image_decode(in, 0, NULL); assert(image != NULL); int rc = jas_image_encode(image, out, 1, NULL); assert(rc == 0); jas_stream_flush(out); jas_stream_close(in); jas_stream_close(out); jas_image_destroy(image); return 0; }
/* Initialize the image format table. */ int jas_init() { jas_image_fmtops_t fmtops; int fmtid; fmtid = 0; #if !defined(EXCLUDE_MIF_SUPPORT) fmtops.decode = mif_decode; fmtops.encode = mif_encode; fmtops.validate = mif_validate; jas_image_addfmt(fmtid, "mif", "mif", "My Image Format (MIF)", &fmtops); ++fmtid; #endif #if !defined(EXCLUDE_PNM_SUPPORT) fmtops.decode = pnm_decode; fmtops.encode = pnm_encode; fmtops.validate = pnm_validate; jas_image_addfmt(fmtid, "pnm", "pnm", "Portable Graymap/Pixmap (PNM)", &fmtops); jas_image_addfmt(fmtid, "pnm", "pgm", "Portable Graymap/Pixmap (PNM)", &fmtops); jas_image_addfmt(fmtid, "pnm", "ppm", "Portable Graymap/Pixmap (PNM)", &fmtops); ++fmtid; #endif #if !defined(EXCLUDE_BMP_SUPPORT) fmtops.decode = bmp_decode; fmtops.encode = bmp_encode; fmtops.validate = bmp_validate; jas_image_addfmt(fmtid, "bmp", "bmp", "Microsoft Bitmap (BMP)", &fmtops); ++fmtid; #endif #if !defined(EXCLUDE_RAS_SUPPORT) fmtops.decode = ras_decode; fmtops.encode = ras_encode; fmtops.validate = ras_validate; jas_image_addfmt(fmtid, "ras", "ras", "Sun Rasterfile (RAS)", &fmtops); ++fmtid; #endif #if !defined(EXCLUDE_JP2_SUPPORT) fmtops.decode = jp2_decode; fmtops.encode = jp2_encode; fmtops.validate = jp2_validate; jas_image_addfmt(fmtid, "jp2", "jp2", "JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops); ++fmtid; fmtops.decode = jpc_decode; fmtops.encode = jpc_encode; fmtops.validate = jpc_validate; jas_image_addfmt(fmtid, "jpc", "jpc", "JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)", &fmtops); ++fmtid; #endif #if !defined(EXCLUDE_JPG_SUPPORT) fmtops.decode = jpg_decode; fmtops.encode = jpg_encode; fmtops.validate = jpg_validate; jas_image_addfmt(fmtid, "jpg", "jpg", "JPEG (ISO/IEC 10918-1)", &fmtops); ++fmtid; #endif #if !defined(EXCLUDE_PGX_SUPPORT) fmtops.decode = pgx_decode; fmtops.encode = pgx_encode; fmtops.validate = pgx_validate; jas_image_addfmt(fmtid, "pgx", "pgx", "JPEG-2000 VM Format (PGX)", &fmtops); ++fmtid; #endif /* We must not register the JasPer library exit handler until after at least one memory allocation is performed. This is desirable as it ensures that the JasPer exit handler is called before the debug memory allocator exit handler. */ atexit(jas_cleanup); return 0; }