/* * Graphics Resolution Converter * File: GRAFCON.C * version 032586 Tuesday Edition * (c) 1986 Antic Publishing * Written by Patrick Bass * * The purpose of this program is to convert a color * picture to black & white, and uh... vice-versa. * *---- Alcyon Include File -----------------*/ #include "osbind.h" #define TRUE (1) #define FALSE (0) #define CANCEL (0) #define NO (2) #define ERROR (-1) #define begin { #define end } #define wend } #define repeat } #define next } #define endif } #define not ! #define equals == #define does_not_equal != #define then #define AND && #define ORed_with | #define DELAY for( delay=0; delay<32767; delay++ ); #define NEO 1 #define DEGAS 2 #define DOODLE 3 #define LOREZ 0 #define MEDREZ 1 #define HIREZ 2 #define SIMPLE 1 #define COMPLEX 2 #define RLE 2 #define FLATHAND 4 #define ARROW 0 #define ESC 27 #define NOTOKEN 0 #define WTOKEN 1 #define BTOKEN 2 #define WHITE 0 #define BLACK 1 /*---------------- Alcyon Declarations/Equates --------*/ int contrl[ 12 ], intin[ 256 ], ptsin[ 256 ], intout[ 256 ], ptsout[ 256 ], workin[]={ 1,1,1,1,1,1,1,1,1,1,2 }, workout[ 57 ], i, j, k, l, character, type_picture, src_rez, dest_rez, read_rez, resolution, type_conversion, src_type, dest_type, write_rez, len_pixline, mx, xres, my, yres, color, max_color, delay, drive, top, bottom, dum, lo_word, hi_word, handle, file_handle, read_handle, pix_handle, for_reading, temp_pixel, action_desired, bytes_read, button, pressed, finished, rle_able, rle_index, box_width, box_height, box_sx, box_sy, box_fx, box_fy, x_offset[]={ 96, 192, 192 }, y_offset[]={ 4, 4, 104 }, white, black, old, current, change, new_palette[ 16 ], org_palette[ 16 ]; char src_picture[ 32767 ], dest_picture[ 32767 ], rle_buffer[ 32767 ], neo_buffer[ 1000 ], path[]="a:*.*\0", in_filename[]="filename.ext\0", out_filename[]="filename.ext\0", rlealert[]="[3][ Format or RLE conversion? ][Format|RLE]", alert0[]="[1][ Welcome to | GrafCon/520 | v.032586 ][ Perform ]", oreadalert[]="[3][ Select the picture to convert. ][ Select ]", owritealert[]="[3][ Select the file to write to. ][ Select ]", stypealert[]="[3][ Source picture is type: ][Neo|Degas|Doodle]", dtypealert[]="[3][ Dest picture will be type: ][Neo|Degas|Doodle]", srezalert[]="[3][ Source resolution is ? ][ Lo | Med | Hi ]", drezalert[]="[3][ Dest resolution will be ? ][ Lo | Med | Hi ]", simalert[]="[3][ Type of Hi-res conversion?][ Simple | Complex ]", pralert[]="[3][ When conversion is|finished, press mouse key.][Go]", alert3[]="[3][ Convert another picture? ][ Yes | No ]", alert4[]="[3][ Thanks for using | GrafCon/520 | v.032586 ][ Exit ]", owrlealert[]="[3][ Select an RLE file to write to.][ Choose it ]"; long max_len=32767, write_handle, write_bytes, org_pix, src_pix, des_pix, answer, temp_answer; /*-------------------------------------------------------------------*/ main() begin initialize(); do begin if( rle_able ) then rle_conversion(); if( not rle_able ) then graphics_conversion(); repeat while( not finished ); terminate(); end /*--------------------------------*/ graphics_conversion() begin select_parameters(); read_the_picture(); convert_the_picture(); wait_for_mousepress(); write_the_picture(); button=form_alert( 2, alert3 ); if( button equals NO ) then finished=TRUE; end /*--------------------------------*/ initialize() begin appl_init(); handle=graf_handle( &i, &i, &i, &i ); v_opnvwk( workin, &handle, workout ); xres=workout[ 0 ]; yres=workout[ 1 ]; max_color=( workout[ 13 ]-1 ); for( i=0; i<16; i++ ) begin new_palette[ i ]=org_palette[ i ]=Setcolor( i, -1 ); next org_pix=Physbase(); src_pix=( ( 0xffff00 & src_picture )+0x0100 ); des_pix=( ( 0xffff00 & dest_picture )+0x0100 ); resolution=Getrez(); box_width=256; box_height=192; form_alert( 1, alert0 ); finished=FALSE; for_reading=0; len_pixline=40; top=0; bottom=200; rle_able=FALSE; type_conversion=form_alert( 2, rlealert ); if( type_conversion equals RLE ) then rle_able=TRUE; end /*---------------------------*/ wait_for_mousepress() begin int mx, my, pressed, dum; do begin graf_mkstate( &mx, &my, &pressed, &dum ); repeat while( not pressed ); end /*---------------------------*/ select_parameters() begin src_type=form_alert( 2, stypealert ); DELAY src_rez=form_alert( 1, srezalert ); DELAY dest_type=form_alert( 2, dtypealert ); DELAY dest_rez=form_alert( 1, drezalert ); DELAY src_rez=src_rez-1; dest_rez=dest_rez-1; write_rez=dest_rez; type_conversion=COMPLEX; if(( src_rez equals HIREZ )AND( dest_rez equals LOREZ )) then begin type_conversion=form_alert( 2, simalert ); endif end /*---------------------------*/ read_the_picture() begin char *source, *dest; form_alert( 1, oreadalert ); drive=Dgetdrv(); path[ 0 ]=( drive+'A' ); fsel_input( path, in_filename, &button ); if( button does_not_equal CANCEL ) then begin form_alert( 1, pralert ); Setscreen( src_pix, src_pix, -1 ); v_hide_c( handle ); read_handle=Fopen( in_filename, for_reading ); if( read_handle > ERROR ) then begin if( src_type equals NEO ) then begin Fread( read_handle, 4L, neo_buffer ); Fread( read_handle, 32L, new_palette ); Fread( read_handle, 12L, out_filename ); Fread( read_handle, 80L, neo_buffer ); Fread( read_handle, 32000L, src_pix ); endif if( src_type equals DEGAS ) then begin Fread( read_handle, 2L, read_rez ); Fread( read_handle, 32L, new_palette ); Fread( read_handle, 32000L, src_pix ); endif if( src_type equals DOODLE ) then begin Fread( read_handle, 32000L, src_pix ); endif endif Fclose( read_handle ); Setpallete( new_palette ); endif Setscreen( des_pix, des_pix, -1 ); source=src_pix; dest=des_pix; for( i=0; i<32000; i++ ) begin ( *dest++ )=( *source++ ); next v_show_c( handle ); end /*---------------------------------*/ convert_the_picture() begin if( src_rez equals LOREZ ) then con_lorez(); if( src_rez equals MEDREZ ) then con_medrez(); if( src_rez equals HIREZ ) then con_hirez(); end /*---------------------------------*/ con_lorez() begin if( dest_rez equals LOREZ ) then wait_for_mousepress(); if( dest_rez equals MEDREZ ) then lomed(); if( dest_rez equals HIREZ ) then lohi(); end /*---------------------------------*/ lomed() begin int *src, *dest, pixword, temp_pixword, pixlo1, pixhi1, pixlo2, pixhi2, row, column; v_hide_c( handle ); Setscreen( des_pix, des_pix, -1 ); Setpallete( new_palette ); src=src_pix; dest=des_pix; for( row=top; row ERROR ) then begin if( dest_type equals NEO ) then begin Fwrite( pix_handle, 4L, &neo_buffer ); Fwrite( pix_handle, 32L, &new_palette ); Fwrite( pix_handle, 12L, &out_filename ); Fwrite( pix_handle, 80L, &neo_buffer ); Fwrite( pix_handle, 32000L, des_pix ); endif if( dest_type equals DEGAS ) then begin Fwrite( pix_handle, 2L, &write_rez ); Fwrite( pix_handle, 32L, &new_palette ); Fwrite( pix_handle, 32000L, des_pix ); endif if( dest_type equals DOODLE ) then begin Fwrite( pix_handle, 32000L, des_pix ); endif endif Fclose( pix_handle ); endif Setscreen( org_pix, org_pix, -1 ); Setpallete( org_palette ); v_show_c( handle ); end /*--------------------------------*/ int condense( leftword, rightword ) int leftword, rightword; begin int word_out; word_out=0; if( leftword&0xc000 ) then word_out=word_out ORed_with 0x8000; if( leftword&0x3000 ) then word_out=word_out ORed_with 0x4000; if( leftword&0x0c00 ) then word_out=word_out ORed_with 0x2000; if( leftword&0x0300 ) then word_out=word_out ORed_with 0x1000; if( leftword&0x00c0 ) then word_out=word_out ORed_with 0x0800; if( leftword&0x0030 ) then word_out=word_out ORed_with 0x0400; if( leftword&0x000c ) then word_out=word_out ORed_with 0x0200; if( leftword&0x0003 ) then word_out=word_out ORed_with 0x0100; if( rightword&0xc000 ) then word_out=word_out ORed_with 0x0080; if( rightword&0x3000 ) then word_out=word_out ORed_with 0x0040; if( rightword&0x0c00 ) then word_out=word_out ORed_with 0x0020; if( rightword&0x0300 ) then word_out=word_out ORed_with 0x0010; if( rightword&0x00c0 ) then word_out=word_out ORed_with 0x0008; if( rightword&0x0030 ) then word_out=word_out ORed_with 0x0004; if( rightword&0x000c ) then word_out=word_out ORed_with 0x0002; if( rightword&0x0003 ) then word_out=word_out ORed_with 0x0001; return( word_out ); end /*---------------------------------*/ rle_conversion() begin src_type=form_alert( 2, stypealert ); DELAY src_rez=form_alert( 1, srezalert ); DELAY read_the_picture(); find_area_to_convert(); rle_the_box(); Setpallete( org_palette ); button=form_alert( 2, alert3 ); if( button equals NO ) then finished=TRUE; end /*---------------------------------*/ rle_the_box() begin int row, column, box[ 10 ], element, pixel, new_pixel, mx, my, pressed, dum; white=0; black=0; change=FALSE; current=NOTOKEN; old=NOTOKEN; rle_index=0; rle_buffer[ rle_index++ ]=ESC; rle_buffer[ rle_index++ ]='G'; rle_buffer[ rle_index++ ]='H'; vsl_color( handle, BLACK ); box[ 0 ]=box_fx-1; box[ 1 ]=box_fy-1; box[ 2 ]=box_fx+box_width; box[ 3 ]=box_fy-1; box[ 4 ]=box_fx+box_width; box[ 5 ]=box_fy+box_height+1; box[ 6 ]=box_fx-1; box[ 7 ]=box_fy+box_height+1; box[ 8 ]=box_fx-1; box[ 9 ]=box_fy-1; v_pline( handle, 5, box ); v_hide_c( handle ); for( row=box_fy; row ERROR ) then begin Fwrite( pix_handle, (long)rle_index+1, rle_buffer ); endif Fclose( pix_handle ); endif v_show_c( handle ); end /*---------------------------------*/ blk_handle() begin current=BTOKEN; if(( current does_not_equal old )AND ( old does_not_equal NOTOKEN )) then begin change++; if( change>TRUE ) then w_record(); endif black++; if( black > 94 ) then w_record(); old=BTOKEN; end /*---------------------------------*/ wht_handle() begin current=WTOKEN; if(( current does_not_equal old )AND ( old does_not_equal NOTOKEN )) then begin change++; if( change>TRUE ) then w_record(); endif white++; if( white > 94 ) then w_record(); old=WTOKEN; end /*---------------------------------*/ w_record() begin rle_buffer[ rle_index++ ]=( black+32 ); rle_buffer[ rle_index++ ]=( white+32 ); black=white=0; end /*---------------------------------*/ find_area_to_convert() begin int off_x, off_y; off_x=x_offset[ resolution ]; off_y=y_offset[ resolution ]; graf_growbox( 0, 0, 2, 2, off_x, off_y, box_width, box_height ); graf_mouse( FLATHAND, 0x0L ); wait_for_mousepress(); do begin graf_dragbox( box_width, box_height, off_x, off_y, 0, 0, xres-1, yres-1, &box_fx, &box_fy ); graf_mkstate( &mx, &my, &pressed, &dum ); repeat while( pressed ); graf_shrinkbox( 0, 0, 2, 2, box_fx, box_fy, box_width, box_height ); graf_mouse( ARROW, 0x0L ); end /*--------------------------------*/ terminate() begin form_alert( 1, alert4 ); v_clsvwk( handle ); appl_exit(); end