diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
commit | 1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch) | |
tree | 64c8c96cf54d8718847339a403e5e67b922e8c3f /other/pamendian.c | |
download | netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip |
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'other/pamendian.c')
-rw-r--r-- | other/pamendian.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/other/pamendian.c b/other/pamendian.c new file mode 100644 index 00000000..16e1fe56 --- /dev/null +++ b/other/pamendian.c @@ -0,0 +1,70 @@ +/****************************************************************************** + pnmendian +******************************************************************************* + + Reverse the endianness of multi-byte samples in a Netpbm stream. + I.e. convert between the true format and the little endian variation of + it. +******************************************************************************/ + +#include "pam.h" + + +static sample +reverseSample(sample const insample, unsigned int const bytesPerSample) { +/*---------------------------------------------------------------------------- + Return a sample whose value is the least significant + 'bytes_per_sample' bytes, in reverse order. +-----------------------------------------------------------------------------*/ + unsigned int bytePos; + sample shiftedInsample; + sample outsample; + shiftedInsample = insample; /* initial value */ + outsample = 0; /* initial value */ + for (bytePos = 0; bytePos < bytesPerSample; ++bytePos) { + outsample = outsample * 256 + (shiftedInsample & 0xff); + shiftedInsample >>= 8; + } + return outsample; +} + + + +int main(int argc, char *argv[]) { + + struct pam inpam, outpam; + tuple * intuplerow; + tuple * outtuplerow; + unsigned int row; + + pnm_init(&argc, argv); + + pnm_readpaminit(stdin, &inpam, PAM_STRUCT_SIZE(tuple_type)); + + outpam = inpam; + outpam.file = stdout; + + pnm_writepaminit(&outpam); + + intuplerow = pnm_allocpamrow(&inpam); + outtuplerow = pnm_allocpamrow(&outpam); + + for (row = 0; row < inpam.height; row++) { + unsigned int col; + pnm_readpamrow(&inpam, intuplerow); + for (col = 0; col < inpam.width; col++) { + unsigned int plane; + for (plane = 0; plane < inpam.depth; plane++) + outtuplerow[col][plane] = + reverseSample(intuplerow[col][plane], + inpam.bytes_per_sample); + } + pnm_writepamrow(&outpam, outtuplerow); + } + + pnm_freepamrow(outtuplerow); + pnm_freepamrow(intuplerow); + + exit(0); +} + |