help and code suggestion
[email protected] ("Robert Stephen Woodman")
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <006801c769b9$b3819a30$660fa8c0@emanretupmoc> |
First of all, I hope that this message is going to the correct place. This
is regarding the GD graphics library (http://www.libgd.org/Main_Page). The
following message is about help and suggested changes:
OK(ay), I think that I do want to use your library. I thank you for
making this library and for distributing it for free. I am a Windows C++
programmer. I was formerly using GDI+, but it is slow and doesn't have very
many options for saving and loading pictures (if it does, then I don't know
about it). Your library is really what I have wanted.
At first, I had some trouble learning how to use it, but it didn't take
me too long to understand it. However, what I soon found to be lacking, was
the fact that it cannot load a gif animation. It can save a gif animation,
but it can load only the first frame. Therefore, I downloaded the source.
After some time, I was able to edit the code so that it did actually load
the entire animation (way cool!). The change was little more than adding a
loop to the gif load. I will happily give you the code, and I certainly ask
nothing for it (I do not even care about acknowledgment). As far as I
remember, I edited only "gd_gif_in.c" and "gd.h".
My problem, is that when I tried to compile this, it all compiled well,
but I got a linker warning, regarding the jpeg load function. After a while,
I realized that "gd_jpeg.c" was not even compiling, because I didn't define
"HAVE_LIBJPEG". When I defined this, then the problem was fixed, but another
problem appeared, namely, that I don't have the source for the following 19
functions:
jpeg_write_scanlines()
jpeg_CreateCompress()
jpeg_CreateDecompress()
jpeg_destroy()
jpeg_destroy_compress()
jpeg_destroy_decompress()
jpeg_finish_compress()
jpeg_finish_decompress()
jpeg_read_header()
jpeg_read_scanlines()
jpeg_resync_to_restart()
jpeg_save_markers()
jpeg_set_defaults()
jpeg_set_quality()
jpeg_simple_progression()
jpeg_start_compress()
jpeg_start_decompress()
jpeg_std_error()
jpeg_write_marker()
I have already downloaded the code from the IJG web site
(http://www.ijg.org), but it does not have it, either (it does have
"jpeglib.h", and "jerror.h", which "gd_jpeg.c" wants, but it still doesn't
have the source for these functions). I do not see why you didn't simply
include the necessary file (the source for these functions).
I would be interested in knowing where I can get the source for these
functions (I imagine that they are all in a single C file). However, what I
would really like, is for you to use what I did to your gif load function,
or for you to do something similar, yourself. Mine is good. I tried to stick
to your style, but I didn't exactly adhere (so you may want to redo it
yourself). If you do make a new DLL out of this, then please tell me.
Whatever fix that you offer (if any), I would appreciate sooner than
later. I don't have any time to meet, but it would be nice for this to be
working and out of the way.
I really do like your library. I hope that you will help me. If you don't
help me, then I will probably just use the precompiled DLL and then fudge
some minimal version of your code, so that I can have the gif, with my
little fix (it is so lame to load just the first frame of a gif animation-I
am sure that users (there are no users now, but there may be someday) of my
program, would agree with me).
I don't get it though-you have all of the gif algorithm working, basically
what I did, was to add a loop-why didn't you already have that?
I don't want to tell you what my program is, because I may never finish
it. I hope to finish it, and then sell it to many people, however, I am not
close to that. It is a graphics program, so picture interfaces, are sorta
important :-). Speed is very important to me, and, from what I have seen,
your code is rather fast. This makes me glad.
Thanks again for the free graphics library. I look forward to your response
(I hope that you respond, but you don't have to).
I tried to include "gd_gif_in.c" and "gd.h", but my e-mail was returned,
because it was too big. Therefore, I have included my modifications, and I
hope that you will be able to piece it together. If you would like for me to
send the actual files, then please tell me where I can do that, because of
the size limitation.
The following is my explanation, as if I had included the files (because
I had at first), and then I have my modifications to the files. It says that
I included the files (even though I have not), because my original e-mail
did have the files.
I have included "gd_gif_in.c" and "gd.h", so that you can use my code, if
you like (I based my work upon version 2.0.33, but it should be very similar
to whatever you are using now).
In "gd.h" simply run a search for "gdImageArray". Also note that I updated
the gif load functions:
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGif (FILE * fd, unsigned short
*FrameCountPtr);
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGifCtx (gdIOCtxPtr in,
unsigned short *FrameCountPtr);
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGifPtr (int size, void *data,
unsigned short *FrameCountPtr);
In "gd_gif_in.c", the main work was in "gdImageCreateFromGifCtx()"
(obviously), since it is the real load function (the other 2 are just
wrappers). I updated the other 2, since I am now using an image array
structure (for gif only), and not just an image structure, but they remain
basically the same. Also, notice the extra parameter (unsigned short
*FrameCountPtr).
If you walk through the function, you should be able to see what I did.
Notice the new loop (for(;;)/*Primary loop*/). Also, notice that I quoted
out the early break (/*goto terminated;*/). Notice the variable "imA"
(gdImageArrayPtr imA = 0;). This is our Image Array pointer. Basically, this
is our array of images. I use "realloc()" every time through the loop, until
we have loaded in all of the frames (I don't know if I neglected to include
some important safety stuff, but it did work well for me).
Changes for "gd.h":
typedef struct gdImageArrayStruct
{
gdImagePtr im;/*We will "realloc()" this, everytime that we need to add a
frame. remember, all this is, is an array of poointers. The pointers are
allocated via "gdImageCreate()".*/
}
gdImageArray;
typedef gdImageArray *gdImageArrayPtr;
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGif (FILE * fd, unsigned short
*FrameCountPtr);
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGifCtx (gdIOCtxPtr in,
unsigned short *FrameCountPtr);
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGifPtr (int size, void *data,
unsigned short *FrameCountPtr);
Changes for "gd_gif_in.c":
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGif(FILE *fdFile, unsigned
short *FrameCountPtr)
{
gdIOCtx *fd = gdNewFileCtx(fdFile);
gdImageArrayPtr imA = gdImageCreateFromGifCtx(fd, FrameCountPtr);
fd->gd_free(fd);
return imA;
}
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGifPtr (int size, void *data,
unsigned short *FrameCountPtr)
{
gdImageArrayPtr imA;
gdIOCtx *in = gdNewDynamicCtxEx (size, data, 0);
imA = gdImageCreateFromGifCtx (in, FrameCountPtr);
in->gd_free (in);
return imA;
}
BGD_DECLARE(gdImageArrayPtr) gdImageCreateFromGifCtx(gdIOCtxPtr fd, unsigned
short *FrameCountPtr)
{
int BitPixel;
#if 0
int ColorResolution;
int Background;
int AspectRatio;
#endif
int Transparent = (-1);
unsigned char buf[16];
unsigned char c;
unsigned char ColorMap[3][MAXCOLORMAPSIZE];
unsigned char localColorMap[3][MAXCOLORMAPSIZE];
int imw, imh;
int useGlobalColormap;
int bitPixel;
int i;
/*1.4//int imageCount = 0; */
char version[4];
/* 2.0.28: threadsafe storage */
int ZeroDataBlock = FALSE;
gdImageArrayPtr imA = 0;
gdImagePtr im;/*This is used as a pointer to the object of imA (im =
imA->im[FrameCount-1]).*/
#define FrameCount *FrameCountPtr/*Number of frames that are in this
animation.*/
FrameCount = 0;/*0 frames, thus far.*/
if (! ReadOK(fd,buf,6)) {
return imA;
}
if (strncmp((char *)buf,"GIF",3) != 0) {
return imA;
}
strncpy(version, (char *)buf + 3, 3);
version[3] = '\0';
if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
return imA;
}
for(;;)/*Primary loop*/
{
if (! ReadOK(fd,buf,7)) {
return imA;
}
BitPixel = 2<<(buf[4]&0x07);
#if 0
ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
Background = buf[5];
AspectRatio = buf[6];
#endif
if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */
if (ReadColorMap(fd, BitPixel, ColorMap)) {
return imA;
}
}
for (;;) {
if (! ReadOK(fd,&c,1)) {
return imA;
}
if (c == ';') { /* GIF terminator */
goto terminated;
}
if (c == '!') { /* Extension */
if (! ReadOK(fd,&c,1)) {
return imA;
}
DoExtension(fd, c, &Transparent, &ZeroDataBlock);
continue;
}
if (c != ',') { /* Not a valid start character */
continue;
}
/*1.4//++imageCount; */
if (! ReadOK(fd,buf,9)) {
return imA;
}
useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
bitPixel = 1<<((buf[8]&0x07)+1);
imw = LM_to_uint(buf[4],buf[5]);
imh = LM_to_uint(buf[6],buf[7]);
FrameCount+=1;/*incriment frame count, since we are preparing to add another
frame.*/
imA = realloc(imA, FrameCount*4);/*4 bytes per pointer*/
if (!(imA[FrameCount-1].im = gdImageCreate(imw, imh))) {
/*image creation failed, so we ought to deallocate it, before we get into
trouble.*/
FrameCount-=1;
imA = realloc(imA, FrameCount*4);/*4 bytes per pointer*/
return imA;
}
im=imA[FrameCount-1].im;/*pointer to use henceforth.*/
im->interlace = BitSet(buf[8], INTERLACE);
if (! useGlobalColormap) {
if (ReadColorMap(fd, bitPixel, localColorMap)) {
return imA;
}
ReadImage(im, fd, imw, imh, localColorMap,
BitSet(buf[8], INTERLACE), &ZeroDataBlock);
} else {
ReadImage(im, fd, imw, imh,
ColorMap,
BitSet(buf[8], INTERLACE), &ZeroDataBlock);
}
if (Transparent != (-1)) {
gdImageColorTransparent(im, Transparent);
}
/*goto terminated;*/
}
}/*end "for(;;)"Primary loop*/
terminated:
/* Terminator before any image was declared! */
if (!im) {
return imA;
}
/* Check for open colors at the end, so
we can reduce colorsTotal and ultimately
BitsPerPixel */
for (i=((im->colorsTotal-1)); (i>=0); i--) {
if (im->open[i]) {
im->colorsTotal--;
} else {
break;
}
}
return imA;
#undef FrameCount
}
Hey, I noticed that in your newer distribution of the source, for the
graphics library, that you included some sample pictures
(gd-2.0.34\tests\gif). The pictures are called "bug" and then are given some
number. When looking at one of them, I notice that it was sort of a fairy
type thing (not what I had thought from the name "bug"). This character,
however, was not well dressed. You shouldn't distribute things like that. I
am glad that you distribute the graphics library, the source, and help
files, but you shouldn't distribute pictures like that. Don't you know that
this sort of thing displeases God? Was not prostitution a snare to Israel?
When we portray women (and girls) this way, do we not encourage
prostitution? Is this not the spirit of prostitution? Remember, Jesus said
that if you look at a women lustfully, that you have already committed
adultery with her, in your heart. Surely such pictures appeal to our natural
lust.
Matthew 5:28
28But I tell you that anyone who looks at a woman lustfully has already
committed adultery with her in his heart.
I hope that you don't take this wrongly (I am serious, but I am not trying
to condemn). God bless you.
Robert Stephen Woodman