Category : Science and Education
Archive   : IMAGE10.ZIP
Filename : IMAGE.C
/* */
/* image.exe */
/* */
/* This is the program that performes image processing */
/* on the contents of the display buffer. This buffer */
/* is 256 x 256 pixels by eight bits each pixel and */
/* can display up to 256 colors from a palette of */
/* 262000 colors. */
/* */
/* The program offers image processing routines */
/* including addition, deletion and other processes. */
/* Written by Peter Vekinis, April 1988 */
/* */
/* The program uses the Mirosoft C Compiler, version */
/* 5.0 which supports the VGA. */
/* */
/**********************************************************/
#include
#include
#include
#include
#include
#include
#include
#define CHAR 1
#define LINE 2
#define NOTHING 0
#define ADD 1
#define MULT 2
unsigned char video_mode;
char *global_buffer;
unsigned palette_value;
int ega;
int condense;
int sstv;
/******************************************/
/* pvgetch() */
/* */
/* This routine checks the keyboard */
/* for HELP (F1) ot returns the code. */
/******************************************/
pvgetch()
{
unsigned int k;
if((k=getch()) == 00) /* ie f1 */
show_help();
else
return k;
}
/******************************************/
/* show_help() */
/* */
/* This routine shows help on the */
/* screen */
/******************************************/
show_help()
{
_setvideomode(_TEXTC80); /* set to characters */
/* read in help file */
system("type image.hlp");
getch();
getch();
_setvideomode(video_mode);
palette_bw();
show_screen();
}
/******************************************/
/* prich() */
/* */
/* This routine prints the character */
/******************************************/
prich(chr)
char chr;
{
union REGS regs;
regs.h.ah=5;
regs.h.dl=chr;
int86(0x21, ®s, ®s);
}
/******************************************/
/* pristr() */
/* */
/* This routine prints the string */
/******************************************/
pristr(str)
char *str;
{
union REGS regs;
while(*str)
{
regs.h.ah=5;
regs.h.dl=*str++;
int86(0x21, ®s, ®s);
}
}
/******************************************/
/* show_screen() */
/* */
/* This routine shows the screen setup*/
/******************************************/
show_screen()
{
if(video_mode < 0x12)
_setcolor(15);
else
_setcolor(253);
_rectangle(_GBORDER, 70, 0, 319, 199);
_rectangle(_GBORDER, 0, 0, 68, 199);
/* now the menu */
if(video_mode < 0x12)
_settextcolor(15);
else
_settextcolor(254);
_settextposition(2,2);
_outtext("IMAGE/1");
_settextposition(4,2);
_outtext("Load..");
_settextposition(5,2);
_outtext("Save..");
_settextposition(6,2);
_outtext("Palet");
_settextposition(7,2);
_outtext("poinT..");
_settextposition(8,2);
_outtext("conVol.");
_settextposition(9,2);
_outtext("Files..");
_settextposition(10,2);
_outtext("cOlors");
_settextposition(11,2);
_outtext("Median");
_settextposition(12,2);
_outtext("rEverse");
_settextposition(13,2);
_outtext("Histo");
_settextposition(14,2);
_outtext("pRint..");
_settextposition(15,2);
_outtext("laplaCe");
_settextposition(16,2);
_outtext("horizoN");
_settextposition(17,2);
_outtext("vertIca");
_settextposition(18,2);
_outtext("binariZ");
_settextposition(19,2);
_outtext("*=Shrnk");
_settextposition(20,2);
_outtext("/=SSTV ");
_settextposition(21,2);
_outtext(".=Morse");
_settextposition(23,2);
_outtext("Quit..");
}
/* the following routine is used if the program abort_ls */
abort_l(message)
char *message;
{
puts(message);
exit(-1);
}
/*****************************************/
/* pvprintf */
/* This routine prints a character */
/* at a certain point on the screen */
/*****************************************/
pvprintf(row_l, col_l, text, value)
char *text;
int value, row_l, col_l;
{
char local_b[15];
if(video_mode < 0x12)
_setcolor(15);
else
_setcolor(255);
_settextposition(row_l, col_l);
_outtext(text);
itoa(value,local_b, 10);
_outtext(local_b);
}
/*****************************************/
/* palette */
/* Sets the palette to all grey scale*/
/*****************************************/
palette_bw()
{
int i, j;
if(video_mode < 0x12)
return;
j = 2;
for(i=2; i < 255; i++)
{
outp(0x3c8,j);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
j++;
}
for(i=2; i < 64; i++)
{
outp(0x3c8,j);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
outp(0x3c9,i);
j+=4;
}
outp(0x3c8,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c8,249);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,60);
outp(0x3c9,10);
outp(0x3c9,40);
outp(0x3c9,30);
outp(0x3c9,50);
outp(0x3c9,10);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
return;
}
/* sets the palette to four gray scales */
palette_bw1()
{
int i, j;
if(video_mode < 0x12)
return;
j = 2;
outp(0x3c8,j);
for(i=2; i < 63; i++)
{
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
}
for(i=64; i < 127; i++)
{
outp(0x3c9,16);
outp(0x3c9,16);
outp(0x3c9,16);
}
for(i=128; i < 191; i++)
{
outp(0x3c9,32);
outp(0x3c9,32);
outp(0x3c9,32);
}
for(i=192; i < 255; i++)
{
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
}
outp(0x3c8,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c8,249);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,60);
outp(0x3c9,10);
outp(0x3c9,40);
outp(0x3c9,30);
outp(0x3c9,50);
outp(0x3c9,10);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
return;
}
/* sets the pallette to eight gray scales */
palette_bw2()
{
int i, j;
if(video_mode < 0x12)
return;
j = 2;
outp(0x3c8,j);
for(i=2; i < 31; i++)
{
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
}
for(i=32; i < 63; i++)
{
outp(0x3c9,8);
outp(0x3c9,8);
outp(0x3c9,8);
}
for(i=64; i < 95; i++)
{
outp(0x3c9,16);
outp(0x3c9,16);
outp(0x3c9,16);
}
for(i=96; i < 127; i++)
{
outp(0x3c9,24);
outp(0x3c9,24);
outp(0x3c9,24);
}
for(i=128; i < 159; i++)
{
outp(0x3c9,32);
outp(0x3c9,32);
outp(0x3c9,32);
}
for(i=160; i < 191; i++)
{
outp(0x3c9,48);
outp(0x3c9,48);
outp(0x3c9,48);
}
for(i=192; i < 223; i++)
{
outp(0x3c9,56);
outp(0x3c9,56);
outp(0x3c9,56);
}
for(i=224; i < 255; i++)
{
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
}
outp(0x3c8,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c8,249);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,60);
outp(0x3c9,10);
outp(0x3c9,40);
outp(0x3c9,30);
outp(0x3c9,50);
outp(0x3c9,10);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
return;
}
/* sets the pallette to 16 gray scales */
palette_bw3()
{
int i, j;
if(video_mode < 0x12)
return;
j = 2;
outp(0x3c8,j);
for(i=2; i < 15; i++)
{
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
}
for(i=16; i < 31; i++)
{
outp(0x3c9,4);
outp(0x3c9,4);
outp(0x3c9,4);
}
for(i=32; i < 47; i++)
{
outp(0x3c9,8);
outp(0x3c9,8);
outp(0x3c9,8);
}
for(i=48; i < 63; i++)
{
outp(0x3c9,12);
outp(0x3c9,12);
outp(0x3c9,12);
}
for(i=64; i < 79; i++)
{
outp(0x3c9,16);
outp(0x3c9,16);
outp(0x3c9,16);
}
for(i=80; i < 95; i++)
{
outp(0x3c9,20);
outp(0x3c9,20);
outp(0x3c9,20);
}
for(i=96; i < 111; i++)
{
outp(0x3c9,24);
outp(0x3c9,24);
outp(0x3c9,24);
}
for(i=112; i < 127; i++)
{
outp(0x3c9,28);
outp(0x3c9,28);
outp(0x3c9,28);
}
for(i=128; i < 143; i++)
{
outp(0x3c9,32);
outp(0x3c9,32);
outp(0x3c9,32);
}
for(i=144; i < 159; i++)
{
outp(0x3c9,36);
outp(0x3c9,36);
outp(0x3c9,36);
}
for(i=160; i < 175; i++)
{
outp(0x3c9,40);
outp(0x3c9,40);
outp(0x3c9,40);
}
for(i=176; i < 191; i++)
{
outp(0x3c9,44);
outp(0x3c9,44);
outp(0x3c9,44);
}
for(i=192; i < 207; i++)
{
outp(0x3c9,48);
outp(0x3c9,48);
outp(0x3c9,48);
}
for(i=208; i < 223; i++)
{
outp(0x3c9,52);
outp(0x3c9,52);
outp(0x3c9,52);
}
for(i=224; i < 239; i++)
{
outp(0x3c9,56);
outp(0x3c9,56);
outp(0x3c9,56);
}
for(i=240; i < 255; i++)
{
outp(0x3c9,60);
outp(0x3c9,60);
outp(0x3c9,60);
}
outp(0x3c8,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c9,0);
outp(0x3c8,249);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,60);
outp(0x3c9,10);
outp(0x3c9,40);
outp(0x3c9,30);
outp(0x3c9,50);
outp(0x3c9,10);
outp(0x3c9,63);
outp(0x3c9,63);
outp(0x3c9,63);
return;
}
/*****************************************/
/* palette_col */
/* Sets the palette to colors */
/*****************************************/
palette_col()
{
int i, j;
j=1;
outp(0x3c8, j);
for(i=1; i < 64; i++, j++)
{
/* purple to blue */
outp(0x3c9, 63-i);
outp(0x3c9, 0);
outp(0x3c9, 63);
}
for(i=0; i < 64; i+=2, j++)
{
/* blue to green blue */
outp(0x3c9, 0);
outp(0x3c9, i);
outp(0x3c9, 63);
}
for(i=0; i < 64; i+=2, j++)
{
/* green blue to green */
outp(0x3c9, 0);
outp(0x3c9, 63);
outp(0x3c9, 63-i);
}
for(i=0; i < 64; i+=2, j++)
{
/* green to yellow green */
outp(0x3c9, i);
outp(0x3c9, 63);
outp(0x3c9, 0);
}
for(i=0; i < 64; i+=2, j++)
{
/* yellow green to red */
outp(0x3c9, 63);
outp(0x3c9, 63-i);
outp(0x3c9, 0);
}
for(i=0; i < 64; i++, j++)
{
/* red to purple red */
outp(0x3c9, 63);
outp(0x3c9, 0);
outp(0x3c9, i);
}
outp(0x3c8, 253);
outp(0x3c9, 60);
outp(0x3c9, 10);
outp(0x3c9, 40);
outp(0x3c9, 30);
outp(0x3c9, 50);
outp(0x3c9, 10);
outp(0x3c9, 63);
outp(0x3c9, 63);
outp(0x3c9, 63);
outp(0x3c8, 0);
outp(0x3c9, 0);
outp(0x3c9, 0);
outp(0x3c9, 0);
return;
}
/* the following opens a window and shows the message. Then */
/* it takes the input and returns it */
/*******************************************/
/* */
/* put_to_display( buf1) */
/* */
/* This routine outputs the image from */
/* the display buffer pointed to by the*/
/* *buf1. buf1 is the address */
/* of the buffer. */
/*******************************************/
char far *buffer;
put_to_display(buf1)
char *buf1;
{
unsigned row, col, i, col1;
unsigned char k;
unsigned char *address = 0xa0000000;
if(condense == 0)
{
row = 50;
col = i=0;
i = 256*24;
while(row < 247)
{
k = *(buf1+i);
if(k > 252)
k = 252;
if((col+71) < 318)
{
if(!ega)
*(address+((row-49)*320)+col+71) = k;
else
{
_setcolor(k / 16);
_setpixel(col+71, row-49);
}
}
i++;
col++;
if(col >= 256)
{
col=0;
row++;
}
}
}
else
{
row = 53;
col = col1 = i = 0;
i = 256*16;
if(sstv)
{
output_sound(1000, 30); /* the VSYNC */
while(row < 173)
{
k = *(buf1+i);
if((col+71) < 191)
{
if(k > 252) k = 252;
output_sound(k, 0);
*(address+((row-49)*320)+col+71) = k;
}
i+=2;
col++;
if(col >= 256)
{
col=0;
output_sound(500, 5);
row++;
}
}
}
while(row < 173)
{
k = *(buf1+i);
if(k > 252)
k = 252;
if((col+71) < 191)
{
if(!ega)
*(address+((row-49)*320)+col+71) = k;
else
{
_setcolor(k / 16);
_setpixel(col+71, row-49);
}
}
i+=2;
col++;
if(col >= 256)
{
col=0;
row++;
}
}
}
}
/*******************************************/
/* */
/* window_show(msg, type, buf) */
/* */
/* This routine opens a window on the */
/* screen and displays the message */
/* pointed to be msg. If type is LINE */
/* then the routine returns the line in*/
/* buf. If the type is CHAR then it */
/* returns the character typed-in. */
/*******************************************/
window_show(msg, type, buf)
char *msg, *buf;
int type;
{
int i, j, k;
long size;
buffer = (char far *)
malloc((unsigned int) _imagesize(100, 150, 300,190));
if(buffer == (char far *)NULL)
abort_l("Not enough memory for window_show\n");
_getimage(100,150,300,190,buffer);
if(video_mode < 0x12)
_setcolor(15);
else
_setcolor(253);
_rectangle(_GFILLINTERIOR, 100,150,300,190);
_setcolor(0);
_rectangle(_GFILLINTERIOR, 102,152,298,188);
if(video_mode < 0x12)
_settextcolor(15);
else
_settextcolor(254);
_settextposition(21, 15);
_outtext(msg);
if(type == CHAR)
k = pvgetch();
else
if(type == LINE)
{
_settextposition(22,15);
i=0;
memset(buf, 0, 20);
while((k = pvgetch()) != 0x0d)
{
*(buf+i)=k;
_settextposition(22,15);
_outtext(buf);
i++;
}
*(buf+i)='\0';
}
_putimage(100,150, buffer, _GPSET);
free((char *) buffer);
return k;
}
/* the following is the morse code */
/* 0 delimits, 1 is dots, 2 is dashes */
unsigned char morse[]={
'E',1,0,
'T',2,0,
'I',1,1,0,
'A',1,2,0,
'N',2,1,0,
'M',2,2,0,
'S',1,1,1,0,
'U',1,1,2,0,
'R',1,2,1,0,
'W',1,2,2,0,
'D',2,1,1,0,
'K',2,1,2,0,
'G',2,2,1,0,
'O',2,2,2,0,
'H',1,1,1,1,0,
'V',1,1,1,2,0,
'F',1,1,2,1,0,
'L',1,2,1,1,0,
'P',1,2,2,1,0,
'J',1,2,2,2,0,
'B',2,1,1,1,0,
'X',2,1,1,2,0,
'C',2,1,2,1,0,
'Y',2,1,2,2,0,
'Z',2,2,1,1,0,
'Q',2,2,1,2,0,
'5',1,1,1,1,1,0,
'4',1,1,1,1,2,0,
'3',1,1,1,2,2,0,
'2',1,1,2,2,2,0,
'1',1,2,2,2,2,0,
'6',2,1,1,1,1,0,
'7',2,2,1,1,1,0,
'8',2,2,2,1,1,0,
'9',2,2,2,2,1,0,
'0',2,2,2,2,2,0,
'_',1,1,1,2,1,2,0};
unsigned char current_color = 1;
unsigned char current_red=0;
unsigned char current_green=0;
unsigned char current_blue=0;
unsigned char local_b[1024];
/* the following is the convolution kernel */
int kernel_v[9] = {-1,0,1,-1,0,1,-1,0,1};
int kernel_h[9] = {-1,-1,-1, 0,0,0,1,1,1};
int kernel[9] = {-1,-1,-1,-1,9,-1,-1,-1,-1};
int kernel_m[9] = {1,1,1,1,1,1,1,1,1};
int kernel_lap[9] = {-1,-1,-1,-1,8,-1,-1,-1,-1};
int kernel_l[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int histo[256];
unsigned char print_parts[72]={
0,0,0,
0,2,0,
0,1,0,
1,0,2,
2,0,1,
0,3,0,
1,2,1,
2,1,2,
3,0,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3,
3,3,3};
/*******************************************/
/* */
/* main() */
/* */
/* This is the main routine of the */
/* program. */
/* */
/*******************************************/
main(argc , argv)
int argc;
char *argv[];
{
register i, j, i1, j1, positive, scale;
int k, k_loc, flag, speed;
unsigned long counter;
char local_buffer [ 128], local_buffer2[128], value;
FILE *stream;
unsigned count;
unsigned disk_buffer;
unsigned char *dsk_buffer, *dsk2_buffer, *string;
struct SREGS segregs;
union REGS regs;
unsigned long temp;
unsigned char i1_loc;
unsigned char print_array[1024];
/* the start up */
/* set to VGA */
struct videoconfig config;
palette_value = 0;
/* show copyright image */
printf("\n\n\n/**************************************************/\n");
printf("/* Image Release 1.0 Image processing program */\n");
printf("/* */\n");
printf("/* Copyright (C) 1989 Peter P. Vekinis */\n");
printf("/* This program is sold according to the share- */\n");
printf("/* ware concept. If you find this program useful */\n");
printf("/* and to get a disk containing additional images*/\n");
printf("/* send $15 to Peter P. Vekinis, 119 N. Harvard */\n");
printf("/* Arlington Heights, IL 60004, USA */\n");
printf("/* Outside the US, add $5 for additional postage */\n");
printf("/* */\n");
printf("/* Image processing was developed in Microsoft C */\n");
printf("/* License is given to modify the program and its*/\n");
printf("/* accompanying source code. */\n");
printf("/* */\n");
printf("/* Press
printf("/**************************************************/\n");
getch();
if(argv[1][0] == '-' && argv[1][1] == 'e')
{
if(!_setvideomode(_MRES16COLOR))
abort_l("No EGA adapter found\n");
ega=1;
}
else
{
if(!_setvideomode(_MRES256COLOR))
abort_l("No VGA adapter found\n");
ega=0;
}
/* get the video mode */
regs.h.ah = 15;
int86(0x10, ®s, ®s);
video_mode = regs.h.al;
/***********************************************/
/* We get the memory from DOS because the C */
/* compiler never returns a buffer with a */
/* zeroed offset. If DOS will return a buffer */
/* at (say) 4567:0000 while the Compiler */
/* will return 4567:000C which is more complex */
/* for the program */
/***********************************************/
regs.x.bx=4096;
regs.h.ah=0x48;
int86(0x21,®s, ®s);
if(regs.x.cflag)
abort_l("No memory for memory buffer\n");
disk_buffer = regs.x.ax;
temp = regs.x.ax;
temp = temp << 16;
dsk_buffer = (unsigned long) temp;
global_buffer = dsk_buffer;
regs.x.bx=4096;
regs.h.ah=0x48;
int86(0x21,®s, ®s);
if(regs.x.cflag)
abort_l("No memory for memory 2 buffer\n");
temp = regs.x.ax;
temp = temp << 16;
dsk2_buffer = (unsigned long) temp;
/* asign the default palette */
palette_bw();
/* draw the rectangles and the menu */
show_screen();
/* the commands */
while(1)
{
k = pvgetch();
switch(k)
{
case '.': /* the morse practice */
window_show("Enter file name please", LINE, local_buffer);
stream = fopen(local_buffer, "r");
if(stream == NULL)
break;
flag = 1;
/* now analyse the text and issue the codes */
speed = 4;
nxt:
while(flag != EOF)
{
if(kbhit())
{
k = getch();
if(k == '+')
speed++;
else
if(k == '-')
{
if(speed < 1)
speed=1;
else
speed--;
}
else
break;
}
flag = toupper(fgetc(stream));
if(flag < 0x20)
goto nxt;
if(flag == 0x20) /* space then wait a little */
for(temp =0; temp < speed * 5000L; temp++)
;
/* get the codes */
for(i=0; i< 212; i++)
{
if(morse[i] == flag)
{
for(j = i+1; j < i+6; j++)
{
if(morse[j] == 0)
{
for(temp =0; temp < speed * 4000L; temp++)
;
break;
}
for(temp =0; temp < speed * 500L; temp++)
;
if(morse[j] == 1)
tone(1000,25 * speed);
for(temp =0; temp < speed * 500L; temp++)
;
if(morse[j] == 2)
tone(1000,60 * speed);
}
}
}
}
fclose(stream);
break;
case '/': /* the sstv sound */
if(sstv)
sstv =0;
else
sstv = 1;
break;
case 'o':
case 'O': /* show the palette */
for(i=0; i < 255; i++)
{
_setcolor(i);
_moveto(i+65, 192);
_lineto(i+65, 198);
}
break;
case '*': /* condense is changed */
memset(dsk2_buffer, 0, 64000);
put_to_display(dsk2_buffer);
if(condense == 0) condense = 1; else condense = 0;
put_to_display(dsk_buffer);
break;
case 'q':
case 'Q': /* quit */
k_loc = window_show("Are you sure (Y)", CHAR, local_buffer);
if(k_loc == 'y')
{
_setvideomode(_TEXTC80);
exit(0);
}
break;
case 'f':
case 'F': /* files */
window_show("Enter file specifier:",LINE, local_buffer);
_setvideomode(_TEXTC80);
strcpy(local_buffer2, "dir ");
strcat(local_buffer2, local_buffer);
strcat(local_buffer2, "/p");
system(local_buffer2);
puts("Press a key to return");
getch();
_setvideomode(video_mode);
palette_bw();
show_screen();
break;
case 'e': /* the reverse */
case 'E':
for(count=0; count<64000; count++)
*(dsk_buffer+count) = 255 - *(dsk_buffer+count);
put_to_display(dsk_buffer);
break;
case 'z': /* the binarize */
case 'Z':
for(count=0; count<64000; count++)
if(*(dsk_buffer+count) < 128)
*(dsk_buffer+count)=0;
else
if(*(dsk_buffer+count) > 128)
*(dsk_buffer+count)=255;
put_to_display(dsk_buffer);
break;
case 'c': /* the laplacian */
case 'C':
for(i=1; i<256; i++) /* rows */
{
pvprintf(22,2,"N:",i);
for(j=1; j<256; j++) /* columns */
{
/* copy the live into the kernel */
copy_kernel(kernel_l, kernel_lap, dsk_buffer, j, i, ADD,0);
if(kernel_l[4] < 0)
kernel_l[4] *=-1;
if(kernel_l[4] > 255)
kernel_l[4] =255;
*(dsk2_buffer+j+(i*256))=(unsigned char )kernel_l[4];
}
}
memcpy(dsk_buffer, dsk2_buffer, 64000);
put_to_display( dsk_buffer);
break;
case 'n': /* the horizontal */
case 'N':
for(i=2; i<254; i++) /* rows */
{
pvprintf(22,2,"N:",i);
for(j=2; j<254; j++) /* columns */
{
copy_kernel(kernel_l, kernel_h, dsk_buffer, j, i, ADD,0);
/* copy the live into the kernel */
if(kernel_l[4] < 0)
kernel_l[4] *=-1;
if(kernel_l[4] > 255)
kernel_l[4] =255;
*(dsk2_buffer+j+(i*256))=(unsigned char )kernel_l[4];
}
}
memcpy(dsk_buffer, dsk2_buffer, 64000);
put_to_display( dsk_buffer);
break;
case 'i': /* the vertical */
case 'I':
for(i=3; i<252; i++) /* rows */
{
pvprintf(22,2,"N:",i);
for(j=2; j<254; j++) /* columns */
{
copy_kernel(kernel_l, kernel_v, dsk_buffer, j, i, ADD,0);
if(kernel_l[4] < 0)
kernel_l[4] *=-1;
if(kernel_l[4] > 255)
kernel_l[4] =255;
*(dsk2_buffer+j+(i*256))=(unsigned char )kernel_l[4];
}
}
memcpy(dsk_buffer, dsk2_buffer, 64000);
put_to_display( dsk_buffer);
break;
case 'r': /* the print */
case 'R':
if(window_show("Select: + or -",CHAR, local_buffer) == '+')
positive=1;
else
positive=0;
i1=0;
/* print the title */
time (&temp);
strcpy(local_buffer, "Printing on ");
strcat(local_buffer,ctime(&temp));
pristr(local_buffer);
prich(0x0d);
prich(0x0a);
prich(0x0d);
prich(0x0a);
/**********************************************/
/* Put the printer data in a buffer on a line */
/* by line basis. This is needed for Epson */
/* printers. Also, fours rows are used per */
/* line for the printing. */
/**********************************************/
for(i=40; i<240; i+=4) /* the row */
{
for(j=0; j<256; j++) /* the column */
{
print_array[i1]=0;
print_array[i1]=
print_parts[(*(dsk_buffer+(i*256)+j)/28)*3] << 6;
print_array[i1+1]=
print_parts[((*(dsk_buffer+(i*256)+j)/28)*3)+1] << 6;
print_array[i1+2]=
print_parts[((*(dsk_buffer+(i*256)+j)/28)*3)+2] << 6;
print_array[i1] |=
print_parts[(*(dsk_buffer+((i+1)*256)+j)/28)*3] << 4;
print_array[i1+1] |=
print_parts[((*(dsk_buffer+((i+1)*256)+j)/28)*3)+1] << 4;
print_array[i1+2] |=
print_parts[((*(dsk_buffer+((i+1)*256)+j)/28)*3)+2] << 4;
print_array[i1] |=
print_parts[(*(dsk_buffer+((i+2)*256)+j)/28)*3] << 2;
print_array[i1+1] |=
print_parts[((*(dsk_buffer+((i+2)*256)+j)/28)*3)+1] << 2;
print_array[i1+2] |=
print_parts[((*(dsk_buffer+((i+2)*256)+j)/28)*3)+2] << 2;
print_array[i1] |=
print_parts[(*(dsk_buffer+((i+3)*256)+j)/28)*3];
print_array[i1+1] |=
print_parts[((*(dsk_buffer+((i+3)*256)+j)/28)*3)+1];
print_array[i1+2] |=
print_parts[((*(dsk_buffer+((i+3)*256)+j)/28)*3)+2];
i1+=3;
}
i1 = 0;
/* now print the buffer */
prich(0x1b);
prich('L');
prich(0);
prich(3);
for(j=0; j<768; j++)
if(positive)
prich(~(print_array[j]| 0x03));
else
prich((print_array[j] & 0xfc));
prich(0x0d);
prich(0x1b);
prich(0x4a);
prich(0x12);
}
prich(12);
break;
case 'h': /* the histogram */
case 'H':
_settextposition(10,10);
_settextcolor(255);
_outtext("Processing...");
/* fill up the cells */
for(count=0; count<255; count++)
histo[count]=0;
for(count=0; count<64000; count++)
histo[*(dsk_buffer+count)]++;
/* display */
_setcolor(0);
_rectangle(_GFILLINTERIOR, 70, 0, 319, 199);
_setcolor(255);
/* put the axes */
_moveto(72, 2);
_lineto(72, 196);
_lineto(317, 196);
/* now the histogram */
for(i=5; i<240; i++)
{
if(palette_value)
_setcolor(i);
_moveto(74+i, 194);
_lineto(74+i, 194 - (histo[i]%195));
}
getch();
put_to_display(dsk_buffer);
break;
case 'l':
case 'L': /* load a file */
window_show("Enter file name please", LINE, local_buffer);
stream = fopen(local_buffer, "rb");
if(stream == NULL)
break;
fread(dsk_buffer, 1, 64000, stream);
fclose(stream);
put_to_display(dsk_buffer);
break;
case 's': /* save a file */
case 'S':
window_show("Enter file name please",LINE, local_buffer);
stream = fopen(local_buffer, "wb");
if(stream == NULL)
break;
fwrite(dsk_buffer, 1, 64000, stream);
fclose(stream);
break;
case 'p':
case 'P': /* the palette change */
switch(palette_value)
{
case 0:
palette_bw();
break;
case 1:
palette_col();
break;
case 2:
palette_bw1();
break;
case 3:
palette_bw2();
break;
case 4:
palette_bw3();
break;
}
if(palette_value > 4)
palette_value=0;
else
palette_value++;
break;
case 't':
case 'T': /* adjust point by point */
window_show("Value (-256 to 256)",LINE, local_buffer);
j = atoi(local_buffer);
for(count=0; count<64000; count++)
{
i1 = *(dsk_buffer+count);
if((i1+j) <= 0)
i1 = 0;
else
if((i1+j) > 255)
i1 = 255;
else
if(i1 == 0)
i1 = 0;
else
i1 +=j;
*(dsk_buffer+count)= i1;
}
put_to_display(dsk_buffer);
break;
case 'v':
case 'V': /* the convolution */
/* show the kernel */
_setcolor(0);
_rectangle(_GFILLINTERIOR, 72, 8, 140, 32);
pvprintf(2,10,"",kernel[0]);
pvprintf(2,13,"",kernel[1]);
pvprintf(2,16,"",kernel[2]);
pvprintf(3,10,"",kernel[3]);
pvprintf(3,13,"",kernel[4]);
pvprintf(3,16,"",kernel[5]);
pvprintf(4,10,"",kernel[6]);
pvprintf(4,13,"",kernel[7]);
pvprintf(4,16,"",kernel[8]);
if(window_show("New kernel (y/n)",CHAR,local_buffer) == 'y')
{
window_show("Kernel[0][0] ?",LINE, local_buffer);
kernel[0] = atoi(local_buffer);
window_show("Kernel[0][1] ?",LINE, local_buffer);
kernel[1] = atoi(local_buffer);
window_show("Kernel[0][2] ?",LINE, local_buffer);
kernel[2] = atoi(local_buffer);
window_show("Kernel[1][0] ?",LINE, local_buffer);
kernel[3] = atoi(local_buffer);
window_show("Kernel[1][1] ?",LINE, local_buffer);
kernel[4] = atoi(local_buffer);
window_show("Kernel[1][2] ?",LINE, local_buffer);
kernel[5] = atoi(local_buffer);
window_show("Kernel[2][0] ?",LINE, local_buffer);
kernel[6] = atoi(local_buffer);
window_show("Kernel[2][1] ?",LINE, local_buffer);
kernel[7] = atoi(local_buffer);
window_show("Kernel[2][2] ?",LINE, local_buffer);
kernel[8] = atoi(local_buffer);
}
/* show the kernel */
_rectangle(_GFILLINTERIOR, 72, 8, 140, 32);
pvprintf(2,10,"",kernel[0]);
pvprintf(2,13,"",kernel[1]);
pvprintf(2,16,"",kernel[2]);
pvprintf(3,10,"",kernel[3]);
pvprintf(3,13,"",kernel[4]);
scale = kernel[4];
pvprintf(3,16,"",kernel[5]);
pvprintf(4,10,"",kernel[6]);
pvprintf(4,13,"",kernel[7]);
pvprintf(4,16,"",kernel[8]);
for(i=1; i<256; i++) /* rows */
{
pvprintf(22,2,"N:",i);
for(j=1; j<256; j++) /* columns */
{
copy_kernel(kernel_l, kernel, dsk_buffer, j, i, ADD,0);
if(scale == 10)
scale = 1;
else
if(scale == 12)
scale = 2;
else
scale = 0;
kernel_l[4] >>= scale;
if(kernel_l[4] < 0)
kernel_l[4] =0;
if(kernel_l[4] > 255)
kernel_l[4] =255;
*(dsk2_buffer+j+(i*256))=kernel_l[4];
}
}
memcpy(dsk_buffer, dsk2_buffer, 64000);
put_to_display( dsk_buffer);
break;
case 'm':
case 'M': /* the median filter */
/* count how many are 0s */
count=0;
for(i=0; i < 9; i++)
if(kernel[i] == 0)
count++;
for(i=1; i<256; i++) /* rows */
{
pvprintf(22,2,"N:",i);
for(j=1; j<256; j++) /* columns */
{
copy_kernel(kernel_l, kernel_m, dsk_buffer, j, i, MULT, count);
if(kernel_l[4] < 0)
kernel_l[4] *=-1;
if(kernel_l[4] > 255)
kernel_l[4] =255;
*(dsk2_buffer+j+(i*256))=(unsigned char )kernel_l[4];
}
}
memcpy(dsk_buffer, dsk2_buffer, 64000);
put_to_display( dsk_buffer);
break;
}
}
}
copy_kernel(kernel_1st, kernel_2nd, buffer, j, i, mode, count)
int kernel_1st[], kernel_2nd[], j, i, mode, count;
unsigned char *buffer;
{
kernel_1st[0]=*(buffer+j+((i-1)*256)-1);
kernel_1st[1]=*(buffer+j+((i-1)*256));
kernel_1st[2]=*(buffer+j+((i-1)*256)+1);
kernel_1st[3]=*(buffer+j+( i *256)-1);
kernel_1st[4]=*(buffer+j+( i *256));
kernel_1st[5]=*(buffer+j+( i *256)+1);
kernel_1st[6]=*(buffer+j+((i+1)*256)-1);
kernel_1st[7]=*(buffer+j+((i+1)*256));
kernel_1st[8]=*(buffer+j+((i+1)*256)+1);
/* multiply with the other kernel */
kernel_1st[0]=kernel_2nd[0]*kernel_1st[0];
kernel_1st[1]=kernel_2nd[1]*kernel_1st[1];
kernel_1st[2]=kernel_2nd[2]*kernel_1st[2];
kernel_1st[3]=kernel_2nd[3]*kernel_1st[3];
kernel_1st[4]=kernel_2nd[4]*kernel_1st[4];
kernel_1st[5]=kernel_2nd[5]*kernel_1st[5];
kernel_1st[6]=kernel_2nd[6]*kernel_1st[6];
kernel_1st[7]=kernel_2nd[7]*kernel_1st[7];
kernel_1st[8]=kernel_2nd[8]*kernel_1st[8];
/* add or multiply for the process */
if(mode == ADD)
{
kernel_1st[4]=kernel_1st[0]+
kernel_1st[1]+
kernel_1st[2]+
kernel_1st[3]+
kernel_1st[4]+
kernel_1st[5]+
kernel_1st[6]+
kernel_1st[7]+
kernel_1st[8];
}
else
{
kernel_1st[4]=(kernel_1st[0]+
kernel_1st[1]+
kernel_1st[2]+
kernel_1st[3]+
kernel_1st[4]+
kernel_1st[5]+
kernel_1st[6]+
kernel_1st[7]+
kernel_1st[8]) / (9-count);
}
}
output_sound(number, duration)
int number, duration;
{
register i, j;
switch(number)
{
case 1000: /* the VSYNC */
tone(1200, 60);
break;
case 500: /* the HSYNC */
tone(1200, 10);
break;
default:
tone((number*3) + 1500, 1);
}
}
#define TIMERMODE 182 /*code for timer chip */
#define FREQSCALE 1193182L /* basic time freq in hz */
#define TIMESCALE 200L /* number of counts in .5 ms */
#define T_MODEPORT 67 /* the port control */
#define FREQPORT 66
#define BEEPPORT 97
#define ON1 79
tone(freq, dur)
int freq, dur;
{
int hibyt, lobyt, port;
unsigned long i, count, divisor;
divisor = FREQSCALE/freq;
lobyt = divisor % 256; /*break integer in lo and hi parts */
hibyt = divisor / 256;
count = TIMESCALE * dur;
outp(T_MODEPORT, TIMERMODE);
outp(FREQPORT, lobyt); /* send data to timer */
outp(FREQPORT, hibyt);
port= inp(BEEPPORT); /* save the setting */
outp(BEEPPORT, ON1);
for(i = 0; i<= count; i++)
;
outp(BEEPPORT, port);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/