vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

djp2.c (1538B)


      1 
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <unistd.h>
      5 #include <stdarg.h>
      6 #include <assert.h>
      7 
      8 #include "jasper/jasper.h"
      9 
     10 
     11 void fatal(const char *fmt, ...)
     12 {
     13 	va_list ap;
     14 	va_start(ap, fmt);
     15 	vfprintf(stderr, fmt, ap);
     16 	va_end(ap);
     17 	fputc('\n', stderr);
     18 	exit(2);
     19 }
     20 
     21 
     22 int open(const char *path, int flags, ...) { assert(0); }
     23 off_t lseek(int fildes, off_t offset, int whence) { assert(0); }
     24 int close(int fd) { return 0; }
     25 double atof(const char *nptr) { assert(0); }
     26 int unlink(const char *path) { assert(0); }
     27 char *tmpnam(char *s) { assert(0); }
     28 int fseek(FILE *stream, long offset, int whence) { assert(0); }
     29 int fclose(FILE *fp) { assert(0); }
     30 
     31 
     32 int main(int argc, char **argv)
     33 {
     34 	int fmtid = 0;
     35 	jas_image_fmtops_t fmtops;
     36 
     37 	fmtops.decode = jp2_decode;
     38 	fmtops.encode = NULL;
     39 	fmtops.validate = jp2_validate;
     40 	jas_image_addfmt(fmtid, "jp2", "jp2",
     41           "JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops);
     42 	++fmtid;
     43 
     44 	fmtops.decode = NULL;
     45 	fmtops.encode = bmp_encode;
     46 	fmtops.validate = NULL;
     47 	jas_image_addfmt(fmtid, "bmp", "bmp",
     48 		"Microsoft Bitmap (BMP)", &fmtops);
     49 	++fmtid;
     50 
     51 	jas_stream_t *in = jas_stream_fdopen(STDIN_FILENO, "rb");
     52 	assert(in != NULL);
     53 
     54 	jas_stream_t *out = jas_stream_fdopen(STDOUT_FILENO, "w+b");
     55 	assert(out != NULL);
     56 
     57 	jas_image_t *image = jas_image_decode(in, 0, NULL);
     58 	assert(image != NULL);
     59 
     60 	int rc = jas_image_encode(image, out, 1, NULL);
     61 	assert(rc == 0);
     62 
     63 	jas_stream_flush(out);
     64 
     65 	jas_stream_close(in);
     66 	jas_stream_close(out);
     67 
     68 	jas_image_destroy(image);
     69 
     70 	return 0;
     71 }
     72