Thread: getting pixel data from image using libpng

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    3

    getting pixel data from image using libpng

    I am trying for create a program that performs 2-dimensional fast fourier transforms on each pixel of data in an image. I am going to transform each channel seperately, then map the coefficients to colours and recombine them into an image.

    But I cannot seem to figure out how to read/interpret the pixel data using libpng. Can someone help me find out how I would read a png image and read each pixel's data into an array?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    We don't work quite that way.

    YOU show US what you've done to try to solve the problem, and where you're stuck - with code, preferably.

    When we see code that you're working with, we can be specific. Without it, we can't be specific.

    Is your file a PNG file? Did you read up on it's format? Did you look at it's contents with a Hex Editor? How did you open the file? What kind of variables did you use?

    See what I mean?

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    3
    I don't really have code to show you that would be of any help. But I can be more specific with the nature of my problem.

    My program reads in a PNG file and I can fetch it's width and height from the info structure. I also know how to read each row into an array of type png_bytep. I have no idea how I am supposed to access the individual color components of each pixel from the byte array though. I apologize for my vague description initially, I am just new to this particular library, and it's common usage is apparently quite different than what I am attemping to use it for.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    If the pixels are 24-bit RGB, then the data is composed of interleaved and repeating R, G, and B samples. R comes first, then G, then B.

    Code:
    unsigned char *red = (unsigned char *)ptrToRow[ Y ] + 3 * X;
    unsigned char *green = (unsigned char *)ptrToRow[ Y ] + 3 * X + 1;
    unsigned char *blue = (unsigned char *)ptrToRow[ Y ] + 3 * X + 2;
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    3
    Thank you very much.

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    this is a good article, though it is SDL >

    Lazy Foo' Productions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Image rotation - doesn't always work
    By ulillillia in forum C Programming
    Replies: 12
    Last Post: 05-03-2007, 12:46 PM
  4. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  5. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM