/* *********************************************************************** * * * Histogram VGA Color Processor * * * * Program by * * Christopher D. Watkins * * * * 'C' conversion by * * Larry Sharp * * * *********************************************************************** */ static Byte far *ColorHistogram; static Byte far *Frequency; static Word far *Hues; int LastColor; Word ColorNum; void Alloc_Mem() { ColorHistogram=_fmalloc(32768); Frequency=_fmalloc(31000); Hues=_fcalloc(31000, sizeof(Word)); if((ColorHistogram==NULL) || (Frequency==NULL) || (Hues==NULL)) { printf("Not enough memory!\n"); printf("Out of memory!\n Hit any key to exit.\n"); getch(); exit(1); } } void Free_Mem() { farfree(ColorHistogram); farfree(Frequency); farfree(Hues); } void SwapByte(Byte *A, Byte *B) { Byte T; T=*A; *A=*B; *B=T; } void SwapWord(Word *A, Word *B) { Word T; T=*A; *A=*B; *B=T; } void Sort(Word First, Word Last) { Word i, j, k; Word Pivot, Temp2; Byte Temp; if(FirstPivot) ++i; while(Frequency[j]Frequency[First]) { SwapByte(&Frequency[First], &Frequency[Last]); SwapWord(&Hues[First], &Hues[Last]); } } void CollectColorData() { Word x, y; gotoxy(1, 1); printf("Collecting color data from Frame# %d\n", Frame_Num); for(y=0; y>4)&62; b1=(Hues[i]>>9)&62; r2=(Hues[j]<<1)&62; g2=(Hues[j]>>4)&62; b2=(Hues[j]>>9)&62; Tempd=Sqr(r1-r2)+Sqr(g1-g2)+Sqr(b1-b2); if(Tempd>4)&62; PalArray[j].Blu=(Hues[j]>>9)&62; } } void GetColorHistogramFromFrequency() { Word j; for(j=0; j<=LastColor; j++) ColorHistogram[Hues[j]]=Frequency[j]; } void DisplayFrame() { Word x, y; for(y=0; y0) { ++LastColor; if(LastColor>31000) { sound(750); delay(1000); nosound(); exit(1); } Hues[LastColor]=j; Frequency[LastColor]=ColorHistogram[j]; } } if(LastColor<0) { ungetch(32); Exit_Graphics(); printf("No colors in frame.\n"); exit(1); } } void AppendFile() { Word x, y; Byte d; for(y=0; y