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