Created
April 2, 2013 15:57
-
-
Save senior-sigan/5293378 to your computer and use it in GitHub Desktop.
Find maximum between two pics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LOL. This code was writing down by Siganiv ILya. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <wand/MagickWand.h> | |
#include <sys/types.h> | |
//gcc `MagickWand-config --cflags --cppflags` -o main main.c `MagickWand-config --ldflags --libs` | |
int main(void) | |
{ | |
MagickWand *mw_1,*mw_2,*mw_res; | |
PixelIterator *imw_1,*imw_2,*imw_res; | |
PixelWand **pmw_1,**pmw_2,**pmw_res; | |
Quantum qr_1,qg_1,qb_1; | |
Quantum qr_2,qg_2,qb_2; | |
char* fname1="test1.jpg"; | |
char* fname2="test2.jpg"; | |
char* res="res.jpg"; | |
unsigned long y; | |
register long x; | |
unsigned int width,height; | |
MagickWandGenesis(); | |
mw_1 = NewMagickWand(); | |
mw_2 = NewMagickWand(); | |
MagickReadImage(mw_1, fname1); | |
MagickReadImage(mw_2, fname2); | |
width = MagickGetImageWidth(mw_1); | |
height = MagickGetImageHeight(mw_1); | |
if (MagickGetImageWidth(mw_2) != width && MagickGetImageHeight(mw_2) != height){ | |
perror("Width and height doesn't match\n"); | |
exit(-1); | |
} | |
printf("width %d\nheight %d\n",width,height); | |
mw_res = NewMagickWand(); | |
MagickSetSize(mw_res,width,height); | |
MagickReadImage(mw_res,"xc:none"); | |
imw_1 = NewPixelIterator(mw_1); | |
imw_2 = NewPixelIterator(mw_2); | |
imw_res = NewPixelIterator(mw_res); | |
for(y = 0;y < height; ++y){ | |
pmw_1 = PixelGetNextIteratorRow(imw_1, &width); | |
pmw_2 = PixelGetNextIteratorRow(imw_2, &width); | |
pmw_res = PixelGetNextIteratorRow(imw_res, &width); | |
for (x = 0;x < (long)width; ++x){ | |
qr_1 = PixelGetRedQuantum(pmw_1[x]); | |
qg_1 = PixelGetGreenQuantum(pmw_1[x]); | |
qb_1 = PixelGetBlueQuantum(pmw_1[x]); | |
qr_2 = PixelGetRedQuantum(pmw_2[x]); | |
qg_2 = PixelGetGreenQuantum(pmw_2[x]); | |
qb_2 = PixelGetBlueQuantum(pmw_2[x]); | |
PixelSetRedQuantum(pmw_res[x], qr_1 > qr_2 ? qr_1 : qr_2 ); | |
PixelSetGreenQuantum(pmw_res[x], qg_1 > qg_2 ? qg_1 : qg_2 ); | |
PixelSetBlueQuantum(pmw_res[x], qb_1 > qb_2 ? qb_1 : qb_2 ); | |
} | |
PixelSyncIterator(imw_res); | |
} | |
MagickWriteImage(mw_res,res); | |
imw_1 = DestroyPixelIterator(imw_1); | |
imw_2 = DestroyPixelIterator(imw_2); | |
mw_1 = DestroyMagickWand(mw_1); | |
mw_2 = DestroyMagickWand(mw_2); | |
MagickWandTerminus(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment