From 367c9cb514c9da766488b9bdb218a18e31cb7624 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 27 Mar 2016 01:38:28 +0000 Subject: Promote Stable (10.47) to Super Stable git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@2691 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/ppm/ppmtoleaf.c | 259 ++++++++++++++++++++++++---------------------- 1 file changed, 134 insertions(+), 125 deletions(-) (limited to 'converter/ppm/ppmtoleaf.c') diff --git a/converter/ppm/ppmtoleaf.c b/converter/ppm/ppmtoleaf.c index fa5fdaf5..dcff0985 100644 --- a/converter/ppm/ppmtoleaf.c +++ b/converter/ppm/ppmtoleaf.c @@ -1,4 +1,4 @@ -/* ppmtoleaf.c - read a portable pixmap and produce a ileaf img file +/* ppmtoleaf.c - read a PPM and produce a ileaf img file * * Copyright (C) 1994 by Bill O'Donnell. * @@ -15,57 +15,60 @@ */ #include + #include "ppm.h" #define MAXCOLORS 256 -pixel **pixels; +pixel ** pixels; colorhash_table cht; -int Red[MAXCOLORS], Green[MAXCOLORS], Blue[MAXCOLORS]; +static int Red[MAXCOLORS], Green[MAXCOLORS], Blue[MAXCOLORS]; static int -colorstobpp( colors ) -int colors; -{ +colorstobpp(unsigned int const colors) { + int bpp; - if ( colors <= 2 ) - bpp = 1; - else if ( colors <= 256 ) - bpp = 8; + if (colors <= 2) + bpp = 1; + else if (colors <= 256) + bpp = 8; else - bpp = 24; + bpp = 24; + return bpp; } static int -GetPixel( x, y ) -int x, y; -{ +GetPixel(int const x, + int const y) { + int color; - color = ppm_lookupcolor( cht, &pixels[y][x] ); + color = ppm_lookupcolor(cht, &pixels[y][x]); + return color; } -/* OK, this routine is not wicked efficient, but it is simple to follow - and it works. */ + static void -leaf_writeimg(width, height, depth, ncolors, maxval) -int width; -int height; -int depth; -int ncolors; -{ - int i,row,col; - +leaf_writeimg(unsigned int const width, + unsigned int const height, + unsigned int const depth, + unsigned int const ncolors, + pixval const maxval) { + + /* OK, this routine is not wicked efficient, but it is simple to follow + and it works. + */ + /* NOTE: byte order in ileaf img file fmt is big-endian, always! */ /* magic */ @@ -115,136 +118,142 @@ int ncolors; /* format, mono/gray = 0x20000000, RGB=0x29000000 */ if (depth == 1) - fputc(0x20, stdout); + fputc(0x20, stdout); else - fputc(0x29, stdout); + fputc(0x29, stdout); + fputc(0x00, stdout); fputc(0x00, stdout); fputc(0x00, stdout); /* colormap size */ - if (depth == 8) - { - fputc((unsigned char)((ncolors >> 8) & 0x00ff), stdout); - fputc((unsigned char)(ncolors & 0x00ff), stdout); - for (i=0; i<256; i++) - fputc((unsigned char) Red[i]*255/maxval, stdout); - for (i=0; i<256; i++) - fputc((unsigned char) Green[i]*255/maxval, stdout); - for (i=0; i<256; i++) - fputc((unsigned char) Blue[i]*255/maxval, stdout); - - for (row=0; row> 8) & 0x00ff), stdout); + fputc((unsigned char)(ncolors & 0x00ff), stdout); + for (i = 0; i < 256; ++i) + fputc((unsigned char) Red[i]*255/maxval, stdout); + for (i=0; i < 256; ++i) + fputc((unsigned char) Green[i]*255/maxval, stdout); + for (i = 0; i < 256; ++i) + fputc((unsigned char) Blue[i]*255/maxval, stdout); + + for (row=0; row < height; ++row) { + unsigned int col; + for (col = 0; col < width; ++col) + fputc(GetPixel(col, row), stdout); + if ((width % 2) != 0) + fputc(0x00, stdout); /* pad to 2-bytes */ + } } else if (depth == 1) { - /* mono image */ - /* no colormap */ - fputc(0x00, stdout); - fputc(0x00, stdout); - - for (row=0; row> (col % 8)); - if (((col + 1) % 8) == 0) { - fputc(bits, stdout); - bits = 0; - } - } - if ((width % 8) != 0) - fputc(bits, stdout); - if ((width % 16) && (width % 16) <= 8) - fputc(0x00, stdout); /* 16 bit pad */ - } + /* mono image */ + /* no colormap */ + + unsigned int row; + + fputc(0x00, stdout); + fputc(0x00, stdout); + + for (row = 0; row < height; ++row) { + unsigned char bits; + unsigned int col; + bits = 0; + for (col = 0; col < width; ++col) { + if (GetPixel(col,row)) + bits |= (unsigned char) (0x0080 >> (col % 8)); + if (((col + 1) % 8) == 0) { + fputc(bits, stdout); + bits = 0; + } + } + if ((width % 8) != 0) + fputc(bits, stdout); + if ((width % 16) && (width % 16) <= 8) + fputc(0x00, stdout); /* 16 bit pad */ + } } else { - /* no colormap, direct or true color (24 bit) image */ - fputc(0x00, stdout); - fputc(0x00, stdout); - - for (row=0; row