PROCbmptocode(name$,width,height) -Ready to test

Discussions related to graphics (2D and 3D), animation and games programming
michael
Posts: 43
Joined: Mon 02 Apr 2018, 17:13

PROCbmptocode(name$,width,height) -Ready to test

Post by michael »

* Has been tested on BBCSDL (windows) and BBC4W
How to use:
* Copy the program bellow into BBCSDL or BBC4W and save the file
1) make an image in Windows Paint that is 50x50 pixels or less in size
2) save the image in 16 color BMP file format
3) Transfer the image to the same place as the supplied program bellow
4) Replace PROCbmptocode("bjuice16",42,39) with only the main file name of your picture and the width and height
5) Execute the program
6) look for " data.BBC" and load it into BBCSDL or BBC4W
7) Execute it and place your image where you like on your screen.
8) The final PROC data should be able to be copied and pasted into any program and others added as you wish

* NOTE: the mouse location tool is active within the tool in case you want to fine tune your scan zone (you will need to verify if the coordinates, as they are divided by 2, as the scanner is set up for BMP image color extraction and so those coordinates are what you will use.)

An example is available on this link: http://www.bbcbasic.co.uk/forum/viewtop ... =12&t=1131
Let me know if there is issues. I think I worked out the bugs.


Code: Select all

      REM BMPTOCODE tool for BBC Basic For Windows and BBCSDL and the output file should work on all versions of BBCSDL
      REM October 29, 2020 .. Version 1
      MODE 8
      VDU 5
      REM try to make sure your icon is no bigger than necessary (less than 50 x 50 pixels or something like that)
      REM replace "bjuice16" with your BMP 16 color image and replace 42 with your width and 39 with your height
      PROCbmptocode("bjuice16",42,39)
      REM If you do not save your image as a 16 color BMP image, you will not get what you desire (WINDOWS 10 Paint tool)
      REPEAT
        PROCwheremou
      UNTIL FALSE
      END
      REM name$=BMPFILE with no .bmp * width and height scans area so try to not scan more than needed
      DEFPROCbmptocode(name$,picwidth,picheight)
      picwidth=picwidth*2:REM the coordinates must be doubled from what the image says on file ***********
      picheight=picheight*2
      A=OPENOUT("data.BBC")
      BPUT#A,"MODE 8"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"PROC"+name$+"(100,100)"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"END"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"DEFPROC"+name$+"(h,v)"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"LOCAL DATA "+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"RESTORE+1"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"FOR y=1 TO "+STR$(picheight)+" STEP 2 "+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"FOR x=1 TO "+STR$(picwidth)+" STEP 2"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"READ c"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"GCOL c"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"LINE h+x,v+y,h+x,v+y"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"NEXT x"+CHR$(13);:BPUT#A,CHR$(10);
      BPUT#A,"NEXT y"+CHR$(13);:BPUT#A,CHR$(10);
      name$=name$+".bmp"
      OSCLI "DISPLAY """+name$+""" "
      x=0:y=0
      xx=100:yy=100
      c=0
      FOR y=1 TO picheight STEP 2
        BPUT#A,"DATA ";
        FOR x=1 TO picwidth STEP 2
          c=POINT(x,y)
          IF x<picwidth-1 THEN c$=STR$(c)+"," ELSE c$=STR$(c)
          BPUT#A,c$;
          GCOL c
          LINE xx+x,yy+y,xx+x,yy+y
        NEXT x
        BPUT#A,CHR$(10);
      NEXT y
      BPUT#A,"ENDPROC"+CHR$(13);:BPUT#A,CHR$(10);
      CLOSE#A
      GCOL 15:MOVE 10,500:PRINT "SAVED to file data.BBC --- close program please"
      ENDPROC
      REM I am leaving this tool within this program in case it is needed later
      REM MOUSE coordinate helper
      DEFPROCwheremou
      LOCAL mx%,my%,mb%
      GCOL 128+6
      MOUSE mx%,my%,mb%:MOVE 10,50:GCOL 15:PRINT mx%/2,my%/2
      GCOL 128+0:WAIT 5
      GCOL 0:MOVE 10,50:PRINT mx%/2,my%/2
      ENDPROC