I want to develop an encryption/decryption algorithm using last bits of a photo.
Everything it's seems ok (bit mask all that stuff), i obtain the desired modified pixels (RGB) from the image.
The only problem is when I try to write them. It's very frustrating and I don't know what I do worng.
Let's say I have a pixel with R=100 G=80 B=120.
I use
SetPixelRed(pixel,100);
SetPixelGreen(pixel,80);
SetPixelBlue(pixel,120);
When I will read the modified pixel from the new image, i will have almost the same value like R=102 G=80 B=118.
It's not a big difference, but for my algorithm it's a disaster.
Please help me with some advices to accurate the pixels...
I tried to increase the precision , but nothing happend ...
SetPixelRed problem?!
-
- Posts: 3
- Joined: 2012-11-26T03:55:01-07:00
- Authentication code: 6789
Re: SetPixelRed problem?!
You need to scale your pixel values. Here is a classic pixel loop in ImageMagick:
Code: Select all
p=pixels;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelAlpha(q,ScaleCharToQuantum(*p++));
SetPixelRed(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelBlue(q,ScaleCharToQuantum(*p++));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: SetPixelRed problem?!
If you save the image as a JPG, the lossy compression will change the colours of the pixels slightly.
Pete
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
-
- Posts: 3
- Joined: 2012-11-26T03:55:01-07:00
- Authentication code: 6789
Re: SetPixelRed problem?!
Thank you very much for the replays.
It seems like my code but if I use GetAuthenticPixels it return always NULL ...
It work just with GetCacheViewVirtualPixels.
About jpg indeed I try to use JPG , how can I fix it? (also i have problem in png, in png works better but after around 30 pixels one is corrupt ... ).
It seems like my code but if I use GetAuthenticPixels it return always NULL ...
It work just with GetCacheViewVirtualPixels.
About jpg indeed I try to use JPG , how can I fix it? (also i have problem in png, in png works better but after around 30 pixels one is corrupt ... ).
-
- Posts: 3
- Joined: 2012-11-26T03:55:01-07:00
- Authentication code: 6789
Re: SetPixelRed problem?!
even if i use ScaleCharToQuantum, i still have the same problems..