Re: [GD-DEVEL] Problem using gdImageGetPixel()
| From: | Takeshi Abe | Date: | Thu, 18 Dec 2008 13:08:34 +0000 |
| Subject: | Re: [GD-DEVEL] Problem using gdImageGetPixel() | ||
| References: | 1 2 3 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-525@lists.php.net to get a copy of this message | ||
Hi Yorn,
On Thu, 18 Dec 2008 13:31:31 +0100, Yorn <yorn@gmx.net> wrote:
> Hey,
>
> However, the example code leads to a segfault...
My guess is that your pic1.jpg is true color (then im->red etc. were not
initialized so segfault).
> What I really want is the following:
> 1) Read a picture (This is where I would like to use libgd for)
> 2) Maybe resize/resample it
> 3) get a plain rgba picture (successive placed into memory), so that I can do
> some internal manipulation
> 4) calculate an YCbCr 420 Plain (where I would be happy to have the exactly
> plain discribed in 3)
>
> Any idea, how I can get this rgb(a) plain?
How about using gdImageRed/gdImageGreen/gdImageBlue/gdImageAlpha, like the followings?
#include <stdio.h>
#include <gd.h>
int main()
{
FILE *in;
gdImagePtr im;
int c;
in = fopen("pic1.jpg", "rb");
im = gdImageCreateFromJpeg(in);
fclose(in);
c = gdImageGetPixel(im, gdImageSX(im) / 2, gdImageSY(im) / 2);
printf("The value of the center pixel is %d", c);
int red = gdImageRed(im, c);
int green = gdImageGreen(im, c);
int blue = gdImageRed(im, c);
printf(" RGB values are %d %d %d\n", red, green, blue);
gdImageDestroy(im);
return(0);
}
Cheers,
-- Takeshi Abe