CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2006
    Posts
    31

    Convert BSAVE (BSV) to BMP or other common format?

    I wasn't sure where to put this post, so I decided to just put it here since it's related to BASIC (GWBASIC). (Feel free to move it somewhere else if there is a better place)

    I have a project at work that I'm working on. I am trying to convert a BSAVEd image to a file format that is easily recognized by mspaint. I have searched and searched and can't find anything. I found some that will work in reverse (bmp to bsv), but that obviously doesn't help. I would like to have it run from within my gwbasic program using the SHELL command with arguements. It's just a monochrome screen grab.

    Any help would be greatly appreciated.

    Side note: we are trying to replace a line printer with a laser printer. I was planning writing the text to a file and the associated graphic to a file and just print them as files instead of line by line, which wouldn't work on the laser printer. If anyone has any better creative solutions to this, please let me know.
    Last edited by Tineras; August 20th, 2008 at 07:43 AM.

  2. #2
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: Convert BSAVE (BSV) to BMP or other common format?

    GW-Basic! I have the manual somewhere!
    God! I haven't used GW-BASIC since I was eight years old!

    Sorry - I think I threw out the manual last time I moved.

    Oh well. Good luck!
    [Mods/Admins - Feel free to delete the post. It's been 10 years since I heard someone mention GW-Basic!]
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Convert BSAVE (BSV) to BMP or other common format?

    I think you'd be better off starting again with Visual Studio Express, which is FREE. There are different flavors to choose from, including C# and VB.Net.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Feb 2006
    Posts
    31

    Re: Convert BSAVE (BSV) to BMP or other common format?

    Well, the problem is that this configuration has been used for many years and I don't think they plan on changing it any time soon. Unfortunately, I'm stuck using GWBASIC.

    I thought it might be easier just to capture the screen, but I cant find a screen capture program that will execute from within gwbasic through the shell command. I tried Screen Thief (v 2.01) for DOS, but it needs keystrokes from the user to capture the screen. I need it to capture as soon as the program runs.
    Last edited by Tineras; August 20th, 2008 at 12:21 PM.

  5. #5
    Join Date
    Feb 2006
    Posts
    31

    Re: Convert BSAVE (BSV) to BMP or other common format?

    Is there a way to force key commands from gwbasic? Or is there a way to force key commands through C?

  6. #6
    Join Date
    Feb 2006
    Posts
    31

    Re: Convert BSAVE (BSV) to BMP or other common format?

    We came up with another solution, so this post can be disregarded. Although, I wouldn't mind hearing any suggestions for my own peace of mind.

    Thanks

  7. #7
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Convert BSAVE (BSV) to BMP or other common format?

    Do you mind posting that solution? Other readers might enjoy that.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  8. #8
    Join Date
    Feb 2006
    Posts
    31

    Re: Convert BSAVE (BSV) to BMP or other common format?

    Quote Originally Posted by S_M_A
    Do you mind posting that solution? Other readers might enjoy that.
    Unfortunately, our "solution" had nothing to do with correcting the problem I mentioned above. We were trying to replace a line-printing (dot matrix style) printer with a network printer. The old printer was malfunctioning. Instead of converting our data to a more friendly format to use with a network printer, we just replaced the printer with another old dot matrix style printer.

    It was a decision I made because I felt I was spending too much time on it.

  9. #9
    Join Date
    Aug 2008
    Posts
    2

    Re: Convert BSAVE (BSV) to BMP or other common format?

    Quote Originally Posted by Tineras
    Well, the problem is that this configuration has been used for many years and I don't think they plan on changing it any time soon. Unfortunately, I'm stuck using GWBASIC...
    Why not just save the BMP in GWBASIC?

    That is pretty easy although after considering some of your other posts on this, interfacing directly with a laser requires a different printer control language (PCL) than with a dot matrix so it might help if you just dumped the image into the appropriate PCL instead of the BMP format.

    Interfacing with a laser will mean that you will probably want to use mixed text and graphics mode of some sort if you want to print something besides the image.

    The dot matrix has an effective resolution of 144 x 72 on most as a lowest common denominator. Bitmapping this is a little tricky because like the Commodore 64 screen, bit masking is in 8 x 8 blocks which is how the pins fire.

    Also scaling needs to be done from screen resolution to the printer dpi.

    If the laser printer supports HP PCL this is pretty doable, but begs the question why not rewrite this as a WIN32 C console application and use a windows printer device context like I do in my ClipShop program?

    Ye Olde ClipShoppe Deluxe

    I can't say that I haven't written in VB since I was eight years old and I didn't need a manual to begin with, but going directly with the WIN32 API in a C program is generally the easiest for this type of thing for me anyway.

    You can use the command line compiler in Visual Express 2005 with the Win32 extensions or just go GNU with MinGW.

    If you decide to stay in GWBASIC you still might consider using a print spooler of sorts written in C.

    Or a print server written in VB6 or whatever.

    Bill Buckels


    Code:
    100 REM Bsv2Bmp.BAS by Bill Buckels Aug 2008
    101 REM This program is herewith released into the Public Domain
    102 REM Use and Copy Freely
    103 REM -------------------
    104 REM A GWBASIC Example Program
    105 REM Demonstrates Saving a Monochrome BMP
    106 REM From a 640 x 200 Monochrome BSaved Image 
    107 REM Variations on this program are relatively easy
    110 REM -------------------
    120 REM I have used a RANDOM ACCESS file for output
    121 REM This is a BINary file in its crudest form.
    122 REM -------------------
    130 REM The header information for other output file formats
    131 REM can be obtained by creating a BMP
    132 REM in Windows Paint, then calculating how big
    133 REM the body is to determine the header
    134 REM followed by viewing and typing the header info
    135 REM in a format that can be used in here.
    136 REM However you need to know how to store the 
    137 REM image data in a BMP compatible manner
    138 REM -------------------
    140 REM This is not meant to be a lesson in GWBASIC
    141 REM I am assuming that if you are writing in GWBASIC
    142 REM that you know the language. RFM
    142 REM -------------------
    200 DEFINT A-Z : KEY OFF
    201 SCREEN 0   : CLS
    202 REM --------------------
    203 REM Get the filenames...
    204 REM Replace this with your own more elegant routines
    205 REM Or an automated naming routine.
    206 REM --------------------
    210 INPUT "Enter BSaved FileName:", BSV$
    211 INPUT "Enter BMP Output Name:", BMP$
    212 INPUT "Reverse Video   (Y/N)";  REV$
    220 REM --------------------
    221 REM Load the input file to the screen
    222 REM --------------------
    223 SCREEN 2
    224 DEF SEG = &HB800
    225 BLOAD BSV$,0
    226 DEF SEG
    230 REM --------------------
    231 REM Reverse Video for Printing if needed
    232 REM --------------------
    233 IF REV$ = "Y" OR REV$ = "y" THEN GOSUB 6000
    236 REM --------------------
    237 REM Read the screen and create the BMP file
    238 REM --------------------
    239 OPEN "R",1,BMP$,1
    240 FIELD 1,1 AS V$
    241 REM write the BMP header
    242 RESTORE 8000
    243 READ VLEN
    244 FOR I = 1 TO VLEN
    245   READ V
    246   LSET V$ = CHR$(V)
    247   PUT 1
    248 NEXT I
    249 REM Write the BMP image body
    500 REM The CGA Screen Memory Starts at $B800
    501 REM The Interleaf is offset by 8192 bytes
    502 REM A BMP file is upside-down
    503 REM So we need to offset to the last raster
    504 REM and walk backwards through the interleaves
    505 LEAF1 = 7920
    506 LEAF2 = 16112
    507 DEF SEG = &HB800
    510 FOR Y = 1 TO 100
    520   REM Odd Interleaf - write twice
    521   FOR S = 1 TO 2
    522   	FOR X = 0 TO 79
    523   	   V = PEEK(LEAF2+X) 
    524   	   LSET V$ = CHR$(V)
    525   	   PUT 1
    526   	NEXT X
    527   NEXT S 	
    528   REM Decrement Interleaf Offset
    529   LEAF2 = LEAF2 - 80
    530   REM Even Interleaf - write twice
    531   FOR S = 1 TO 2
    532   	FOR X = 0 TO 79
    533   	   V = PEEK(LEAF1+X) 
    534   	   LSET V$ = CHR$(V)
    535   	   PUT 1
    536   	NEXT X
    537   NEXT S	
    538   REM Decrement Interleaf Offset
    539   LEAF1 = LEAF1 - 80
    540 NEXT Y
    550 DEF SEG
    600 CLOSE 1
    650 SCREEN 0 
    660 REM EXIT TO DOS
    700 SYSTEM
    6000 REM REVERSE VIDEO SUBROUTINE
    6010	DIM PIC(8002) 'picture buffer
    6020	GET (0,0)-(639,199), PIC
    6030	PUT (0,0),PIC,PRESET
    6040 	ERASE PIC
    6050 RETURN
    8000 REM 640 x 400 Monochrome BMP header (62 bytes)
    8010 REM DATA below is Length followed by Ascii Values
    8020 REM Ascii values are expressed in Hexadecimal
    8030 DATA 62
    8040 DATA &H42, &H4D, &H3E, &H7D, &H00, &H00, &H00, &H00
    8050 DATA &H00, &H00, &H3E, &H00, &H00, &H00, &H28, &H00
    8060 DATA &H00, &H00, &H80, &H02, &H00, &H00, &H90, &H01
    8070 DATA &H00, &H00, &H01, &H00, &H01, &H00, &H00, &H00
    8080 DATA &H00, &H00, &H00, &H7D, &H00, &H00, &H00, &H00
    8090 DATA &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00
    8100 DATA &H00, &H00, &H00, &H00, &H00, &H00, &H00, &H00 
    8110 DATA &H00, &H00, &HFF, &HFF, &HFF, &H00
    9000 REM The End

  10. #10
    Join Date
    Aug 2008
    Posts
    2

    Smile Re: Convert BSAVE (BSV) to BMP or other common format?

    Quote Originally Posted by Tineras
    Unfortunately, our "solution" had nothing to do with correcting the problem I mentioned above... <snip>It was a decision I made because I felt I was spending too much time on it.
    I hear ya! Printers can be a time-consuming exercise. However if you should need to revisit this later and want to do an HP PCL compatible interface for this legacy system, I have lots of old code like the following that you can modify for the occasion.

    Perhaps when you run-out of ribbons. Modifying this to run in GWBASIC probably wouldn't take much. This is the shortest example I have for the HP.

    Bill

    Code:
    // BV> I need source to print graphics on a HP laserjet/deskjet
    // BV > w/o color...
    // hpixel.c by bill buckels 1994
    // short example of writing mixed text and graphics
    // on the hp printer. use and copy freely
    #include <dos.h>
    #include <stdio.h>
    #define VGA   0x12
    #define TEXT  0x03
    union REGS inregs, outregs;
    // set and get video mode
    unsigned char setcrtmode(unsigned char vidmode)
    {
        inregs.h.ah = 0;
        inregs.h.al = vidmode;   // set mode
        int86(0x10,&inregs,&outregs);
        inregs.h.ah = 0x0f;      // get mode
        int86(0x10,&inregs,&outregs);
        return outregs.h.al;     // return mode
    }
    // simple write dot
    void wdot(unsigned x, unsigned y, unsigned char color)
    {
       inregs.h.ah = 0x0c;
       inregs.h.al = color;
       inregs.h.bh = 0;
       inregs.x.cx = x;
       inregs.x.dx = y;
       int86(0x10,&inregs,&outregs);
    }
    // simple draw box
    void wbox(int x1, int y1, int x2, int y2, unsigned char color)
    {
        int x,y;
        x2++;
        for(x=x1;x<x2;x++)wdot(x,y1,color);    // top of box
        x2--;y1++;
        for(y=y1;y<y2;y++)
        {
         wdot(x1,y,color);                    // middle of box
         wdot(x2,y,color);
        }
        x2++;
        for(x=x1;x<x2;x++)wdot(x,y2,color);  // bottom of box
    }
    // centre justified simple text
    int wtext(char *str, int x, int y, unsigned char colorvalue)
    {
        int scanline,byte,character,nibble,counter,target=strlen(str);
        unsigned char far *romfont=(unsigned char far *) 0xffa6000eL;
        // a pointer to the 8 x 8 BITMAPPED font in the PC ROM
        for(counter=0;counter<target;counter++){
            if(str[counter]<' '||str[counter]>'z')str[counter]=32;
            }
        x=(x-(target*4));           // extrapolate the left edge
        for (scanline=0;scanline<8;scanline++) // finish the current scanline
        {                                // before advancing to the next
         for (byte=0;byte<target;byte++) // run the scanline
         {  // use the current character as an indices for the font
         character = romfont[(str[byte]&0x7f)*8+scanline];
         for (nibble=0;nibble<8;nibble++)
            if (character & 0x80>>nibble)
                  wdot(x+byte*8+nibble,y,colorvalue);
         }
         y++;
        }
    }
    // simple read dot
    unsigned char rdot(unsigned x, unsigned y)
    {
       inregs.h.ah = 0x0d;
       inregs.h.bh = 0;
       inregs.x.cx = x;
       inregs.x.dx = y;
       int86(0x10,&inregs,&outregs);
       return outregs.h.al;
    
    }
    // basic hp pcl printer codes - refer to manual
    char reset[]       ={ 0x1B,0x45};
    char linesperinch[]={ 0x1B,0x26,0x6C,0x36,0x44}; // 6 lpi
    char left_column[] ={ 0x1B,0x26,0x6C,
                          0x31,/* left column here */ 0x4C};
    char fontstyle[]   ={ 0x1B,0x28,0x31,0x30,0x55}; // IBM-PC (USA)
    char prolog[]      ={ 0x1B,0x29,0x30,0x4E,
                          0x1B,0x29,0x73,0x30,0x42,
                          0x1B,0x26,0x6C,0x36,0x30,0x46};
    char resolution[]  ={ 0x1B,0x2A,0x74,
                          '3','0','0', /* 300 dpi */ 0x52};
    char epilog[]      ={ 0x1B,0x2A,0x70,0x2D,0x34,0x30,0x59,
                          0x1B,0x2A,0x72,0x41};
    char blank_line[]  ={ 0x1B,0x2A,0x62,0x57};
    char image_line[]  ={ 0x1B,0x2A,0x62,
                          '1','6','0', /* 160 bytes */ 0x57};
    char form_feed[]   ={ 0x0c};
    char line_feed[]   ={ 0x0d,0x0a};
    int main(int argc, char *argv[])
    {
      FILE *fp;
      char buffer[128];
      unsigned char ditherbuffer1[160],ditherbuffer2[160];
      unsigned int color;
      unsigned char tempcolor,tempcolor1,tempcolor2;
      unsigned char tempdither1,tempdither2;
      unsigned x,y,x2,y2;
      // create a simple graphic...
      if(setcrtmode(VGA)!=VGA)
      {
        puts("VGA Adapter Required");return 0;
      }
      sprintf(buffer, "Printed using HPIXEL by Bill Buckels");
      tempcolor=0;
      for(x=0;x<176;x+=8)
      {
          wbox(x,x,639-x,479-x,(tempcolor%15)+1); tempcolor++;
      }
      // do the printer setup...
      inregs.h.ah = 2;
      inregs.x.dx = 0;          // assume = LPT1 = 0
      int86(0x17,&inregs,&outregs);
      if(outregs.h.ah!=0x90)
      {
        wtext("Printer On LPT1 Not Responding...",319,235,15);
        if(getch()==0)getch();
        setcrtmode(TEXT);return 0;
      }
      wtext(buffer,321,237,1);wtext(buffer,319,235,14);
      fp=fopen("prn","wb");
      fwrite(reset,sizeof(reset),1,fp);
      fwrite(linesperinch,sizeof(linesperinch),1,fp);
      fwrite(left_column,sizeof(left_column),1,fp);
      fwrite(fontstyle,sizeof(fontstyle),1,fp);
      fwrite(prolog,sizeof(prolog),1,fp);
      fwrite(resolution,sizeof(resolution),1,fp);
      fwrite(epilog,sizeof(epilog),1,fp);
      // print the graphic...
      for(y=0;y<480;y++)
      {
          x=0;  // traverse 4 pixels per byte
          for(x2=0;x2<160;x2++)                  // create a dither
          {
            tempcolor=rdot(x,y); x++;
            tempcolor1  = tempcolor>>2;
            tempcolor2  = tempcolor-tempcolor1;
            tempdither1 = (tempcolor1<<6);
            tempdither2 = (tempcolor2<<6);
            tempcolor=rdot(x,y); x++;
            tempcolor1  = tempcolor>>2;
            tempcolor2  = tempcolor-tempcolor1;
            tempdither1 |=(tempcolor1<<4);
            tempdither2 |=(tempcolor2<<4);
            tempcolor=rdot(x,y); x++;
            tempcolor1  = tempcolor>>2;
            tempcolor2  = tempcolor-tempcolor1;
            tempdither1 |=(tempcolor1<<2);
            tempdither2 |=(tempcolor2<<2);
            tempcolor=rdot(x,y); x++;
            tempcolor1  = tempcolor>>2;
            tempcolor2  = tempcolor-tempcolor1;
            tempdither1 |=tempcolor1;
            tempdither2 |=tempcolor2;
            ditherbuffer1[x2]=tempdither1;
            ditherbuffer2[x2]=tempdither2;
          }
          // send it to the printer - pelsize 2 bits wide x 2 bits high
            fwrite(image_line,sizeof(image_line),1,fp);
            fwrite(ditherbuffer1,160,1,fp);  // 160 bytes
            fwrite(image_line,sizeof(image_line),1,fp);
            fwrite(ditherbuffer2,160,1,fp);  // 160 bytes
       }
      // write some blank lines and a title line...
      for(x=0;x<50;x++)fwrite(blank_line,sizeof(blank_line),1,fp);
      fwrite(buffer,strlen(buffer),1,fp);
      // clean up and quit
      fwrite(form_feed,sizeof(form_feed),1,fp);
      fwrite(reset,sizeof(reset),1,fp);
      fclose(fp);
      setcrtmode(TEXT);
      return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured