Sorry, didn't read it properly:
new_red(((image_data[column][row]<<16)));
This is not correct syntax. You want to take the new_red and shift it 16 bits. The above code calls a function called new_red - this function probably don't exist.
Printable View
so what about just leaving it as:
int red = ((image_data[column][row]<<16));
oh ok so:
image_data[column][row] = new_red<<16 | new_green<<8 | new_blue;
and the top 8 bits dont really need to worry about as they are transparency am i correct
Yes, but if they actually contain something other than zero, you'd have to copy those bits out and move them back in on the above line - otherwise they BECOME zero and thus "lost". But you better ask someone who knows your project setup whether there is any data stored in the "alpha" bits.
--
Mats
that what i think i heard today, tutor said to ignore it.
can u just confirm that this is correct:
image_data[column][row] = new_red<<16 | new_green<<8 | new_blue;
Yes, conceptually that is right. Becuse << has lower priority than the | operand, you will still not get quite the right thing:
written out with the order of precedence, you'll get:
new_red<<(16 | new_green)<<(8 | new_blue);
That's not wha tyou want. So use brackets to make sure things get done the right order.
--
Mats
ok i see thanks
I've got similar problems.
i modify a picture array that is stored in a static int.
but when returning to main function, and attempting to display, only a black scrren is shown
above is skeleton code, everything else works but the screen is black.Code:int **invert(int width, int height, int image_data[height][width])
{
static int new_image_data[height][width];
//begin accessing pixels in array
//exctract colours from a single pixel
//invert colours
//combine colours into new pixel
return (int **)new_image_data;
}
int main(int argc, char * argv[])
{
int temparray[height][width];
**temparray=image_invert(width,height,image_data);
//these procedures are provided by instructor
set_data(temparray);
display_image();
//i think display_image() is meant to the data set by set_data(temparray)
}
The image is not getting returned properly to the main program.
Any ideas?
I found out why the image was black, i was copying **temparray (which was empty) into it.
data is still not being returned correctly.
what should i do?
> **temparray=image_invert(width,height,image_data);
You can't assign arrays.
This (if it works at all) just assigns one location in the array, not all of them.
If you really want to create a new array, then you need to pass the result as another parameter, in much the same way that say strcpy receives an output array as well as an input array.
> static int new_image_data[height][width];
You can't create a new static object based on variable width and height.