/*
* collect the image
*/
for (no_samples = MIN_AVAIL(); no_samples > 0; --no_samples) {
IT_IN(0);
img=x(0);
pheight=img.height;
pwidth=img.width;
mat_PP=img.image_PP;
if(IIP_GetRGBColormap(red_A,green_A,blue_A,256)) {
fprintf(stderr,"imgcolorsep: Problem getting RGB Values from colormap\n");
return(1);
}
comp1_P=Dsp_AllocateMatrix(pwidth,pheight);
comp2_P=Dsp_AllocateMatrix(pwidth,pheight);
comp3_P=Dsp_AllocateMatrix(pwidth,pheight);
if(comp1_P==NULL || comp3_P==NULL || comp2_P==NULL ) {
fprintf(stderr,"imgcolorsep: allocation failure\n");
return(2);
}
for(i=0; i 255) pixel=255;
red=red_A[pixel];
green=green_A[pixel];
blue=blue_A[pixel];
switch(colorSpace) {
case RGB:
comp1_P->matrix_PP[i][k]=red;
comp2_P->matrix_PP[i][k]=green;
comp3_P->matrix_PP[i][k]=blue;
break;
case YCbCr:
case YUV:
yl=0.3*red+0.6*green+0.1*blue;
v=red-yl;
u=blue-yl;
cb=u/2+128;
cr=v/1.6+128;
cb = cb;
cr= cr;
#if 1
if(cb > 255) cb=255;
if(cb > 255) cb=255;
#endif
if(cb <0) cb=0;
if(cr <0) cr=0;
#if 1
if(yl >255) yl=255;
if(u > 255) u=255;
if(v > 255) v=255;
#endif
if(yl <0) yl=0;
if(u <0) u=0;
if(v <0) v=0;
if(colorSpace == YUV) {
comp1_P->matrix_PP[i][k]=yl;
comp2_P->matrix_PP[i][k]=u;
comp3_P->matrix_PP[i][k]=v;
} else {
comp1_P->matrix_PP[i][k]=yl;
comp2_P->matrix_PP[i][k]=cb;
comp3_P->matrix_PP[i][k]=cr;
}
}
}
}
/*
* output image components
*/
if(IT_OUT(0) ){ KrnOverflow("imgcolorsep",0); return(99); }
img.image_PP=comp1_P->matrix_PP;
img.width=comp1_P->width;
img.height=comp1_P->height;
y(0) = img;
/*
* output green image
*/
if(IT_OUT(0) ){ KrnOverflow("imgcolorsep",0); return(99); }
img.image_PP= comp2_P->matrix_PP;
img.width= comp2_P->width;
img.height= comp2_P->height;
y(0) = img;
/*
* output blue image
*/
if(IT_OUT(0) ){ KrnOverflow("imgcolorsep",0); return(99); }
img.image_PP=comp3_P->matrix_PP;
img.width=comp3_P->width;
img.height=comp3_P->height;
y(0) = img;
}
return(0);