i want to save an image as a bin file for the vic20 in graphics mode.

You need an actual VIC.

Moderator: Moderators

Post Reply
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

i want to save an image as a bin file for the vic20 in graphics mode.

Post by funkheld »

Hello good.
i want to save an image as a bin file for the vic20 in graphics mode.
picture is 176x176 byte.

can't do that in pure base.

Thank you.
greeting

new purebasic program (01.01.2020):

Code: Select all

Global text1.s,text2.s,byteinhalt.c,bytestueck.l,einzelbit.l,y.l,yy.l

Declare lade_bild()
Declare speicher_bild()

Enumeration
  #Window_0
  #Button_0
  #Button_1
  #String_0
EndEnumeration

InitSprite()
InitKeyboard()

OpenWindow(#Window_0,780,600,500,220,"vi20 hires", #PB_Window_SystemMenu)

ButtonGadget(#Button_0, 10,10, 80, 25, "Bild laden")
ButtonGadget(#Button_1, 10,35, 80, 25, "Bild erstellen")
StringGadget(#String_0, 10, 100, 100, 20, "")

CreateImage(0, 176,176)
StartDrawing(ImageOutput(0))
Box(0,0,176,176, RGB(255,255,255))
StopDrawing()

ImageGadget(0, 160, 10, 0, 0, ImageID(0))

Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      
      If EventGadget = #Button_0
        Pattern$ = "Text (*.bin;*.bmp)"
        Pattern = 0    
        text1 = OpenFileRequester("Bitte Datei zum Laden auswählen", StandardFile$, Pattern$, Pattern)
        text1=GetFilePart(text1)
        SetGadgetText(#string_0, text1)
        lade_bild()
      EndIf
      
      If EventGadget = #Button_1
        speicher_bild()
      EndIf
      
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
  
ForEver

Procedure speicher_bild()
  If text1=""
    Goto weiter
  EndIf
  
  text1=Left(text1,Len(text1)-4)
  
  CreateFile(0, "d:\winvice\bilder\"+text1+".bin")
  
  ByteInhalt=0
  WriteByte(0, ByteInhalt)
  ByteInhalt=17
  WriteByte(0, ByteInhalt)
  
  StartDrawing(ImageOutput(0))
  For y = 0 To 175 Step 16
    For bytestueck = 0 To 20
  	  For yy=0 To 15
    	  byteInhalt = 0
    	  For einzelbit = 0 To 7
      	  If Point( ByteStueck * 8 + 7 - Einzelbit,y+yy)
            ByteInhalt + ( 1 << Einzelbit )
          EndIf
    	  Next
    	  WriteByte(0, ByteInhalt)
  	  Next
    Next
  Next
  
  StopDrawing()
  CloseFile(0)
  
  SetGadgetText(#string_0, "gespeichert")
  weiter:
  text1=""
EndProcedure

Procedure lade_bild()
  LoadImage(1,"d:\winvice\bilder\"+text1)
  StartDrawing(ImageOutput(0))
  DrawImage(ImageID(1), 0,0)
  StopDrawing()
  ImageGadget(0, 160, 10, 0, 0, ImageID(0))
EndProcedure
[code]
Attachments
verdreht.jpg
Last edited by funkheld on Wed Jan 01, 2020 8:02 am, edited 2 times in total.
User avatar
Mike
Herr VC
Posts: 4839
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: i want to save an image as a bin file for the vic20 in graphics mode.

Post by Mike »

Several points to note here:
  • Your post is missing the information how you display the "bin file" on the VIC-20,
  • "speicher_bild()" does not save the picture data with a two byte load address. This is most probably not what you've intended, given the two byte shift in the result display,
  • You got the bit order wrong within a byte (i.e. how the VIC chip displays a byte),
  • Judging from the row skew in the result display, you are saving a 176x176 bitmap, but only display a 168x176 bitmap on the VIC-20. Again, most probably not what you wanted.
Back to the drawing board methinks.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: i want to save an image as a bin file for the vic20 in graphics mode.

Post by funkheld »

now it works with the graphic image in Vic20.

I painted a BMP picture with 176x176 pixels and with that
Purebasic program converted into a bin file.

greeting
Attachments
grafik1.jpg
User avatar
Mike
Herr VC
Posts: 4839
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: i want to save an image as a bin file for the vic20 in graphics mode.

Post by Mike »

Nice! Here's the equivalent program with MINIGRAFIK (download). Just decompress and drag the *.d64 file into the VICE main window. It needs at least a +8K RAM expansion:

Image

Here's the source listing:

Code: Select all

10 @ON:@CLR
11 CX=21:CY=36:A=16:B=16:GOSUB18
12 CX=44:CY=90:A=10:B=35:GOSUB18
13 X1=85:Y1=30:X2=124:Y2=68:GOSUB34
14 X1=95:Y1=101:X2=153:Y2=145:GOSUB34
15 GETA$:IFA$=""THEN15
16 @RETURN:END
17 :
18 X=0:Y=B:S=B*B:T=A*A*(2*Y-1):U=2*B*B:V=2*A*A:E=0
19 X1=CX+X:Y1=CY+Y:P1=X1>=0ANDX1<160:P2=Y1>=0ANDY1<192
20 X2=CX-X:Y2=CY-Y:P3=X2>=0ANDX2<160:P4=Y2>=0ANDY2<192
21 IFP1ANDP2THEN:@1,X1,Y1
22 IFP1ANDP4THEN:@1,X1,Y2
23 IFP3ANDP4THEN:@1,X2,Y2
24 IFP3ANDP2THEN:@1,X2,Y1
25 IFX=AANDY=0THENRETURN
26 F=E+S:D=0
27 G=F-T:IFABS(F)>ABS(G)THENF=G:D=1
28 G=E-T:IFABS(F)>ABS(G)THENF=G:D=2
29 E=F
30 IFD<2THENX=X+1:S=S+U
31 IFD>0THENY=Y-1:T=T-V
32 GOTO19
33 :
34 @1,X1,Y1TOX2,Y1:@1,X2,Y2TOX1,Y2
35 @1,X2,Y1TOX2,Y2:@1,X1,Y2TOX1,Y1
36 RETURN
Plotting double-width lines left as exercise to the reader. ;)
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: i want to save an image as a bin file for the vic20 in graphics mode.

Post by funkheld »

is a nice thing, what you can get out of such a small vic20.

greeting
Post Reply