home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
192.lha
/
Snip_v1.3
/
gfx_txt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-04-28
|
5KB
|
195 lines
#include "snip:defs.h"
typedef union bits32
{
UBYTE bytes[8];
ULONG longword[2];
} long_byte;
extern char *charcode;
extern short scratchheight, scratchwidth, scratchsize;
extern short x_offset, y_offset;
extern char *scratch;
extern long_byte char_bitmap[];
/*
* Given the (x,y) coordinate of the upper left of an 8x8 character position
* within a window, this fills the 8-byte buffer with the bitmap of the
* character at that position. The function after this one converts that
* bitmap to the corresponding ASCII character.
*
*/
get_byte(rp, xstart, ystart, buf)
register struct RastPort *rp;
register short xstart, ystart;
register UBYTE buf[8];
{
register short x,y;
register UBYTE tx_byte;
for (y=0; y<8; y++)
{
tx_byte = 0;
for (x=0; x<8; x++)
{
/* NB: I match _any_ colour here */
if (ReadPixel(rp, xstart+x, ystart+y))
{
tx_byte |= (1 << (7-x));
}
}
buf[y] = tx_byte;
}
}
/*
* Given an 8x8 matrix of bits which has been read from a window, this
* function compares it to the bit patterns of all known characters.
*
* If it matches, the ASCII code of the character is returned, otherwise
* the ASCII '?' is returned. All the usual ASCII characters are tested for,
* so the function will only fail to find a match under these conditions:
* - different font in use (you can use the -f option to get around this)
* - cursor over letter (since all colours are tested for in a letter,
* a cursor'ed letter is seen as a solid square)
* - non-standard character like e with grave accent, (c) copyright
* symbol, etc. I'm not sure if the bitmaps are different for different
* keymaps, but I didn't consider these a vital issue anyway.
* - characters are non-plain text, like italics or underline
* - characters in inverse video, or any 2 non-background pens
*
*/
UBYTE test_byte(bitmap)
register ULONG bitmap[2];
{
register short count;
register long_byte *pattern = (long_byte *)char_bitmap;
for (count = 0; count < 95; count++) /* must remember to fix magic numbers like 95 */
{
if ( bitmap[0] == pattern->longword[0] &&
bitmap[1] == pattern->longword[1]
)
{
return(charcode[count]);
}
else
pattern++;
}
/* for (count=0; count<8; count++) */
/* printf("0x%x, ",bitmap[bytes[count]]); */
/* printf("\n"); */
return('?'); /* unknown character (eg accented letter) */
}
/*
* This function will take a rectangular region of a window, and call the
* preceding functions on each 8x8 square within it to create an array of
* strings which can be supplied somehow to other programs.
*
* I expect to use this mostly with terminal programs, when there is info
* on the screen I want to record without having to write it down (UGH!)
* or trying to call it up again and ASCII-capture it, then edit it, etc.
*
* Also for some editors it may be handier than their own cut-and-paste
* functions, especially those which don't support column operations
* (ie almost all).
*
*/
interpret(rp, x1, y1, x2, y2)
register struct RastPort *rp;
register short x1, y1, x2, y2;
{
long_byte buf;
register short xstart, ystart = y1 + 1;
register short counter = 0;
UBYTE letter;
scratchwidth = ((x2 - x1)+1) >> 3; /* figure # chars horizontally */
scratchheight = ((y2 - y1)+1) >> 3; /* figure number of characters vertically */
scratchsize = (scratchwidth + 1) * scratchheight;
scratch = AllocMem( scratchsize , NULL);
if (NOT scratch)
{
Wr(Output(),"Out of memory!\n");
_abort();
}
while (ystart < y2)
{
xstart = x1 + 1;
while (xstart < x2)
{
get_byte(rp, xstart, ystart, &buf);
letter = test_byte(&buf);
scratch[counter++] = letter;
xstart += 8;
}
scratch[counter++] = '\0'; /* create null-terminated lines */
ystart += 8;
}
}
/*
* Given an (x,y) point in a window, calculate the point to the upper left
* of the 8x8 character position it represents.
*
*/
compute_xy1(window, x1, y1)
register struct Window *window;
register short *x1, *y1;
{
*x1 = ((window->MouseX - ((window->MouseX - window->BorderLeft) % 8)) - 1) + x_offset;
*y1 = ((window->MouseY - ((window->MouseY - window->BorderTop) % 8)) - 1) + y_offset;
}
/*
* This works the same way, but calculates the point to the lower-right of
* the 8x8 character square.
*
*/
compute_xy2(window, x2, y2)
register struct Window *window;
register short *x2, *y2;
{
compute_xy1(window, x2, y2);
*x2 += 9;
*y2 += 9;
}
/*
* Draw a box in complement mode in the target window.
*
*/
do_box(rp, x1, y1, x2, y2)
register struct RastPort *rp;
register short x1, y1, x2, y2;
{
Move(rp, x1, y1);
Draw(rp, x2, y1);
Draw(rp, x2, y2);
Draw(rp, x1, y2);
Draw(rp, x1, y1+1);
}