gd library - help

Linux specific questions.
Post Reply
DNAarray
Posts: 29
Joined: May 15, 2006 21:17

gd library - help

Post by DNAarray »

In the examples, there is an example to use the gd library "gd_test.bas". It creates a file called test.gif. This library is pretty awesome and I would like to use it as a basis for many programs like picture viewer and to convert my, sf.phpcad.net, to a much better desktop application. probably textcad. In the example there is this line.

declare function saveImgToGIF( byval img as gdImagePtr, filename as string ) as integer

Is there anyway to display this image on a freebasic screen?

Thanks, Bill
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

hey, I never used this lib before, and i don't have the lib (can't find -lgd on compile), but I made some guesses as to how the lib handles things internally. Maybe this works, but if not then sorry. It's only a guess.

Code: Select all

#Include "gd\gd.bi"
#Include "crt.bi"

Dim As gdImagePtr myGIF
Dim As FILE Ptr GIF_File


Sub GIF_Blit( giffy As gdImagePtr, x As Integer, y As Integer )
  
  Dim As Integer calc
  
  calc = giffy->sy * giffy->sx
  calc += 4
  
  Dim As uByte img( calc - 1 )
  
  Cast( uShort Ptr, Varptr( img( 0 ) ) )[0] = giffy->sx Shl 3
  Cast( uShort Ptr, Varptr( img( 0 ) ) )[1] = giffy->sy
  
  For calc = 0 To giffy->sy - 1
  
    MemSet( Varptr( Cast( uShort Ptr, Varptr( img( 0 ) ) )[2] ) + ( calc * giffy->sx ), giffy->pixels[calc], giffy->sx )
    
  Next
  
  Put( x, y ), img


End Sub


screen 13

GIF_File = fopen( "anemone.gif", "r" )

myGIF = gdImageCreateFromGif( GIF_File )

GIF_Blit( myGIF )

Sleep


gdImageDestroy( myGIF )



DNAarray
Posts: 29
Joined: May 15, 2006 21:17

thanks

Post by DNAarray »

libgd2-xpm-dev - GD Graphics Library version 2 (development version)


You should try a debian based system. I use hard disk install of kanotix and love it.

apt-get install libgd2-xpm-dev and you are done.


I will give your idea a go.
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

Actually I'm on windows XD.

I love coding blindly and seeing if it works. It's really fun.
DNAarray
Posts: 29
Joined: May 15, 2006 21:17

didn't work

Post by DNAarray »

I could not get it to work, kept getting segmentation fault. But, did get a verticle line of dots one time
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

You would be better off using another lib than gd. gd is a lib for opening, manipulating and saving images, not displaying them. I have heard people talk about FreeImage
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

I'm so blind or is bpp are missing?
Cast( uShort Ptr, Varptr( img( 0 ) ) )[0] = (giffy->sx Shl 3) or BPP
BPP=1 or 2 or 4

Joshy
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

Honestly, it was a quick hack.

I don't have the library to run the code, GIF->sx, GIF->sy might not even contain the image dimensions... Just a lame guess. ;)
DNAarray
Posts: 29
Joined: May 15, 2006 21:17

I think you can could get it to work

Post by DNAarray »

I think you could get it to work if you had a library for it. The png works, but somehow the WBMP does not make a correct header fro a bmp file. Thus, I tryed to use pload, but could not get that to work.

declare function gdImageCreateTrueColor alias "gdImageCreateTrueColor" (byval sx as integer, byval sy as integer) as gdImagePtr


that is in Frebasic/inc/gd.bi

Maybe, the you dont need to compile and can use the one from php for windows.

How to Obtain the php_gd2.dll

The GD dll's are provided in the latest download packages of the PHP installation for windows.

Download the zip package for Windows from the following page:-

http://www.php.net/downloads.php

Unzip the package and copy the php_gd2.dll from the ./ext/ dir to the /ext/ dir of your installation.

( In some cases it is also necessary to place a copy of all the DLL's in the ./ext/ dir in the ./system32 dir. )


If you download the Windows binaries from php . net the gd . dll is included with it . http : / / www . php . net / do_download . php ? download_file = php ...
DNAarray
Posts: 29
Joined: May 15, 2006 21:17

Found dll

Post by DNAarray »

http://www.boutell.com/gd/

This is the site of the library. Although freeimage, imagemagick are good, i think this one might be the best.
markem
Posts: 49
Joined: Aug 30, 2006 23:17
Contact:

Re: gd library - help

Post by markem »

I realize this is AGES old, but the answer to the question about if you can display a GD image - it answer is - Yes. You can do it.

Really simply, GD has a way to get the width and height of an image (imageX and imageY I think).

So you get the width and height and then clear your Freebasic buffer and then just do a FOR statement. Using GD, you just get the pixel at the X,Y location and then put it into your FreeBasic buffer. That will transfer the image to FreeBasic.

You might want to look at FLTK also. I think FLTK means Fast, Light, Tool Kit. FLTK will read graphics and do a lot of other things.

So there you have it - two answers in one post and my head hasn't exploded yet. :-)
Post Reply