home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d571
/
gwin.lha
/
Gwin
/
Examples
/
changecolor.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-22
|
5KB
|
180 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 Red = 0;
int Green = 1;
int Blue = 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(G,x1,x2,y1,y2);
upset(G,"colo",white);
uoutln(G);
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(;;){
if(ugrin(G,&x,&y)) {UEND();exit(0);}
getboxdata(x,y,&index,&more,&color);
if(index < 0 )break;
ugetrgb(G,(float)index,&redvalue,&greenvalue,&bluevalue);
if(more){
increment = 1;
}else{
increment = -1;
}
if(color == Red ) redvalue = redvalue + increment;
if(color == Green) greenvalue = greenvalue + increment;
if(color == Blue ) bluevalue = bluevalue + increment;
usetrgb(G,(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);
{UEND();exit(1);}
}
ugetrgb(G,(float)boxindex,&redvalue,&greenvalue,&bluevalue);
upset(G,"colo",color);
uset(G,"fill");
umove(G,x1,y1);
udraw(G,x1,y2);
udraw(G,x2,y2);
udraw(G,x2,y1);
udraw(G,x1,y1);
uset(G,"nofi");
upset(G,"colo",black);
umove(G,x1,y1+.3333*(y2-y1));
udraw(G,x2,y1+.3333*(y2-y1));
umove(G,x1,y1+.6666*(y2-y1));
udraw(G,x2,y1+.6666*(y2-y1));
umove(G,x1+.5*(x2-x1),y1);
udraw(G,x1+.5*(x2-x1),y2);
sprintf(redint,"%2.0f",redvalue);
sprintf(greenint,"%2.0f",greenvalue);
sprintf(blueint,"%2.0f",bluevalue);
upset(G,"bcol",color);
uprint(G,x1+.7*(x2-x1),y1+.78*(y2-y1),redint);
uprint(G,x1+.7*(x2-x1),y1+.45*(y2-y1),greenint);
uprint(G,x1+.7*(x2-x1),y1+.11*(y2-y1),blueint);
upset(G,"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 = Red;
if(y >= rmax && y < gmax) *color = Green;
if(y < rmax) *color = Blue;
}
}
}