From a1244b26bcf2f8c84fe4fba31c7c92b23943611a Mon Sep 17 00:00:00 2001 From: avolkov Date: Thu, 22 Dec 2005 01:08:59 +0000 Subject: [PATCH] Supporting generation of antialiased melee planet images using alpha channel git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2099 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/maskimg/mask_cra.png | Bin 0 -> 1300 bytes tools/maskimg/maskabig.cra.png | Bin 0 -> 506 bytes tools/maskimg/maskabig.png | Bin 0 -> 507 bytes tools/maskimg/maskamed.cra.png | Bin 0 -> 269 bytes tools/maskimg/maskamed.png | Bin 0 -> 288 bytes tools/maskimg/maskasml.png | Bin 0 -> 159 bytes tools/maskimg/maskimg.c | 127 +++++++++++++++++++++++++++++---- tools/maskimg/maskimg.dsp | 12 +--- 8 files changed, 115 insertions(+), 24 deletions(-) create mode 100755 tools/maskimg/mask_cra.png create mode 100755 tools/maskimg/maskabig.cra.png create mode 100755 tools/maskimg/maskabig.png create mode 100755 tools/maskimg/maskamed.cra.png create mode 100755 tools/maskimg/maskamed.png create mode 100755 tools/maskimg/maskasml.png diff --git a/tools/maskimg/mask_cra.png b/tools/maskimg/mask_cra.png new file mode 100755 index 0000000000000000000000000000000000000000..6b0385e42d994da409a9a802111f47f929cf6e8c GIT binary patch literal 1300 zcmd_q@lP9N9LMobOKH2ay&+yLl(t7KkxOMYbX!x&{5yP-@AKsK zB=6+;>A5NPp0iUf3V^-4tFxb+FOhlCT1EE5-OQgr6~qhisMG0W?Vu>u=rnpQY&GL$ zS&B883`Vx0fwfpH6rmd|Mb(0>eTsl(!NLuX$HM|F!?0|vgJsw!@igf?RbHB9>OF8c z*!p^d-4O@`1Q!@aFa=CJEl?aU2#jF08cjkdB+xX?5QZTzOcR8rX9)xW0>Wr(YZCy0 z;{>6}FL1&$XdzvjnRg3Zunm5{5DXe!{%ABRHN)$b%u#c~A)VwClH`?awkosK*C#m~ z4liLGlGhu86ncR`k{}_Dfq?-Dka%8_LhTYSokj=g22LdW65lg`_I9bKr>ePqXlO`2 z1CEoeL)MI2X2gsvb8=0M$tsVI%5JxtBOHUwab1wRE)d8vWQ-x5PRoESin81lmqob~ zgQQE_GGSRvr4f(Isg&tVe0+Rdi69tMsBx;`Q|eO%MF}blQ%xx|Gm6jW3lip`1cM1E ziB|~}1q$+*o10SrC6!W?#E6noF5(*L=1vx3N@`*bBO}VhM0I2&m&>WW;Ca=Sv#t15 zZ)QbRd9|+2Y*Uw(RKMTP6PBRz{3z7X>jbI_6(y9*Wff2}8C4z4su}eS+#p@Kb|tQ6 z3T0%oYN256%@&JAEs0o6ql@%rtLDpZYFbQlyDhY~x~jFdw#Eq8pv7WYXxV83O@oFt zY;0_3fR@i|T6SK`Yj5EW={6jj!&-iM1M~CR^0Fm4U#V2|D-cD!rc!eh*15$aT^IGn zMr)0}y{(7CVUchTx+u;>(H@>gM$Md&=(hVeYT`8>L1`f=??0S#`MMY1C&bo z`nvT>>9+;lx`)>@lo}(McWx2aE5+9uYeJesw zHrlHD4&NI&`*q!t_|MLzbY$z>WXHX;S3f$w{rF?XVLxwPDC~XNa&P|&{_c%a;qO0N zMQFccJO9M+>w)}-71Q7Q{o4yY!z}&d=HPdR!EcJLsa5x7a&G_r&v$>g j{`S=8#*1$T?mTY(;}_q9oB4Ook(Z-8+S^&~cx~!mZVqWm literal 0 HcmV?d00001 diff --git a/tools/maskimg/maskabig.cra.png b/tools/maskimg/maskabig.cra.png new file mode 100755 index 0000000000000000000000000000000000000000..37fc4180a5e314f1320b5b39964c0850094ef38f GIT binary patch literal 506 zcmV00000{Akx40005ONkl6z|u`Ej}YU(Pum0<*EbxwgDCH#7P9_VRFdRk^qfe!qWq@@00X zoZoS$630EH-yA1gsM%aSz#_?dZgxm(zA%9LPGNo+>~JWHBo7B#{{7GxdG7~fB?pTn zO9582=7^ECXg@6JY>{NLHj)eSZWN6Om$-Mu`n{;j!nBS zjn34j+ceij+nrJi^T)=>)+W0aXx9KR0bqZx_i}bh==}`v0DB4vG(0afVL)1fA(RFH zR0MyGBr5>0E5gWK7zUi54)NjPW<{mdR=xGA3Iie*(_x6&mQdTWh)|1ISg3_P4 w1GMuHh-Wp>&XE8}XI$SIVgBX?i;lCwFK)?Ee3nLIQUCw|07*qoM6N<$f^(GQx&QzG literal 0 HcmV?d00001 diff --git a/tools/maskimg/maskabig.png b/tools/maskimg/maskabig.png new file mode 100755 index 0000000000000000000000000000000000000000..781a33fe6719b4156a6dc8eb3a373c8a230881ff GIT binary patch literal 507 zcmV002V>00000@ph+M0005PNklg z6nVcno~neBNU}1HYJ{f9hBtK*fg(@5sMAOkdHSC^j!2Qmf2o7W6nXHQD#oD5;!i3c ziz0uX9bTtPm^8nsa!iUW1Aqe{*-Lo;al!MN?gIv(8k<6*I{L2Eb8HI0tP2B53JN8_ z0lI00)mwyNTS6hd4a2U40(RlxVP0cBE;!4#8VXpkbrpqmTa{U>mXldI%gC&ZrDRsh zd7n{PLx(B~u%V0^+CXLv%#~TLb!1k@+A^zcH!|zSu4LAg^87NKYbczJiy2~0Q9P$t9me`{g!vH(@y~$gXPF0kO+)SY!bW`045eoE_SC# zac6h$DDL5FF<RD8}c4P TV6S~1Xy21h_{ej6S>du|0YP%P literal 0 HcmV?d00001 diff --git a/tools/maskimg/maskamed.png b/tools/maskimg/maskamed.png new file mode 100755 index 0000000000000000000000000000000000000000..e868d77534f21734d9904e0e6e8ed5a2e6b9a31a GIT binary patch literal 288 zcmV+*0pI?KP)qV`eE zZIM#lHeaf`DOReR>XU_KN;Q0_pj@d20N`D0?BYQ%b_$;R9cK)K)U`33>oT${xFZ?b z6)=<@!+Pe>AlT7dD+Id|CL?2xl7LoOh@ m&LGPHY}KH=xJ*VC*5Dn$U;BafebA%;0000trans) + if (opts.alpha && (mask->color_type & PNG_COLOR_MASK_PALETTE)) + { + verbose(2, "Warning: ignoring palette in mask image; using indices\n"); + } + if (opts.alpha && mask->bit_depth != 8) + { + verbose(1, "Mask image for the alpha channel must be 8bpp\n"); + freeImage(img); + freeImage(mask); + return EXIT_FAILURE; + } + if (!opts.alpha && mask->trans) { mask->trans_index = getImageTransIndex(mask); verbose(2, "Using mask image transparency info; trans index %d\n", mask->trans_index); } - else + else if (!opts.alpha) { mask->trans_index = 0; verbose(2, "Mask image has no transparency info; using index %d\n", mask->trans_index); } - if (!opts.maskon && !opts.maskoff) + if (!opts.maskon && !opts.maskoff && !opts.alpha) { freeImage(img); freeImage(mask); - verbose(1, "Nothing to do; specify -0 or -1\n"); + verbose(1, "Nothing to do; specify -0 or -1, or use -a\n"); return EXIT_SUCCESS; } - maskImage(img, mask, opts.maskon, opts.maskoff); + if (opts.alpha && (opts.maskon || opts.maskoff)) + { + verbose(2, "Options -0 and -1 have no effect when -a specified\n"); + } + + if (opts.alpha) + alphaImage(img, mask); + else + maskImage(img, mask, opts.maskon, opts.maskoff); + writeImage(img, opts.outfile); freeImage(img); @@ -175,9 +196,10 @@ void verbose(int level, const char* fmt, ...) void usage() { fprintf(stderr, - "maskimg [-0] [-1] [-o ] -m \n" + "maskimg [-0] [-1] [-a] [-o ] -m \n" "Options:\n" "\t-o write resulting png into \n" + "\t-a use mask image as alpha channel and create result with alpha\n" "\t-m specifies mask image to use (must be present)\n" "\t-0 mask pixels off by setting them to transparent color\n" "\t-1 mask pixels on by bumping red channel slightly\n" @@ -191,13 +213,16 @@ void parse_arguments(int argc, char *argv[], struct options *opts) memset(opts, 0, sizeof (struct options)); - while (-1 != (ch = getopt(argc, argv, "h?o:m:01v"))) + while (-1 != (ch = getopt(argc, argv, "h?ao:m:01v"))) { switch (ch) { case 'o': opts->outfile = optarg; break; + case 'a': + opts->alpha = 1; + break; case 'm': opts->maskfile = optarg; break; @@ -230,7 +255,7 @@ void parse_arguments(int argc, char *argv[], struct options *opts) if (!opts->maskfile) { - fprintf(stderr, "Not mask image specified, use -m\n"); + fprintf(stderr, "No mask image specified, use -m\n"); usage(); exit(EXIT_FAILURE); } @@ -429,9 +454,16 @@ int writeImage(image_t* img, const char* filename) png_set_IHDR(png_ptr, info_ptr, img->w, img->h, img->bit_depth, img->color_type, img->interlace_type, img->compression_type, img->filter_type); - png_set_sBIT(png_ptr, info_ptr, img->sig_bit); - png_set_shift(png_ptr, img->sig_bit); - png_set_tRNS(png_ptr, info_ptr, NULL, 0, img->trans_values); + if (img->sig_bit) + { + png_set_sBIT(png_ptr, info_ptr, img->sig_bit); + png_set_shift(png_ptr, img->sig_bit); + } + if (!(img->color_type & (PNG_COLOR_MASK_PALETTE | PNG_COLOR_MASK_ALPHA)) + && img->trans_values) + { + png_set_tRNS(png_ptr, info_ptr, NULL, 0, img->trans_values); + } png_write_info(png_ptr, info_ptr); png_set_packing(png_ptr); png_write_image(png_ptr, (png_byte **) img->lines); @@ -464,8 +496,8 @@ void maskImage(image_t* img, image_t* mask, int maskon, int maskoff) for (y = 0; y < img->h; ++y) { - imgp = img->data + img_pitch * y; - maskp = mask->data + mask_pitch * y; + imgp = img->lines[y]; + maskp = mask->lines[y]; for (x = 0; x < img->w; ++x, imgp += img->bpp, maskp += mask->bpp) { @@ -489,3 +521,70 @@ void maskImage(image_t* img, image_t* mask, int maskon, int maskoff) } } } + +void alphaImage(image_t* img, image_t* mask) +{ + png_uint_32 x, y; + //png_bytep imgp, maskp; + int dpitch; + png_bytep newdata; + + dpitch = img->w * 4; + newdata = malloc(img->h * dpitch); + if (!newdata) + { + verbose(1, "Out of memory converting image to rgba\n"); + exit(EXIT_FAILURE); + } + + for (y = 0; y < img->h; ++y) + { + png_bytep sp = img->lines[y]; + png_bytep dp = newdata + dpitch * y; + png_bytep mp = mask->lines[y]; + + for (x = 0; x < img->w; ++x, sp += img->bpp, dp += 4, mp += mask->bpp) + { + if (img->sig_bit) + { + png_byte c; + + c = sp[0] << (8 - img->sig_bit->red); + dp[0] = c | (c >> img->sig_bit->red); + c = sp[1] << (8 - img->sig_bit->green); + dp[1] = c | (c >> img->sig_bit->green); + c = sp[2] << (8 - img->sig_bit->blue); + dp[2] = c | (c >> img->sig_bit->blue); + } + else + { + dp[0] = sp[0]; + dp[1] = sp[1]; + dp[2] = sp[2]; + } + dp[3] = mp[0]; + } + } + + if (img->sig_bit) + { + img->sig_bit->red = 8; + img->sig_bit->green = 8; + img->sig_bit->blue = 8; + img->sig_bit->alpha = 8; + img->sig_bit->gray = 8; + } + + img->trans_values = 0; + img->color_type = PNG_COLOR_TYPE_RGB_ALPHA; + img->channels = 4; + img->bpp = 4; + + free(img->data); + img->data = newdata; + { // init lines + png_uint_32 i; + for (i = 0; i < img->h; ++i) + img->lines[i] = img->data + img->w * img->bpp * i; + } +} diff --git a/tools/maskimg/maskimg.dsp b/tools/maskimg/maskimg.dsp index c6199701e..7d1d28d4e 100755 --- a/tools/maskimg/maskimg.dsp +++ b/tools/maskimg/maskimg.dsp @@ -50,7 +50,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=xilink6.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib advapi32.lib shell32.lib libpng10.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib advapi32.lib shell32.lib libpng.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "maskimg - Win32 Debug" @@ -74,7 +74,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=xilink6.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib advapi32.lib shell32.lib libpng10.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib advapi32.lib shell32.lib libpng.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF @@ -99,14 +99,6 @@ SOURCE=..\..\src\getopt\getopt.h # End Source File # Begin Source File -SOURCE=.\lzhuf.c -# End Source File -# Begin Source File - -SOURCE=.\lzhuf.h -# End Source File -# Begin Source File - SOURCE=.\maskimg.c # End Source File # End Group