From b2e350036b3d3e65d9d130f2eafbd06b2f69f34d Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 18 Aug 2022 02:06:21 +0000 Subject: Fix bogus depth calculation for non-visual PAM input git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4414 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/pamcat.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'editor') diff --git a/editor/pamcat.c b/editor/pamcat.c index a2b2ef41..f44062c5 100644 --- a/editor/pamcat.c +++ b/editor/pamcat.c @@ -354,14 +354,15 @@ computeOutputParms(unsigned int const fileCt, if (inpamP->tuple_type != firstTupletype) allSameTt = false; - if (!inpamP->visual) - allVisual = false; + if (inpamP->visual) { + maxColorDepth = MAX(maxColorDepth, inpamP->color_depth); - if (inpamP->have_opacity) - haveOpacity = true; + if (inpamP->have_opacity) + haveOpacity = true; + } else + allVisual = false; maxDepth = MAX(maxDepth, inpamP->depth); - maxColorDepth = MAX(maxColorDepth, inpamP->color_depth); maxMaxval = MAX(maxMaxval, inpamP->maxval); if (PAM_FORMAT_TYPE(inpamP->format) > PAM_FORMAT_TYPE(newFormat)) @@ -370,7 +371,6 @@ computeOutputParms(unsigned int const fileCt, assert(newCols > 0); assert(newRows > 0); assert(maxMaxval > 0); - assert(maxColorDepth > 0); assert(newFormat > 0); if (newCols > INT_MAX) @@ -387,8 +387,11 @@ computeOutputParms(unsigned int const fileCt, */ outpamP->height = (unsigned int)newRows; outpamP->width = (unsigned int)newCols; - outpamP->depth = MAX(maxDepth, + if (allVisual) + outpamP->depth = MAX(maxDepth, maxColorDepth + (haveOpacity ? 1 : 0)); + else + outpamP->depth = maxDepth; outpamP->allocation_depth = 0; /* This means same as depth */ outpamP->maxval = maxMaxval; outpamP->format = newFormat; -- cgit 1.4.1