From 4bae8cde8fc1838c56138bffe573c8d9fd8d9478 Mon Sep 17 00:00:00 2001 From: visionmercer <62051836+visionmercer@users.noreply.github.com> Date: Tue, 12 May 2026 09:29:36 +0200 Subject: [PATCH] Less spaces in command history. smaller save file size. --- include/imgout.bm | 8 +++--- pixler.bas | 68 +++++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/include/imgout.bm b/include/imgout.bm index 633512a..c254344 100644 --- a/include/imgout.bm +++ b/include/imgout.bm @@ -20,7 +20,7 @@ Sub SaveBinaryPPM (imageHandle As Long, fileName As String) length = inPosition + w * h * 4 head = "P6" + Chr$(10) head = head + "# Created with QB64" + Chr$(10) - head = head + LTrim$(Str$(w) + Str$(h)) + Chr$(10) + head = head + LTrim$(str$(w) + tst(h)) + Chr$(10) head = head + "255" + Chr$(10) filebuffer = _MemNew(w * h * 3) outPosition = filebuffer.OFFSET @@ -56,7 +56,7 @@ Sub save24bitBmp (imageHandle As Long, fileName As String) _Source imageHandle header = "BM" + MKL$(_Width * _Height * 3 + 54) +_ - String$(4, 0) + MKL$(54) + MKL$(40) +_ + String$(4, 0) + MKL$(54) + MKL$(40) +_ MKL$(_Width) + MKL$(_Height) +_ MKI$(1) + MKI$(24) + MKL$(0) + MKL$(0) +_ MKL$(11811) + MKL$(11811) + MKL$(0) + MKL$(0) @@ -95,7 +95,7 @@ Sub save8bitPNG (imagehandle As Long, filename As String) IHDR = "IHDR" + MKL$(FlipBytes(_Width(imagehandle))) + MKL$(FlipBytes(_Height(imagehandle))) + Chr$(8) + Chr$(3) + String$(3, 0) IHDR = MKL$(FlipBytes(&H0D)) + IHDR + MKL$(FlipBytes(crc32(IHDR))) IEND = MKL$(0) + "IEND" + MKL$(FlipBytes(&HAE426082)) - PLTE = "PLTE" + PLTE = "PLTE" for c = 0 to 255 PLTE = PLTE + chr$(_Red32(_PaletteColor(c))) PLTE = PLTE + chr$(_Green32(_PaletteColor(c))) @@ -200,4 +200,4 @@ Function crc32~& (IN$) Next J Next I crc32~& = Not CRC -End Function \ No newline at end of file +End Function diff --git a/pixler.bas b/pixler.bas index 3298d6b..bcead01 100644 --- a/pixler.bas +++ b/pixler.bas @@ -43,7 +43,7 @@ layers(2).ihandle=_newimage(320,320,32) layers(3).ihandle=_newimage(320,320,32) _dest layers(0).ihandle -addcommand "canvas ("+str$(_width)+","+str$(_height)+")" +addcommand "canvas ("+tst(_width)+","+tst(_height)+")" for y = 0 to _height - 16 step 16 for x = 0 to _width - 16 step 16 if ((x + y) / 16 AND 1) = 0 then @@ -90,7 +90,7 @@ canvas if showcolorpicker then colorpicker if showcommands then commandlist - + 'Mouse Handling while _mouseinput:mw=mw+_mousewheel:wend @@ -137,10 +137,10 @@ canvas select case keyin case "+" state.brushsize=state.brushsize+1 - addcommand "brushsize ("+str$(state.brushsize)+")" + addcommand "brushsize ("+tst(state.brushsize)+")" case "-" if state.brushsize>1 then state.brushsize=state.brushsize-1 - addcommand "brushsize ("+str$(state.brushsize)+")" + addcommand "brushsize ("+tst(state.brushsize)+")" case chr$(19) ' ctrl+s 'TODO: save logic case chr$(27)' esc @@ -166,11 +166,11 @@ sub commandlist dim i as long dim listWidth as integer:listWidth = 150 dim x as integer:x=_width-listWidth - + ' Draw background for the list line (x,0)-(_width-1,_height - 1),backgroundcolor1, bf line (x,0)-(x,_height-1),backgroundcolor2 - + _printmode _keepbackground dim y as integer for i = ubound(commands) - 1 to 0 step -1 @@ -213,12 +213,6 @@ sub toolbox end if end sub -sub palettemanager(col as _unsigned long) - line (0,0)-(_width-1,_height-1),col,bf - _display - sleep -end sub - sub colorpicker dim img as long img=_newimage(16,16,32) @@ -319,8 +313,8 @@ sub canvas exit sub end if end if - - dim r as integer + + dim r as integer ' 3. Calculate Canvas Coordinates dim canX as long @@ -343,10 +337,10 @@ sub canvas _source layers(1).ihandle if mouseclicked then floodfill canX,canY,state.fcolor - addcommand "floodfill ("+str$(canX)+","+str$(canY)+","+hex$(state.fcolor)+")" + addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.fcolor)+")" else floodfill canX,canY,state.bcolor - addcommand "floodfill ("+str$(canX)+","+str$(canY)+","+hex$(state.bcolor)+")" + addcommand "floodfill ("+tst(canX)+","+tst(canY)+","+hex$(state.bcolor)+")" end if _dest 0 _source 0 @@ -392,10 +386,10 @@ sub canvas _dest layers(1).ihandle if canX=state.startX and canY=state.startY then thickpixel canX,canY,drawCol - addcommand "pixel ("+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" + addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" else thickline state.startX, state.startY, canX, canY, drawCol - addcommand "line ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" + addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" end if state.startX = canX: state.startY = canY case 2 ' Straight Line @@ -436,21 +430,21 @@ sub canvas redim finalP(pointCount * 2 - 1) as long for p = 0 to (pointCount * 2) - 1: finalP(p) = polypoints(p): next dim tmpstr as string - if state.tool =8 then - filledPolygon finalP(), state.fcolor + if state.tool =8 then + filledPolygon finalP(), state.fcolor tmpstr="fpolygon (" for i=0 to ubound(finalP)-1 - tmpstr=tmpstr+str$(finalP(i))+"," + tmpstr=tmpstr+tst(finalP(i))+"," next i - tmpstr=tmpstr+str$(finalP(i))+","+hex$(state.fcolor)+")" + tmpstr=tmpstr+tst(finalP(i))+","+hex$(state.fcolor)+")" addcommand tmpstr - else + else Polygon finalP(), state.fcolor tmpstr="polygon (" for i=0 to ubound(finalP)-1 - tmpstr=tmpstr+str$(finalP(i))+"," + tmpstr=tmpstr+tst(finalP(i))+"," next i - tmpstr=tmpstr+str$(finalP(i))+","+hex$(state.fcolor)+")" + tmpstr=tmpstr+tst(finalP(i))+","+hex$(state.fcolor)+")" addcommand tmpstr end if else @@ -460,25 +454,25 @@ sub canvas case 2 ' Line if canX=state.startX and canY=state.startY then thickpixel canX,canY,drawCol - addcommand "pixel ("+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" + addcommand "pixel ("+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" else thickline state.startX, state.startY, canX, canY, drawCol - addcommand "line ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" + addcommand "line ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" end if case 3 ' Circle r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2)) thickcircle state.startX, state.startY, r + 1, drawCol - addcommand "circle ("+str$(state.startX)+","+str$(state.startY)+","+str$(int(r))+","+hex$(drawCol)+")" - case 4 + addcommand "circle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")" + case 4 r = int(sqr((canX - state.startX)^2 + (canY - state.startY)^2)) filledcircle state.startX, state.startY, r + 1, drawCol - addcommand "fcircle ("+str$(state.startX)+","+str$(state.startY)+","+str$(int(r))+","+hex$(drawCol)+")" + addcommand "fcircle ("+tst(state.startX)+","+tst(state.startY)+","+tst(int(r))+","+hex$(drawCol)+")" case 5 ' Box line (state.startX, state.startY)-(canX, canY), drawCol, b - addcommand "box ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" + addcommand "box ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" case 6 ' Filled Box line (state.startX, state.startY)-(canX, canY), drawCol, bf - addcommand "fbox ("+str$(state.startX)+","+str$(state.startY)+","+str$(canX)+","+str$(canY)+","+hex$(drawCol)+")" + addcommand "fbox ("+tst(state.startX)+","+tst(state.startY)+","+tst(canX)+","+tst(canY)+","+hex$(drawCol)+")" end select end if @@ -631,6 +625,11 @@ _display loop end sub +sub palettemanager(col as _unsigned long) + line (0,0)-(_width-1,_height-1),col,bf + 'TODO: build palette mamager ui +end sub + FUNCTION closestcolor~& (colour AS _UNSIGNED LONG, carr() AS _UNSIGNED LONG) DIM r AS INTEGER DIM g AS INTEGER @@ -655,3 +654,8 @@ FUNCTION closestcolor~& (colour AS _UNSIGNED LONG, carr() AS _UNSIGNED LONG) NEXT i closestcolor = carr(nearest) END FUNCTION + +' trimmed str$ +function tst$(numb) + tst=_trim$(str$(numb)) +end function