Thread: Image processing (was Need help (new to C))

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    Good tutorial!
    Makes things very much clearer.

    Another question.
    I'm writing some code to process images. The images are stored as a 2D array of pixels.
    When i run the code, i get segmentation violation. This usually occurs when trying to access values that are out side of the array your using.
    The problem is I'm pretty sure that the my values are all withing the array. Is there any other cause of segmentation violations?

    The other problem i have, when i compile i get the following warning:
    Image_lib.c:43: warning: return from incompatible pointer type
    from the code below
    Code:
    int (*image_invert(int width, int height, int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]))[]
    {
    //(body of code)
    return (int **)new_image_data;
    }
    The declaration of the above function was provided by instructor.
    it should be returning a 2D array or reference to one (not sure which).
    Any suggestions?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I don't know what that is, but here's my suggestion: if you're going to return an int **, then declare that as the return type.
    Code:
    int **image_invert(int width, int height, int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y])
    {
    //(body of code)
    return (int **)new_image_data;
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    To return your input pointer...
    Code:
    int (*image_invert(int width, int height, int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]))[]
    {
    //(body of code)
    return new_image_data;
    }
    But why did you call it new_image_data?
    Did you create a local array, because you can't return that.
    Did you allocate it using malloc, because there are several ways to malloc a 2D array, and only one of them would work here.

    PS.
    Thread split.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Simple Image Processing
    By ejohns85 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2009, 12:10 PM
  3. Replies: 4
    Last Post: 03-02-2003, 09:12 AM
  4. Memory Allocation in Intell Image processing liberary
    By nisar in forum Windows Programming
    Replies: 0
    Last Post: 01-12-2003, 07:29 AM
  5. Image rotation using intel image processing
    By sunis in forum Windows Programming
    Replies: 1
    Last Post: 11-18-2002, 02:40 AM