5 #include "lib/config.h"
9 main(int argc, char *argv[]){
14 struct DecomposeImageInfo dii;
15 ExceptionInfo exception;
17 ImageInfo *image_info=NULL;
18 struct BlockInfo *bi=NULL;
20 Image *out_image=NULL;
22 InitializeMagick(NULL);
23 GetExceptionInfo(&exception);
25 image_info=CloneImageInfo((ImageInfo *) NULL);
26 (void) strcpy(image_info->filename, argv[1]);
27 image=ReadImage(image_info,&exception);
28 if(exception.severity != UndefinedException)
29 CatchException(&exception);
32 fprintf(stderr, "Invalid image format");
35 if(image->columns < 4 || image->rows < 4){
36 fprintf(stderr, "Image too small (%dx%d)", (int)image->columns, (int)image->rows);
41 QuantizeInfo quantize_info;
42 GetQuantizeInfo(&quantize_info);
43 quantize_info.colorspace = RGBColorspace;
44 QuantizeImage(&quantize_info, image);
46 PixelPacket *pixels = (PixelPacket *) AcquireImagePixels(image, 0, 0, image->columns, image->rows, &exception);
47 if (exception.severity != UndefinedException) CatchException(&exception);
48 bi=computeBlockInfo(pixels, image->columns, image->rows, &dii.bi_len);
52 //dii.diff_threshold=1000;
54 dii.init_decomp_num=5;
56 decomposeImage(&dii, bi);
58 showBlockInfoAsImage(bi, dii.bi_len, image->columns, image->rows, &out_image, &exception);
59 if (exception.severity != UndefinedException) CatchException(&exception);
61 image_info=CloneImageInfo((ImageInfo *) NULL);
62 strcpy(out_image->filename, "/proc/self/fd/1"); /*out_image->file=stdout did'n work for me*/
63 out_image->compression=JPEGCompression;
64 if(WriteImage(image_info, out_image)==0)
65 CatchException(&out_image->exception);
67 DestroyImage(out_image);
69 DestroyImageInfo(image_info);
70 DestroyExceptionInfo(&exception);