From: b Date: Wed, 30 Nov 2022 22:11:18 +0000 (+0000) Subject: new palette mix tool is done but needs debug X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=38ded552e380ab93d37ca5bd870b21c8102d35a2;p=ott%2Fenhance new palette mix tool is done but needs debug --- diff --git a/403.cpp b/403.cpp deleted file mode 100644 index 3e0bf86..0000000 --- a/403.cpp +++ /dev/null @@ -1,304 +0,0 @@ - // //It's 403fication Time! - // // Take a picture and add a Megan to it! - // // - // // Requires Dev Image Library, -// // //on Pentium III libdevil must be - // // recompiled with --disable-ssl2 --disable-ssl3 - // // - // // ~~bicyclesonthemoon - -#define INPIX_MUSTARD 1 -#define OUTPIX_MUSTARD 2 -#define MEGPIX_MUSTARD 3 -#define ARGUMENT_MUSTARD 4 -#define SEAISH_MUSTARD 5 -#define ANIMATED_MUSTARD 6 -#define FAIL 900 -#define OK 0 - -#define MEGPIX "403.png" -#define XM 553 -#define XA 262 -#define XB 226 -#define YM 395 -#define YA 131 - -/*#define NPBPIX0 "npb0.png" -#define X0 411 -#define X01 21 -#define X02 96 -#define Y0 404 -#define Y01 214 -#define Y02 68 - -#define NPBPIX1 "npb1.png" -#define X1 411 -#define X11 22 -#define X12 133 -#define Y1 404 -#define Y11 241 -#define Y12 94 - -#define NPBPIX2 "npb2.png" -#define X2 411 -#define X21 213 -#define Y2 404 -#define Y21 234*/ - -#include -#include -#include - -void mustard(int mustard); -void loadmeg(const char *path); -void m403(const char *path); -int main (int argc, const char *argv[]); - -ILuint inPix, outPix, megPix; -ILboolean q=true; -ILboolean inH=false; -ILboolean outH=false; -ILboolean megH=false; -ILuint inX, inY, outX, outY; -ILubyte *newdata; - -int main (int argc, const char *argv[]) -{ - if(argc<3) - mustard(ARGUMENT_MUSTARD); - if (argc>=4) - { - if (argv[3][0]=='q' || argv[3][0]=='Q') - q=false; - } - - ilInit(); - if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL); - if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL); - ilClearColour(255,255,255,255); - ilGenImages(1, &inPix); - inH=true; - ilBindImage(inPix); - if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD); - if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD); - //if(!ilConvertPal(IL_PAL_RGBA32))mustard(FAIL); - - inX=ilGetInteger(IL_IMAGE_WIDTH); - inY=ilGetInteger(IL_IMAGE_HEIGHT); - if(ilGetInteger(IL_NUM_IMAGES)>1) - mustard(ANIMATED_MUSTARD); - - m403(argv[2]); - //ok - mustard(0); -} - -void loadmeg(const char *path) -{ - ilGenImages(1, &megPix); - megH=true; - ilBindImage(megPix); - if(!ilLoadImage(path))mustard(MEGPIX_MUSTARD); - if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(MEGPIX_MUSTARD); -} - -void m403(const char *path) -{ - unsigned long i,j; - outX=(inX+XB+6>XM)?(inX+XB+6):XM; - outY=(inY+YA+6>YM)?(inY+YA+6):YM; - ilGenImages(1, &outPix); - outH=true; - loadmeg(MEGPIX); - newdata=ilGetData(); - ilBindImage(outPix); - if(!ilTexImage(outX,outY,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL))mustard(OUTPIX_MUSTARD); - if(!ilClearImage())mustard(FAIL); - - ilSetPixels(0,0/**/,0,XM,YM,1,IL_RGBA,IL_UNSIGNED_BYTE,newdata); - if(!ilOverlayImage(inPix,((inX/2. -// - -// Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) -// on Pentium III libdevil must be recompiled with -// --disable-ssl2 --disable-ssl3 -// (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) - -#include -#include -#include "IL/il.h" - -int mustard(const char *t,int m,int e); -int main(int argc, char *argv[]); - -ILuint inpix1, inpix2, outpix; -unsigned char q =0; - - -int main(int argc, char *argv[]) -{ - - ILubyte *pal1, *pal2, *data1, *data2, *data; - ILubyte pal[256*3]; - unsigned short i,j; - unsigned long k; - ILuint col1, col2, col, x1, x2, y1, y2; - - unsigned short p1, p2, p3; - - if (argc<4) - return mustard("insert inpix1 inpix2 outpix [p1 p2]",0,1); - if(argc>=5) - p1=atoi(argv[4]); - else - p1=1; - if(argc>=6) - p2=atoi(argv[5]); - else - p2=0; - if(argc>=7) - q=1; - p3=p1+p2; - - ilInit(); - - ilEnable(IL_ORIGIN_SET); - ilEnable(IL_FILE_OVERWRITE); - - ilGenImages(1,&inpix1); - ilGenImages(1,&inpix2); - ilGenImages(1,&outpix); - - ilBindImage(inpix1); - if(!ilLoadImage(argv[1])) - return mustard("inpix1 load fail.",1,1); - if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) - return mustard("inpix1 not indexed.",1,1); - ilConvertPal(IL_PAL_RGB24); - col1=ilGetInteger(IL_PALETTE_NUM_COLS); - if(col1>16) - return mustard("inpix1 too many colors.",1,1); - x1=ilGetInteger(IL_IMAGE_WIDTH); - y1=ilGetInteger(IL_IMAGE_HEIGHT); - pal1=ilGetPalette(); - data1=ilGetData(); - - ilBindImage(inpix2); - if(!ilLoadImage(argv[2])) - return mustard("inpix2 load fail.",1,1); - if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) - return mustard("inpix2 not indexed.",1,1); - ilConvertPal(IL_PAL_RGB24); - col2=ilGetInteger(IL_PALETTE_NUM_COLS); - if(col2>16) - return mustard("inpix2 too many colors.",1,1); - if(col1!=col2) - return mustard("different palette size.",1,1); - x2=ilGetInteger(IL_IMAGE_WIDTH); - if(x1!=x2) - return mustard("different widths",1,1); - y2=ilGetInteger(IL_IMAGE_HEIGHT); - if(y1!=y2) - return mustard("different heights",1,1); - pal2=ilGetPalette(); - data2=ilGetData(); - col=col1*col2; - - for(i=0;i. -// - -// Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) -// on Pentium III libdevil must be recompiled with -// --disable-ssl2 --disable-ssl3 -// (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) - -#define INPIX_MUSTARD 1 -#define OUTPIX_MUSTARD 2 -#define NPBPIX_MUSTARD 3 -#define ARGUMENT_MUSTARD 4 -#define SEAISH_MUSTARD 5 -#define ANIMATED_MUSTARD 6 -#define FAIL 900 -#define OK 0 - -#define NPBPIX2 "/eizm/mem/ong1/npb.png" -#define X2 311 -#define X21 210 -#define Y2 475 -#define Y21 407 - -#include -#include -#include - -void mustard(int mustard); -void loadnpb(const char *path); -void npbottify0(const char *path); -void npbottify1(const char *path); -void npbottify2(const char *path); -int main (int argc, const char *argv[]); - -ILuint inPix, outPix, npbPix; -ILboolean q=true; -ILboolean inH=false; -ILboolean outH=false; -ILboolean npbH=false; -ILuint inX, inY, outX, outY; -ILubyte *newdata; - -int main (int argc, const char *argv[]) -{ - if(argc<3) - mustard(ARGUMENT_MUSTARD); - if (argc>=4) - { - if (argv[3][0]=='q' || argv[3][0]=='Q') - q=false; - } - - ilInit(); - if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL); - if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL); - ilClearColour(255,255,0,0); - ilGenImages(1, &inPix); - inH=true; - ilBindImage(inPix); - if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD); - if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD); - //if(!ilConvertPal(IL_PAL_RGBA32))mustard(FAIL); - - inX=ilGetInteger(IL_IMAGE_WIDTH); - inY=ilGetInteger(IL_IMAGE_HEIGHT); - if(ilGetInteger(IL_NUM_IMAGES)>1) - mustard(ANIMATED_MUSTARD); - - // if(inX<=X02&&inY<=Y02) - // npbottify0(argv[2]); - // else if(inX<=X12&&inY<=Y12) - // npbottify1(argv[2]); - else - npbottify2(argv[2]); - //ok - mustard(0); -} - -void loadnpb(const char *path) -{ - ilGenImages(1, &npbPix); - npbH=true; - ilBindImage(npbPix); - if(!ilLoadImage(path))mustard(NPBPIX_MUSTARD); - if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(NPBPIX_MUSTARD); - } - -void npbottify2(const char *path) -{ - unsigned long i,j; - outX=(X21+inX+2>X2)?(X21+inX+2):X2; - outY=(Y21+inY+2>Y2)?(Y21+inY+2):Y2; - ilGenImages(1, &outPix); - outH=true; - loadnpb(NPBPIX2); - newdata=ilGetData(); - ilBindImage(outPix); - if(!ilTexImage(outX,outY,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL))mustard(OUTPIX_MUSTARD); - if(!ilClearImage())mustard(FAIL); - ilSetPixels(outX-X2,0,0,X2,Y2,1,IL_RGBA,IL_UNSIGNED_BYTE,newdata); - newdata=ilGetData(); - for(i=outX-X21-inX-2;i. + + +Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) +on Pentium III libdevil must be recompiled with +--disable-ssl2 --disable-ssl3 +(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) + +*/ + +#include +#include +#include + +#include "core.h" +#include "pal_mix.h" + +struct rel_data +{ + ILuint p0; + ILuint p1; + ILuint p; +}; + +int palette_mix_value (ILuint n, struct PixelInfo *p, void *data); +ILuint mix_value_1ch (ILint64 x, ILint64 y, struct rel_data *rel); + +char PAL_MIX_MISSING_ARGS[] = "Missing parameters.\npal_mix inPix1 inpix2 outPix [p1 p2]\n"; + +int subtool_pal_mix (int argc, char **argv, int argi, char **err) +{ + uint_fast16_t id[3] = {0, 1, 2}; + ILint xyf0[3] = {0, 0, 0}; + struct IL_full_info info[3]; + FLAG_TYPE flags[3] = { + MUST_BE_INDEXED | NOT_WRITABLE | OK_PALETTE_ONLY, + MUST_BE_INDEXED | NOT_WRITABLE | OK_PALETTE_ONLY, + MUST_BE_INDEXED | NOT_READABLE | OK_PALETTE_ONLY + }; + ILubyte new_pal[0x100 * 4]; + struct rel_data data; + ILuint i; + int r; + + if (argc < argi + 3) + { + *err = PAL_MIX_MISSING_ARGS; + return EINVAL; + } + + if (argc >= argi + 5) + { + sscanf(argv[argi+3],"%u",&(data.p0)); + sscanf(argv[argi+4],"%u",&(data.p1)); + } + else + { + data.p0 = 1; + data.p1 = 0; + } + data.p = data.p0 + data.p1; + + r = load_picture(0, argv[argi], &(info[0]), &(flags[0])); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + r = load_picture(1, argv[argi+1], &(info[1]), &(flags[1])); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + if ((info[0].image_height != info[1].image_height) || (info[0].image_width != info[1].image_width) || (info[0].num_images != info[1].num_images)) + { + *err = SIZE_MISMATCH; + return EINVAL; + } + + if ((info[0].palette_num_cols * info[1].palette_num_cols) > 0x100) + { + *err = BAD_PALETTE_SIZE; + return EINVAL; + } + + if ((flags[0] & HAS_ALPHA) || (flags[1] & HAS_ALPHA)) + { + flags[0] |= MUST_HAVE_ALPHA; + flags[1] |= MUST_HAVE_ALPHA; + flags[2] |= MUST_HAVE_ALPHA; + } + else + flags[2] |= CANNOT_HAVE_ALPHA; + + r = convert_picture(0, &(info[0]), &(flags[0])); + if (r!=0) + { + *err = CONVERT_FAILED; + return EIO; + } + + r = convert_picture(1, &(info[1]), &(flags[1])); + if (r!=0) + { + *err = CONVERT_FAILED; + return EIO; + } + + r = build_picture_from_info(2, &(info[0]), &(info[2]), &(flags[2])); + if (r!=0) + { + *err = CREATE_FAILED; + return EIO; + } + + for (i=0; i<=info[2].num_images; ++i) + { + set_palette ( + 2, + new_pal, + info[0].palette_num_cols * info[1].palette_num_cols * info[0].palette_bpp, + info[0].palette_type, + i + ); + } + + r = perform_action_palette_mix( + id, + &palette_mix_value, + flags, + &data + ); + if (r) + { + *err = CONVERT_FAILED; + return r; + } + + flags[0] &= ~OK_PALETTE_ONLY; + flags[1] &= ~OK_PALETTE_ONLY; + flags[2] &= ~OK_PALETTE_ONLY; + + r = perform_action( + 3, + id, + xyf0, xyf0, xyf0, + 0, 0, 0, + &palette_mix_index, + flags, + &data + ); + if (r) + { + *err = CONVERT_FAILED; + return r; + } + + r = save_picture(2, argv[argi+2], flags[2]); + if (r!=0) + { + *err = SAVE_FAILED; + return r; + } + + return 0; +} + +int palette_mix_value (ILuint n, struct PixelInfo *p, void *data) +{ + if (n < 3) + return EIO; + + p[2].red = mix_value_1ch(p[0].red, p[1].red, data); + p[2].green = mix_value_1ch(p[0].green, p[1].green, data); + p[2].blue = mix_value_1ch(p[0].blue, p[1].blue, data); + if (p[2].flags & EFF_ALPHA) + p[2].alpha = mix_value_1ch(p[0].alpha, p[1].alpha, data); + + return 0; +} + +ILuint mix_value_1ch (ILint64 x, ILint64 y, struct rel_data *rel) +{ + ILint64 v = (x * rel->p0 + y * rel->p1) / rel->p; + return (ILuint) v; +} + +/* +#include +#include +#include "IL/il.h" + +int mustard(const char *t,int m,int e); +int main(int argc, char *argv[]); + +ILuint inpix1, inpix2, outpix; +unsigned char q =0; + + +int main(int argc, char *argv[]) +{ + + ILubyte *pal1, *pal2, *data1, *data2, *data; + ILubyte pal[256*3]; + unsigned short i,j; + unsigned long k; + ILuint col1, col2, col, x1, x2, y1, y2; + + unsigned short p1, p2, p3; + + if (argc<4) + return mustard("insert inpix1 inpix2 outpix [p1 p2]",0,1); + if(argc>=5) + p1=atoi(argv[4]); + else + p1=1; + if(argc>=6) + p2=atoi(argv[5]); + else + p2=0; + if(argc>=7) + q=1; + p3=p1+p2; + + ilInit(); + + ilEnable(IL_ORIGIN_SET); + ilEnable(IL_FILE_OVERWRITE); + + ilGenImages(1,&inpix1); + ilGenImages(1,&inpix2); + ilGenImages(1,&outpix); + + ilBindImage(inpix1); + if(!ilLoadImage(argv[1])) + return mustard("inpix1 load fail.",1,1); + if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) + return mustard("inpix1 not indexed.",1,1); + ilConvertPal(IL_PAL_RGB24); + col1=ilGetInteger(IL_PALETTE_NUM_COLS); + if(col1>16) + return mustard("inpix1 too many colors.",1,1); + x1=ilGetInteger(IL_IMAGE_WIDTH); + y1=ilGetInteger(IL_IMAGE_HEIGHT); + pal1=ilGetPalette(); + data1=ilGetData(); + + ilBindImage(inpix2); + if(!ilLoadImage(argv[2])) + return mustard("inpix2 load fail.",1,1); + if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) + return mustard("inpix2 not indexed.",1,1); + ilConvertPal(IL_PAL_RGB24); + col2=ilGetInteger(IL_PALETTE_NUM_COLS); + if(col2>16) + return mustard("inpix2 too many colors.",1,1); + if(col1!=col2) + return mustard("different palette size.",1,1); + x2=ilGetInteger(IL_IMAGE_WIDTH); + if(x1!=x2) + return mustard("different widths",1,1); + y2=ilGetInteger(IL_IMAGE_HEIGHT); + if(y1!=y2) + return mustard("different heights",1,1); + pal2=ilGetPalette(); + data2=ilGetData(); + col=col1*col2; + + for(i=0;i. + + +Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/) +on Pentium III libdevil must be recompiled with +--disable-ssl2 --disable-ssl3 +(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954) +*/ + +int subtool_pal_mix (int argc, char **argv, int argi, char **err);