Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gd.h>
- typedef struct {
- int rx, ry, gx, gy, bx, by;
- } coloffset;
- /* expect im and out to have the same dimensions */
- void chromab(gdImagePtr im, gdImagePtr out, int frm,
- coloffset offsetfunc(int, int, int)) {
- int x, y, colin, colout, coldest, black, sx, sy,
- r, g, b, rx, ry, gx, gy, bx, by;
- coloffset co;
- black = gdImageColorResolve(out, 0, 0, 0);
- gdImageFilledRectangle(out, 0, 0, out->sx, out->sy, black);
- for (y=0; y<im->sy; y++)
- for (x=0; x<im->sx; x++) {
- co = offsetfunc(frm, x, y);
- rx = co.rx; ry = co.ry;
- gx = co.gx; gy = co.gy;
- bx = co.bx; by = co.by;
- colin = gdImageGetPixel(im, x, y);
- /* red */
- coldest = gdImageGetPixel(out, x+rx, y+ry);
- r = gdImageRed (out, coldest) + gdImageRed(im, colin);
- g = gdImageGreen(out, coldest);
- b = gdImageBlue (out, coldest);
- r = r<255?r:255; g = g<255?g:255; b = b<255?b:255;
- colout = gdImageColorResolve(out, r, g, b);
- gdImageSetPixel(out, x+rx, y+ry, colout);
- gdImageColorDeallocate(out, colout);
- /* green */
- coldest = gdImageGetPixel(out, x+gx, y+gy);
- r = gdImageRed (out, coldest);
- g = gdImageGreen(out, coldest) + gdImageGreen(im, colin);
- b = gdImageBlue (out, coldest);
- r = r<255?r:255; g = g<255?g:255; b = b<255?b:255;
- colout = gdImageColorResolve(out, r, g, b);
- gdImageSetPixel(out, x+gx, y+gy, colout);
- gdImageColorDeallocate(out, colout);
- /* blue */
- coldest = gdImageGetPixel(out, x+bx, y+by);
- r = gdImageRed (out, coldest);
- g = gdImageGreen(out, coldest);
- b = gdImageBlue (out, coldest) + gdImageBlue(im, colin);
- r = r<255?r:255; g = g<255?g:255; b = b<255?b:255;
- colout = gdImageColorResolve(out, r, g, b);
- gdImageSetPixel(out, x+bx, y+by, colout);
- gdImageColorDeallocate(out, colout);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment