Classic Computer Magazine Archive PROGRAM LISTING: 86-07/GRAFCON.C



/* 
 *  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<bottom; row++ ) begin
          for( column=0; column<20; column++ ) begin

               temp_pixword=( *src++ );
               pixword=( *src++ );
               blend( temp_pixword, pixword );
               pixhi1=hi_word; pixlo1=lo_word;

               temp_pixword=( *src++ );
               pixword=( *src++ );
               blend( temp_pixword, pixword );
               pixhi2=hi_word; pixlo2=lo_word;

               ( *dest++ )=pixhi1; ( *dest++ )=pixhi2;
               ( *dest++ )=pixlo1; ( *dest++ )=pixlo2;
          next
     next
     v_show_c( handle );
end

/*---------------------------------*/
lohi()
begin
     int  *src, *upper_dest, *lower_dest,
          pixword,
          lo0_pixword, hi0_pixword,
          lo1_pixword, hi1_pixword,
          pixlo1, pixlo0, pixhi1, pixhi0,
          row, column;

     v_hide_c( handle );
     Setscreen( des_pix, des_pix, -1 );
     Setpallete( new_palette );
     src=src_pix;
     upper_dest=des_pix;

     for( row=top; row<bottom; row++ ) begin
          for( column=0; column<20; column++ ) begin

               hi0_pixword=( *src++ ); lo0_pixword=( *src++ );
               hi1_pixword=( *src++ ); lo1_pixword=( *src++ );

               blend( hi0_pixword, lo0_pixword );
               pixhi0=hi_word; pixlo0=lo_word;

               blend( hi1_pixword, lo1_pixword );
               pixhi1=hi_word; pixlo1=lo_word;

               lower_dest=( upper_dest+len_pixline );
               ( *upper_dest++ )=pixhi0; ( *upper_dest++ )=pixlo0;
               ( *lower_dest++ )=pixhi1; ( *lower_dest )=pixlo1;
          next
          upper_dest=upper_dest+len_pixline;
     next
     v_show_c( handle );
end

/*---------------------------------*/
blend( leftword, rightword )
int  leftword, rightword;
begin
     hi_word=lo_word=0;

     if( leftword&0x8000 ) then hi_word=hi_word ORed_with 0x8000;
     if( rightword&0x8000 ) then hi_word=hi_word ORed_with 0x4000;
     if( leftword&0x4000 ) then hi_word=hi_word ORed_with 0x2000;
     if( rightword&0x4000 ) then hi_word=hi_word ORed_with 0x1000;

     if( leftword&0x2000 ) then hi_word=hi_word ORed_with 0x0800;
     if( rightword&0x2000 ) then hi_word=hi_word ORed_with 0x0400;
     if( leftword&0x1000 ) then hi_word=hi_word ORed_with 0x0200;
     if( rightword&0x1000 ) then hi_word=hi_word ORed_with 0x0100;

     if( leftword&0x0800 ) then hi_word=hi_word ORed_with 0x0080;
     if( rightword&0x0800 ) then hi_word=hi_word ORed_with 0x0040;
     if( leftword&0x0400 ) then hi_word=hi_word ORed_with 0x0020;
     if( rightword&0x0400 ) then hi_word=hi_word ORed_with 0x0010;

     if( leftword&0x0200 ) then hi_word=hi_word ORed_with 0x0008;
     if( rightword&0x0200 ) then hi_word=hi_word ORed_with 0x0004;
     if( leftword&0x0100 ) then hi_word=hi_word ORed_with 0x0002;
     if( rightword&0x0100 ) then hi_word=hi_word ORed_with 0x0001;

     if( leftword&0x0080 ) then lo_word=lo_word ORed_with 0x8000;
     if( rightword&0x0080 ) then lo_word=lo_word ORed_with 0x4000;
     if( leftword&0x0040 ) then lo_word=lo_word ORed_with 0x2000;
     if( rightword&0x0040 ) then lo_word=lo_word ORed_with 0x1000;

     if( leftword&0x0020 ) then lo_word=lo_word ORed_with 0x0800;
     if( rightword&0x0020 ) then lo_word=lo_word ORed_with 0x0400;
     if( leftword&0x0010 ) then lo_word=lo_word ORed_with 0x0200;
     if( rightword&0x0010 ) then lo_word=lo_word ORed_with 0x0100;

     if( leftword&0x0008 ) then lo_word=lo_word ORed_with 0x0080;
     if( rightword&0x0008 ) then lo_word=lo_word ORed_with 0x0040;
     if( leftword&0x0004 ) then lo_word=lo_word ORed_with 0x0020;
     if( rightword&0x0004 ) then lo_word=lo_word ORed_with 0x0010;

     if( leftword&0x0002 ) then lo_word=lo_word ORed_with 0x0008;
     if( rightword&0x0002 ) then lo_word=lo_word ORed_with 0x0004;
     if( leftword&0x0001 ) then lo_word=lo_word ORed_with 0x0002;
     if( rightword&0x0001 ) then lo_word=lo_word ORed_with 0x0001;
end

/*---------------------------------*/
separate( leftword, rightword )
int  leftword, rightword;
begin
     hi_word=lo_word=0;

     if( leftword&0x8000 ) then hi_word=hi_word ORed_with 0x8000;
     if( leftword&0x4000 ) then lo_word=lo_word ORed_with 0x8000;
     if( leftword&0x2000 ) then hi_word=hi_word ORed_with 0x4000;
     if( leftword&0x1000 ) then lo_word=lo_word ORed_with 0x4000;

     if( leftword&0x0800 ) then hi_word=hi_word ORed_with 0x2000;
     if( leftword&0x0400 ) then lo_word=lo_word ORed_with 0x2000;
     if( leftword&0x0200 ) then hi_word=hi_word ORed_with 0x1000;
     if( leftword&0x0100 ) then lo_word=lo_word ORed_with 0x1000;

     if( leftword&0x0080 ) then hi_word=hi_word ORed_with 0x0800;
     if( leftword&0x0040 ) then lo_word=lo_word ORed_with 0x0800;
     if( leftword&0x0020 ) then hi_word=hi_word ORed_with 0x0400;
     if( leftword&0x0010 ) then lo_word=lo_word ORed_with 0x0400;

     if( leftword&0x0008 ) then hi_word=hi_word ORed_with 0x0200;
     if( leftword&0x0004 ) then lo_word=lo_word ORed_with 0x0200;
     if( leftword&0x0002 ) then hi_word=hi_word ORed_with 0x0100;
     if( leftword&0x0001 ) then lo_word=lo_word ORed_with 0x0100;

     if( rightword&0x8000 ) then hi_word=hi_word ORed_with 0x0080;
     if( rightword&0x4000 ) then lo_word=lo_word ORed_with 0x0080;
     if( rightword&0x2000 ) then hi_word=hi_word ORed_with 0x0040;
     if( rightword&0x1000 ) then lo_word=lo_word ORed_with 0x0040;

     if( rightword&0x0800 ) then hi_word=hi_word ORed_with 0x0020;
     if( rightword&0x0400 ) then lo_word=lo_word ORed_with 0x0020;
     if( rightword&0x0200 ) then hi_word=hi_word ORed_with 0x0010;
     if( rightword&0x0100 ) then lo_word=lo_word ORed_with 0x0010;

     if( rightword&0x0080 ) then hi_word=hi_word ORed_with 0x0008;
     if( rightword&0x0040 ) then lo_word=lo_word ORed_with 0x0008;
     if( rightword&0x0020 ) then hi_word=hi_word ORed_with 0x0004;
     if( rightword&0x0010 ) then lo_word=lo_word ORed_with 0x0004;

     if( rightword&0x0008 ) then hi_word=hi_word ORed_with 0x0002;
     if( rightword&0x0004 ) then lo_word=lo_word ORed_with 0x0002;
     if( rightword&0x0002 ) then hi_word=hi_word ORed_with 0x0001;
     if( rightword&0x0001 ) then lo_word=lo_word ORed_with 0x0001;
end

/*---------------------------------*/
con_medrez()
begin
     if( dest_rez equals LOREZ ) then medlo();
     if( dest_rez equals MEDREZ ) then wait_for_mousepress();
     if( dest_rez equals HIREZ ) then medhi();
end

/*---------------------------------*/
medlo()
begin
     int  *src, *dest,
          pixlo1, pixlo2, pixhi1, 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<bottom; row++ ) begin
          for( column=0; column<20; column++ ) begin

               pixhi1=( *src++ ); pixhi2=( *src++ );
               pixlo1=( *src++ ); pixlo2=( *src++ );

               separate( pixhi1, pixlo1 );
               pixhi1=hi_word; pixlo1=lo_word;

               separate( pixhi2, pixlo2 );
               pixhi2=hi_word; pixlo2=lo_word;

               ( *dest++ )=pixhi1; ( *dest++ )=pixlo1;
               ( *dest++ )=pixhi2; ( *dest++ )=pixlo2;
          next
     next
     v_show_c( handle );
end

/*---------------------------------*/
medhi()
begin
     int  *src, *upper_dest, *lower_dest,
          pixword, lo_pixword, hi_pixword,
          pixlo1, pixlo2, pixhi1, pixhi2,
          row, column;

     v_hide_c( handle );
     Setscreen( des_pix, des_pix, -1 );
     Setpallete( new_palette );
     src=src_pix;
     upper_dest=des_pix;

     for( row=top; row<bottom; row++ ) begin
          for( column=0; column<len_pixline; column++ ) begin

               lower_dest=( upper_dest+len_pixline );
               ( *upper_dest++ )=( *src++ );
               ( *lower_dest )=( *src++ );

          next
          upper_dest=upper_dest+len_pixline;
     next
     v_show_c( handle );
end

/*---------------------------------*/
con_hirez()
begin
     if( dest_rez equals LOREZ ) then hilo();
     if( dest_rez equals MEDREZ ) then himed();
     if( dest_rez equals HIREZ ) then wait_for_mousepress();
end

/*---------------------------------*/
hilo()
begin
     int  *upper_src, *lower_src, *dest, 
          pixword, lo_pixword, hi_pixword,
          pixlo1, pixlo2, pixhi1, pixhi2,
          row, column;

     v_hide_c( handle );
     Setscreen( des_pix, des_pix, -1 );
     Setpallete( new_palette );
     upper_src=src_pix;
     dest=des_pix;

     for( row=top; row<bottom; row++ ) begin
          for( column=0; column<20; column++ ) begin

               lower_src=( upper_src+len_pixline );

               if( type_conversion equals SIMPLE ) then begin
                    pixhi1=( *upper_src++ ); pixhi2=( *upper_src++ );
                    pixhi1=condense( pixhi1, pixhi2 );

                    pixlo1=( *lower_src++ ); pixlo2=( *lower_src );
                    pixlo1=condense( pixlo1, pixlo2 );

                    pixhi1=pixhi1 ORed_with pixlo1;
                    pixhi2=0;
                    pixlo1=0;
                    pixlo2=0;
               endif

               if( type_conversion equals COMPLEX ) then begin
                    pixhi1=( *upper_src++ ); pixhi2=( *upper_src++ );
                    separate( pixhi1, pixhi2 );
                    pixhi1=hi_word; pixhi2=lo_word;

                    pixlo1=( *lower_src++ ); pixlo2=( *lower_src );
                    separate( pixlo1, pixlo2 );
                    pixlo1=hi_word; pixlo2=lo_word;
               endif

               ( *dest++ )=pixhi1; ( *dest++ )=pixhi2;
               ( *dest++ )=pixlo1; ( *dest++ )=pixlo2;

          next
          upper_src=upper_src+len_pixline;
     next
     v_show_c( handle );
end

/*---------------------------------*/
himed()
begin
     int  *dest, *upper_src, *lower_src,
          row, column;

     v_hide_c( handle );
     Setscreen( des_pix, des_pix, -1 );
     Setpallete( new_palette );
     upper_src=src_pix;
     dest=des_pix;

     for( row=top; row<bottom; row++ ) begin
          for( column=0; column<len_pixline; column++ ) begin

               lower_src=upper_src+len_pixline;

               ( *dest++ )=( *upper_src++ );
               ( *dest++ )=( *lower_src );

          next
          upper_src=upper_src+len_pixline;
     next
     v_show_c( handle );
end

/*---------------------------------*/
write_the_picture()
begin
     Setscreen( org_pix, org_pix, -1 );
     Setpallete( org_palette );

     form_alert( 1, owritealert );
     pix_handle=ERROR;
     fsel_input( path, out_filename, &button );
     v_hide_c( handle );
     Setscreen( des_pix, des_pix, -1 );
     Setpallete( new_palette );

     if( button does_not_equal CANCEL ) then begin
          pix_handle=Fcreate( out_filename, 0 );

          if( pix_handle > 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<box_fy+box_height; row++ ) begin
          for( column=box_fx; column<box_fx+box_width; column++ ) begin

               v_get_pixel( handle, column, row, &element, &pixel );
      
               if( element ) then begin
                    change=TRUE;
                    blk_handle();
               endif

               if( not element ) then begin
                    change=FALSE;
                    wht_handle();
               endif

               vsl_color( handle, ( max_color-pixel ));
               box[ 0 ]=box[ 2 ]=column;
               box[ 1 ]=box[ 3 ]=row;
               v_pline( handle, 2, box );

               graf_mkstate( &mx, &my, &pressed, &dum );
               if( pressed ) then begin
                    column=box_fx+box_width;
                    row=box_fy+box_height;
               endif
          next
     next
     v_show_c( handle );

     w_record();
     rle_buffer[ rle_index++ ]=ESC;
     rle_buffer[ rle_index++ ]='G';
     rle_buffer[ rle_index++ ]='N';

     form_alert( 1, owrlealert );
     pix_handle=ERROR;
     Setscreen( org_pix, org_pix, -1 );
     Setpallete( org_palette );
     fsel_input( path, out_filename, &button );
     v_hide_c( handle );

     if( button does_not_equal CANCEL ) then begin
          pix_handle=Fcreate( out_filename, 0 );

          if( pix_handle > 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



Back to previous page