home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD2.img
/
d4xx
/
d433
/
gwin
/
exsrc.lzh
/
changecolor.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-12
|
4KB
|
179 lines
#include <stdio.h>
#include "gwin.user.h"
/* I used this routine, embedded a geographic display system, */
/* to adjust the relative brightnesses of the colors I was */
/* using so that I could get 35mm slides without the white */
/* "blooming" compared to the red. I held a photocell up to */
/* each square region on the screen and read the intrinsic */
/* brightness with a voltmeter. I then adjusted each color */
/* by clicking on the sub-squares to adjust the amount of red,*/
/* blue, and green being used and adjusted to taste and to */
/* the camera response. */
#define MAXBOXES 32
float black = 0.0;
float red = 1.0;
float green = 2.0;
float border = 3.0;
float yellow = 5.0;
float white = 7.0;
float forestgreen = 13.0;
float aqua = 14.0;
float darkblue = 10.0;
float blue = 11.0;
int R = 0;
int G = 1;
int B = 2;
struct boxstruct {
int active;
float x1,y1,x2,y2,color;
} boxdata[MAXBOXES];
main()
{
ustart("high2",0.,600.,0.,400.);
adjust_color();
}
adjust_color()
{
float x,y,redvalue,greenvalue,bluevalue;
int index,more,color,increment;
float x1,y1,x2,y2;
x1 = 0.0;
y1 = 0.0;
x2 = 100.0;
y2 = 100.0;
udarea(x1,x2,y1,y2);
upset("colo",white);
uoutln();
draw_box((int)red,red, 1.,1.,13.,20.);
draw_box((int)green,green, 15.,1.,27.,20.);
draw_box((int)blue,blue, 29.,1.,41.,20.);
draw_box((int)yellow,yellow, 43.,1.,55.,20.);
draw_box((int)white,white, 57.,1.,69.,20.);
draw_box((int)forestgreen,forestgreen,71.,1.,83.,20.);
draw_box((int)aqua,aqua, 85.,1.,97.,20.);
draw_box((int)border,border, 1.,21.,13.,40.);
for(;;){
ugrin(&x,&y);
getboxdata(x,y,&index,&more,&color);
if(index < 0 )break;
ugetrgb((float)index,&redvalue,&greenvalue,&bluevalue);
if(more){
increment = 1;
}else{
increment = -1;
}
if(color == R) redvalue = redvalue + increment;
if(color == G) greenvalue = greenvalue + increment;
if(color == B) bluevalue = bluevalue + increment;
usetrgb((float)index,redvalue,greenvalue,bluevalue);
draw_box(index,boxdata[index].color,
boxdata[index].x1,
boxdata[index].y1,
boxdata[index].x2,
boxdata[index].y2);
}
uend();
}
draw_box(boxindex,color,x1,y1,x2,y2)
int boxindex;
float color;
float x1,y1,x2,y2;
{
float redvalue,greenvalue,bluevalue;
char redint[10],greenint[10],blueint[10];
if(boxindex >= MAXBOXES){
printf("Box index limit of %d exceeded.\n",MAXBOXES);
exit(1);
}
ugetrgb((float)boxindex,&redvalue,&greenvalue,&bluevalue);
upset("colo",color);
uset("fill");
umove(x1,y1);
udraw(x1,y2);
udraw(x2,y2);
udraw(x2,y1);
udraw(x1,y1);
uset("nofi");
upset("colo",black);
umove(x1,y1+.3333*(y2-y1));
udraw(x2,y1+.3333*(y2-y1));
umove(x1,y1+.6666*(y2-y1));
udraw(x2,y1+.6666*(y2-y1));
umove(x1+.5*(x2-x1),y1);
udraw(x1+.5*(x2-x1),y2);
sprintf(redint,"%2.0f",redvalue);
sprintf(greenint,"%2.0f",greenvalue);
sprintf(blueint,"%2.0f",bluevalue);
upset("bcol",color);
uprint(x1+.7*(x2-x1),y1+.78*(y2-y1),redint);
uprint(x1+.7*(x2-x1),y1+.45*(y2-y1),greenint);
uprint(x1+.7*(x2-x1),y1+.11*(y2-y1),blueint);
upset("bcol",black);
boxdata[boxindex].active = 1;
boxdata[boxindex].x1 = x1;
boxdata[boxindex].x2 = x2;
boxdata[boxindex].y1 = y1;
boxdata[boxindex].y2 = y2;
boxdata[boxindex].color = color;
}
getboxdata(x,y,index,more,color)
float x,y;
int *index,*more,*color;
{
int i;
float rmax, gmax;
*more = 0;
*index = -1;
for(i=0;i<MAXBOXES;i++){
if( x >= boxdata[i].x1
&& x <= boxdata[i].x2
&& y >= boxdata[i].y1
&& y <= boxdata[i].y2){
*index = i;
if(x > boxdata[i].x1
+ .5*(boxdata[i].x2 - boxdata[i].x1)){
*more = 1;
}else{
*more = 0;
}
rmax = boxdata[i].y1 + .3333*(boxdata[i].y2 - boxdata[i].y1);
gmax = boxdata[i].y1 + .6666*(boxdata[i].y2 - boxdata[i].y1);
if(y >= gmax) *color = R;
if(y >= rmax && y < gmax) *color = G;
if(y < rmax) *color = B;
}
}
}