diff options
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/Makefile | 15 | ||||
-rw-r--r-- | converter/other/cameratopam/Makefile | 3 | ||||
-rw-r--r-- | converter/other/fiasco/Makefile | 2 | ||||
-rw-r--r-- | converter/other/fiasco/codec/Makefile | 2 | ||||
-rw-r--r-- | converter/other/fiasco/input/Makefile | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/Makefile | 2 | ||||
-rw-r--r-- | converter/other/fiasco/output/Makefile | 7 | ||||
-rw-r--r-- | converter/other/jbig/Makefile | 4 | ||||
-rw-r--r-- | converter/other/jpeg2000/Makefile | 4 | ||||
-rw-r--r-- | converter/other/jpeg2000/libjasper/Makefile.common | 4 | ||||
-rw-r--r-- | converter/other/pamtosvg/pamtosvg.test | 6 | ||||
-rw-r--r-- | converter/other/pnmtopalm/Makefile | 4 | ||||
-rw-r--r-- | converter/other/pnmtopalm/gen_palm_colormap.c | 33 | ||||
-rw-r--r-- | converter/pbm/pbmtonokia.c | 669 | ||||
-rw-r--r-- | converter/ppm/ppmtobmp.c | 2 | ||||
-rw-r--r-- | converter/ppm/ppmtompeg/Makefile | 5 | ||||
-rw-r--r-- | converter/ppm/xvminitoppm.c | 4 |
17 files changed, 531 insertions, 239 deletions
diff --git a/converter/other/Makefile b/converter/other/Makefile index 4585c45d..6cde424d 100644 --- a/converter/other/Makefile +++ b/converter/other/Makefile @@ -20,10 +20,9 @@ ifneq ($(BUILD_FIASCO), N) SUBDIRS += fiasco endif -INCLUDES = -I$(SRCDIR)/util ifneq ($(TIFFLIB),NONE) ifneq ($(TIFFHDR_DIR)x,x) - INCLUDES += -I$(TIFFHDR_DIR) + EXTERN_INCLUDES += -I$(TIFFHDR_DIR) endif endif @@ -31,30 +30,30 @@ ifeq ($(shell libpng-config --version),) ifneq ($(PNGLIB),NONE) HAVE_PNGLIB = Y ifneq ($(PNGHDR_DIR)x,x) - INCLUDES += -I$(PNGHDR_DIR) + EXTERN_INCLUDES += -I$(PNGHDR_DIR) endif ifneq ($(ZHDR_DIR)x,x) - INCLUDES += -I$(ZHDR_DIR) + EXTERN_INCLUDES += -I$(ZHDR_DIR) endif endif else HAVE_PNGLIB = Y - INCLUDES += $(shell libpng-config --cflags) + EXTERN_INCLUDES += $(shell libpng-config --cflags) endif ifneq ($(JPEGLIB),NONE) ifneq ($(JPEGHDR_DIR)x,x) - INCLUDES += -I$(JPEGHDR_DIR) + EXTERN_INCLUDES += -I$(JPEGHDR_DIR) endif endif ifneq ($(URTLIB),NONE) ifneq ($(URTHDR_DIR)x,x) - INCLUDES += -I$(URTHDR_DIR) + EXTERN_INCLUDES += -I$(URTHDR_DIR) endif endif ifneq ($(XML2_LIBS),NONE) ifneq ($(XML2_CFLAGS),NONE) - INCLUDES += $(XML2_CFLAGS) + EXTERN_INCLUDES += $(XML2_CFLAGS) endif endif diff --git a/converter/other/cameratopam/Makefile b/converter/other/cameratopam/Makefile index c50c9176..178b4fff 100644 --- a/converter/other/cameratopam/Makefile +++ b/converter/other/cameratopam/Makefile @@ -5,9 +5,10 @@ endif SUBDIR = converter/other/cameratopam VPATH=.:$(SRCDIR)/$(SUBDIR) +EXTERN_INCLUDES = ifneq ($(JPEGLIB),NONE) ifneq ($(JPEGHDR_DIR)x,x) - INCLUDES += -I$(JPEGHDR_DIR) + EXTERN_INCLUDES += -I$(JPEGHDR_DIR) CFLAGS += -DHAVE_JPEG endif endif diff --git a/converter/other/fiasco/Makefile b/converter/other/fiasco/Makefile index 0dd945ed..0330802c 100644 --- a/converter/other/fiasco/Makefile +++ b/converter/other/fiasco/Makefile @@ -7,7 +7,7 @@ VPATH=.:$(SRCDIR)/$(SUBDIR) include $(BUILDDIR)/Makefile.config -INCLUDES = \ +COMP_INCLUDES = \ -I$(SRCDIR)/$(SUBDIR)/codec -I$(SRCDIR)/$(SUBDIR)/input \ -I$(SRCDIR)/$(SUBDIR)/output -I$(SRCDIR)/$(SUBDIR)/lib \ diff --git a/converter/other/fiasco/codec/Makefile b/converter/other/fiasco/codec/Makefile index 9a9d502a..c5f94c28 100644 --- a/converter/other/fiasco/codec/Makefile +++ b/converter/other/fiasco/codec/Makefile @@ -8,7 +8,7 @@ VPATH=.:$(SRCDIR)/$(SUBDIR) include $(BUILDDIR)/Makefile.config -INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) -I$(SRCDIR)/$(FIASCOSUBDIR)/lib \ +COMP_INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) -I$(SRCDIR)/$(FIASCOSUBDIR)/lib \ -I$(SRCDIR)/$(FIASCOSUBDIR)/input -I$(SRCDIR)/$(FIASCOSUBDIR)/output OBJECTS = approx.o bintree.o coder.o coeff.o \ diff --git a/converter/other/fiasco/input/Makefile b/converter/other/fiasco/input/Makefile index c01af772..6cd8e34b 100644 --- a/converter/other/fiasco/input/Makefile +++ b/converter/other/fiasco/input/Makefile @@ -13,8 +13,8 @@ OBJECTS = basis.o matrices.o mc.o nd.o read.o tree.o weights.o MERGE_OBJECTS = $(OBJECTS) -INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) -I$(SRCDIR)/$(FIASCOSUBDIR)/lib \ - -I$(SRCDIR)/$(FIASCOSUBDIR)/codec +COMP_INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) -I$(SRCDIR)/$(FIASCOSUBDIR)/lib \ + -I$(SRCDIR)/$(FIASCOSUBDIR)/codec all: libfiasco_input.a diff --git a/converter/other/fiasco/lib/Makefile b/converter/other/fiasco/lib/Makefile index 99d7c1d7..bd129016 100644 --- a/converter/other/fiasco/lib/Makefile +++ b/converter/other/fiasco/lib/Makefile @@ -21,7 +21,7 @@ OBJECTS = \ MERGE_OBJECTS = $(OBJECTS) -INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) +COMP_INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) all: libfiasco_lib.a diff --git a/converter/other/fiasco/output/Makefile b/converter/other/fiasco/output/Makefile index 3bdc4635..fc1d4155 100644 --- a/converter/other/fiasco/output/Makefile +++ b/converter/other/fiasco/output/Makefile @@ -12,9 +12,10 @@ OBJECTS = matrices.o mc.o nd.o tree.o weights.o write.o MERGE_OBJECTS = $(OBJECTS) -INCLUDES = -I$(SRCDIR)/$(FIASCOSUBDIR) \ - -I$(SRCDIR)/$(FIASCOSUBDIR)/lib \ - -I$(SRCDIR)/$(FIASCOSUBDIR)/codec +COMP_INCLUDES = \ + -I$(SRCDIR)/$(FIASCOSUBDIR) \ + -I$(SRCDIR)/$(FIASCOSUBDIR)/lib \ + -I$(SRCDIR)/$(FIASCOSUBDIR)/codec all: libfiasco_output.a diff --git a/converter/other/jbig/Makefile b/converter/other/jbig/Makefile index ca98ef29..4be21582 100644 --- a/converter/other/jbig/Makefile +++ b/converter/other/jbig/Makefile @@ -9,9 +9,9 @@ include $(BUILDDIR)/Makefile.config LIBJBIG_OBJECTS = jbig.o jbig_tab.o -INCLUDES = +EXTERN_INCLUDES = ifneq ($(JBIGHDR_DIR),NONE) - INCLUDES += -I$(JBIGHDR_DIR) + EXTERN_INCLUDES += -I$(JBIGHDR_DIR) endif ifneq ($(JBIGHDR_DIR),NONE) diff --git a/converter/other/jpeg2000/Makefile b/converter/other/jpeg2000/Makefile index 70cfafb7..c5e74361 100644 --- a/converter/other/jpeg2000/Makefile +++ b/converter/other/jpeg2000/Makefile @@ -9,9 +9,9 @@ SUBDIRS = libjasper include $(BUILDDIR)/Makefile.config -INCLUDES = +EXTERN_INCLUDES = ifneq ($(JASPERHDR_DIR),NONE) - INCLUDES += -I$(JASPERHDR_DIR) + EXTERN_INCLUDES += -I$(JASPERHDR_DIR) endif diff --git a/converter/other/jpeg2000/libjasper/Makefile.common b/converter/other/jpeg2000/libjasper/Makefile.common index 71a11832..84781769 100644 --- a/converter/other/jpeg2000/libjasper/Makefile.common +++ b/converter/other/jpeg2000/libjasper/Makefile.common @@ -17,10 +17,10 @@ $(SUBDIRS:%=%/partlist): %/partlist: $(CURDIR)/% $(MAKE) -C $(dir $@) -f $(SRCDIR)/$(SUBDIR)/$(dir $@)Makefile \ SRCDIR=$(SRCDIR) BUILDDIR=$(BUILDDIR) $(notdir $@) -INCLUDES = -I$(JASPERSRCDIR)/include -I$(JASPERSRCDIR)/importinc - include $(SRCDIR)/Makefile.common +INCLUDES = -I$(JASPERSRCDIR)/include -I$(JASPERSRCDIR)/importinc + DEFS = -DHAVE_LIBM=1 -DSTDC_HEADERS=1 -DHAVE_FCNTL_H=1 -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STDDEF_H=1 -DEXCLUDE_BMP_SUPPORT -DEXCLUDE_RAS_SUPPORT -DEXCLUDE_MIF_SUPPORT -DEXCLUDE_JPG_SUPPORT -DEXCLUDE_PGX_SUPPORT -DEXCLUDE_PNM_SUPPORT $(LIB_OBJECTS):%.o:%.c diff --git a/converter/other/pamtosvg/pamtosvg.test b/converter/other/pamtosvg/pamtosvg.test index df3a07d3..3217287e 100644 --- a/converter/other/pamtosvg/pamtosvg.test +++ b/converter/other/pamtosvg/pamtosvg.test @@ -1,6 +1,8 @@ +echo "Test 1. Should print nothing" # This will print nothing if successful (diff will find no difference) -ppmmake black 20 20 | ppmdraw -script="line 5 2 15 17" | pamtosvg | \ +ppmmake black 20 20 | ppmdraw -script="line 5 2 15 17" | ./pamtosvg | \ diff testline.svg - +echo "Test 2. Should print nothing" # This will print nothing if successful (diff will find no difference) -pamtosvg ../../../../testgrid.pbm | diff testgrid.svg - +./pamtosvg ../../../testgrid.pbm | diff testgrid.svg - diff --git a/converter/other/pnmtopalm/Makefile b/converter/other/pnmtopalm/Makefile index 2a76297e..d7bf2829 100644 --- a/converter/other/pnmtopalm/Makefile +++ b/converter/other/pnmtopalm/Makefile @@ -24,8 +24,8 @@ $(BINARIES): %: %.o palmcolormap.o $(NETPBMLIB) $(LIBOPT) $(LD) $(LDFLAGS) -o $@ $< palmcolormap.o $(LIBOPTS) \ $(MATHLIB) $(LDLIBS) $(RPATH) $(LADD) -gen_palm_colormap : $(SUBDIR)/gen_palm_colormap.c palmcolormap.o - $(CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) -o $@ $< palmcolormap.o \ +gen_palm_colormap : % : %.c palmcolormap.o + $(CC) -I importinc $(CFLAGS) $(LDFLAGS) -o $@ $< palmcolormap.o \ $(LIBOPTS) $(MATHLIB) $(LDLIBS) $(LADD) diff --git a/converter/other/pnmtopalm/gen_palm_colormap.c b/converter/other/pnmtopalm/gen_palm_colormap.c index 4b65e631..b71854b2 100644 --- a/converter/other/pnmtopalm/gen_palm_colormap.c +++ b/converter/other/pnmtopalm/gen_palm_colormap.c @@ -7,18 +7,25 @@ #include "palm.h" -int main( int argc, char **argv ) { - - int i; - Color_s current; - Colormap default_map = palmcolor_build_default_8bit_colormap (); - - printf("P3\n%d 1\n255\n", default_map->ncolors); - for (i = 0; i < default_map->ncolors; i++) { - current = default_map->color_entries[i]; - printf ("%d %d %d\n", (current & 0xFF0000) >> 16, (current & 0xFF00) >> 8, (current & 0xFF)); - /* printf ("%x: %d %d %d\n", (current & 0xFF000000) >> 24, (current & 0xFF0000) >> 16, (current & 0xFF00) >> 8, (current & 0xFF)); */ - }; - return 0; +int +main(int argc, + char ** argv) { + + Colormap const defaultMap = palmcolor_build_default_8bit_colormap(); + + unsigned int i; + + printf("P3\n%d 1\n255\n", defaultMap->ncolors); + + for (i = 0; i < defaultMap->ncolors; ++i) { + Color_s const current = defaultMap->color_entries[i]; + + printf("%u %u %u\n", + (unsigned char)(current >> 16), + (unsigned char)(current >> 8), + (unsigned char)(current >> 0)); + } + + return 0; } diff --git a/converter/pbm/pbmtonokia.c b/converter/pbm/pbmtonokia.c index 214958c5..3c47eac3 100644 --- a/converter/pbm/pbmtonokia.c +++ b/converter/pbm/pbmtonokia.c @@ -1,231 +1,510 @@ -/* pbmtonokia.c - convert a portable bitmap to Nokia Smart Messaging +/* pbmtonokia.c - convert a PBM image to Nokia Smart Messaging Formats (NOL, NGG, HEX) -** Copyright (C)2001 OMS Open Media System GmbH, Tim Rühsen -** <tim.ruehsen@openmediasystem.de>. -** -** 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. + Copyright information is at end of file. +*/ -History - 07.06.2001 Created - 20.11.2001 Handle Picture Messages - new option -txt to embed text into Picture Messages - new option -net to specify operator network code for - Nokia Operator Logos +#define _BSD_SOURCE /* Make sure strcasecmp() is in string.h */ +#include <string.h> +#include <assert.h> -Notes: - - limited to rows <= 255 and columns <= 255 - - limited to b/w graphics, not animated +#include "pm_c_util.h" +#include "nstring.h" +#include "mallocvar.h" +#include "shhopt.h" +#include "pbm.h" -Testing: - Testing was done with SwissCom SMSC (Switzerland) and IC3S SMSC (Germany). - The data was send with EMI/UCP protocol over TCP/IP. +enum outputFormat { + FMT_HEX_NOL, + FMT_HEX_NGG, + FMT_HEX_NPM, + FMT_NOL, + FMT_NGG, + FMT_NPM +}; - - 7.6.2001: tested with Nokia 3210: 72x14 Operator Logo - - 7.6.2001: tested with Nokia 6210: 72x14 Operator Logo and - 72x14 Group Graphic -Todo: - - more testing - - sendsms compatibility ? - - are -fmt NOL and -fmt NGG working ok? */ +struct cmdlineInfo { + /* All the information the user supplied in the command line, + in a form easy for the program to use. + */ + const char * inputFileName; /* Filename of input files */ + int outputFormat; + const char * networkCode; + const char * txt; /* NULL means unspecified */ +}; -#define _BSD_SOURCE /* Make sure strcasecmp() is in string.h */ -#include <string.h> -#include "nstring.h" -#include "pbm.h" -#define FMT_HEX_NOL 1 -#define FMT_HEX_NGG 2 -#define FMT_HEX_NPM 3 -#define FMT_NOL 4 -#define FMT_NGG 5 - -static void -usage(char *myname) -{ - pm_message("Copyright (C)2001 OMS GmbH"); - pm_message("Contact: Tim Ruehsen <tim.ruehsen@openmediasystem.de>\n"); - pm_usage("[options] [pbmfile]\n" - " Options:\n" - " -fmt <HEX_NOL|HEX_NGG|HEX_NPM|NOL|NGG> " - "Output format (default=HEX_NOL)\n" - " -net <network code> " - "Network code for NOL operator logos\n" - " -txt <text message> " - "Text for NPM picture messages\n"); - - exit(1); +static const char * +uppercase(const char * const subject) { + + char * buffer; + + buffer = malloc(strlen(subject) + 1); + + if (buffer == NULL) + pm_error("Out of memory allocating buffer for uppercasing a " + "%u-character string", strlen(subject)); + else { + unsigned int i; + + i = 0; + while (subject[i]) { + buffer[i] = TOUPPER(subject[i]); + ++i; + } + buffer[i] = '\0'; + } + return buffer; } -int -main(int argc, char *argv[]) -{ - FILE *fp; - bit **image; - unsigned int c; - int argpos, output=FMT_HEX_NOL, rows, cols, row, col, p, it, len; - char header[32], *myname; - char network_code[6+1]; - char *text=NULL; - - if ((myname=strrchr(argv[0],'/'))!=NULL) myname++; else myname=argv[0]; - pbm_init(&argc, argv); - strcpy(network_code, "62F210"); /* default is German D1 net */ - - for(argpos=1;argpos<argc;argpos++) { - if (argv[argpos][0]=='-') { - if (argv[argpos][1]=='-') { - if (argc>argpos+1 && ISDIGIT(argv[argpos+1][0])) - {argpos++;break;} - } else if (STREQ(argv[argpos],"-fmt") && argc>argpos+1) { - ++argpos; - if (!strcasecmp(argv[argpos],"HEX_NOL")) output=FMT_HEX_NOL; - else if (!strcasecmp(argv[argpos],"HEX_NGG")) - output=FMT_HEX_NGG; - else if (!strcasecmp(argv[argpos],"HEX_NPM")) - output=FMT_HEX_NPM; - else if (!strcasecmp(argv[argpos],"NOL")) output=FMT_NOL; - else if (!strcasecmp(argv[argpos],"NGG")) output=FMT_NGG; - else usage(myname); - } else if (STREQ(argv[argpos],"-net") && argc>argpos+1) { - char * const network_code_arg=argv[++argpos]; - unsigned int it; - len=strlen(network_code_arg); - if (len!=6) - pm_error("Network code must be 6 hex-digits long"); - for (it=0;it<strlen(network_code_arg);it++) { - if (!ISXDIGIT(network_code_arg[it])) - pm_error("Network code must contain hex-digits only"); - network_code[it]=TOUPPER(network_code_arg[it]); - } - network_code[it] = '\0'; - } else if (STREQ(argv[argpos],"-txt") && argc>argpos+1) { - text=argv[++argpos]; +static void +parseCommandLine(int argc, char ** argv, + struct cmdlineInfo * const cmdlineP) { +/*---------------------------------------------------------------------------- + Note that the file spec array we return is stored in the storage that + was passed to us as the argv array. +-----------------------------------------------------------------------------*/ + optEntry * option_def; + /* Instructions to optParseOptions3 on how to parse our options. + */ + optStruct3 opt; + + unsigned int option_def_index; + unsigned int fmtSpec, netSpec, txtSpec; + const char * fmtOpt; + const char * netOpt; + + MALLOCARRAY_NOFAIL(option_def, 100); + + option_def_index = 0; /* incremented by OPTENT3 */ + OPTENT3(0, "fmt", OPT_STRING, &fmtOpt, + &fmtSpec, 0); + OPTENT3(0, "net", OPT_STRING, &netOpt, + &netSpec, 0); + OPTENT3(0, "txt", OPT_STRING, &cmdlineP->txt, + &txtSpec, 0); + + opt.opt_table = option_def; + opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ + opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + + optParseOptions3(&argc, argv, opt, sizeof(opt), 0); + /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + + if (fmtSpec) { + if (STRCASEEQ(fmtOpt, "HEX_NOL")) + cmdlineP->outputFormat = FMT_HEX_NOL; + else if (STRCASEEQ(fmtOpt, "HEX_NGG")) + cmdlineP->outputFormat = FMT_HEX_NGG; + else if (STRCASEEQ(fmtOpt, "HEX_NPM")) + cmdlineP->outputFormat = FMT_HEX_NPM; + else if (STRCASEEQ(fmtOpt, "NOL")) + cmdlineP->outputFormat = FMT_NOL; + else if (STRCASEEQ(fmtOpt, "NGG")) + cmdlineP->outputFormat = FMT_NGG; + else if (STRCASEEQ(fmtOpt, "NPM")) + cmdlineP->outputFormat = FMT_NPM; + else + pm_error("-fmt option must be HEX_NGG, HEX_NOL, HEX_NPM, " + "NGG, NOL or NPM. You specified '%s'", fmtOpt); + } else + cmdlineP->outputFormat = FMT_HEX_NOL; + + if (netSpec) { + if (strlen(netOpt) != 6) + pm_error("-net option must be 6 hex digits long. " + "You specified %u characters", strlen(netOpt)); + else if (!strishex(netOpt)) + pm_error("-net option must be hexadecimal. You specified '%s'", + netOpt); + else + cmdlineP->networkCode = uppercase(netOpt); + } else + cmdlineP->networkCode = strdup("62F210"); /* German D1 net */ + + if (!txtSpec) + cmdlineP->txt = NULL; + else if (strlen(cmdlineP->txt) > 120) + pm_error("Text message is longer (%u characters) than " + "the 120 characters allowed by the format.", + strlen(cmdlineP->txt)); + + if (argc-1 == 0) + cmdlineP->inputFileName = "-"; + else if (argc-1 != 1) + pm_error("Program takes zero or one argument (filename). You " + "specified %u", argc-1); + else + cmdlineP->inputFileName = argv[1]; +} + + + +static void +freeCmdline(struct cmdlineInfo const cmdline) { + + strfree(cmdline.networkCode); +} + + + +static void +convertToHexNol(bit ** const image, + unsigned int const cols, + unsigned int const rows, + const char * const networkCode, + FILE * const ofP) { + + unsigned int row; + + /* header */ + fprintf(ofP, "06050415820000%s00%02X%02X01", networkCode, cols, rows); + + /* image */ + for (row = 0; row < rows; ++row) { + unsigned int col; + unsigned int p; + unsigned int c; + + c = 0; + + for (p = 0, col = 0; col < cols; ++col) { + if (image[row][col] == PBM_BLACK) + c |= 0x80 >> p; + if (++p == 8) { + fprintf(ofP, "%02X",c); + p = c = 0; } - else usage(myname); - } else break; + } + if (p > 0) + fprintf(ofP, "%02X", c); } +} - if (argpos==argc) { - image = pbm_readpbm(stdin, &cols, &rows); - } else { - fp=pm_openr(argv[argpos]); - image = pbm_readpbm(fp, &cols, &rows); - pm_close(fp); - } - memset(header,0,sizeof(header)); - switch (output) { - case FMT_HEX_NOL: - /* header */ - printf("06050415820000%s00%02X%02X01",network_code,cols,rows); - - /* image */ - for (row=0;row<rows;row++) { - for (p=c=col=0;col<cols;col++) { - if (image[row][col]==PBM_BLACK) c|=0x80>>p; - if (++p==8) { - printf("%02X",c); - p=c=0; - } +static void +convertToHexNgg(bit ** const image, + unsigned int const cols, + unsigned int const rows, + FILE * const ofP) { + + unsigned int row; + + /* header */ + fprintf(ofP, "0605041583000000%02X%02X01", cols, rows); + + /* image */ + for (row = 0; row < rows; ++row) { + unsigned int col; + unsigned int p; + unsigned int c; + + for (p = 0, c = 0, col = 0; col < cols; ++col) { + if (image[row][col] == PBM_BLACK) + c |= 0x80 >> p; + if (++p == 8) { + fprintf(ofP, "%02X", c); + p = c = 0; } - if (p) printf("%02X",c); } - break; - case FMT_HEX_NGG: - /* header */ - printf("0605041583000000%02X%02X01",cols,rows); - - /* image */ - for (row=0;row<rows;row++) { - for (p=c=col=0;col<cols;col++) { - if (image[row][col]==PBM_BLACK) c|=0x80>>p; - if (++p==8) { - printf("%02X",c); - p=c=0; - } + if (p > 0) + fprintf(ofP, "%02X", c); + } +} + + + + +static void +convertToHexNpm(bit ** const image, + unsigned int const cols, + unsigned int const rows, + const char * const text, + FILE * const ofP) { + + unsigned int row; + + /* header */ + fprintf(ofP, "060504158A0000"); + + /* text */ + if (text) { + size_t const len = strlen(text); + + unsigned int it; + + fprintf(ofP, "00%04X", len); + + for (it = 0; it < len; ++it) + fprintf(ofP, "%02X", text[it]); + } + + /* image */ + fprintf(ofP, "02%04X00%02X%02X01", (cols * rows) / 8 + 4, cols, rows); + + for (row = 0; row < rows; ++row) { + unsigned int col; + unsigned int p; + unsigned int c; + + for (p = 0, c = 0, col = 0; col < cols; ++col) { + if (image[row][col] == PBM_BLACK) + c |= 0x80 >> p; + if (++p == 8) { + fprintf(ofP, "%02X", c); + p = c = 0; } - if (p) printf("%02X",c); } - break; - case FMT_HEX_NPM: - /* header */ - printf("060504158A0000"); + if (p > 0) + fprintf(ofP, "%02X", c); + } +} + - /* text */ - if (text!=NULL) { - printf("00%04X",(len=strlen(text))); - for (it=0;it<len;it++) printf("%02X",text[it]); + +static void +convertToNol(bit ** const image, + unsigned int const cols, + unsigned int const rows, + FILE * const ofP) { + + unsigned int row; + char header[32]; + unsigned int it; + + /* header - this is a hack */ + + header[ 0] = 'N'; + header[ 1] = 'O'; + header[ 2] = 'L'; + header[ 3] = 0; + header[ 4] = 1; + header[ 5] = 0; + header[ 6] = 4; + header[ 7] = 1; + header[ 8] = 1; + header[ 9] = 0; + header[10] = cols; + header[11] = 0; + header[12] = rows; + header[13] = 0; + header[14] = 1; + header[15] = 0; + header[16] = 1; + header[17] = 0; + header[18] = 0x53; + header[19] = 0; + + fwrite(header, 20, 1, ofP); + + /* image */ + for (row = 0; row < rows; ++row) { + unsigned int col; + unsigned int p; + unsigned int c; + + for (p = 0, c = 0, col = 0; col < cols; ++col) { + char const output = image[row][col] == PBM_BLACK ? '1' : '0'; + + putc(output, ofP); } + } - /* image */ - printf("02%04X00%02X%02X01",(cols*rows)/8+4,cols,rows); - for (row=0;row<rows;row++) { - for (p=c=col=0;col<cols;col++) { - if (image[row][col]==PBM_BLACK) c|=0x80>>p; - if (++p==8) { - printf("%02X",c); - p=c=0; - } - } - if (p) printf("%02X",c); + /* padding (to keep gnokii happy) */ + for (it = 0; it < 8 - cols * rows % 8; ++it) + putc('0', ofP); +} + + + + +static void +convertToNgg(bit ** const image, + unsigned int const cols, + unsigned int const rows, + FILE * const ofP) { + + unsigned int row; + char header[32]; + unsigned int it; + + /* header - this is a hack */ + + header[ 0] = 'N'; + header[ 1] = 'G'; + header[ 2] = 'G'; + header[ 3] = 0; + header[ 4] = 1; + header[ 5] = 0; + header[ 6] = cols; + header[ 7] = 0; + header[ 8] = rows; + header[ 9] = 0; + header[10] = 1; + header[11] = 0; + header[12] = 1; + header[13] = 0; + header[14] = 0x4a; + header[15] = 0; + + fwrite(header, 16, 1, ofP); + + /* image */ + + for (row = 0; row < rows; ++row) { + unsigned int col; + unsigned int p; + unsigned int c; + + for (p = 0, c = 0, col = 0; col < cols; ++col) { + char const output = image[row][col] == PBM_BLACK ? '1' : '0'; + + putc(output, ofP); } - break; - case FMT_NOL: - /* header - this is a hack */ - header[0]='N'; - header[1]='O'; - header[2]='L'; - header[4]=header[7]=header[8]=header[14]=header[16]=1; - header[6]=4; - header[10]=cols; - header[12]=rows; - header[18]=0x53; - fwrite(header,20,1,stdout); - - /* image */ - for (row=0;row<rows;row++) { - for (p=c=col=0;col<cols;col++) { - if (image[row][col]==PBM_BLACK) putchar('1'); - else putchar('0'); + } + + /* padding (to keep gnokii happy) */ + for (it = 0; it < 8 - cols * rows % 8; ++it) + putc('0', ofP); +} + + + +static void +convertToNpm(bit ** const image, + unsigned int const cols, + unsigned int const rows, + const char * const text, + FILE * const ofP) { + + unsigned int row; + char header[132]; + size_t len; + + if (text) + len = strlen(text); + else + len = 0; + + /* header and optional text */ + + header[ 0] = 'N'; + header[ 1] = 'P'; + header[ 2] = 'M'; + header[ 3] = 0; + header[ 4] = len; + header[ 5] = 0; + memcpy(&header[5], text, len); + header[ 6 + len] = cols; + header[ 7 + len] = rows; + header[ 8 + len] = 1; + header[ 9 + len] = 1; + header[10 + len] = 0; /* unknown */ + + assert(10 + len < sizeof(header)); + + fwrite(header, 11 + len, 1, ofP); + + /* image: stream of bits, each row padded to a byte boundary + inspired by gnokii/common/gsm-filesystems.c + */ + for (row = 0; row < rows; row++) { + unsigned int byteNumber; + int bitNumber; + char buffer[32]; /* picture messages are (always?) 72 x 28 */ + unsigned int col; + + byteNumber = 0; + bitNumber = 7; + + MEMSZERO(buffer); + + for (col = 0; col < cols; ++col) { + if (image[row][col] == PBM_BLACK) + buffer[byteNumber] |= (1 << bitNumber); + --bitNumber; + if (bitNumber < 0 && col < (cols - 1)) { + bitNumber = 7; + ++byteNumber; } } + fwrite(buffer, byteNumber + 1, 1, ofP); + } +} + + + +int +main(int argc, + char * argv[]) { + + struct cmdlineInfo cmdline; + FILE * ifP; + bit ** bits; + int rows, cols; + + pbm_init(&argc, argv); + + parseCommandLine(argc, argv, &cmdline); + + ifP = pm_openr(cmdline.inputFileName); + bits = pbm_readpbm(ifP, &cols, &rows); + pm_close(ifP); + + switch (cmdline.outputFormat) { + case FMT_HEX_NGG: + convertToHexNgg(bits, cols, rows, stdout); + break; + case FMT_HEX_NOL: + convertToHexNol(bits, cols, rows, cmdline.networkCode, stdout); + break; + case FMT_HEX_NPM: + convertToHexNpm(bits, cols, rows, cmdline.txt, stdout); break; case FMT_NGG: - /* header - this is a hack */ - header[0]='N'; - header[1]='G'; - header[2]='G'; - header[4]=header[10]=header[12]=1; - header[6]=cols; - header[8]=rows; - header[14]=0x4a; - fwrite(header,16,1,stdout); - - /* image */ - for (row=0;row<rows;row++) { - for (p=c=col=0;col<cols;col++) { - if (image[row][col]==PBM_BLACK) putchar('1'); - else putchar('0'); - } - } + convertToNgg(bits, cols, rows, stdout); + break; + case FMT_NOL: + convertToNol(bits, cols, rows, stdout); + break; + case FMT_NPM: + convertToNpm(bits, cols, rows, cmdline.txt, stdout); break; - default: - pm_error("Output format %d not implemented!\n" - "Contact Tim Ruehsen <tim.ruehsen@openmediasystem.de>\n", - output); - return 1; } + +freeCmdline(cmdline); + return 0; } + + +/* Copyright (C)2001 OMS Open Media System GmbH, Tim Rühsen +** <tim.ruehsen@openmediasystem.de>. +** +** 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. + + Created 2001.06.07 + +Notes: + - limited to rows <= 255 and columns <= 255 + - limited to b/w graphics, not animated + +Testing: + Testing was done with SwissCom SMSC (Switzerland) and IC3S SMSC (Germany). + The data was send with EMI/UCP protocol over TCP/IP. + + - 7.6.2001: tested with Nokia 3210: 72x14 Operator Logo + - 7.6.2001: tested with Nokia 6210: 72x14 Operator Logo and + 72x14 Group Graphic +*/ diff --git a/converter/ppm/ppmtobmp.c b/converter/ppm/ppmtobmp.c index 071f3b12..b9ac063e 100644 --- a/converter/ppm/ppmtobmp.c +++ b/converter/ppm/ppmtobmp.c @@ -647,7 +647,7 @@ choose_colortype_bpp(struct cmdline_info const cmdline, pm_error("There are too many colors in the image to " "represent in the\n" "number of bits per pixel you requested: %d.\n" - "You may use Ppmquant to reduce the number of " + "You may use Pnmquant to reduce the number of " "colors in the image.", cmdline.bpp); else diff --git a/converter/ppm/ppmtompeg/Makefile b/converter/ppm/ppmtompeg/Makefile index 5e923fee..6db72ea9 100644 --- a/converter/ppm/ppmtompeg/Makefile +++ b/converter/ppm/ppmtompeg/Makefile @@ -18,11 +18,12 @@ else JPEGLIBX = $(JPEGLIB) endif -INCLUDES = -I$(SRCDIR)/$(SUBDIR)/headers +COMP_INCLUDES = -I$(SRCDIR)/$(SUBDIR)/headers +EXTERN_INCLUDES = ifneq ($(JPEGHDR_DIR),NONE) ifneq ($(JPEGHDR_DIR)x,x) - INCLUDES += -I$(JPEGHDR_DIR) + EXTERN_INCLUDES += -I$(JPEGHDR_DIR) endif endif diff --git a/converter/ppm/xvminitoppm.c b/converter/ppm/xvminitoppm.c index dfc76fcf..8cea1f9d 100644 --- a/converter/ppm/xvminitoppm.c +++ b/converter/ppm/xvminitoppm.c @@ -12,6 +12,7 @@ #include <assert.h> #include <string.h> +#include <errno.h> #include "pm_c_util.h" #include "nstring.h" @@ -61,7 +62,8 @@ getline(FILE * const ifP, rc = fgets(buf, size, ifP); if (rc == NULL) { if (ferror(ifP)) - pm_perror("read error"); + pm_error("read error. fgets() failed, errno=%d (%s)", + errno, strerror(errno)); else pm_error("unexpected EOF"); } |