Author |
Topic: BBC Basic version: BMPTOCODE happy face example (Read 364 times) |
|
michael
Senior Member
member is offline


Posts: 335
|
 |
BBC Basic version: BMPTOCODE happy face example
« Thread started on: Apr 22nd, 2016, 01:36am » |
|
Here is the first fully generated program image that BMPTOCODE made from the BBC BASIC version.
Keep in mind that BMPTOCODE is more for making icons ,decoration images and reuseable images in your code that can work like custom commands.
This is a 79 x 79 pixel image
( and I mean that the entire program and image conversion and compression was created from generated code from BMPTOCODE) Most of the code size in the interpreter could be reused for other images if you put the interpreter in a DEF PROC_.
Its all about complexity: The less complex the image, the smaller the code will be.. (less colors helps too) I will be making a Dropbox link soon for the app when I am done more testing. Code:
VDU 22,8
VDU 23,23,1|
OFF:VDU 5:COLOUR 0:CLG
PROC_image(100,500)
WAIT 0:END
DEF PROC_image(h,v)
u=0:r=0:g=0:b=0:a=0:c=0:t=0
ost$=""
READ x,y:REPEAT
READ nst$,t
IF nst$="0" THEN r=0:g=0:b=0 :REM 'black 0 0 0
IF nst$="1" THEN r=192:g=128:b=64:REM ' brown 192 128 64
IF nst$="2" THEN r=64:g=64:b=192 :REM'dark blue 64 64 192
IF nst$="3" THEN r=128:g=128:b=128:REM' dark grey 128 128 128
IF nst$="4" THEN r=128:g=0:b=0:REM'dark red 128 0 0
IF nst$="5" THEN r=224:g=192:b=0 :REM'dark yellow 224 192 0
IF nst$="6" THEN r=128:g=160:b=192:REM'flat blue 128 160 192
IF nst$="7" THEN r=32:g=192:b=64 :REM'green 32 192 64
IF nst$="8" THEN r=166:g=202:b=240:REM'light blue 166 202 240
IF nst$="9" THEN r=192:g=192:b=192:REM 'light gray 192 192 192
IF nst$="a" THEN r=192:g=224:b=0:REM 'light green 192 224 0
IF nst$="b" THEN r=224:g=32:b=64:REM'light red 224 32 64
IF nst$="c" THEN r=0:g=160:b=192 :REM'medblue 0 160 192
IF nst$="d" THEN r=224:g=128:b=64 :REM 'orange 224 128 64
IF nst$="e" THEN r=224:g=160:b=192:REM'pink 224 160 192
IF nst$="f" THEN r=160:g=64:b=192:REM'purple 160 64 192
IF nst$="g" THEN r=192:g=220:b=192:REM'tan 192 220 192
IF nst$="h" THEN r=255:g=255:b=255:REM'white 255 255 255
IF nst$="i" THEN r=255:g=255:b=0:REM'yellow 255 255 0
COLOUR 0,r,g,b:GCOL 0
FOR u=0 TO t
a=a+1: MOVE h+c,v-a:DRAW h+c,v-a:IF a>x THEN c=c+1:a=0
NEXT u
UNTIL nst$="100000"
MOVE 0,0:ENDPROC
DATA 79,79
DATA 0,595,b,9,0,65,b,17,0,57,b,25,0,51,b,29,0,48,b,31,0,45,b,12,0,9,b,12,0,42,b,10,0,16,b,10,0,38,b,9,0
DATA 21,b,9,0,36,b,8,0,25,b,8,0,34,b,7,0,29,b,7,0,32,b,7,0,32,b,6,0,30,b,6,0,35,b,6,0,28,b,6,0,37
DATA b,6,0,27,b,5,0,39,b,6,0,25,b,5,0,41,b,5,0,24,b,5,0,28,i,3,0,10,b,5,0,23,b,5,0,28,i,4,0,10,b
DATA 5,0,21,b,5,0,29,i,4,0,10,b,5,0,20,b,5,0,30,i,5,0,10,b,5,0,19,b,5,0,12,i,2,0,15,i,5,0,9,b,5
DATA 0,18,b,5,0,11,i,6,0,14,i,4,0,10,b,5,0,17,b,5,0,11,i,7,0,13,i,5,0,9,b,5,0,17,b,4,0,12,i,7,0
DATA 14,i,4,0,10,b,4,0,17,b,4,0,12,i,7,0,15,i,4,0,9,b,4,0,16,b,5,0,12,i,5,0,17,i,4,0,10,b,4,0,15
DATA b,4,0,37,i,4,0,10,b,4,0,15,b,4,0,37,i,4,0,10,b,4,0,15,b,4,0,38,i,4,0,9,b,4,0,14,b,4,0,39,i
DATA 4,0,10,b,4,0,13,b,4,0,39,i,4,0,10,b,4,0,13,b,4,0,39,i,4,0,10,b,4,0,13,b,4,0,39,i,4,0,10,b,4
DATA 0,13,b,4,0,39,i,4,0,10,b,4,0,13,b,4,0,39,i,5,0,9,b,4,0,13,b,4,0,39,i,5,0,9,b,4,0,13,b,4,0
DATA 39,i,5,0,9,b,4,0,13,b,4,0,39,i,4,0,10,b,4,0,13,b,4,0,39,i,4,0,10,b,4,0,14,b,4,0,38,i,4,0,9
DATA b,4,0,15,b,4,0,16,i,2,0,17,i,5,0,9,b,4,0,15,b,4,0,15,i,4,0,16,i,4,0,10,b,4,0,15,b,4,0,14,i
DATA 6,0,15,i,4,0,10,b,4,0,16,b,4,0,12,i,7,0,14,i,5,0,9,b,5,0,16,b,4,0,12,i,7,0,14,i,4,0,10,b,4
DATA 0,17,b,5,0,12,i,5,0,15,i,3,0,10,b,5,0,17,b,5,0,33,i,4,0,10,b,5,0,18,b,5,0,31,i,5,0,9,b,5,0
DATA 19,b,5,0,30,i,4,0,11,b,5,0,20,b,5,0,29,i,3,0,11,b,5,0,22,b,4,0,29,i,2,0,12,b,5,0,22,b,5,0,43
DATA b,5,0,24,b,5,0,41,b,5,0,25,b,6,0,39,b,6,0,26,b,6,0,37,b,6,0,28,b,6,0,35,b,6,0,30,b,6,0,33,b
DATA 6,0,32,b,7,0,29,b,7,0,34,b,8,0,25,b,8,0,36,b,9,0,21,b,9,0,38,b,10,0,17,b,10,0,41,b,12,0,9,b,12
DATA 0,44,b,33,0,47,b,29,0,51,b,25,0,57,b,18,0,64,b,9,100000,0
|
« Last Edit: Apr 22nd, 2016, 01:50am by michael » |
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: BBC Basic version: BMPTOCODE happy face exampl
« Reply #1 on: Apr 22nd, 2016, 12:16pm » |
|
Hi Michael,
OK, I see: its a runlength encoder, which generates data statements. Would it be worth including (like a header) at the beginning of the data the number of colours used as well as the size of the image? You might also consider including the palette (i.e. the RGB code for each of your colours) as part of the data.
If the image contained 16 or fewer colours you wouldn't need to define the colours each time - you could just set up the relevant custom palette, then use GCOL x to set the colour you need.
If you limited your colours to (no more than) 256, and your run lengths to 255 (longer runs would have to be written as several shorter ones, but in small images you won't need to) then you could encode each in a single byte (which you could store as a character, using CHR$), and concatenate them to make a string - one approach might be to have a string for each line of the image, though with the new very long strings of BB4W6 and above you could encode the whole image as one string.
If we follow this kind of approach, I expect we'll end up pretty close to an existing image format....
You sent me the program which generates the data, which looks like it displays the bitmap, works out the data for each point, and then writes it, together with the display routine, to a program file. Would it make sense to have it just generate the data statements, which you could then append to a general purpose plotting routine/program? Could you simply read in the bitmap file as data, parse the header data, and then just read the data for each point directly? I suspect that would be MUCH faster than reading it off the screen.
Best wishes,
D
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: BBC Basic version: BMPTOCODE happy face exampl
« Reply #2 on: Apr 22nd, 2016, 3:19pm » |
|
If you look at the data statements, you will see numbers.. Big ones.. 1) First it declares the color 2) The color is indicated by a letter or number 3) It then indicates how many times that color is repeated 4) that number is tallied in the cycle until it runs out and a new color is checked.. and so on. 5) meanwhile the location on the image must be maintained along with the borders.
The problem with many colors is each one is potentially this long: 255,255,255 That can add up to A LOT of code. ( no good for a program) So I selected only the colors I needed in paint on the default colors and made characters for each one. That way I could compress it down super small
If you want to see some monster code from the uncompressed version I can show that.. Its insane!!
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
|