Thread: desperate help needed

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    25

    desperate help needed

    this program im writing as some of u probs already know is sposed to invert and scroll pictures. As a student as was required to write a function to invert the photo and procedures to horizontally and vertically scroll an image. these procedures and function were to be seperate from the mainline file and stored in a file Image_lib.c with the mainline being Image.c

    the problems I'm having so far are

    1) My invert function sets all the image data to 0 for some reason and so the image comes out as blank

    and

    2) I get segmentation faults whenever my procedure deals with an imported value.

    this is the code to my procedure/function

    Code:
    #include <stdio.h>
    #include <ep100lib.h>
    #include <math.h>
    #include <stdlib.h>
    #define EP100_LIB_MAX_X 1024
    #define EP100_LIB_MAX_Y 1024
    
    int (*Image_Invert(int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_X], int height, int width))[]
    {
    int row, column, red, green, blue;
    int newred, newgreen, newblue;
    static int new_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    
    for(row=0;row < height; row++)
    	{
    	for(column=0; column < width; column++);
    		{
    		red = ((image_data[row][column]>>16) &0xff);
    		green = ((image_data[row][column]>>8) &0xff);
    		blue = ((image_data[row][column]) &0xff);
    	
    		newred = 255 - red;
    		newgreen = 255 - green;
    		newblue = 255- blue;
    		
    		new_data[row][column] = ((newred<<16) + (newgreen<<8) + (newblue));
    		}
    	}
    return (int **)new_data;
    }
    
    void Image_Horizontal_Scroll(int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y], int height, int width, int horizontal_scroll_amount)
    {
    int row;
    int column;
    int new_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    int new_column;
    
    horizontal_scroll_amount = horizontal_scroll_amount % width;
    
    for (row=0; row < height; row++)
    	{
    	for (column=0; column < width; column++)
    		{
    		if (column + horizontal_scroll_amount < 0)
    			{
    			new_data[row][width + column + horizontal_scroll_amount] = image_data[row][column];
    			}
    		else if (0 <= column + horizontal_scroll_amount < width)
    			{
    			new_data[row][column + horizontal_scroll_amount] = image_data[row][column];
    			}
    		else if (column + horizontal_scroll_amount >= width)
    			{ 
    			new_data[row][column - width + horizontal_scroll_amount] = image_data[row][column];
    			}
    		}
    	}
    
    image_data = new_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    }

    And this is where i have called the functions/procedures in my mainline


    Code:
    			else
    				{
    				Image_Horizontal_Scroll(image_data, height, width, horizontal_scroll_amount);
    				ep100_lib_get_data(image_data);
    				}
    and

    Code:
    		if (invert == true)
    			{
    			ep100_lib_set_data(Image_Invert(image_data, height, width));
    			ep100_lib_get_data(image_data);
    			}

    serious help is needed people.. I have literally been punching my computer for around 4 hours now

    thanx alot

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Why does image_invert and horizontalscroll have a different interface?

    > return (int **)new_data;
    return new_data;
    should suffice.

    > image_data = new_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    Did this even compile?
    Or did you just ignore a bunch of warnings?

    memcpy( image_data, new_data, sizeof new_data );
    Will copy the whole array.
    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. Desperate help needed. C++ Uni Assignment.
    By ILLaViTaR in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2009, 01:30 PM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. Desperate Help needed
    By roco090 in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2005, 09:43 PM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM