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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/****************************************************************************/
/* */
/* IMG* Image Processing Tools Library */
/* Program: imgSubSample.c */
/* Author: Simon A.J. Winder */
/* Date: Thu Oct 20 20:45:59 1994 */
/* Copyright (C) 1994 Simon A.J. Winder */
/* */
/****************************************************************************/
#include "tools.h"
#define PRGNAME "SubSample"
#define ERROR(e) imgError(e,PRGNAME)
#define SUBSAMPLE_CASE_LOOP(type,tag) \
case type: \
for(y=yy=0;y<out_height;y++,yy+=y_scale) \
{ CAT(it_,tag) *in_ptr,*out_ptr; \
in_ptr=((CAT(it_,tag) **)(in1->field))[yy]; \
out_ptr=((CAT(it_,tag) **)(out1->field))[y]; \
for(x=0;x<out_width;x++) \
{ \
*out_ptr++ = *in_ptr; \
in_ptr+=x_scale; \
} \
} \
break
int main(int argc,char **argv)
{
it_image *in1,*out1;
int x_scale,y_scale,x,y,width,height,xx,yy,out_width,out_height;
IFHELP
{
fprintf(stderr,"img%s - Perform sub-sampling on each image\n",PRGNAME);
fprintf(stderr,"img%s [stride]\n",PRGNAME);
fprintf(stderr,"img%s [x_stride y_stride]\n",PRGNAME);
fprintf(stderr," stdin: Any\n");
fprintf(stderr," stdout: Any\n");
exit(0);
}
imgStart(PRGNAME);
if(argc>3)
ERROR("invalid arguments");
x_scale=y_scale=2;
if(argc>1)
x_scale=atoi(argv[1]);
if(argc==3)
y_scale=atoi(argv[2]);
else
y_scale=x_scale;
if(x_scale<1 || y_scale<1)
ERROR("invalid arguments");
do {
in1=i_read_image_file(stdin,IT_ANY,IM_FRAGMENT);
if(in1==NULL)
ERROR("can't import image file");
width=in1->width;
height=in1->height;
out_width=(width+x_scale-1)/x_scale;
out_height=(height+y_scale-1)/y_scale;
out1=i_create_image(out_width,out_height,in1->type,IM_FRAGMENT);
if(out1==NULL)
ERROR("out of memory");
out1->min_value=in1->min_value;
out1->max_value=in1->max_value;
out1->valid_x=in1->valid_x/x_scale;
out1->valid_y=in1->valid_y/y_scale;
out1->valid_width=in1->valid_width/x_scale;
out1->valid_height=in1->valid_height/y_scale;
switch(in1->type)
{
case IT_BIT:
for(y=yy=0;y<out_height;y++,yy+=y_scale)
for(x=xx=0;x<out_width;x++,xx+=x_scale)
im_put_bit_value(out1,x,y,im_get_bit_value(in1,xx,yy));
break;
SUBSAMPLE_CASE_LOOP(IT_BYTE,byte);
SUBSAMPLE_CASE_LOOP(IT_LONG,long);
SUBSAMPLE_CASE_LOOP(IT_FLOAT,float);
SUBSAMPLE_CASE_LOOP(IT_DOUBLE,double);
SUBSAMPLE_CASE_LOOP(IT_RGB,rgb);
SUBSAMPLE_CASE_LOOP(IT_COMPLEX,complex);
SUBSAMPLE_CASE_LOOP(IT_POLAR,polar);
default:
ERROR("unrecognised image type");
break;
}
i_destroy_image(in1);
i_write_image_file(stdout,out1,IF_BINARY);
i_destroy_image(out1);
} while(!feof(stdin));
imgFinish(PRGNAME);
return(0);
}
/* Version 1.0 (Oct 1994) */
/* Version 1.1 (Nov 1994) */
|