From f83833dd6f1f8deb2faa5686da22991f58087f56 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 23 Oct 2010 19:09:38 +0000 Subject: Rename icontopbm to sunicontopnm git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1342 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/Makefile | 2 +- converter/other/sunicontopnm.c | 171 +++++++++++++++++++++++++++++++++++++++++ converter/pbm/Makefile | 10 ++- converter/pbm/icontopbm.c | 171 ----------------------------------------- 4 files changed, 181 insertions(+), 173 deletions(-) create mode 100644 converter/other/sunicontopnm.c delete mode 100644 converter/pbm/icontopbm.c (limited to 'converter') diff --git a/converter/other/Makefile b/converter/other/Makefile index cded8f33..c2cbb0a9 100644 --- a/converter/other/Makefile +++ b/converter/other/Makefile @@ -87,7 +87,7 @@ PORTBINARIES = avstopam bmptopnm fitstopnm \ pgmtopbm pgmtoppm ppmtopgm pnmtoddif \ pnmtopclxl \ pnmtosgi pnmtosir pamtotga pnmtoxwd \ - rlatopam sgitopnm sirtopnm xwdtopnm zeisstopnm + rlatopam sgitopnm sirtopnm sunicontopnm xwdtopnm zeisstopnm ifneq ($(DONT_HAVE_PROCESS_MGMT),Y) PORTBINARIES += pstopnm diff --git a/converter/other/sunicontopnm.c b/converter/other/sunicontopnm.c new file mode 100644 index 00000000..bad47c24 --- /dev/null +++ b/converter/other/sunicontopnm.c @@ -0,0 +1,171 @@ +/* icontopbm.c - read a Sun icon file and produce a portable bitmap +** +** Copyright (C) 1988 by Jef Poskanzer. +** +** Permission to use, copy, modify, and distribute this software and its +** documentation for any purpose and without fee is hereby granted, provided +** that the above copyright notice appear in all copies and that both that +** copyright notice and this permission notice appear in supporting +** documentation. This software is provided "as is" without express or +** implied warranty. +*/ + +/* + Most icon images are monochrome: Depth=1 + Depth=8 images are extremely rare. At least some of these are color + images but we can't tell the pallete color order. + Output will be in pgm. Convert to ppm with pgmtoppm or pamlookup + if necessary. +*/ + +#include +#include + +#include "nstring.h" +#include "pbm.h" +#include "pgm.h" + + + +static void +ReadIconFileHeader(FILE * const file, + int * const widthP, + int * const heightP, + int * const depthP, + int * const bitsPerItemP) { + + unsigned int fieldCt; + + fieldCt = 0; + *widthP = *heightP = -1; + + for ( ; ; ) { + char variable[80+1]; + int ch; + unsigned int i; + int value; + + while ((ch = getc(file)) == ',' || ch == '\n' || ch == '\t' || + ch == ' ') + ; + for (i = 0; + ch != '=' && ch != ',' && ch != '\n' && ch != '\t' && + ch != ' ' && (i < (sizeof(variable) - 1)); + ++i) { + variable[i] = ch; + if ((ch = getc( file )) == EOF) + pm_error( "invalid input file -- premature EOF" ); + } + variable[i] = '\0'; + + if (streq(variable, "*/") && fieldCt > 0) + break; + + if (fscanf( file, "%d", &value ) != 1) + continue; + + if (streq( variable, "Width")) { + *widthP = value; + ++fieldCt; + } else if (streq( variable, "Height")) { + *heightP = value; + ++fieldCt; + } else if (streq( variable, "Depth")) { + if (value != 1 && value != 8) + pm_error("invalid depth"); + *depthP = value; + ++fieldCt; + } else if (streq(variable, "Format_version")) { + if (value != 1) + pm_error("invalid Format_version"); + ++fieldCt; + } else if (streq(variable, "Valid_bits_per_item")) { + if (value != 16 && value !=32) + pm_error("invalid Valid_bits_per_item"); + *bitsPerItemP = value; + ++fieldCt; + } + } + + if (fieldCt < 5) + pm_error("invalid sun icon file header: " + "only %u out of required 5 fields present", fieldCt); + + if (*widthP <= 0) + pm_error("invalid width (must be positive): %d", *widthP); + if (*heightP <= 0) + pm_error("invalid height (must be positive): %d", *heightP); + +} + + +int +main(int argc, const char ** argv) { + + FILE * ifP; + bit * bitrow; + gray * grayrow; + int rows, cols, depth, row, format, maxval, colChars, bitsPerItem; + + pm_proginit(&argc, argv); + + if (argc-1 > 1) + pm_error("Too many arguments (%u). Program takes at most one: " + "name of input file", argc-1); + + if (argc-1 == 1) + ifP = pm_openr(argv[1]); + else + ifP = stdin; + + ReadIconFileHeader(ifP, &cols, &rows, &depth, &bitsPerItem); + + if (depth == 1) { + format = PBM_TYPE; + maxval = 1; + pbm_writepbminit(stdout, cols, rows, 0); + bitrow = pbm_allocrow_packed(cols); + colChars = cols / 8; + } else { + assert(depth == 8); + format = PGM_TYPE; + maxval = 255; + grayrow = pgm_allocrow(cols); + colChars = cols / depth; + } + + for (row = 0; row < rows; ++row) { + unsigned int colChar; + for (colChar = 0; colChar < colChars; ++colChar) { + unsigned int data; + int status; + + /* read 8 bits */ + if (row==0 && colChar == 0) + status = fscanf(ifP, " 0x%2x", &data); + else if (colChar % (bitsPerItem/8) == 0) + status = fscanf(ifP, ", 0x%2x", &data); + else + status = fscanf(ifP, "%2x", &data); + + /* write 8 bits */ + if (status == 1) { + if (format == PBM_TYPE) + bitrow[colChar] = data; + else + grayrow[colChar] = data; + } else + pm_error("error scanning bits item %u" , colChar); + } + + /* output row */ + if (format == PBM_TYPE) + pbm_writepbmrow_packed(stdout, bitrow, cols, 0); + else + pgm_writepgmrow(stdout, grayrow, cols, maxval, 0); + } + + pm_close(ifP); + pm_close(stdout); + return 0; +} diff --git a/converter/pbm/Makefile b/converter/pbm/Makefile index 0461eedc..07b768c0 100644 --- a/converter/pbm/Makefile +++ b/converter/pbm/Makefile @@ -9,7 +9,7 @@ include $(BUILDDIR)/config.mk PORTBINARIES = atktopbm brushtopbm cistopbm cmuwmtopbm \ ddbugtopbm g3topbm escp2topbm \ - icontopbm macptopbm mdatopbm mgrtopbm mrftopbm \ + macptopbm mdatopbm mgrtopbm mrftopbm \ pbmto10x pbmto4425 pbmtoascii pbmtoatk \ pbmtobbnbg pbmtocis pbmtocmuwm pbmtodjvurle \ pbmtoepsi pbmtoepson pbmtoescp2 \ @@ -73,6 +73,14 @@ thinkjettopbm.c:%.c:%.c1 $(SRCDIR)/lib/util/lexheader grep -v "^[[:space:]]*int yywrap(void);" \ >$@ +install.bin: install.bin.local +.PHONY: install.bin.local +install.bin.local: $(PKGDIR)/bin +# Remember that $(SYMLINK) might just be a copy command. +# In December 2010, sunicontopnm replaced icontopbm + cd $(PKGDIR)/bin ; \ + $(SYMLINK) sunicontopnm icontopbm + thisdirclean: localclean .PHONY: localclean localclean: diff --git a/converter/pbm/icontopbm.c b/converter/pbm/icontopbm.c deleted file mode 100644 index bad47c24..00000000 --- a/converter/pbm/icontopbm.c +++ /dev/null @@ -1,171 +0,0 @@ -/* icontopbm.c - read a Sun icon file and produce a portable bitmap -** -** Copyright (C) 1988 by Jef Poskanzer. -** -** Permission to use, copy, modify, and distribute this software and its -** documentation for any purpose and without fee is hereby granted, provided -** that the above copyright notice appear in all copies and that both that -** copyright notice and this permission notice appear in supporting -** documentation. This software is provided "as is" without express or -** implied warranty. -*/ - -/* - Most icon images are monochrome: Depth=1 - Depth=8 images are extremely rare. At least some of these are color - images but we can't tell the pallete color order. - Output will be in pgm. Convert to ppm with pgmtoppm or pamlookup - if necessary. -*/ - -#include -#include - -#include "nstring.h" -#include "pbm.h" -#include "pgm.h" - - - -static void -ReadIconFileHeader(FILE * const file, - int * const widthP, - int * const heightP, - int * const depthP, - int * const bitsPerItemP) { - - unsigned int fieldCt; - - fieldCt = 0; - *widthP = *heightP = -1; - - for ( ; ; ) { - char variable[80+1]; - int ch; - unsigned int i; - int value; - - while ((ch = getc(file)) == ',' || ch == '\n' || ch == '\t' || - ch == ' ') - ; - for (i = 0; - ch != '=' && ch != ',' && ch != '\n' && ch != '\t' && - ch != ' ' && (i < (sizeof(variable) - 1)); - ++i) { - variable[i] = ch; - if ((ch = getc( file )) == EOF) - pm_error( "invalid input file -- premature EOF" ); - } - variable[i] = '\0'; - - if (streq(variable, "*/") && fieldCt > 0) - break; - - if (fscanf( file, "%d", &value ) != 1) - continue; - - if (streq( variable, "Width")) { - *widthP = value; - ++fieldCt; - } else if (streq( variable, "Height")) { - *heightP = value; - ++fieldCt; - } else if (streq( variable, "Depth")) { - if (value != 1 && value != 8) - pm_error("invalid depth"); - *depthP = value; - ++fieldCt; - } else if (streq(variable, "Format_version")) { - if (value != 1) - pm_error("invalid Format_version"); - ++fieldCt; - } else if (streq(variable, "Valid_bits_per_item")) { - if (value != 16 && value !=32) - pm_error("invalid Valid_bits_per_item"); - *bitsPerItemP = value; - ++fieldCt; - } - } - - if (fieldCt < 5) - pm_error("invalid sun icon file header: " - "only %u out of required 5 fields present", fieldCt); - - if (*widthP <= 0) - pm_error("invalid width (must be positive): %d", *widthP); - if (*heightP <= 0) - pm_error("invalid height (must be positive): %d", *heightP); - -} - - -int -main(int argc, const char ** argv) { - - FILE * ifP; - bit * bitrow; - gray * grayrow; - int rows, cols, depth, row, format, maxval, colChars, bitsPerItem; - - pm_proginit(&argc, argv); - - if (argc-1 > 1) - pm_error("Too many arguments (%u). Program takes at most one: " - "name of input file", argc-1); - - if (argc-1 == 1) - ifP = pm_openr(argv[1]); - else - ifP = stdin; - - ReadIconFileHeader(ifP, &cols, &rows, &depth, &bitsPerItem); - - if (depth == 1) { - format = PBM_TYPE; - maxval = 1; - pbm_writepbminit(stdout, cols, rows, 0); - bitrow = pbm_allocrow_packed(cols); - colChars = cols / 8; - } else { - assert(depth == 8); - format = PGM_TYPE; - maxval = 255; - grayrow = pgm_allocrow(cols); - colChars = cols / depth; - } - - for (row = 0; row < rows; ++row) { - unsigned int colChar; - for (colChar = 0; colChar < colChars; ++colChar) { - unsigned int data; - int status; - - /* read 8 bits */ - if (row==0 && colChar == 0) - status = fscanf(ifP, " 0x%2x", &data); - else if (colChar % (bitsPerItem/8) == 0) - status = fscanf(ifP, ", 0x%2x", &data); - else - status = fscanf(ifP, "%2x", &data); - - /* write 8 bits */ - if (status == 1) { - if (format == PBM_TYPE) - bitrow[colChar] = data; - else - grayrow[colChar] = data; - } else - pm_error("error scanning bits item %u" , colChar); - } - - /* output row */ - if (format == PBM_TYPE) - pbm_writepbmrow_packed(stdout, bitrow, cols, 0); - else - pgm_writepgmrow(stdout, grayrow, cols, maxval, 0); - } - - pm_close(ifP); - pm_close(stdout); - return 0; -} -- cgit 1.4.1