imgcolorsep

Capsim Block Documentation

Short Description

This star inputs an image and outputs multiple images representing color components.

Top
Input Connections
Port Type Name
0 image_t x
Top
Output Connections
Port Type Name
0 image_t y
Top
Parameters
Num Description Type Name Default Value
0 Color Space:0=RGB,1=YCbCr,2=YUB int colorSpace 0
Top
States
Num Type Name Initial Value Description
0 unsigned_short red_A[256]
1 unsigned_short green_A[256]
2 unsigned_short blue_A[256]
Top

Declarations


 

	int no_samples;
	int i,j,k;
	float	temp;
	dsp_floatMatrix_t	matrix;
	dsp_floatMatrix_Pt	comp1_P;
	dsp_floatMatrix_Pt	comp3_P;
	dsp_floatMatrix_Pt	comp2_P;
	dsp_floatMatrix_Pt	subMatrix_P;
	int	pwidth;
	int	pheight;
	float**		mat_PP;
	image_t	img;
	int	pixel;
	int	yl,cr,cb,u,v;
	int	red,green,blue;



Top

Initialization Code



 

#if 0
	if(IIP_GetRGBColormap(red_A,green_A,blue_A,256)) {
		fprintf(stderr,"imgcolorsep: Problem getting RGB Values from colormap\n");
		return(1);
	}
#endif




Top

Main Code



 

/*
 * 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);




Top

Wrapup Code



 





Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2002  XCAD Corporation 

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.xcad.com
    XCAD Corporation
    Raleigh, North Carolina 
*/


Top

Description



 

/* imgcolorsep.s */
/***********************************************************************
                             imgcolorsep()
************************************************************************
This star inputs an image and outputs multiple images representing
color components.
For RGB, three images are output for each image inputted.
The first image is the red color, the second, green and the fouth blue.
For YCbCr, the outputed images are the luminance (Y) and chrominance (Cb,Cr)
images.
The star obtains the RGB values from the current installed color map.
To view the images, connect this star to the imgdisp star.
Set the Animation parameter to 0 (FALSE)
After the simulation, uninstall the color map, next 
load the 16 level gray color map.
Finally, select Update All Images from the Image pulldown menu.
This will display the image components in gray scale.
Programmer:  	Sasan Ardalan	
Date: 		August 15, 1993
*/