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

This is a discussion on Image processing (was Need help (new to C)) within the C Programming forums, part of the General Programming Boards category; Good tutorial! Makes things very much clearer. Another question. I'm writing some code to process images. The images are stored ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 08:12 AM
  4. Memory Allocation in Intell Image processing liberary
    By nisar in forum Windows Programming
    Replies: 0
    Last Post: 01-12-2003, 06:29 AM
  5. Image rotation using intel image processing
    By sunis in forum Windows Programming
    Replies: 1
    Last Post: 11-18-2002, 01:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21