Help CatchSprite

Just starting out? Need help? Post your questions and find answers here.
qqqnnn
User
User
Posts: 22
Joined: Mon Jan 11, 2010 7:45 pm

Help CatchSprite

Post by qqqnnn »

Code: Select all


ReadFile(0, "c:/0.jpg")
size=Lof(0) 
*buffer=AllocateMemory(size) 
*target=AllocateMemory(size) 
ReadData(0, *buffer, size)
CloseFile(0)

For c=0 To size-1
  pos=*buffer+c
  pos2=*target+c
  t=PeekB(pos)
  q = t + 13
  If q > 255
    q = q - 256
  EndIf
  PokeB(pos2, q)
Next c

If CreateFile (1,"c:/0.dat")
  WriteData(1, *target, size)
  CloseFile(1)
EndIf

ReadFile(0, "c:/0.dat")
size=Lof(0) 
*buffer2=AllocateMemory(size)
*target2=AllocateMemory(size) 
ReadData(0, *buffer2, size)
CloseFile(0)
Debug size
For c=0 To size-1
  pos=*buffer2+c
  pos2=*target2+c
  t=PeekB(pos)
  q = t - 13
  If q < 0
    q = q + 256
  EndIf
  PokeB(pos2, q)
Next

If OpenWindow(0, 0, 0, 320, 200, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  InitSprite() 
	OpenWindowedScreen(WindowID(0), 0, 0, 320, 200, #False, 0, 0)
	CatchSprite(0,*buffer2)
	DisplaySprite(0, 0, 0)

    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow

  EndIf
EndIf
Why is there an error? Help me
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Help CatchSprite

Post by netmaestro »

You'll need UseJPEGImageDecoder().
BERESHEIT
qqqnnn
User
User
Posts: 22
Joined: Mon Jan 11, 2010 7:45 pm

Re: Help CatchSprite

Post by qqqnnn »

Added

Code: Select all

UseJPEGImageDecoder()
UseJPEGImageEncoder()
Not OK
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Help CatchSprite

Post by Kaeru Gaman »

1st build a correct GameLoop. you left out the FlipBuffers.

Code: Select all

Repeat
  Repeat
    Event = WaitWindowEvent(10)
    If Event = #PB_Event_CloseWindow
      EXIT = 1
    EndIf
  Until Event = #Null Or EXIT

  ClearScreen( $000000 )
  DisplaySprite(0, 0, 0)
  FlipBuffers()
Until EXIT
2nd devide the probings.
first test your file encoding with an own binary file and compare byte by byte, this helps improving the calculations first.
then test it with a bitmap sprite, not JPG.


a tip:
you can use .a variables and PeekA/PokeA
you'll not need some <0 or >255 test then.

and better use PNG instead of JPG, JPG looks shitty if you don't switch color-subsampling off.
oh... and have a nice day.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Help CatchSprite

Post by Rook Zimbabwe »

As a purist I just use BMP files with RGB(0,0,0) = BLACK for transparent and rgb(0,0,1) for black...
Than gain I just use LoadSprite() as welll

Easier cause I am lazy!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply