From: b Date: Wed, 30 Nov 2022 19:40:05 +0000 (+0000) Subject: NPB is ready and working! X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=a6e64597266e909a6404ecdfd5d530e79bf8e9b9;p=ott%2Fenhance NPB is ready and working! --- diff --git a/npb.c b/npb.c index 422ebd9..63bcb00 100644 --- a/npb.c +++ b/npb.c @@ -60,12 +60,12 @@ on Pentium III libdevil must be recompiled with #define NPB_ONG1_B 69 #define NPB_403_L 224 -#define NPB_403_R 265 +#define NPB_403_R 295 #define NPB_403_T 261 #define NPB_403_B 261 -char NPB_MISSING_ARGS[] = "Missing parameters.\nnpb [-o -4 -r -b -c] inPix outPix\n"; +char NPB_MISSING_ARGS[] = "Missing parameters.\nnpb [-o -4 -r -b -e -c] inPix outPix\n"; int subtool_npb (int argc, char **argv, int argi, char **err) { @@ -74,16 +74,21 @@ int subtool_npb (int argc, char **argv, int argi, char **err) uint_fast8_t corners = 0; uint_fast8_t fullsize = 0; uint_fast8_t fill_white = 0; + uint_fast8_t fill_white_all = 0; uint_fast8_t npb_after = 0; uint_fast8_t expand_left = 0; uint_fast8_t expand_right = 0; uint_fast8_t expand_up = 0; uint_fast8_t expand_down = 0; - uint_fast8_t border_outside = 0; uint_fast8_t fixed_frame = 0; + uint_fast8_t override_new_border = 0; + uint_fast8_t override_external_border = 0; ILuint cut_border = 0; - ILuint new_border = 2; + ILuint new_border; + ILuint external_border; + ILuint new_border_default = 2; + ILuint external_border_default = 0; ILuint max = 0xFF; //upscale_value(0xFF, info[0].image_bpc); // bpc=1 ILint width_content, height_content, x0_content_own, y0_content_own, x0_content_global, y0_content_global; ILint width_border, height_border, x0_border, y0_border; @@ -108,15 +113,16 @@ int subtool_npb (int argc, char **argv, int argi, char **err) ILint f0[2] = {0, 0}; struct option long_options[] = { - {"ong1", no_argument, NULL, 'o'}, - {"403", no_argument, NULL, '4'}, - {"remove-border", required_argument, NULL, 'r'}, - {"new-border", required_argument, NULL, 'b'}, - {"corners", no_argument, NULL, 'c'}, - {"help", no_argument, NULL, 'h'}, - {0, 0, 0, 0} + {"ong1", no_argument, NULL, 'o'}, + {"403", no_argument, NULL, '4'}, + {"remove-border", required_argument, NULL, 'r'}, + {"new-border", required_argument, NULL, 'b'}, + {"external-border",required_argument, NULL, 'e'}, + {"corners", no_argument, NULL, 'c'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0} }; - char short_options[] = "o4r:b:ch"; + char short_options[] = "o4r:b:e:ch"; int opt; int r; @@ -140,6 +146,11 @@ int subtool_npb (int argc, char **argv, int argi, char **err) case 'b': sscanf(optarg, "%u", &new_border); fullsize = 1; + override_new_border = 1; + break; + case 'e': + sscanf(optarg, "%u", &external_border); + override_external_border = 1; break; case 'c': corners = 1; @@ -191,8 +202,9 @@ int subtool_npb (int argc, char **argv, int argi, char **err) space_b = NPB_403_B; expand_right = 1; expand_up = 1; - border_outside = 1; - fill_white = 1; + new_border_default = 0; + external_border_default = 2; + fill_white_all = 1; } else if (ong1) { @@ -245,6 +257,12 @@ int subtool_npb (int argc, char **argv, int argi, char **err) npb_after = 1; } + /* determine borders' sizes */ + if (!override_new_border) + new_border = new_border_default; + if (!override_external_border) + external_border = external_border_default; + /* load selected npb */ r = load_picture_mem(1, npb_pix, npb_size, &(info_npb), &(flags_npb)); @@ -256,21 +274,13 @@ int subtool_npb (int argc, char **argv, int argi, char **err) /* determine rectangle of content with new border */ - if (border_outside) - { - width_border = width_content; - height_border = height_content; - } - else - { - width_border = width_content + new_border * 2; - height_border = height_content + new_border * 2; - } + width_border = width_content + new_border * 2; + height_border = height_content + new_border * 2; /* npb rectangle too */ width_npb = info_npb.image_width; - height_npb = info_npb.image_width; + height_npb = info_npb.image_height; x0_npb = 0; y0_npb = 0; @@ -281,32 +291,24 @@ int subtool_npb (int argc, char **argv, int argi, char **err) /* determine content border placement in full picture */ - if (expand_right && (width_border <= (space_r - space_l +1))) + if (expand_right && (width_border >= (space_r - space_l +1))) x0_border = space_l; - else if (expand_left && (width_border <= (space_r - space_l +1))) + else if (expand_left && (width_border >= (space_r - space_l +1))) x0_border = space_r - width_border + 1; else x0_border = (space_l + space_r + 1 - width_border) / 2; - if (expand_down && (height_border <= (space_b - space_t +1))) + if (expand_down && (height_border >= (space_b - space_t +1))) y0_border = space_t; - else if (expand_up && (height_border <= (space_b - space_t +1))) + else if (expand_up && (height_border >= (space_b - space_t +1))) y0_border = space_b - height_border + 1; else y0_border = (space_t + space_b + 1 - height_border) / 2; /* determine content placement in border in full picture */ - if (border_outside) - { - x0_content_global = x0_border; - y0_content_global = y0_border; - } - else - { - x0_content_global = x0_border + new_border; - y0_content_global = y0_border + new_border; - } + x0_content_global = x0_border + new_border; + y0_content_global = y0_border + new_border; /* adjust full picture size & offsets if content doesn't fit */ @@ -331,16 +333,16 @@ int subtool_npb (int argc, char **argv, int argi, char **err) /* adjust for external border */ - if (border_outside) + if (external_border > 0) { - width_total += 2 * new_border; - height_total += 2 * new_border; - x0_border += new_border; - y0_border += new_border; - x0_content_global += new_border; - y0_content_global += new_border; - x0_npb += new_border; - y0_npb += new_border; + width_total += 2 * external_border; + height_total += 2 * external_border; + x0_border += external_border; + y0_border += external_border; + x0_content_global += external_border; + y0_content_global += external_border; + x0_npb += external_border; + y0_npb += external_border; } /* ok setup done, now perform actions */ @@ -359,15 +361,15 @@ int subtool_npb (int argc, char **argv, int argi, char **err) color.red = max; color.green = max; color.blue = max; - color.alpha = (border_outside && fill_white) ? max : 0; + color.alpha = fill_white_all ? max : 0; r = perform_action_1picture( 2, //id - border_outside ? new_border : 0, //x0 - border_outside ? new_border : 0, //y0 + external_border, //x0 + external_border, //y0 0, //f0 - border_outside ? (width_total - 2 * new_border) : width_total, //width - border_outside ? (height_total - 2 * new_border) : height_total, //height + (width_total - 2 * external_border), //width + (height_total - 2 * external_border), //height 1, //frames &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -381,7 +383,7 @@ int subtool_npb (int argc, char **argv, int argi, char **err) /* 3: draw border outside */ - if (border_outside && (new_border >0)) + if (external_border >0) { color.red = 0; color.green = 0; @@ -394,7 +396,7 @@ int subtool_npb (int argc, char **argv, int argi, char **err) 0, //y0 0, //f0 width_total, //width - new_border, //height + external_border, //height 1, //frames &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -409,10 +411,10 @@ int subtool_npb (int argc, char **argv, int argi, char **err) r = perform_action_1picture( //bottom 2, //id 0, //x0 - height_total - new_border, //y0 + height_total - external_border, //y0 0, //f0 width_total, //width - new_border, //height + external_border, //height 1, //frames &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -427,10 +429,10 @@ int subtool_npb (int argc, char **argv, int argi, char **err) r = perform_action_1picture( //left 2, //id 0, //x0 - new_border, //y0 + external_border, //y0 0, //f0 - new_border, //width - height_total - 2*new_border, //height + external_border, //width + height_total - 2*external_border, //height 1, //frames &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -444,11 +446,11 @@ int subtool_npb (int argc, char **argv, int argi, char **err) r = perform_action_1picture( //right 2, //id - width_total - new_border, //x0 - new_border, //y0 + width_total - external_border, //x0 + external_border, //y0 0, //f0 - new_border, //width - height_total - 2*new_border, //height + external_border, //width + height_total - 2*external_border, //height 1, //frames &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -462,10 +464,12 @@ int subtool_npb (int argc, char **argv, int argi, char **err) if (corners) { + color.alpha = 0; + r = perform_action_1picture_1pixel( //top-left 2, //id - new_border, //x0 - new_border, //y0 + 0, //x0 + 0, //y0 0, //f0 &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -479,8 +483,8 @@ int subtool_npb (int argc, char **argv, int argi, char **err) r = perform_action_1picture_1pixel( //top-right 2, //id - width_total - new_border - 1, //x0 - new_border, //y0 + width_total - 1, //x0 + 0, //y0 0, //f0 &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -494,8 +498,8 @@ int subtool_npb (int argc, char **argv, int argi, char **err) r = perform_action_1picture_1pixel( //bottom-right 2, //id - width_total - new_border - 1, //x0 - height_total - new_border - 1, //y0 + width_total - 1, //x0 + height_total - 1, //y0 0, //f0 &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -509,8 +513,8 @@ int subtool_npb (int argc, char **argv, int argi, char **err) r = perform_action_1picture_1pixel( //bottom-left 2, //id - new_border, //x0 - height_total - new_border - 1, //y0 + 0, //x0 + height_total - 1, //y0 0, //f0 &fill_color, //function flags_total | IN_WINDOW | NOT_READABLE, //flags @@ -555,7 +559,7 @@ int subtool_npb (int argc, char **argv, int argi, char **err) /* 5: fill_background */ - if ((!border_outside) && fill_white) + if (fill_white) { color.red = max; color.green = max; @@ -609,7 +613,7 @@ int subtool_npb (int argc, char **argv, int argi, char **err) /* 7: draw border */ - if ((!border_outside) && (new_border >0)) + if (new_border >0) { color.red = 0; color.green = 0; @@ -729,320 +733,3 @@ int subtool_npb (int argc, char **argv, int argi, char **err) return 0; } -/* -#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 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 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 npbottify0(const char *path) -{ - //newdata= new ILubyte[X0*Y0*4]; - ilGenImages(1, &outPix); - outH=true; - loadnpb(NPBPIX0); - ilBindImage(outPix); - if(!ilCopyImage(npbPix))mustard(FAIL); - //if(!ilTexImage(X0,Y0,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL))mustard(OUTPIX_MUSTARD); - //if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(OUTPIX_MUSTARD); - newdata=ilGetData(); - for(unsigned long i=0;i=X01+(X02-inX)/2)&& - (i< X01+(X02-inX)/2+inX)&& - (j>=Y01+(Y02-inY)/2)&& - (j< Y01+(Y02-inY)/2+inY)) - { - newdata[4*(i+X0*j)+0]=0xFF; - newdata[4*(i+X0*j)+1]=0xFF; - newdata[4*(i+X0*j)+2]=0xFF; - newdata[4*(i+X0*j)+3]=0xFF; - } - else if((i>=X01)&&(i=Y01)&&(j=X11+(X12-inX)/2)&& - (i< X11+(X12-inX)/2+inX)&& - (j>=Y11+(Y12-inY)/2)&& - (j< Y11+(Y12-inY)/2+inY)) - { - newdata[4*(i+X1*j)+0]=0xFF; - newdata[4*(i+X1*j)+1]=0xFF; - newdata[4*(i+X1*j)+2]=0xFF; - newdata[4*(i+X1*j)+3]=0xFF; - } - else if((i>=X11)&&(i=Y11)&&(jX2)?(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