diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-11-04 00:43:30 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-11-04 00:43:30 +0000 |
commit | 382ba12465b6c4a7398deb1ca0583ac7506823a5 (patch) | |
tree | 07dc254076e92f4b97f5035f52156b5724512a6f /converter/other/pamtotga.c | |
parent | e57c025f5a698fdd2b01175da5ff0cd50709bbd5 (diff) | |
download | netpbm-mirror-382ba12465b6c4a7398deb1ca0583ac7506823a5.tar.gz netpbm-mirror-382ba12465b6c4a7398deb1ca0583ac7506823a5.tar.xz netpbm-mirror-382ba12465b6c4a7398deb1ca0583ac7506823a5.zip |
Ignore extra planes in BLACKANDWHITE or GRAYSCALE input intead of generating bogus 16-bit color map
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3416 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pamtotga.c')
-rw-r--r-- | converter/other/pamtotga.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/converter/other/pamtotga.c b/converter/other/pamtotga.c index 4b4cfb98..271e894d 100644 --- a/converter/other/pamtotga.c +++ b/converter/other/pamtotga.c @@ -341,14 +341,13 @@ computeImageType_cht(struct pam * const pamP, validateTupleType(pamP); - withAlpha = (streq(pamP->tuple_type, "RGB_ALPHA")); - if (cmdline.defaultFormat) { /* default the image type */ - if (withAlpha) { + if (streq(pamP->tuple_type, "RGB_ALPHA")) { baseImgType = TGA_RGB_TYPE; *chvP = NULL; - } else if (pamP->depth > 1) { + withAlpha = true; + } else if (streq(pamP->tuple_type, "RGB")) { pm_message("computing colormap..."); *chvP = pnm_computetuplefreqtable(pamP, tuples, MAXCOLORS, &ncolors); @@ -357,11 +356,15 @@ computeImageType_cht(struct pam * const pamP, baseImgType = TGA_RGB_TYPE; } else baseImgType = TGA_MAP_TYPE; + withAlpha = false; } else { baseImgType = TGA_MONO_TYPE; *chvP = NULL; + withAlpha = false; } } else { + withAlpha = (streq(pamP->tuple_type, "RGB_ALPHA")); + baseImgType = cmdline.imgType; if (baseImgType == TGA_MAP_TYPE) { @@ -377,9 +380,6 @@ computeImageType_cht(struct pam * const pamP, MAXCOLORS); } else *chvP = NULL; - if (baseImgType == TGA_MONO_TYPE && pamP->depth > 1) - pm_error("For Mono TGA output, input must be " - "GRAYSCALE or BLACKANDWHITE PAM or PBM or PGM"); } if (baseImgType == TGA_MAP_TYPE) { @@ -431,7 +431,7 @@ computeTgaHeader(struct pam * const pamP, tgaHeaderP->CoMapType = 1; tgaHeaderP->Length_lo = ncolors % 256; tgaHeaderP->Length_hi = ncolors / 256; - tgaHeaderP->CoSize = 8 * pamP->depth; + tgaHeaderP->CoSize = withAlpha ? 32 : 24; } else { tgaHeaderP->CoMapType = 0; tgaHeaderP->Length_lo = 0; @@ -443,7 +443,7 @@ computeTgaHeader(struct pam * const pamP, tgaHeaderP->PixelSize = 8; break; case TGA_RGB_TYPE: - tgaHeaderP->PixelSize = 8 * MAX((withAlpha ? 4: 3), pamP->depth); + tgaHeaderP->PixelSize = 8 * (withAlpha ? 4: 3); break; case TGA_MONO_TYPE: tgaHeaderP->PixelSize = 8; |