Qbasicnews.com
April 12, 2021, 06:50:14 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: jpg and tga  (Read 10620 times)
xteraco
Ancient QBer
****
Posts: 450



WWW
« on: February 17, 2005, 05:53:20 AM »

how would i got about loading a jpg image in fb w/ and w/out using any libs  .. .ok, and howw about a tga???   where can i dload other libs?
Logged

url=http://www.random-seed.net][/url]
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #1 on: February 17, 2005, 08:09:39 AM »

For JPEG wait until Antoni finishes porting his loader.
For GIF you can try Rich Geldreich's one which I ported and posted in this forum two days ago.
For TGA/BMP/PCX there are plenty for QB, you just have to port them.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #2 on: February 17, 2005, 08:19:07 AM »

In XP, there are GDI+ API calls delaing with JPEGS. Unfortunately they only works in XP...

When did i say I was porting the loader? It was supposed to be a secret...I speak too much   :oops:

In fact the huffman decoder is giving me some headaches. My "creative" bit operations are not easily ported...
Logged

Antoni
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #3 on: February 17, 2005, 08:39:17 AM »

You can do it using SDL_image... but you would have trouble trying to load it on your own (the decompression algorithms for JPG and TGA are complex and confusing Smiley).

Download Example ZIP

Here is an example of doing it with SDL_image.

[syntax="FreeBASIC"]
DIM myFirstImage AS SDL_Surface PTR
DIM mySecondImage AS SDL_Surface PTR

myFirstImage = IMG_Load("something.jpg")
mySecondImage = IMG_Load("something_else.tga")
[/syntax]

You should check whether the loading failed - this can be done by checking for either of the pointers being NULL (zero). Example:

[syntax="FreeBASIC"]
IF myFirstImage = 0 THEN
    PRINT "Failed to load first image!"
    SDL_Quit
    END
END IF
[/syntax]


There is a more detailed example in the ZIP file I've put a link to at the top of this post.

By the way, you need to include a lot of DLLs if you use SDL_image. Smiley

Hope this helps.

-shiftLynx
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #4 on: February 17, 2005, 08:47:50 AM »

By the way, here is a full list of the types of images you can load with SDL_image: BMP, PNM, XPM, XCF, PCX, GIF, JPEG, TIF, PNG, TGA and LBM.

Just use IMG_Load to load any of them.


-shiftLynx
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
xteraco
Ancient QBer
****
Posts: 450



WWW
« Reply #5 on: February 17, 2005, 09:11:34 AM »

dang shiftLynx....your @ the top of my 1337 c0d3rz list!!! Cheesy
Logged

url=http://www.random-seed.net][/url]
xteraco
Ancient QBer
****
Posts: 450



WWW
« Reply #6 on: February 17, 2005, 09:53:51 AM »

hmm, i know the jpg is smaller in size compared to a bmp, but sinse its harder to load, or more is done to load it than w/ bmp, would it be more efficient to use a bmp??? or a jpg???
Logged

url=http://www.random-seed.net][/url]
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #7 on: February 17, 2005, 10:01:24 AM »

Happy to help. Cheesy

It would be better to use JPG (or TGA or any other of those compressed formats). Once the IMG_Load function has loaded the JPG into memory, it is in the same format as any other BMP would be - the loading routine decompresses the file into its full form, which is then stored in memory.

Therefore, there is no difference in efficiency between using BMP or a compressed format - the only reason it would be better to use a compressed image file format is that the files you distribute with your program will be much smaller. Smiley

-shiftLynx
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
xteraco
Ancient QBer
****
Posts: 450



WWW
« Reply #8 on: February 17, 2005, 10:16:23 AM »

thnx again...
Logged

url=http://www.random-seed.net][/url]
adosorken
*/-\*
*****
Posts: 3655



WWW
« Reply #9 on: February 17, 2005, 10:36:34 AM »

Quote from: "xteraco"
hmm, i know the jpg is smaller in size compared to a bmp, but sinse its harder to load, or more is done to load it than w/ bmp, would it be more efficient to use a bmp??? or a jpg???

It is more efficient to use BMP, and also preferred if you need to retain pixel perfect image quality since JPG is lossy. Use JPGs for stuff like photographs and realistic textures, but BMP is better suited for sprites and abstract textures.
Logged

I'd knock on wood, but my desk is particle board.
Z!re
*/-\*
*****
Posts: 4599


« Reply #10 on: February 17, 2005, 10:48:11 AM »

PNG is also good, it's still lossy but not nearly as much as JPEG (PNG might lose like 100 pixels on a 640x480 images, so.. no big deal Tongue )
Logged
shiftLynx
Wandering Guru
***
Posts: 340



WWW
« Reply #11 on: February 17, 2005, 10:51:43 AM »

Quote from: "adosorken"
It is more efficient to use BMP, and also preferred if you need to retain pixel perfect image quality since JPG is lossy. Use JPGs for stuff like photographs and realistic textures, but BMP is better suited for sprites and abstract textures.


True, true! Smiley

Maybe you could use PNG. PNG is a lossless compressed format and the algorithm is free to use without any patent issues (Greg Roelofs is cool). Smiley

But yeah, as ado said, JPGs aren't really used for games... TGAs are used for Counter-Strike and Half-Life, so they must be quite good. Smiley I would stick with either PCX or PNG.

-shiftLynx
Logged

img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Z!re
*/-\*
*****
Posts: 4599


« Reply #12 on: February 17, 2005, 10:59:05 AM »

TGA can hold alpha channels, if I'm not misstaken.


And PNG does lose some pixels, not something you'll notice unless you run a byte compare.
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #13 on: February 17, 2005, 12:03:32 PM »

AFAIK, PNG and GIF are not lossy formats.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Joakim
Senior Member
**
Posts: 230



WWW
« Reply #14 on: February 17, 2005, 12:20:19 PM »

I belive PNG can hold an alpha channel too, so it's just a matter of taste (and as other people said before me, it's lossless). I prefer PNG myself.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!