Re: Merging Of Images
- Posted by "Cuny, David" <ATB.DCUNY at HW1.CAHWNET.GOV> Apr 14, 1997
- 954 views
re: merging of images --------------------- I had a similar problem with putting up text in graphics mode. The only way I could get text to the screen without the default background color was to OR it to the screen - but the colors showed up inverted. I couldn't build an inverse color lookup table, because different color backgrounds caused different colors to appear. It finally occured to me that if I wrote a character to the background using the *background* color, I'd get a black character on the screen. I could then display the character again, this time using the correct foreground color. You may be able to create a mask for your image, instead of resorting to false colors. putsyx ------ I had seen it in someone else's "windows" program, and wondered if it would be useful in my graphics-mode GUI. I re-wrote your putsxy routine so that it can use the .FNT files that are included in my Fonter program. Unfortunately, it's still to slow for a text-intensive application like mine even on a pentium. I'm including the routine and a demo, but *not* any font files - they're just too darned big, even compressed. You can download them from Robert's page if you are interested. The font file DEFAULT.FNT is required. If there are any other fonts in the directory, the demo will list their names using their font. Good points: - About twice as fast - Can use multiple font files Bad points: - Font files required - Font file takes a moment to load - Can't directionally print If you find this interesting, I can clean it up a bit. I'm thinking of going back to my Fonter program some time and adding a binary font format, for size and speed. Right now, I've got about 25 font files, but they come to about a 1 Meg - too much for me to e-mail to Robert. Binary format would take a giant bite out of this size. If anyone in interested, let me know and I'll update the Fonter program, and add the new fonts (after finishing the editor, of course...) -- David Cuny -- START OF PUTSXY.E -------------- -- I made a number of changes to your routine. Some of them are for -- speed; others allow you to load my font files. -- here, i declare the font table. there are two advantages: -- 1. undefined fonts are blank, so they need no special handling -- 2. i can use ascii code + 1 as indexes, instead of indexed lookup sequence font_table font_table = repeat( repeat( repeat( 0, 8 ), 16 ), 256 ) -- this procedure loads a font file into the sequence. -- it's a bit ugly. binary font files would be simpler. global procedure load_font_file( sequence file ) -- load one of my font files into the table atom handle -- file handle integer ascii -- font being looked at sequence s -- line read from file -- open the file handle = open( file, "r" ) if handle = -1 then clear_screen() puts( 1, "Unable to load font file " & file & ".\n" ) abort( 0 ) end if -- read the entire file while 1 do -- get a line s = gets( handle ) -- end of file marker? if match( "end", s ) then -- end marks end of file exit -- beginning of font definition? elsif s[1] = '-' or s[1] = '#' then -- code, or number? if s[1] = '-' then -- ascii code follows the "-" -- example: "-a" means "define character 'a'" ascii = s[2] else -- number follows -- example: "#32" means "define ascii character 32" -- convert number that follows -- there is a euphoria routine that does this, but -- i'm too lazy to look it up ascii = 0 for i = 2 to length( s ) do if s[i] = '\n' or s[i] = ' ' then exit else ascii = ( ascii * 10 ) + ( s[i] - '0' ) end if end for end if -- offset by 1. this handles code 0 ascii = ascii + 1 -- next 16 lines are the font, in an 16x8 grid -- 'x' indicates a bit on -- '.' indicates a bit off -- 16 bits high for i = 1 to 16 do -- get a line s = gets( handle ) -- 8 bits wide for j = 1 to 8 do -- convert x to 1, other to 0 font_table[ascii][i][j] = ( s[j] = 'x' ) end for end for -- hopefully a comment. else -- ignore end if end while close( handle ) end procedure global procedure putsxy(sequence pixel_loc, sequence display_text, atom foreground, atom background) -- My version of putsxy -- Direction is not used, so I can't print a string vertically. -- Rather than print the characters out one byte at a time, I append -- them onto the end of the image. When the string is complete, I can -- print the image. -- Since I have a complete table of fonts (some may be blank), I can -- access the fonts directly, rather than indirect them. sequence image -- the image of the text -- text is 16 bits tall image = repeat( {}, 16 ) -- lookup each byte for i = 1 to length(display_text) do -- for each scan line for j = 1 to 16 do -- add 8 bits of character image[j] = image[j] & font_table[display_text[i]+1][j] end for end for -- convert 1 and 0 to foreground and background colors image = image * (foreground-background) image = image + background -- display the image display_image(pixel_loc,image) end procedure -- load the default font into memory load_font_file( "default.fnt" ) -- END OF PUTSXY.E -------------- -- START OF DEMO.EX ------------ -- Demo of re-written putsxy() -- Displays all the font files in the directory, using each -- file's font. include graphics.e include image.e include putsxy.e include file.e -- graphics mode available? if graphics_mode(18) then -- try other modes puts(1, "Mode Failure\n") abort(100) end if -- read and display the fonts sequence fontList integer line, col line = 1 col = 1 fontList = dir( "*.fnt" ) for i = 1 to length( fontList ) do load_font_file( fontList[i][D_NAME] ) putsxy( {col*8, line*16}, "Font: " & fontList[i][D_NAME], CYAN, BRIGHT_WHITE ) line = line + 1 if line > 25 then line = 1 col = col + 30 end if end for -- wait for a key while 1 do if get_key() != -1 then exit end if end while if graphics_mode(-1) then puts(1, "Mode Failure\n") abort(100) end if -- END OF DEMO.EX --------------