From 89ee8a92e9c79a09799fc69ec8646aa50603d859 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 15 Sep 2018 19:18:08 +0000 Subject: Add pnm_maketuplergbn, pnm_makerowrgbn, and pnm_makearrayrgbn git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3324 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpamn.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/pam.h | 12 ++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libpamn.c b/lib/libpamn.c index 65c8979f..8ae57037 100644 --- a/lib/libpamn.c +++ b/lib/libpamn.c @@ -69,7 +69,8 @@ allocpamrown(const struct pam * const pamP, overflow will not occur in our calculations. NOTE: pnm_readpaminit() ensures this assumption is valid. -----------------------------------------------------------------------------*/ - int const bytes_per_tuple = allocationDepth(pamP) * sizeof(samplen); + unsigned int const bytes_per_tuple = + allocationDepth(pamP) * sizeof(samplen); tuplen * tuplerown; const char * error; @@ -643,6 +644,63 @@ pnm_unapplyopacityrown(struct pam * const pamP, +void +pnm_maketuplergbn(const struct pam * const pamP, + tuplen const tuple) { + + if (allocationDepth(pamP) < 3) + pm_error("allocation depth %u passed to pnm_maketuplergb(). " + "Must be at least 3.", allocationDepth(pamP)); + + if (pamP->depth < 3) + tuple[2] = tuple[1] = tuple[0]; +} + + + +void +pnm_makerowrgbn(const struct pam * const pamP, + tuplen * const tuplerow) { + + if (pamP->depth < 3) { + unsigned int col; + + if (allocationDepth(pamP) < 3) + pm_error("allocation depth %u passed to pnm_makerowrgb(). " + "Must be at least 3.", allocationDepth(pamP)); + + for (col = 0; col < pamP->width; ++col) { + tuplen const thisTuple = tuplerow[col]; + thisTuple[2] = thisTuple[1] = thisTuple[0]; + } + } +} + + + +void +pnm_makearrayrgbn(const struct pam * const pamP, + tuplen ** const tuples) { + + if (pamP->depth < 3) { + unsigned int row; + if (allocationDepth(pamP) < 3) + pm_error("allocation depth %u passed to pnm_makearrayrgb(). " + "Must be at least 3.", allocationDepth(pamP)); + + for (row = 0; row < pamP->height; ++row) { + tuplen * const tuplerow = tuples[row]; + unsigned int col; + for (col = 0; col < pamP->width; ++col) { + tuplen const thisTuple = tuplerow[col]; + thisTuple[2] = thisTuple[1] = thisTuple[0]; + } + } + } +} + + + static void fillInMap(pnm_transformMap const ungammaTransformMap, sample const maxval, diff --git a/lib/pam.h b/lib/pam.h index c2cfb4c7..74b20f46 100644 --- a/lib/pam.h +++ b/lib/pam.h @@ -482,6 +482,18 @@ void pnm_unapplyopacityrown(struct pam * const pamP, tuplen * const tuplenrow); +void +pnm_maketuplergbn(const struct pam * const pamP, + tuplen const tuple); + +void +pnm_makerowrgbn(const struct pam * const pamP, + tuplen * const tuplerow); + +void +pnm_makearrayrgbn(const struct pam * const pamP, + tuplen ** const tuples); + pnm_transformMap * pnm_creategammatransform(const struct pam * const pamP); -- cgit 1.4.1