From a6d5c4496187c06a7446fb1b4e0015cf3879e8d7 Mon Sep 17 00:00:00 2001 From: icabod Date: Tue, 3 Aug 2021 22:09:30 +0100 Subject: [PATCH] Allow definition of a colour as mask. Allow inversion of image data. Added "-odb=" option. --- 1616sq.png | Bin 176 -> 210 bytes CommandLinePngConv.cpp | 56 ++++++++++- CommandLinePngConv.h | 5 + ZxImage.cpp | 217 +++++++++++++++++------------------------ ZxImage.h | 7 ++ pngconv.cpp | 5 + pngconv.dsp | 10 +- pngconv.rc | 8 +- pngconv.txt | 95 +++++++++++++----- typedefs.h | 9 +- 10 files changed, 248 insertions(+), 164 deletions(-) diff --git a/1616sq.png b/1616sq.png index 3b790e8f00bac7bac8ce9dd237bd4763290584ae..7f19d808343ad77f927e09da291e8b355adc83f1 100644 GIT binary patch delta 193 zcmdnMc!_a>WIY=L1B3kM|A|0~Ey>&6h2cL4F4((#GEjuGz$3Dlfq`2Pgc<8o;wJ(H z*-JcqUD>a3v-1jA{$Cwx02GS%ba4!+m@{{>rO*Kd9_F`y{-0lzOV delta 159 zcmcb_xPftkWIYQ51H;x|=C6PhXMsm#F#`j)5C}6~x?A@LD9B#o>FdgVjhl^E!Qy?G zi2+c^-_yl0q+(9(L~|wv0}dv`|No66gN__qR^FYYqOwf+T2J$YjU1w7PQCLlJXHQ7 z5n;^6<0CC@^vBV8nY*hE$Mz<-AG}kW^fw4>xnClYwx^0&%u!fG;lzSjK(iS diff --git a/CommandLinePngConv.cpp b/CommandLinePngConv.cpp index c74bd77..d3b5108 100644 --- a/CommandLinePngConv.cpp +++ b/CommandLinePngConv.cpp @@ -11,6 +11,8 @@ static char THIS_FILE[]=__FILE__; #endif +#include + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -25,6 +27,9 @@ CCommandLinePngConv::CCommandLinePngConv() , m_bZigZag(false) , m_bReverse(false) , m_bUpsideDown(false) +, m_bUseRGBMask(false) +, m_bInverseByte(false) +, m_sLeadText("db ") { m_pOrigin.x = m_pOrigin.y = 0; m_pSize.x = m_pSize.y = -1; @@ -76,6 +81,12 @@ void CCommandLinePngConv::ParseParam(std::string param, bool bFlag, bool bLast) m_bReverse = false; else if (!param.compare("usd")) m_bUpsideDown = true; + else if (!param.compare(0, 3, "mc=")) + m_bUseRGBMask = DecodeRGB3(param.substr(3)); + else if (!param.compare("iimg")) + m_bInverseByte = true; + else if (!param.compare(0, 4, "odb=")) + m_sLeadText = param.substr(4); else m_bCommandLineError = true; } @@ -110,7 +121,6 @@ std::string CCommandLinePngConv::Help() help += "\n -ss Silent operation"; help += "\n -pos=x,y Origin of conversion image, may be negative 0,0 = top left"; help += "\n -size=x,y Size of conversion image in pixels"; - help += "\n -imask Inverse mask. Default is Pixel On"; help += "\n -mask= Mask format - one of:"; help += "\n b : Output only Image (default)"; help += "\n m : Output only Mask"; @@ -118,9 +128,14 @@ std::string CCommandLinePngConv::Help() help += "\n bm : Alternate Image and Mask bytes"; help += "\n mmbb : Alternate Mask and Image lines"; help += "\n bbmm : Alternate Image and Mask lines"; + help += "\n -mc=rgb Take mask from 3-char RGB value rather than alpha channel"; + help += "\n -imask Inverse mask. Default is Pixel On"; + help += "\n -iimg Inverse image. Default is White = On"; help += "\n -ostd Send output to stdout rather than a file"; help += "\n This option implies -ss to remove junk from output"; help += "\n -otxt Output as text"; + help += "\n -odb= Leading text when -otxt option used. Default is \"db \"."; + help += "\n \"-odb=\" will give no leading text in output."; help += "\n -obin Output as binary (default)"; help += "\n -ltr|rtl Set output left-to-right (default) or right-to-left"; help += "\n -zz ZigZag Output (alternate ltr, rtl)"; @@ -182,3 +197,42 @@ ZXIMAGEFORMAT CCommandLinePngConv::DecodeMask(std::string param) return retval; } + +bool CCommandLinePngConv::DecodeRGB3(std::string param) +{ + // check the string that's been passed in and decode + if (param.size() != 3 || param.find_first_not_of("0123456789abcdef") != std::string::npos) + { + m_bCommandLineError = true; + } + else + { + // it's 3 characters long and hexadecimal + // for now we'll use a map to provide the conversion from character to number. + // yes it's messy, but it will work for now. really. *cough* + std::map hexmap; + hexmap['0'] = 0x00; + hexmap['1'] = 0x10; + hexmap['2'] = 0x20; + hexmap['3'] = 0x30; + hexmap['4'] = 0x40; + hexmap['5'] = 0x50; + hexmap['6'] = 0x60; + hexmap['7'] = 0x70; + hexmap['8'] = 0x80; + hexmap['9'] = 0x90; + hexmap['a'] = 0xa0; + hexmap['b'] = 0xb0; + hexmap['c'] = 0xc0; + hexmap['d'] = 0xd0; + hexmap['e'] = 0xe0; + hexmap['f'] = 0xf0; + + m_rgbaMaskColour.btRed = hexmap[param[0]]; + m_rgbaMaskColour.btGrn = hexmap[param[1]]; + m_rgbaMaskColour.btBlu = hexmap[param[2]]; + + } + + return !m_bCommandLineError; +} diff --git a/CommandLinePngConv.h b/CommandLinePngConv.h index ab8ec5f..a5234f0 100644 --- a/CommandLinePngConv.h +++ b/CommandLinePngConv.h @@ -23,8 +23,11 @@ class CCommandLinePngConv : public CCommandLine virtual std::string Help(); std::string m_sPngFileName; std::string m_sOutFileName; + std::string m_sLeadText; POINT m_pOrigin; POINT m_pSize; + RGBA m_rgbaMaskColour; + bool m_bUseRGBMask; bool m_bUpsideDown; bool m_bReverse; bool m_bZigZag; @@ -32,9 +35,11 @@ class CCommandLinePngConv : public CCommandLine bool m_bTxtOut; bool m_bSilent; bool m_bVersion; + bool m_bInverseByte; bool m_bInverseMask; ZXIMAGEFORMAT m_nMaskFormat; protected: + bool DecodeRGB3(std::string param); ZXIMAGEFORMAT DecodeMask(std::string param); POINT DecodeXY(std::string param); }; diff --git a/ZxImage.cpp b/ZxImage.cpp index 8a617f4..b7e6d34 100644 --- a/ZxImage.cpp +++ b/ZxImage.cpp @@ -30,6 +30,8 @@ CZxImage::CZxImage(POINT _size) , m_bReverse(false) , m_bUpsideDown(false) , m_bZigZag(false) +, m_bUseRGBMask(false) +, m_bByteInvert(false) { // correct the X size so it's a multiple of 8 if (m_ptSize.x % 8) @@ -71,7 +73,10 @@ CZxImage::ProcessRGBAImage(CRGBAImage &_rgba) try { byteon = _rgba(y_idx, (8*x_idx) + b_idx).PixelIsOn(m_nGreyThreshold); - maskon = _rgba(y_idx, (8*x_idx) + b_idx).PixelIsMasked(m_nMaskThreshold); + if (!m_bUseRGBMask) + maskon = _rgba(y_idx, (8*x_idx) + b_idx).PixelIsMasked(m_nMaskThreshold); + else + maskon = _rgba(y_idx, (8*x_idx) + b_idx).PixelIsMasked(m_rgbMaskColour); } catch (CRGBAImage::CExBoundsViolation) { @@ -87,7 +92,27 @@ CZxImage::ProcessRGBAImage(CRGBAImage &_rgba) if (m_bMaskInvert) m_imgMask[y_idx][x_idx] = 255 - m_imgMask[y_idx][x_idx]; + if (m_bByteInvert) + m_imgByte[y_idx][x_idx] = 255 - m_imgByte[y_idx][x_idx]; + } + } +} + +void CZxImage::SetLeadText(std::string _ss) +{ + m_sLeadText = _ss; + // if the string is not empty we may need to add a space to it... unless it's a tab or space already + if (!m_sLeadText.empty()) + { + // first up, ensure the "\t" is converted to a tab character... + int pos = 0; + while (std::string::npos != (pos = m_sLeadText.find("\\t", pos))) + { + m_sLeadText = m_sLeadText.substr(0, pos) + std::string("\t") + m_sLeadText.substr(pos + 2); } + char theval = m_sLeadText[m_sLeadText.size() - 1]; + if (theval != ' ' && theval != '\t') + m_sLeadText += " "; } } @@ -159,153 +184,91 @@ std::ostream& operator<< (std::ostream& ost, const CZxImage& zxi) } int x_idx = x_init; - - switch (zxf) + if (zxi.m_bTextOutput) ost << zxi.m_sLeadText; + for (x_line = 0; x_line < x_count; ++x_line) { - case ZXIMAGE_FORMAT_B: - case ZXIMAGE_FORMAT_BBMM: - { - // output a line of bytes - x_idx = x_init; - if (zxi.m_bTextOutput) ost << "db "; - for (x_line = 0; x_line < x_count; ++x_line) - { - if (zxi.m_bTextOutput) - { - ost << static_cast(zxi.m_imgByte[y_idx][x_idx]); - if (x_line + 1 < x_count) ost << ","; - } - else - { - ost << zxi.m_imgByte[y_idx][x_idx]; - } - x_idx += x_delta; - } - if (zxi.m_bTextOutput) ost << std::endl; - } - break; - case ZXIMAGE_FORMAT_M: - case ZXIMAGE_FORMAT_MMBB: + switch (zxf) { - // output a line of mask - x_idx = x_init; - if (zxi.m_bTextOutput) ost << "db "; - for (x_line = 0; x_line < x_count; ++x_line) + case ZXIMAGE_FORMAT_B: + case ZXIMAGE_FORMAT_BBMM: + if (zxi.m_bTextOutput) + ost << static_cast(zxi.m_imgByte[y_idx][x_idx]); + else + ost << zxi.m_imgByte[y_idx][x_idx]; + break; + + case ZXIMAGE_FORMAT_M: + case ZXIMAGE_FORMAT_MMBB: + if (zxi.m_bTextOutput) + ost << static_cast(zxi.m_imgMask[y_idx][x_idx]); + else + ost << zxi.m_imgMask[y_idx][x_idx]; + break; + + case ZXIMAGE_FORMAT_BM: + if (zxi.m_bTextOutput) + ost << static_cast(zxi.m_imgByte[y_idx][x_idx]) << "," << static_cast(zxi.m_imgMask[y_idx][x_idx]); + else + ost << zxi.m_imgByte[y_idx][x_idx] << zxi.m_imgMask[y_idx][x_idx]; + break; + + case ZXIMAGE_FORMAT_MB: + if (zxi.m_bTextOutput) + ost << static_cast(zxi.m_imgMask[y_idx][x_idx]) << "," << static_cast(zxi.m_imgByte[y_idx][x_idx]); + else + ost << zxi.m_imgMask[y_idx][x_idx] << zxi.m_imgByte[y_idx][x_idx]; + break; + + default: { - if (zxi.m_bTextOutput) - { - ost << static_cast(zxi.m_imgMask[y_idx][x_idx]); - if (x_line + 1 < x_count) ost << ","; - } - else - { - ost << zxi.m_imgMask[y_idx][x_idx]; - } - x_idx += x_delta; + // whoops! + std::ostringstream except; + except << zxf; + throw CZxImage::CExUnknownMask(except.str()); } - if (zxi.m_bTextOutput) ost << std::endl; + break; } - break; - case ZXIMAGE_FORMAT_BM: - { - // output alternating byte/mask - x_idx = x_init; - if (zxi.m_bTextOutput) ost << "db "; - for (x_line = 0; x_line < x_count; ++x_line) - { - if (zxi.m_bTextOutput) - { - ost << static_cast(zxi.m_imgByte[y_idx][x_idx]) << "," << static_cast(zxi.m_imgMask[y_idx][x_idx]); - if (x_line + 1 < x_count) ost << ","; - } - else - { - ost << zxi.m_imgByte[y_idx][x_idx] << zxi.m_imgMask[y_idx][x_idx]; - } - x_idx += x_delta; - } - if (zxi.m_bTextOutput) ost << std::endl; - } - break; - case ZXIMAGE_FORMAT_MB: - { - // output alternating mask/byte - x_idx = x_init; - if (zxi.m_bTextOutput) ost << "db "; - for (x_line = 0; x_line < x_count; ++x_line) - { - if (zxi.m_bTextOutput) - { - ost << static_cast(zxi.m_imgMask[y_idx][x_idx]) << "," << static_cast(zxi.m_imgByte[y_idx][x_idx]); - if (x_line + 1 < x_count) ost << ","; - } - else - { - ost << zxi.m_imgMask[y_idx][x_idx] << zxi.m_imgByte[y_idx][x_idx]; - } - x_idx += x_delta; - } - if (zxi.m_bTextOutput) ost << std::endl; - } - break; - default: - { - // whoops! - std::ostringstream except; - except << zxf; - throw CZxImage::CExUnknownMask(except.str()); - } - break; + + if (zxi.m_bTextOutput && (x_line + 1 < x_count)) ost << ","; + x_idx += x_delta; } + if (zxi.m_bTextOutput) ost << std::endl; + + // now some clean-up in case we were doing a line-by-line thing... // we need to go through and print out the other line. - switch (zxf) + x_idx = x_init; + if (ZXIMAGE_FORMAT_BBMM == zxf || ZXIMAGE_FORMAT_MMBB == zxf) { - case ZXIMAGE_FORMAT_BBMM: + x_idx = x_init; + if (zxi.m_bTextOutput) ost << zxi.m_sLeadText; + for (x_line = 0; x_line < x_count; ++x_line) { - // output a line of masks now - x_idx = x_init; - if (zxi.m_bTextOutput) ost << "db "; - for (x_line = 0; x_line < x_count; ++x_line) + switch (zxf) { + case ZXIMAGE_FORMAT_BBMM: if (zxi.m_bTextOutput) - { ost << static_cast(zxi.m_imgMask[y_idx][x_idx]); - if (x_line + 1 < x_count) ost << ","; - } else - { - ost << zxi.m_imgByte[y_idx][x_idx]; - } - x_idx += x_delta; - } - if (zxi.m_bTextOutput) ost << std::endl; - } - break; - case ZXIMAGE_FORMAT_MMBB: - { - // output a line of bytes now - x_idx = x_init; - if (zxi.m_bTextOutput) ost << "db "; - for (x_line = 0; x_line < x_count; ++x_line) - { + ost << zxi.m_imgMask[y_idx][x_idx]; + break; + + case ZXIMAGE_FORMAT_MMBB: if (zxi.m_bTextOutput) - { ost << static_cast(zxi.m_imgByte[y_idx][x_idx]); - if (x_line + 1 < x_count) ost << ","; - } else - { ost << zxi.m_imgByte[y_idx][x_idx]; - } - x_idx += x_delta; + break; + + default: + break; } - if (zxi.m_bTextOutput) ost << std::endl; + + if (zxi.m_bTextOutput && (x_line + 1 < x_count)) ost << ","; + x_idx += x_delta; } - break; - default: - break; + if (zxi.m_bTextOutput) ost << std::endl; } y_idx += y_delta; diff --git a/ZxImage.h b/ZxImage.h index 22b86c8..2bb2460 100644 --- a/ZxImage.h +++ b/ZxImage.h @@ -19,7 +19,9 @@ class CZxImage public: friend std::ostream& operator<< (std::ostream& ost, const CZxImage& zxi); ProcessRGBAImage(CRGBAImage &_rgba); + void SetRGBMask(RGBA _rgba) {m_rgbMaskColour = _rgba; m_bUseRGBMask = true;}; void InvertMask(bool _invert = true) {m_bMaskInvert = _invert;}; + void InvertByte(bool _invert = true) {m_bByteInvert = _invert;}; void SetMaskFormat(ZXIMAGEFORMAT _format) {m_nMaskFormat = _format;}; void SetGreyThreshold(int _grey) {if (_grey >= 0 && _grey <= 255) m_nGreyThreshold = _grey;}; void SetMaskThreshold(int _mask) {if (_mask >= 0 && _mask <= 255) m_nMaskThreshold = _mask;}; @@ -27,6 +29,7 @@ class CZxImage void SetReverseOutput(bool _rev = true) {m_bReverse = _rev;}; void SetUpsideDown(bool _usd = true) {m_bUpsideDown = _usd;}; void SetZigZag(bool _zz = true) {m_bZigZag = _zz;}; + void SetLeadText(std::string _ss); CZxImage(POINT _size); virtual ~CZxImage(); @@ -34,6 +37,10 @@ class CZxImage protected: ZXIMAGEFORMAT m_nMaskFormat; + RGBA m_rgbMaskColour; + std::string m_sLeadText; + bool m_bUseRGBMask; + bool m_bByteInvert; bool m_bMaskInvert; int m_nGreyThreshold; int m_nMaskThreshold; diff --git a/pngconv.cpp b/pngconv.cpp index 8e36c2c..4690bb6 100644 --- a/pngconv.cpp +++ b/pngconv.cpp @@ -73,8 +73,12 @@ int main(int argc, char* argv[]) // set up our conversion options zximg.InvertMask(cmdLine.m_bInverseMask); + zximg.InvertByte(cmdLine.m_bInverseByte); zximg.SetMaskFormat(cmdLine.m_nMaskFormat); + if (cmdLine.m_bUseRGBMask) + zximg.SetRGBMask(cmdLine.m_rgbaMaskColour); + zximg.ProcessRGBAImage(rgbaimg); // set the output format @@ -82,6 +86,7 @@ int main(int argc, char* argv[]) zximg.SetReverseOutput(cmdLine.m_bReverse); zximg.SetUpsideDown(cmdLine.m_bUpsideDown); zximg.SetZigZag(cmdLine.m_bZigZag); + zximg.SetLeadText(cmdLine.m_sLeadText); // now we'll set up our output stream. // we'll send to either stdout or a file. diff --git a/pngconv.dsp b/pngconv.dsp index 5b71374..65e6e3d 100644 --- a/pngconv.dsp +++ b/pngconv.dsp @@ -58,8 +58,9 @@ InputPath=.\Release\pngconv.exe SOURCE="$(InputPath)" "$(OutDir)\pngconv.txt" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - copy $(ProjDir)\pngconv.txt $(OutDir) /y - + copy "$(ProjDir)\pngconv.txt" "$(OutDir)" /y + date /t >> "$(OutDir)\pngconv.txt" + # End Custom Build !ELSEIF "$(CFG)" == "pngconv - Win32 Debug" @@ -92,8 +93,9 @@ InputPath=.\Debug\pngconv.exe SOURCE="$(InputPath)" "$(OutDir)\pngconv.txt" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - copy $(ProjDir)\pngconv.txt $(OutDir) /y - + copy "$(ProjDir)\pngconv.txt" "$(OutDir)" /y + date /t >> "$(OutDir)\pngconv.txt" + # End Custom Build !ENDIF diff --git a/pngconv.rc b/pngconv.rc index e3bc26f..75b97c8 100644 --- a/pngconv.rc +++ b/pngconv.rc @@ -66,8 +66,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,0,1,0 - PRODUCTVERSION 0,0,1,0 + FILEVERSION 0,0,2,0 + PRODUCTVERSION 0,0,2,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -85,14 +85,14 @@ BEGIN VALUE "Comments", "\0" VALUE "CompanyName", "raww\0" VALUE "FileDescription", "PNG to Spectrum Conversion Utility\0" - VALUE "FileVersion", "0, 0, 1, 0\0" + VALUE "FileVersion", "0, 0, 2, 0\0" VALUE "InternalName", "pngconv.exe\0" VALUE "LegalCopyright", "© 2006 Robert Cooper\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "pngconv.exe\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "pngconv\0" - VALUE "ProductVersion", "0, 0, 1, 0\0" + VALUE "ProductVersion", "0, 0, 2, 0\0" VALUE "SpecialBuild", "\0" END END diff --git a/pngconv.txt b/pngconv.txt index ae2b78a..2990dfc 100644 --- a/pngconv.txt +++ b/pngconv.txt @@ -1,12 +1,29 @@ -PngConv v0.0.1 +PngConv v0.0.2 =------------= -PNGConv is a PNG to ZX Spectrum Image Convertor. The aim is to allow you to perform image conversions from the command-line, primarily from with a makefile or batch file. This is an early test release, so don't rely on it to do what you would expect. +PNGConv is a PNG to ZX Spectrum Image Convertor. The aim is to allow you to +perform image conversions from the command-line, primarily from with a makefile +or batch file. This is an early test release, so don't rely on it to do what you +would expect. + History: ======== -v0.0.1 : First public release. + +v0.0.2 - 07/11/2006 +------ ++ Allow definition of a colour as mask. Overrides use of Alpha channel if + specified. ++ Allow inversion of image data as well as mask. Default was White = On. +- Shuffled around a loop to remove some duplicate code and make things a + little more manageable. ++ Added "-odb=" option to provide alternate leading text on output. + +v0.0.1 - 06/11/2006 +------ ++ First public release. + Command Line @@ -15,52 +32,68 @@ PngConv [options] input [output] Detail: -input : This parameter is required and is the source .png file. There is no required format - the image will be converted internally to the correct format, providing the image can be read by pnglib. Masking for the output sprite is taken from the alpha channel of the input. +input : This parameter is required and is the source .png file. There + is no required format - the image will be converted internally + to the correct format, providing the image can be read by + pnglib. Masking for the output sprite is taken from the alpha + channel of the input, or the specified colour. + +output : This is the output file. If this parameter is not given the + output will default to ".out". -output : This is the output file. If this parameter is not given the output will default to ".out". +-h|help : Display the help. --h|help : Display the help. +-ver : Display version information. --ver : Display version information. +-ss : Silent mode. --ss : Silent mode. +-pos=x,y : Origin of image to be pulled from the input. + Defaults to 0,0 (top-left). --pos=x,y : Origin of image to be pulled from the input. Defaults to 0,0 (top-left). +-size=x,y : Size of the output image. Defaults to the size of the input. + Can be larger than the input. --size=x,y : Size of the output image. Defaults to the size of the input. Can be larger than the input. +-mask= : Format of the output mask: + b : Output only Image (default) + m : Output only Mask + mb : Alternate Mask and Image bytes + bm : Alternate Image and Mask bytes + mmbb : Alternate Mask and Image lines + bbmm : Alternate Image and Mask lines --mask= : Format of the output mask: - b : Output only Image (default) - m : Output only Mask - mb : Alternate Mask and Image bytes - bm : Alternate Image and Mask bytes - mmbb : Alternate Mask and Image lines - bbmm : Alternate Image and Mask lines +-mc=rgb : Take mask from the specified RGB colour (3 hex-digits). + Overrides use of alpha channel for the mask. --imask : Invert the mask bits. +-imask : Invert the mask bits. --ostd : Send output to stdout (console) rather than a file. - This option implies -ss. +-iimg : Invert the image bits (default is black off, white on). --otxt : Output as text. +-ostd : Send output to stdout (console) rather than a file. + This option implies -ss. --obin : Output as binary (default). +-otxt : Output as text. --ltr|rtl : Output left-to-right (default), or right-to-left. +-odb= : Set leading text to . Defaults to "db ". Tab characters + can be entered using "\t". -odb= on it's own gives no + leading text. --zz : ZigZag (alternate lines ltr/rtl). +-obin : Output as binary (default). --usd : Output upside-down (bottom line first in memory). +-ltr|rtl : Output left-to-right (default), or right-to-left. + +-zz : ZigZag (alternate lines ltr/rtl). + +-usd : Output upside-down (bottom line first in memory). Future additions ================ - Output as screen$ format. -- Invert bytes (not just mask). - Support colour. + Examples ======== @@ -73,7 +106,15 @@ To convert a sprite from a section of an image: To output just the mask information: pngconv -mask=m image.png mask.out -To output alternate lines of inverted mask then byte, upside-down, zig-zagging the sprite, as text to stdout: +To output the mask information using purple as the mask: + pngconv -mask=m -mc=f0f image.png mask.out + +To output the image data as text with "Data " leading: + pngconv -otxt -odb=Data\t image.png mask.out + +To output alternate lines of inverted mask then byte, upside-down, zig-zagging +the sprite, as text to stdout: pngconv -mask=mmbb -imask -usd -zz -otxt -ostd image.png +Documentation produced on: \ No newline at end of file diff --git a/typedefs.h b/typedefs.h index 77d0c62..b3660b2 100644 --- a/typedefs.h +++ b/typedefs.h @@ -3,7 +3,7 @@ #ifndef __PNGCONV__TYPEDEFS__H__INC #define __PNGCONV__TYPEDEFS__H__INC -#define PNGCONV_VERSION_STRING "0.0.1" +#define PNGCONV_VERSION_STRING "0.0.2" #define PNGCONV_BUILD_DATE __DATE__ #define PNGCONV_BUILD_TIME __TIME__ #define PNGCONV_SHORT_TITLE "PngConv" @@ -56,6 +56,13 @@ struct RGBA return (int)btAlp <= threshold; } + inline bool PixelIsMasked(RGBA _rgba) { + int bludif = abs(_rgba.btBlu - btBlu); + int reddif = abs(_rgba.btRed - btRed); + int grndif = abs(_rgba.btGrn - btGrn); + return (bludif < 16) && (reddif < 16) && (grndif < 16); + } + rgbaval btRed; rgbaval btGrn; rgbaval btBlu;