diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2016-06-26 18:15:09 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2016-06-26 18:15:09 +0000 |
commit | aab4792db8e0adcaf63cf57a1f5e0b18666dae47 (patch) | |
tree | bbfa9c4e12783d2dfd785c4e10964366550e9a60 /converter/other | |
parent | fe14f983ade44baa0794e4ce58a1a5334e46cf68 (diff) | |
download | netpbm-mirror-aab4792db8e0adcaf63cf57a1f5e0b18666dae47.tar.gz netpbm-mirror-aab4792db8e0adcaf63cf57a1f5e0b18666dae47.tar.xz netpbm-mirror-aab4792db8e0adcaf63cf57a1f5e0b18666dae47.zip |
Promote Development to Advanced as Release 10.75.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2803 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
118 files changed, 2777 insertions, 2612 deletions
diff --git a/converter/other/anytopnm b/converter/other/anytopnm index 397faae5..e5de85cc 100755 --- a/converter/other/anytopnm +++ b/converter/other/anytopnm @@ -527,14 +527,18 @@ if [ $# -gt 1 ] ; then "input file name." 1>&2 exit 1 elif [ $# -eq 1 ] ; then - inputFile="$1" + if [ $1 = "--version" -o $1 = "-version" ] ; then + pamtopnm --version ; exit $? + else + inputFile="$1" + fi else - inputFile="-" + inputFile="-" + fi -tempdir="${TMPDIR-/tmp}/anytopnm.$$" -mkdir -m 0700 $tempdir || \ - { echo "Could not create temporary file. Exiting."; exit 1;} +tempdir=$(mktemp -d "${TMPDIR:-/tmp}/anytopnm.XXXXXXXX") || + ( echo "Could not create temporary file. Exiting." 1>&2; exit 1; ) trap 'rm -rf $tempdir' 0 # Take out all spaces diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c index bb49f4a4..c39b4fd7 100644 --- a/converter/other/bmptopnm.c +++ b/converter/other/bmptopnm.c @@ -80,6 +80,19 @@ struct pixelformat { */ }; +typedef struct { + /* These are all encodings of floating point */ + unsigned long x; + unsigned long y; + unsigned long z; +} cieXyz; + +typedef struct { + cieXyz red; + cieXyz grn; + cieXyz blu; +} cieXyzTriple; + struct bmpInfoHeader { enum rowOrder rowOrder; unsigned int cols; @@ -103,6 +116,7 @@ struct bmpInfoHeader { unsigned short cPlanes; BMPCompType compression; struct pixelformat pixelformat; + cieXyzTriple endPoints; }; @@ -208,21 +222,30 @@ GetLong(FILE * const fp) { -typedef struct { - long dummy[12]; -} cieXyzTriple; +static cieXyz +GetCieXyz(FILE * const ifP) { + + cieXyz retval; + + retval.x = GetLong(ifP); + retval.y = GetLong(ifP); + retval.z = GetLong(ifP); + + return retval; +} + + static cieXyzTriple -GetCieXyzTriple(FILE * const fp) { +GetCieXyzTriple(FILE * const ifP) { - cieXyzTriple v; - unsigned int i; + cieXyzTriple retval; - for (i = 0; i < 12; ++i) - if (pm_readlittlelong(fp, &v.dummy[i]) == -1) - pm_error(er_read, ifname); + retval.red = GetCieXyz(ifP); + retval.grn = GetCieXyz(ifP); + retval.blu = GetCieXyz(ifP); - return v; + return retval; } @@ -249,11 +272,7 @@ bmpReadfileheader(FILE * const ifP, unsigned int * const bytesReadP, unsigned int * const offBitsP) { - unsigned short xHotSpot; - unsigned short yHotSpot; unsigned long offBits; - unsigned long int fileSize; - if (GetByte(ifP) != 'B') pm_error("'%s' is not a BMP file. (It doesn't start with 'BM')", @@ -263,27 +282,27 @@ bmpReadfileheader(FILE * const ifP, ifname); - fileSize = GetLong(ifP); /* This is not always reliable. */ - xHotSpot = GetShort(ifP); - yHotSpot = GetShort(ifP); + /* fileSize = */ GetLong(ifP); /* This is not always reliable. */ + /* xHotSpot = */ GetShort(ifP); + /* yHotSpot = */ GetShort(ifP); offBits = GetLong(ifP); *offBitsP = offBits; + assert(BMPlenfileheader() == 14); + *bytesReadP = 14; } static void -readOs2InfoHeader(FILE * const ifP, - struct bmpInfoHeader * const headerP) { +readOs2InfoHeaderRest(FILE * const ifP, + struct bmpInfoHeader * const headerP) { unsigned short colsField, rowsField; unsigned short planesField, bitCountField; - headerP->class = C_OS2; - pm_readlittleshortu(ifP, &colsField); if (colsField == 0) pm_error("Invalid BMP file: says width is zero"); @@ -319,9 +338,6 @@ readOs2InfoHeader(FILE * const ifP, headerP->cBitCount); headerP->compression = BMPCOMP_RGB; - - pm_message("OS/2 BMP, %dx%dx%d", - headerP->cols, headerP->rows, headerP->cBitCount); } @@ -366,12 +382,9 @@ readWindowsBasic40ByteInfoHeader(FILE * const ifP, Return the information from the info header as *headerP. -----------------------------------------------------------------------------*/ - int colorsimportant; /* ColorsImportant value from header */ int colorsused; /* ColorsUsed value from header */ unsigned short planesField, bitCountField; - headerP->class = C_WIN; - headerP->cols = GetLong(ifP); if (headerP->cols == 0) pm_error("Invalid BMP file: says width is zero"); @@ -410,7 +423,7 @@ readWindowsBasic40ByteInfoHeader(FILE * const ifP, /* See comments in bmp.h for info about the definition of the following word and its relationship to the color map size (headerP->cmapsize). */ - colorsimportant = GetLong(ifP); /* ColorsImportant */ + /* colorsimportant = */ GetLong(ifP); /* ColorsImportant */ if (headerP->cBitCount <= 8) { if (colorsused != 0) { @@ -544,7 +557,15 @@ defaultPixelformat(unsigned int const bitCount) { static void readV4InfoHeaderExtension(FILE * const ifP, - struct bmpInfoHeader * const headerP) { + struct bmpInfoHeader * const headerP, + unsigned int * const bytesReadP) { + + unsigned long redMsk, grnMsk, bluMsk, trnMsk; + + redMsk = GetLong(ifP); + grnMsk = GetLong(ifP); + bluMsk = GetLong(ifP); + trnMsk = GetLong(ifP); if (headerP->bitFields) { /* A document from Microsoft says on Windows 95 there is no @@ -552,25 +573,44 @@ readV4InfoHeaderExtension(FILE * const ifP, (5,5,5) or (5,6,5) for 16 bit and (8,8,8) for 32 bit. It calls these RGB555, RGB565, RGB888. */ - headerP->pixelformat.red = bitPositionFromMask(GetLong(ifP)); - headerP->pixelformat.grn = bitPositionFromMask(GetLong(ifP)); - headerP->pixelformat.blu = bitPositionFromMask(GetLong(ifP)); - headerP->pixelformat.trn = bitPositionFromMask(GetLong(ifP)); + headerP->pixelformat.red = bitPositionFromMask(redMsk); + headerP->pixelformat.grn = bitPositionFromMask(grnMsk); + headerP->pixelformat.blu = bitPositionFromMask(bluMsk); + headerP->pixelformat.trn = bitPositionFromMask(trnMsk); computeConventionalBgr(&headerP->pixelformat, headerP->cBitCount); } else headerP->pixelformat = defaultPixelformat(headerP->cBitCount); GetLong(ifP); /* Color space */ - GetCieXyzTriple(ifP); /* Endpoints */ + + headerP->endPoints = GetCieXyzTriple(ifP); /* 36 bytes */ + GetLong(ifP); /* GammaRed */ GetLong(ifP); /* GammaGreen */ GetLong(ifP); /* GammaBlue */ + + *bytesReadP = 68; } static void +readV5InfoHeaderExtension(FILE * const ifP, + struct bmpInfoHeader * const headerP, + unsigned int * const bytesReadP) { + + GetLong(ifP); /* Intent */ + GetLong(ifP); /* ProfileData */ + GetLong(ifP); /* ProfileSize */ + GetLong(ifP); /* Reserved */ + + *bytesReadP = 16; +} + + + +static void defaultV4InfoHeaderExtension(struct bmpInfoHeader * const headerP) { headerP->pixelformat = defaultPixelformat(headerP->cBitCount); @@ -580,9 +620,9 @@ defaultV4InfoHeaderExtension(struct bmpInfoHeader * const headerP) { static void -readWindowsInfoHeader(FILE * const ifP, - unsigned int const cInfoHeaderSize, - struct bmpInfoHeader * const headerP) { +readWindowsInfoHeaderRest(FILE * const ifP, + unsigned int const cInfoHeaderSize, + struct bmpInfoHeader * const headerP) { /* There are 3 major formats of Windows BMP, identified by the 3 info header lengths. The original @@ -590,23 +630,34 @@ readWindowsInfoHeader(FILE * const ifP, new with Windows 95 and NT 4.0. The "V5 header" is 124 bytes and was new with Windows 98 and Windows 2000. */ + unsigned int bytesRead; + readWindowsBasic40ByteInfoHeader(ifP, headerP); - if (cInfoHeaderSize >= 108) - readV4InfoHeaderExtension(ifP, headerP); - else + bytesRead = 40; + + if (cInfoHeaderSize >= BMP_HDRLEN_WIN_V4) { + unsigned int v4BytesRead; + readV4InfoHeaderExtension(ifP, headerP, &v4BytesRead); + bytesRead += v4BytesRead; + + assert(bytesRead == BMP_HDRLEN_WIN_V4); + } else defaultV4InfoHeaderExtension(headerP); - if (cInfoHeaderSize >= 124) { - /* Read off the V5 info header extension. */ - GetLong(ifP); /* Intent */ - GetLong(ifP); /* ProfileData */ - GetLong(ifP); /* ProfileSize */ - GetLong(ifP); /* Reserved */ + if (cInfoHeaderSize >= BMP_HDRLEN_WIN_V5) { + unsigned int v5BytesRead; + readV5InfoHeaderExtension(ifP, headerP, &v5BytesRead); + bytesRead += v5BytesRead; + assert(bytesRead == BMP_HDRLEN_WIN_V5); } - pm_message("Windows BMP, %dx%dx%d", - headerP->cols, headerP->rows, headerP->cBitCount); + for (; bytesRead < cInfoHeaderSize;) { + GetByte(ifP); + ++bytesRead; + } + + assert(bytesRead == cInfoHeaderSize); } @@ -614,38 +665,43 @@ readWindowsInfoHeader(FILE * const ifP, static void bmpReadinfoheader(FILE * const ifP, unsigned int * const bytesReadP, - struct bmpInfoHeader * const headerP) { + struct bmpInfoHeader * const headerP, + const char ** const errorP) { unsigned int const cInfoHeaderSize = GetLong(ifP); - switch (cInfoHeaderSize) { - case 12: - readOs2InfoHeader(ifP, headerP); - break; - case 40: - readWindowsInfoHeader(ifP, cInfoHeaderSize, headerP); - break; - case 108: - pm_error("%s: this is a Version 4 Windows BMP; " - "this program knows only Version 1"); - break; - case 124: - pm_error("%s: this is a Version 5 Windows BMP; " - "this program knows only Version 1"); - break; - default: - pm_error("%s: unknown Info Header size: %u bytes", - ifname, cInfoHeaderSize); - break; + const char * error; + + BMPdetermineclass(cInfoHeaderSize, &headerP->class, &error); + + if (error) { + pm_asprintf(errorP, "Cannot determine the class of BMP from the " + "info header size %u. %s", cInfoHeaderSize, error); + pm_strfree(error); + } else { + switch (headerP->class) { + case BMP_C_WIN_V1: + case BMP_C_WIN_V2: + case BMP_C_WIN_V3: + case BMP_C_WIN_V4: + case BMP_C_WIN_V5: + readWindowsInfoHeaderRest(ifP, cInfoHeaderSize, headerP); + break; + case BMP_C_OS2_1x: + case BMP_C_OS2_2x: + readOs2InfoHeaderRest(ifP, headerP); + break; + } + *errorP = NULL; + *bytesReadP = cInfoHeaderSize; } - *bytesReadP = cInfoHeaderSize; } static void bmpReadColormap(FILE * const ifP, - int const class, + enum bmpClass const class, xel ** const colormapP, unsigned int const cmapsize, unsigned int * const bytesReadP) { @@ -661,36 +717,32 @@ bmpReadColormap(FILE * const ifP, 'class' is the class of BMP image - Windows or OS/2. -----------------------------------------------------------------------------*/ - + xel * const colormap = pnm_allocrow(MAX(1, cmapsize)); + unsigned int i; - - xel * colormap; unsigned int bytesRead; - colormap = pnm_allocrow(MAX(1,cmapsize)); - - bytesRead = 0; /* initial value */ - - for (i = 0; i < cmapsize; ++i) { + for (i = 0, bytesRead = 0; i < cmapsize; ++i) { /* There is a document that says the bytes are ordered R,G,B,Z, but in practice it appears to be the following instead: */ - unsigned int r, g, b; - - b = GetByte(ifP); - g = GetByte(ifP); - r = GetByte(ifP); + unsigned int const b = GetByte(ifP); + unsigned int const g = GetByte(ifP); + unsigned int const r = GetByte(ifP); + + unsigned int j; PNM_ASSIGN(colormap[i], r, g, b); bytesRead += 3; - if (class == C_WIN) { + for (j = 3; j < BMPlenrgb(class); ++j) { GetByte(ifP); bytesRead += 1; } } - *colormapP = colormap; + + *colormapP = colormap; *bytesReadP = bytesRead; } @@ -1199,22 +1251,28 @@ bmpReadraster(FILE * const ifP, static void reportHeader(struct bmpInfoHeader const header, - unsigned int const offBits) { + unsigned int const offBits, + bool const verbose) { - pm_message("BMP image header says:"); - pm_message(" Class of BMP: %s", - header.class == C_WIN ? "Windows" : - header.class == C_OS2 ? "OS/2" : - "???"); - pm_message(" Width: %d pixels", header.cols); - pm_message(" Height: %d pixels", header.rows); - pm_message(" Depth: %d planes", header.cPlanes); - pm_message(" Row order: %s", - header.rowOrder == BOTTOMUP ? "bottom up" : "top down"); - pm_message(" Byte offset of raster within file: %u", offBits); - pm_message(" Bits per pixel in raster: %u", header.cBitCount); - pm_message(" Compression: %s", BMPCompTypeName(header.compression)); - pm_message(" Colors in color map: %u", header.cmapsize); + if (verbose) { + pm_message("BMP image header says:"); + pm_message(" Class of BMP: %s", BMPClassName(header.class)); + pm_message(" Width: %d pixels", header.cols); + pm_message(" Height: %d pixels", header.rows); + pm_message(" Depth: %d planes", header.cPlanes); + pm_message(" Row order: %s", + header.rowOrder == BOTTOMUP ? "bottom up" : "top down"); + pm_message(" Byte offset of raster within file: %u", offBits); + pm_message(" Bits per pixel in raster: %u", header.cBitCount); + pm_message(" Compression: %s", BMPCompTypeName(header.compression)); + pm_message(" Colors in color map: %u", header.cmapsize); + } else { + pm_message("%s BMP, %ux%ux%u", + BMPClassName(header.class), + header.cols, + header.rows, + header.cBitCount); + } } @@ -1352,14 +1410,18 @@ readBmp(FILE * const ifP, } { unsigned int bytesRead; - bmpReadinfoheader(ifP, &bytesRead, &bmpHeader); + const char * error; + bmpReadinfoheader(ifP, &bytesRead, &bmpHeader, &error); + if (error) + pm_error("Failed to read the BMP info header. Image may " + "not be a valid BMP. %s", error); + if (verbose) pm_message("Read %u bytes of header", bytesRead); pos += bytesRead; } - if (verbose) - reportHeader(bmpHeader, offBits); + reportHeader(bmpHeader, offBits, verbose); warnIfOffBitsWrong(bmpHeader, offBits); diff --git a/converter/other/cameratopam/camera.c b/converter/other/cameratopam/camera.c index a1adba95..04a6ed01 100644 --- a/converter/other/cameratopam/camera.c +++ b/converter/other/cameratopam/camera.c @@ -1504,12 +1504,12 @@ get_timestamp(FILE * const ifp) static void parse_exif(FILE * const ifp, int base) { - int entries, tag, type, len, val, save; + int entries, tag, len, val, save; entries = get2(ifp); while (entries--) { tag = get2(ifp); - type = get2(ifp); + /* type = */ get2(ifp); len = get4(ifp); val = get4(ifp); save = ftell(ifp); diff --git a/converter/other/fiasco/binerror.c b/converter/other/fiasco/binerror.c index 77243c64..80a2e461 100644 --- a/converter/other/fiasco/binerror.c +++ b/converter/other/fiasco/binerror.c @@ -7,8 +7,8 @@ * Credits: Modelled after variable argument routines from Jef * Poskanzer's pbmplus package. * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/binerror.h b/converter/other/fiasco/binerror.h index e7ff43c9..4f313aca 100644 --- a/converter/other/fiasco/binerror.h +++ b/converter/other/fiasco/binerror.h @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/buttons.c b/converter/other/fiasco/buttons.c index 82ed18cd..fc54d84a 100644 --- a/converter/other/fiasco/buttons.c +++ b/converter/other/fiasco/buttons.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/buttons.h b/converter/other/fiasco/buttons.h index a09f3423..079715f5 100644 --- a/converter/other/fiasco/buttons.h +++ b/converter/other/fiasco/buttons.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/approx.c b/converter/other/fiasco/codec/approx.c index 5072fae3..d47bac62 100644 --- a/converter/other/fiasco/codec/approx.c +++ b/converter/other/fiasco/codec/approx.c @@ -1,10 +1,10 @@ /* - * approx.c: Approximation of range images with matching pursuit + * approx.c: Approximation of range images with matching pursuit * - * Written by: Ullrich Hafner - * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * Written by: Ullrich Hafner + * + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -34,7 +34,7 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ @@ -52,227 +52,205 @@ typedef struct mp /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, - const word_t *domain_blocks, const coding_t *c); + const word_t *domain_blocks, const coding_t *c); static void matching_pursuit (mp_t *mp, bool_t full_search, real_t price, - unsigned max_edges, int y_state, const range_t *range, - const domain_pool_t *domain_pool, const coeff_t *coeff, - const wfa_t *wfa, const coding_t *c); + unsigned max_edges, int y_state, const range_t *range, + const domain_pool_t *domain_pool, const coeff_t *coeff, + const wfa_t *wfa, const coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t approximate_range (real_t max_costs, real_t price, int max_edges, - int y_state, range_t *range, domain_pool_t *domain_pool, - coeff_t *coeff, const wfa_t *wfa, const coding_t *c) -/* - * Approximate image block 'range' by matching pursuit. This functions - * calls the matching pursuit algorithm several times (with different - * parameters) in order to find the best approximation. Refer to function - * 'matching_pursuit()' for more details about parameters. - * - * Return value: - * approximation costs - */ -{ - mp_t mp; - bool_t success = NO; - - /* - * First approximation attempt: default matching pursuit algorithm. - */ - mp.exclude [0] = NO_EDGE; - matching_pursuit (&mp, c->options.full_search, price, max_edges, - y_state, range, domain_pool, coeff, wfa, c); - - /* - * Next approximation attempt: remove domain block mp->indices [0] - * from domain pool (vector with smallest costs) and run the - * matching pursuit again. - */ - if (c->options.second_domain_block) - { - mp_t tmp_mp = mp; + int y_state, range_t *range, domain_pool_t *domain_pool, + coeff_t *coeff, const wfa_t *wfa, const coding_t *c) { +/*---------------------------------------------------------------------------- + Approximate image block 'range' by matching pursuit. This functions + calls the matching pursuit algorithm several times (with different + parameters) in order to find the best approximation. Refer to function + 'matching_pursuit()' for more details about parameters. + + Return value: approximation costs +-----------------------------------------------------------------------------*/ + mp_t mp; + + /* + * First approximation attempt: default matching pursuit algorithm. + */ + mp.exclude [0] = NO_EDGE; + matching_pursuit(&mp, c->options.full_search, price, max_edges, + y_state, range, domain_pool, coeff, wfa, c); + + /* + * Next approximation attempt: remove domain block mp->indices [0] + * from domain pool (vector with smallest costs) and run the + * matching pursuit again. + */ + if (c->options.second_domain_block) { + mp_t tmp_mp; - tmp_mp.exclude [0] = tmp_mp.indices [0]; - tmp_mp.exclude [1] = NO_EDGE; - - matching_pursuit (&tmp_mp, c->options.full_search, price, max_edges, - y_state, range, domain_pool, coeff, wfa, c); - if (tmp_mp.costs < mp.costs) /* success */ - { - success = YES; - mp = tmp_mp; - } - } - - /* - * Next approximation attempt: check whether some coefficients have - * been quantized to zero. Vectors causing the underflow are - * removed from the domain pool and then the matching pursuit - * algorithm is run again (until underflow doesn't occur anymore). - */ - if (c->options.check_for_underflow) - { - int iteration = -1; - mp_t tmp_mp = mp; - - do - { - int i; - - iteration++; - tmp_mp.exclude [iteration] = NO_EDGE; - - for (i = 0; isdomain (tmp_mp.indices [i]); i++) - if (tmp_mp.weight [i] == 0) - { - tmp_mp.exclude [iteration] = tmp_mp.indices [i]; - break; - } - - if (isdomain (tmp_mp.exclude [iteration])) /* try again */ - { - tmp_mp.exclude [iteration + 1] = NO_EDGE; - - matching_pursuit (&tmp_mp, c->options.full_search, price, - max_edges, y_state, range, domain_pool, - coeff, wfa, c); - if (tmp_mp.costs < mp.costs) /* success */ - { - success = YES; - mp = tmp_mp; - } - } - } while (isdomain (tmp_mp.exclude [iteration]) - && iteration < MAXEDGES - 1); - } - - /* - * Next approximation attempt: check whether some coefficients have - * been quantized to +/- max-value. Vectors causing the overflow are - * removed from the domain pool and then the matching pursuit - * algorithm is run again (until overflow doesn't occur anymore). - */ - if (c->options.check_for_overflow) - { - int iteration = -1; - mp_t tmp_mp = mp; + tmp_mp = mp; /* initial value */ + + tmp_mp.exclude[0] = tmp_mp.indices [0]; + tmp_mp.exclude[1] = NO_EDGE; + + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, + y_state, range, domain_pool, coeff, wfa, c); + if (tmp_mp.costs < mp.costs) /* success */ + mp = tmp_mp; + } + + /* + * Next approximation attempt: check whether some coefficients have + * been quantized to zero. Vectors causing the underflow are + * removed from the domain pool and then the matching pursuit + * algorithm is run again (until underflow doesn't occur anymore). + */ + if (c->options.check_for_underflow) { + mp_t tmp_mp; + int iteration; + + tmp_mp = mp; /* initial value */ + iteration = -1; /* initial value */ - do - { - int i; + do { + int i; + + ++iteration; + tmp_mp.exclude[iteration] = NO_EDGE; + + for (i = 0; isdomain(tmp_mp.indices[i]); ++i) { + if (tmp_mp.weight [i] == 0) { + tmp_mp.exclude[iteration] = tmp_mp.indices [i]; + break; + } + } + if (isdomain (tmp_mp.exclude [iteration])) { + /* try again */ + tmp_mp.exclude [iteration + 1] = NO_EDGE; + + matching_pursuit(&tmp_mp, c->options.full_search, price, + max_edges, y_state, range, domain_pool, + coeff, wfa, c); + if (tmp_mp.costs < mp.costs) /* success */ + mp = tmp_mp; + } + } while (isdomain (tmp_mp.exclude [iteration]) + && iteration < MAXEDGES - 1); + } + + /* + * Next approximation attempt: check whether some coefficients have + * been quantized to +/- max-value. Vectors causing the overflow are + * removed from the domain pool and then the matching pursuit + * algorithm is run again (until overflow doesn't occur anymore). + */ + if (c->options.check_for_overflow) { + mp_t tmp_mp; + int iteration; + + tmp_mp = mp; /* initial value */ + iteration = -1; /* initial value */ + + do { + int i; - iteration++; - tmp_mp.exclude [iteration] = NO_EDGE; - - for (i = 0; isdomain (tmp_mp.indices [i]); i++) - { - rpf_t *rpf = tmp_mp.indices [i] ? coeff->rpf : coeff->dc_rpf; - - if (tmp_mp.weight [i] == btor (rtob (200, rpf), rpf) - || tmp_mp.weight [i] == btor (rtob (-200, rpf), rpf)) - { - tmp_mp.exclude [iteration] = tmp_mp.indices [i]; - break; - } - } + ++iteration; + tmp_mp.exclude[iteration] = NO_EDGE; + + for (i = 0; isdomain (tmp_mp.indices [i]); ++i) { + rpf_t * const rpf = + tmp_mp.indices [i] ? coeff->rpf : coeff->dc_rpf; + + if (tmp_mp.weight [i] == btor (rtob (200, rpf), rpf) + || tmp_mp.weight [i] == btor (rtob (-200, rpf), rpf)) { + tmp_mp.exclude [iteration] = tmp_mp.indices [i]; + break; + } + } - if (isdomain (tmp_mp.exclude [iteration])) /* try again */ - { - tmp_mp.exclude [iteration + 1] = NO_EDGE; - - matching_pursuit (&tmp_mp, c->options.full_search, price, - max_edges, y_state, range, domain_pool, - coeff, wfa, c); - if (tmp_mp.costs < mp.costs) /* success */ - { - success = YES; - mp = tmp_mp; - } - } - } while (isdomain (tmp_mp.exclude [iteration]) - && iteration < MAXEDGES - 1); - } - - /* - * Finally, check whether the best approximation has costs - * smaller than 'max_costs'. - */ - if (mp.costs < max_costs) - { - int edge; - bool_t overflow = NO; - bool_t underflow = NO; - int new_index, old_index; - - new_index = 0; - for (old_index = 0; isdomain (mp.indices [old_index]); old_index++) - if (mp.weight [old_index] != 0) - { - rpf_t *rpf = mp.indices [old_index] ? coeff->rpf : coeff->dc_rpf; - - if (mp.weight [old_index] == btor (rtob (200, rpf), rpf) - || mp.weight [old_index] == btor (rtob (-200, rpf), rpf)) - overflow = YES; - - mp.indices [new_index] = mp.indices [old_index]; - mp.into [new_index] = mp.into [old_index]; - mp.weight [new_index] = mp.weight [old_index]; - new_index++; - } - else - underflow = YES; + if (isdomain(tmp_mp.exclude[iteration])) { + /* try again */ + tmp_mp.exclude[iteration + 1] = NO_EDGE; + + matching_pursuit(&tmp_mp, c->options.full_search, price, + max_edges, y_state, range, domain_pool, + coeff, wfa, c); + if (tmp_mp.costs < mp.costs) /* success */ + mp = tmp_mp; + } + } while (isdomain (tmp_mp.exclude [iteration]) + && iteration < MAXEDGES - 1); + } + + /* + * Finally, check whether the best approximation has costs + * smaller than 'max_costs'. + */ + if (mp.costs < max_costs) { + int edge; + int new_index, old_index; + + new_index = 0; + for (old_index = 0; isdomain (mp.indices[old_index]); ++old_index) { + if (mp.weight [old_index] != 0) { + mp.indices [new_index] = mp.indices [old_index]; + mp.into [new_index] = mp.into [old_index]; + mp.weight [new_index] = mp.weight [old_index]; + ++new_index; + } + } + mp.indices [new_index] = NO_EDGE; + mp.into [new_index] = NO_EDGE; + + /* + * Update of probability models + */ + { + word_t * const domain_blocks = + domain_pool->generate(range->level, y_state, + wfa, + domain_pool->model); + domain_pool->update(domain_blocks, mp.indices, + range->level, y_state, wfa, + domain_pool->model); + coeff->update (mp.weight, mp.into, range->level, coeff); + + Free(domain_blocks); + } - mp.indices [new_index] = NO_EDGE; - mp.into [new_index] = NO_EDGE; - - /* - * Update of probability models - */ - { - word_t *domain_blocks = domain_pool->generate (range->level, y_state, - wfa, - domain_pool->model); - domain_pool->update (domain_blocks, mp.indices, - range->level, y_state, wfa, domain_pool->model); - coeff->update (mp.weight, mp.into, range->level, coeff); - - Free (domain_blocks); - } - - for (edge = 0; isedge (mp.indices [edge]); edge++) - { - range->into [edge] = mp.into [edge]; - range->weight [edge] = mp.weight [edge]; - } - range->into [edge] = NO_EDGE; - range->matrix_bits = mp.matrix_bits; - range->weights_bits = mp.weights_bits; - range->err = mp.err; - } - else - { - range->into [0] = NO_EDGE; - mp.costs = MAXCOSTS; - } + for (edge = 0; isedge (mp.indices [edge]); ++edge) { + range->into [edge] = mp.into [edge]; + range->weight [edge] = mp.weight [edge]; + } + range->into [edge] = NO_EDGE; + range->matrix_bits = mp.matrix_bits; + range->weights_bits = mp.weights_bits; + range->err = mp.err; + } else { + range->into [0] = NO_EDGE; + mp.costs = MAXCOSTS; + } - return mp.costs; + return mp.costs; } + + /***************************************************************************** - local variables + local variables *****************************************************************************/ @@ -310,15 +288,15 @@ static bool_t used [MAXSTATES]; /***************************************************************************** - private code + private code *****************************************************************************/ static void matching_pursuit (mp_t *mp, bool_t full_search, real_t price, - unsigned max_edges, int y_state, const range_t *range, - const domain_pool_t *domain_pool, const coeff_t *coeff, - const wfa_t *wfa, const coding_t *c) + unsigned max_edges, int y_state, const range_t *range, + const domain_pool_t *domain_pool, const coeff_t *coeff, + const wfa_t *wfa, const coding_t *c) /* * Find an approximation of the current 'range' with a linear * combination of vectors of the 'domain_pool'. The linear @@ -339,38 +317,38 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, * No return value. * * Side effects: - * vectors, factors, rate, distortion and costs are stored in 'mp' + * vectors, factors, rate, distortion and costs are stored in 'mp' */ { - unsigned n; /* current vector of the OB */ - int index; /* best fitting domain image */ - unsigned domain; /* counter */ - real_t norm; /* norm of range image */ - real_t additional_bits; /* bits for mc, nd, and tree */ - word_t *domain_blocks; /* current set of domain images */ - const real_t min_norm = 2e-3; /* lower bound of norm */ - unsigned best_n = 0; - unsigned size = size_of_level (range->level); + unsigned n; /* current vector of the OB */ + int index; /* best fitting domain image */ + unsigned domain; /* counter */ + real_t norm; /* norm of range image */ + real_t additional_bits; /* bits for mc, nd, and tree */ + word_t *domain_blocks; /* current set of domain images */ + const real_t min_norm = 2e-3; /* lower bound of norm */ + unsigned best_n = 0; + unsigned size = size_of_level (range->level); /* * Initialize domain pool and inner product arrays */ domain_blocks = domain_pool->generate (range->level, y_state, wfa, - domain_pool->model); + domain_pool->model); for (domain = 0; domain_blocks [domain] >= 0; domain++) { used [domain] = NO; - rem_denominator [domain] /* norm of domain */ - = get_ip_state_state (domain_blocks [domain], domain_blocks [domain], - range->level, c); + rem_denominator [domain] /* norm of domain */ + = get_ip_state_state (domain_blocks [domain], domain_blocks [domain], + range->level, c); if (rem_denominator [domain] / size < min_norm) - used [domain] = YES; /* don't use domains with small norm */ + used [domain] = YES; /* don't use domains with small norm */ else - rem_numerator [domain] /* inner product <s_domain, b> */ - = get_ip_image_state (range->image, range->address, - range->level, domain_blocks [domain], c); + rem_numerator [domain] /* inner product <s_domain, b> */ + = get_ip_image_state (range->image, range->address, + range->level, domain_blocks [domain], c); if (!used [domain] && fabs (rem_numerator [domain]) < min_norm) - used [domain] = YES; + used [domain] = YES; } /* @@ -389,15 +367,15 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, norm += square (c->pixels [range->address * size + n]); additional_bits = range->tree_bits + range->mv_tree_bits - + range->mv_coord_bits + range->nd_tree_bits - + range->nd_weights_bits; + + range->mv_coord_bits + range->nd_tree_bits + + range->nd_weights_bits; mp->err = norm; mp->weights_bits = 0; mp->matrix_bits = domain_pool->bits (domain_blocks, NULL, range->level, - y_state, wfa, domain_pool->model); + y_state, wfa, domain_pool->model); mp->costs = (mp->matrix_bits + mp->weights_bits - + additional_bits) * price + mp->err; + + additional_bits) * price + mp->err; n = 0; do @@ -406,7 +384,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, * Current approximation is: b = d_0 o_0 + ... + d_(n-1) o_(n-1) * with corresponding costs 'range->err + range->bits * p'. * For all remaining state images s_i (used[s_i] == NO) set - * o_n : = s_i - \sum(k = 0, ... , n-1) {(<s_i, o_k> / ||o_k||^2) o_k} + * o_n : = s_i - \sum(k = 0, ... , n-1) {(<s_i, o_k> / ||o_k||^2) o_k} * and try to beat current costs. * Choose that vector for the next orthogonalization step, * which has minimal costs: s_index. @@ -415,235 +393,235 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, real_t min_matrix_bits = 0; real_t min_weights_bits = 0; - real_t min_error = 0; + real_t min_error = 0; real_t min_weight [MAXEDGES]; real_t min_costs = full_search ? MAXCOSTS : mp->costs; for (index = -1, domain = 0; domain_blocks [domain] >= 0; domain++) - if (!used [domain]) - { - real_t matrix_bits, weights_bits; - /* - * To speed up the search through the domain images, - * the costs of using domain image 'domain' as next vector - * can be approximated in a first step: - * improvement of image quality - * <= square (rem_numerator[domain]) / rem_denominator[domain] - */ - { - word_t vectors [MAXEDGES + 1]; - word_t states [MAXEDGES + 1]; - real_t weights [MAXEDGES + 1]; - unsigned i, k; - - for (i = 0, k = 0; k < n; k++) - if (mp->weight [k] != 0) - { - vectors [i] = mp->indices [k]; - states [i] = domain_blocks [vectors [i]]; - weights [i] = mp->weight [k]; - i++; - } - vectors [i] = domain; - states [i] = domain_blocks [domain]; - weights [i] = 0.5; - vectors [i + 1] = -1; - states [i + 1] = -1; - - weights_bits = coeff->bits (weights, states, range->level, - coeff); - matrix_bits = domain_pool->bits (domain_blocks, vectors, - range->level, y_state, - wfa, domain_pool->model); - } - if (((matrix_bits + weights_bits + additional_bits) * price + - mp->err - - square (rem_numerator [domain]) / rem_denominator [domain]) - < min_costs) - { - /* - * 1.) Compute the weights (linear factors) c_i of the - * linear combination - * b = c_0 v_0 + ... + c_(n-1) v_(n-1) + c_n v_'domain' - * Use backward substitution to obtain c_i from the linear - * factors of the lin. comb. b = d_0 o_0 + ... + d_n o_n - * of the corresponding orthogonal vectors {o_0, ..., o_n}. - * Vector o_n of the orthogonal basis is obtained by using - * vector 'v_domain' in step n of the Gram Schmidt - * orthogonalization (see above for definition of o_n). - * Recursive formula for the coefficients c_i: - * c_n := <b, o_n> / ||o_n||^2 - * for i = n - 1, ... , 0: - * c_i := <b, o_i> / ||o_i||^2 + - * \sum (k = i + 1, ... , n){ c_k <v_k, o_i> - * / ||o_i||^2 } - * 2.) Because linear factors are stored with reduced precision - * factor c_i is rounded with the given precision in step i - * of the recursive formula. - */ - - unsigned k; /* counter */ - int l; /* counter */ - real_t m_bits; /* number of matrix bits to store */ - real_t w_bits; /* number of weights bits to store */ - real_t r [MAXEDGES]; /* rounded linear factors */ - real_t f [MAXEDGES]; /* linear factors */ - int v [MAXEDGES]; /* mapping of domains to vectors */ - real_t costs; /* current approximation costs */ - real_t m_err; /* current approximation error */ - - f [n] = rem_numerator [domain] / rem_denominator [domain]; - v [n] = domain; /* corresponding mapping */ - for (k = 0; k < n; k++) - { - f [k] = ip_image_ortho_vector [k] / norm_ortho_vector [k]; - v [k] = mp->indices [k]; - } - - for (l = n; l >= 0; l--) - { - rpf_t *rpf = domain_blocks [v [l]] - ? coeff->rpf : coeff->dc_rpf; - - r [l] = f [l] = btor (rtob (f [l], rpf), rpf); - - for (k = 0; k < (unsigned) l; k++) - f [k] -= f [l] * ip_domain_ortho_vector [v [l]][k] - / norm_ortho_vector [k] ; - } - - /* - * Compute the number of output bits of the linear combination - * and store the weights with reduced precision. The - * resulting linear combination is - * b = r_0 v_0 + ... + r_(n-1) v_(n-1) + r_n v_'domain' - */ - { - word_t vectors [MAXEDGES + 1]; - word_t states [MAXEDGES + 1]; - real_t weights [MAXEDGES + 1]; - int i; - - for (i = 0, k = 0; k <= n; k++) - if (f [k] != 0) - { - vectors [i] = v [k]; - states [i] = domain_blocks [v [k]]; - weights [i] = f [k]; - i++; - } - vectors [i] = -1; - states [i] = -1; - - w_bits = coeff->bits (weights, states, range->level, coeff); - m_bits = domain_pool->bits (domain_blocks, vectors, - range->level, y_state, - wfa, domain_pool->model); - } - - /* - * To compute the approximation error, the corresponding - * linear factors of the linear combination - * b = r_0 o_0 + ... + r_(n-1) o_(n-1) + r_n o_'domain' - * with orthogonal vectors must be computed with following - * formula: - * r_i := r_i + - * \sum (k = i + 1, ... , n) { r_k <v_k, o_i> - * / ||o_i||^2 } - */ - for (l = 0; (unsigned) l <= n; l++) - { - /* - * compute <v_n, o_n> - */ - real_t a; - - a = get_ip_state_state (domain_blocks [v [l]], - domain_blocks [domain], - range->level, c); - for (k = 0; k < n; k++) - a -= ip_domain_ortho_vector [v [l]][k] - / norm_ortho_vector [k] - * ip_domain_ortho_vector [domain][k]; - ip_domain_ortho_vector [v [l]][n] = a; - } - norm_ortho_vector [n] = rem_denominator [domain]; - ip_image_ortho_vector [n] = rem_numerator [domain]; - - for (k = 0; k <= n; k++) - for (l = k + 1; (unsigned) l <= n; l++) - r [k] += ip_domain_ortho_vector [v [l]][k] * r [l] - / norm_ortho_vector [k]; - /* - * Compute approximation error: - * error := ||b||^2 + - * \sum (k = 0, ... , n){r_k^2 ||o_k||^2 - 2 r_k <b, o_k>} - */ - m_err = norm; - for (k = 0; k <= n; k++) - m_err += square (r [k]) * norm_ortho_vector [k] - - 2 * r [k] * ip_image_ortho_vector [k]; - if (m_err < 0) /* TODO: return MAXCOSTS */ - warning ("Negative image norm: %f" - " (current domain: %d, level = %d)", - (double) m_err, domain, range->level); - - costs = (m_bits + w_bits + additional_bits) * price + m_err; - if (costs < min_costs) /* found a better approximation */ - { - index = domain; - min_costs = costs; - min_matrix_bits = m_bits; - min_weights_bits = w_bits; - min_error = m_err; - for (k = 0; k <= n; k++) - min_weight [k] = f [k]; - } - } - } + if (!used [domain]) + { + real_t matrix_bits, weights_bits; + /* + * To speed up the search through the domain images, + * the costs of using domain image 'domain' as next vector + * can be approximated in a first step: + * improvement of image quality + * <= square (rem_numerator[domain]) / rem_denominator[domain] + */ + { + word_t vectors [MAXEDGES + 1]; + word_t states [MAXEDGES + 1]; + real_t weights [MAXEDGES + 1]; + unsigned i, k; + + for (i = 0, k = 0; k < n; k++) + if (mp->weight [k] != 0) + { + vectors [i] = mp->indices [k]; + states [i] = domain_blocks [vectors [i]]; + weights [i] = mp->weight [k]; + i++; + } + vectors [i] = domain; + states [i] = domain_blocks [domain]; + weights [i] = 0.5; + vectors [i + 1] = -1; + states [i + 1] = -1; + + weights_bits = coeff->bits (weights, states, range->level, + coeff); + matrix_bits = domain_pool->bits (domain_blocks, vectors, + range->level, y_state, + wfa, domain_pool->model); + } + if (((matrix_bits + weights_bits + additional_bits) * price + + mp->err - + square (rem_numerator [domain]) / rem_denominator [domain]) + < min_costs) + { + /* + * 1.) Compute the weights (linear factors) c_i of the + * linear combination + * b = c_0 v_0 + ... + c_(n-1) v_(n-1) + c_n v_'domain' + * Use backward substitution to obtain c_i from the linear + * factors of the lin. comb. b = d_0 o_0 + ... + d_n o_n + * of the corresponding orthogonal vectors {o_0, ..., o_n}. + * Vector o_n of the orthogonal basis is obtained by using + * vector 'v_domain' in step n of the Gram Schmidt + * orthogonalization (see above for definition of o_n). + * Recursive formula for the coefficients c_i: + * c_n := <b, o_n> / ||o_n||^2 + * for i = n - 1, ... , 0: + * c_i := <b, o_i> / ||o_i||^2 + + * \sum (k = i + 1, ... , n){ c_k <v_k, o_i> + * / ||o_i||^2 } + * 2.) Because linear factors are stored with reduced precision + * factor c_i is rounded with the given precision in step i + * of the recursive formula. + */ + + unsigned k; /* counter */ + int l; /* counter */ + real_t m_bits; /* number of matrix bits to store */ + real_t w_bits; /* number of weights bits to store */ + real_t r [MAXEDGES]; /* rounded linear factors */ + real_t f [MAXEDGES]; /* linear factors */ + int v [MAXEDGES]; /* mapping of domains to vectors */ + real_t costs; /* current approximation costs */ + real_t m_err; /* current approximation error */ + + f [n] = rem_numerator [domain] / rem_denominator [domain]; + v [n] = domain; /* corresponding mapping */ + for (k = 0; k < n; k++) + { + f [k] = ip_image_ortho_vector [k] / norm_ortho_vector [k]; + v [k] = mp->indices [k]; + } + + for (l = n; l >= 0; l--) + { + rpf_t *rpf = domain_blocks [v [l]] + ? coeff->rpf : coeff->dc_rpf; + + r [l] = f [l] = btor (rtob (f [l], rpf), rpf); + + for (k = 0; k < (unsigned) l; k++) + f [k] -= f [l] * ip_domain_ortho_vector [v [l]][k] + / norm_ortho_vector [k] ; + } + + /* + * Compute the number of output bits of the linear combination + * and store the weights with reduced precision. The + * resulting linear combination is + * b = r_0 v_0 + ... + r_(n-1) v_(n-1) + r_n v_'domain' + */ + { + word_t vectors [MAXEDGES + 1]; + word_t states [MAXEDGES + 1]; + real_t weights [MAXEDGES + 1]; + int i; + + for (i = 0, k = 0; k <= n; k++) + if (f [k] != 0) + { + vectors [i] = v [k]; + states [i] = domain_blocks [v [k]]; + weights [i] = f [k]; + i++; + } + vectors [i] = -1; + states [i] = -1; + + w_bits = coeff->bits (weights, states, range->level, coeff); + m_bits = domain_pool->bits (domain_blocks, vectors, + range->level, y_state, + wfa, domain_pool->model); + } + + /* + * To compute the approximation error, the corresponding + * linear factors of the linear combination + * b = r_0 o_0 + ... + r_(n-1) o_(n-1) + r_n o_'domain' + * with orthogonal vectors must be computed with following + * formula: + * r_i := r_i + + * \sum (k = i + 1, ... , n) { r_k <v_k, o_i> + * / ||o_i||^2 } + */ + for (l = 0; (unsigned) l <= n; l++) + { + /* + * compute <v_n, o_n> + */ + real_t a; + + a = get_ip_state_state (domain_blocks [v [l]], + domain_blocks [domain], + range->level, c); + for (k = 0; k < n; k++) + a -= ip_domain_ortho_vector [v [l]][k] + / norm_ortho_vector [k] + * ip_domain_ortho_vector [domain][k]; + ip_domain_ortho_vector [v [l]][n] = a; + } + norm_ortho_vector [n] = rem_denominator [domain]; + ip_image_ortho_vector [n] = rem_numerator [domain]; + + for (k = 0; k <= n; k++) + for (l = k + 1; (unsigned) l <= n; l++) + r [k] += ip_domain_ortho_vector [v [l]][k] * r [l] + / norm_ortho_vector [k]; + /* + * Compute approximation error: + * error := ||b||^2 + + * \sum (k = 0, ... , n){r_k^2 ||o_k||^2 - 2 r_k <b, o_k>} + */ + m_err = norm; + for (k = 0; k <= n; k++) + m_err += square (r [k]) * norm_ortho_vector [k] + - 2 * r [k] * ip_image_ortho_vector [k]; + if (m_err < 0) /* TODO: return MAXCOSTS */ + warning ("Negative image norm: %f" + " (current domain: %d, level = %d)", + (double) m_err, domain, range->level); + + costs = (m_bits + w_bits + additional_bits) * price + m_err; + if (costs < min_costs) /* found a better approximation */ + { + index = domain; + min_costs = costs; + min_matrix_bits = m_bits; + min_weights_bits = w_bits; + min_error = m_err; + for (k = 0; k <= n; k++) + min_weight [k] = f [k]; + } + } + } - if (index >= 0) /* found a better approximation */ + if (index >= 0) /* found a better approximation */ { - if (min_costs < mp->costs) - { - unsigned k; - - mp->costs = min_costs; - mp->err = min_error; - mp->matrix_bits = min_matrix_bits; - mp->weights_bits = min_weights_bits; - - for (k = 0; k <= n; k++) - mp->weight [k] = min_weight [k]; - - best_n = n + 1; - } - - mp->indices [n] = index; - mp->into [n] = domain_blocks [index]; - - used [index] = YES; - - /* - * Gram-Schmidt orthogonalization step n - */ - orthogonalize (index, n, range->level, min_norm, domain_blocks, c); - n++; - } + if (min_costs < mp->costs) + { + unsigned k; + + mp->costs = min_costs; + mp->err = min_error; + mp->matrix_bits = min_matrix_bits; + mp->weights_bits = min_weights_bits; + + for (k = 0; k <= n; k++) + mp->weight [k] = min_weight [k]; + + best_n = n + 1; + } + + mp->indices [n] = index; + mp->into [n] = domain_blocks [index]; + + used [index] = YES; + + /* + * Gram-Schmidt orthogonalization step n + */ + orthogonalize (index, n, range->level, min_norm, domain_blocks, c); + n++; + } } while (n < max_edges && index >= 0); mp->indices [best_n] = NO_EDGE; mp->costs = (mp->matrix_bits + mp->weights_bits + additional_bits) * price - + mp->err; + + mp->err; Free (domain_blocks); } static void orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, - const word_t *domain_blocks, const coding_t *c) + const word_t *domain_blocks, const coding_t *c) /* * Step 'n' of the Gram-Schmidt orthogonalization procedure: * vector 'index' is orthogonalized with respect to the set @@ -655,8 +633,8 @@ orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, * No return value. * * Side effects: - * The remainder values (numerator and denominator) of - * all 'domain_blocks' are updated. + * The remainder values (numerator and denominator) of + * all 'domain_blocks' are updated. */ { unsigned domain; @@ -676,25 +654,25 @@ orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, for (domain = 0; domain_blocks [domain] >= 0; domain++) if (!used [domain]) { - unsigned k; - real_t tmp = get_ip_state_state (domain_blocks [index], - domain_blocks [domain], level, c); - - for (k = 0; k < n; k++) - tmp -= ip_domain_ortho_vector [domain][k] / norm_ortho_vector [k] - * ip_domain_ortho_vector [index][k]; - ip_domain_ortho_vector [domain][n] = tmp; - rem_denominator [domain] -= square (tmp) / norm_ortho_vector [n]; - rem_numerator [domain] -= ip_image_ortho_vector [n] - / norm_ortho_vector [n] - * ip_domain_ortho_vector [domain][n] ; - - /* - * Exclude vectors with small denominator - */ - if (!used [domain]) - if (rem_denominator [domain] / size_of_level (level) < min_norm) - used [domain] = YES; + unsigned k; + real_t tmp = get_ip_state_state (domain_blocks [index], + domain_blocks [domain], level, c); + + for (k = 0; k < n; k++) + tmp -= ip_domain_ortho_vector [domain][k] / norm_ortho_vector [k] + * ip_domain_ortho_vector [index][k]; + ip_domain_ortho_vector [domain][n] = tmp; + rem_denominator [domain] -= square (tmp) / norm_ortho_vector [n]; + rem_numerator [domain] -= ip_image_ortho_vector [n] + / norm_ortho_vector [n] + * ip_domain_ortho_vector [domain][n] ; + + /* + * Exclude vectors with small denominator + */ + if (!used [domain]) + if (rem_denominator [domain] / size_of_level (level) < min_norm) + used [domain] = YES; } } diff --git a/converter/other/fiasco/codec/approx.h b/converter/other/fiasco/codec/approx.h index c54b78c9..42f1458a 100644 --- a/converter/other/fiasco/codec/approx.h +++ b/converter/other/fiasco/codec/approx.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/bintree.c b/converter/other/fiasco/codec/bintree.c index ddd74e15..b050ab63 100644 --- a/converter/other/fiasco/codec/bintree.c +++ b/converter/other/fiasco/codec/bintree.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/bintree.h b/converter/other/fiasco/codec/bintree.h index cdb80c94..3dc88ac1 100644 --- a/converter/other/fiasco/codec/bintree.h +++ b/converter/other/fiasco/codec/bintree.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/coder.c b/converter/other/fiasco/codec/coder.c index 94e367dd..ce4a24f1 100644 --- a/converter/other/fiasco/codec/coder.c +++ b/converter/other/fiasco/codec/coder.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/coder.h b/converter/other/fiasco/codec/coder.h index c6f4bb7c..2fe81d81 100644 --- a/converter/other/fiasco/codec/coder.h +++ b/converter/other/fiasco/codec/coder.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/coeff.c b/converter/other/fiasco/codec/coeff.c index 0cd64f17..6d33bad5 100644 --- a/converter/other/fiasco/codec/coeff.c +++ b/converter/other/fiasco/codec/coeff.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/coeff.h b/converter/other/fiasco/codec/coeff.h index 118cd0fc..6193e2ee 100644 --- a/converter/other/fiasco/codec/coeff.h +++ b/converter/other/fiasco/codec/coeff.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/control.c b/converter/other/fiasco/codec/control.c index 94c23c83..2ea06052 100644 --- a/converter/other/fiasco/codec/control.c +++ b/converter/other/fiasco/codec/control.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/control.h b/converter/other/fiasco/codec/control.h index f601d8b8..6c0834a1 100644 --- a/converter/other/fiasco/codec/control.h +++ b/converter/other/fiasco/codec/control.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/cwfa.h b/converter/other/fiasco/codec/cwfa.h index 9c4e7fee..dd86fbfc 100644 --- a/converter/other/fiasco/codec/cwfa.h +++ b/converter/other/fiasco/codec/cwfa.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/decoder.c b/converter/other/fiasco/codec/decoder.c index 26284596..8e2855ef 100644 --- a/converter/other/fiasco/codec/decoder.c +++ b/converter/other/fiasco/codec/decoder.c @@ -4,8 +4,8 @@ * Written by: Ullrich Hafner * Michael Unger * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -603,7 +603,6 @@ decode_range (unsigned range_state, unsigned range_label, unsigned range_level, * 'wfa->level_of_state []' is changed */ { - unsigned root_state [3]; /* dummy (for alloc_state_images) */ image_t *state_image; /* regenerated state image */ word_t **images; /* pointer to array of pointers to state images */ @@ -613,7 +612,6 @@ decode_range (unsigned range_state, unsigned range_label, unsigned range_level, enlarge_image (range_level - (wfa->level_of_state [range_state] - 1), FORMAT_4_4_4, -1, wfa); - root_state [0] = range_state; state_image = alloc_image (width_of_level (range_level + 1), height_of_level (range_level + 1), NO, FORMAT_4_4_4); diff --git a/converter/other/fiasco/codec/decoder.h b/converter/other/fiasco/codec/decoder.h index 8cd211e0..7823ab91 100644 --- a/converter/other/fiasco/codec/decoder.h +++ b/converter/other/fiasco/codec/decoder.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/dfiasco.c b/converter/other/fiasco/codec/dfiasco.c index 2fdec573..d45c9e39 100644 --- a/converter/other/fiasco/codec/dfiasco.c +++ b/converter/other/fiasco/codec/dfiasco.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/dfiasco.h b/converter/other/fiasco/codec/dfiasco.h index bcc3c7f9..eed12b6b 100644 --- a/converter/other/fiasco/codec/dfiasco.h +++ b/converter/other/fiasco/codec/dfiasco.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/domain-pool.c b/converter/other/fiasco/codec/domain-pool.c index 7cc3900e..1c14a30c 100644 --- a/converter/other/fiasco/codec/domain-pool.c +++ b/converter/other/fiasco/codec/domain-pool.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/domain-pool.h b/converter/other/fiasco/codec/domain-pool.h index d1488779..a2c46141 100644 --- a/converter/other/fiasco/codec/domain-pool.h +++ b/converter/other/fiasco/codec/domain-pool.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/ip.c b/converter/other/fiasco/codec/ip.c index ade0d916..56b0ae9a 100644 --- a/converter/other/fiasco/codec/ip.c +++ b/converter/other/fiasco/codec/ip.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/ip.h b/converter/other/fiasco/codec/ip.h index e5e4dd65..0c693826 100644 --- a/converter/other/fiasco/codec/ip.h +++ b/converter/other/fiasco/codec/ip.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/motion.c b/converter/other/fiasco/codec/motion.c index 876a2998..0d1fa099 100644 --- a/converter/other/fiasco/codec/motion.c +++ b/converter/other/fiasco/codec/motion.c @@ -4,8 +4,8 @@ * Written by: Ullrich Hafner * Michael Unger * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/motion.h b/converter/other/fiasco/codec/motion.h index 2ea382f7..82d1f1ec 100644 --- a/converter/other/fiasco/codec/motion.h +++ b/converter/other/fiasco/codec/motion.h @@ -4,8 +4,8 @@ * Written by: Ullrich Hafner * Michael Unger * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/mwfa.c b/converter/other/fiasco/codec/mwfa.c index 43a7dae2..0be08a4f 100644 --- a/converter/other/fiasco/codec/mwfa.c +++ b/converter/other/fiasco/codec/mwfa.c @@ -4,8 +4,8 @@ * Written by: Michael Unger * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/mwfa.h b/converter/other/fiasco/codec/mwfa.h index 52f41866..2c1e7c9f 100644 --- a/converter/other/fiasco/codec/mwfa.h +++ b/converter/other/fiasco/codec/mwfa.h @@ -4,8 +4,8 @@ * Written by: Michael Unger * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/options.c b/converter/other/fiasco/codec/options.c index c8e4d2e2..af2cfb48 100644 --- a/converter/other/fiasco/codec/options.c +++ b/converter/other/fiasco/codec/options.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/options.h b/converter/other/fiasco/codec/options.h index 3af6be01..783c41ef 100644 --- a/converter/other/fiasco/codec/options.h +++ b/converter/other/fiasco/codec/options.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/prediction.c b/converter/other/fiasco/codec/prediction.c index e056d10f..e78e5acc 100644 --- a/converter/other/fiasco/codec/prediction.c +++ b/converter/other/fiasco/codec/prediction.c @@ -4,8 +4,8 @@ * Written by: Ullrich Hafner * Michael Unger * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/prediction.h b/converter/other/fiasco/codec/prediction.h index 1068501a..0646dfd8 100644 --- a/converter/other/fiasco/codec/prediction.h +++ b/converter/other/fiasco/codec/prediction.h @@ -4,8 +4,8 @@ * Written by: Ullrich Hafner * Michael Unger * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/subdivide.c b/converter/other/fiasco/codec/subdivide.c index 2ace18e4..348f838a 100644 --- a/converter/other/fiasco/codec/subdivide.c +++ b/converter/other/fiasco/codec/subdivide.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/subdivide.h b/converter/other/fiasco/codec/subdivide.h index b6840e58..bd9cd10e 100644 --- a/converter/other/fiasco/codec/subdivide.h +++ b/converter/other/fiasco/codec/subdivide.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/tiling.c b/converter/other/fiasco/codec/tiling.c index 21e4428a..9af43da0 100644 --- a/converter/other/fiasco/codec/tiling.c +++ b/converter/other/fiasco/codec/tiling.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/tiling.h b/converter/other/fiasco/codec/tiling.h index 2eb04fe0..6668ad8b 100644 --- a/converter/other/fiasco/codec/tiling.h +++ b/converter/other/fiasco/codec/tiling.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/wfa.h b/converter/other/fiasco/codec/wfa.h index 9253affd..59020fc1 100644 --- a/converter/other/fiasco/codec/wfa.h +++ b/converter/other/fiasco/codec/wfa.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/wfalib.c b/converter/other/fiasco/codec/wfalib.c index 61d64d2f..75792627 100644 --- a/converter/other/fiasco/codec/wfalib.c +++ b/converter/other/fiasco/codec/wfalib.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/codec/wfalib.h b/converter/other/fiasco/codec/wfalib.h index 4622fcd2..5c1e0907 100644 --- a/converter/other/fiasco/codec/wfalib.h +++ b/converter/other/fiasco/codec/wfalib.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/display.c b/converter/other/fiasco/display.c index cf160329..d8d32fa6 100644 --- a/converter/other/fiasco/display.c +++ b/converter/other/fiasco/display.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner * * Based on mpeg2decode, (C) 1994, MPEG Software Simulation Group * and mpeg2play, (C) 1994 Stefan Eckart diff --git a/converter/other/fiasco/display.h b/converter/other/fiasco/display.h index 5f30b117..8049456a 100644 --- a/converter/other/fiasco/display.h +++ b/converter/other/fiasco/display.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/doc/README.LIB b/converter/other/fiasco/doc/README.LIB index 4bf8c382..ce8a6b2b 100644 --- a/converter/other/fiasco/doc/README.LIB +++ b/converter/other/fiasco/doc/README.LIB @@ -1,5 +1,5 @@ --------------------------------------------------------------------------- - FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) + FIASCO (Fractal Image And Sequence COdec) Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de>, http://ulli.linuxave.net Version 1.0 diff --git a/converter/other/fiasco/doc/fiasco_c_options_new.3 b/converter/other/fiasco/doc/fiasco_c_options_new.3 index 52efb86c..d873b642 100644 --- a/converter/other/fiasco/doc/fiasco_c_options_new.3 +++ b/converter/other/fiasco/doc/fiasco_c_options_new.3 @@ -429,4 +429,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_coder.3 b/converter/other/fiasco/doc/fiasco_coder.3 index 3d1c6b87..9f2e0f8e 100644 --- a/converter/other/fiasco/doc/fiasco_coder.3 +++ b/converter/other/fiasco/doc/fiasco_coder.3 @@ -103,4 +103,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_d_options_new.3 b/converter/other/fiasco/doc/fiasco_d_options_new.3 index 4294330a..d7f2181a 100644 --- a/converter/other/fiasco/doc/fiasco_d_options_new.3 +++ b/converter/other/fiasco/doc/fiasco_d_options_new.3 @@ -119,4 +119,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_decoder_new.3 b/converter/other/fiasco/doc/fiasco_decoder_new.3 index 05e981a9..5d1d0d08 100644 --- a/converter/other/fiasco/doc/fiasco_decoder_new.3 +++ b/converter/other/fiasco/doc/fiasco_decoder_new.3 @@ -191,4 +191,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_get_error_message.3 b/converter/other/fiasco/doc/fiasco_get_error_message.3 index 09d593fb..ce53e6d9 100644 --- a/converter/other/fiasco/doc/fiasco_get_error_message.3 +++ b/converter/other/fiasco/doc/fiasco_get_error_message.3 @@ -38,4 +38,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_image_new.3 b/converter/other/fiasco/doc/fiasco_image_new.3 index 10625b63..ac3297bf 100644 --- a/converter/other/fiasco/doc/fiasco_image_new.3 +++ b/converter/other/fiasco/doc/fiasco_image_new.3 @@ -92,4 +92,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_options_new.3 b/converter/other/fiasco/doc/fiasco_options_new.3 index 26e070ca..f26586a7 100644 --- a/converter/other/fiasco/doc/fiasco_options_new.3 +++ b/converter/other/fiasco/doc/fiasco_options_new.3 @@ -438,4 +438,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_renderer_new.3 b/converter/other/fiasco/doc/fiasco_renderer_new.3 index b24d8462..8b5e47cd 100644 --- a/converter/other/fiasco/doc/fiasco_renderer_new.3 +++ b/converter/other/fiasco/doc/fiasco_renderer_new.3 @@ -122,4 +122,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/doc/fiasco_set_verbosity.3 b/converter/other/fiasco/doc/fiasco_set_verbosity.3 index 746854b1..3e88399a 100644 --- a/converter/other/fiasco/doc/fiasco_set_verbosity.3 +++ b/converter/other/fiasco/doc/fiasco_set_verbosity.3 @@ -43,4 +43,4 @@ Finite Automata\fP, Ph.D. thesis, Mensch & Buch Verlag, ISBN 3-89820-002-7, October 1999. .SH AUTHOR -Ullrich Hafner <hafner@bigfoot.de> +Ullrich Hafner diff --git a/converter/other/fiasco/fiasco.h b/converter/other/fiasco/fiasco.h index 59367bb8..88f999fc 100644 --- a/converter/other/fiasco/fiasco.h +++ b/converter/other/fiasco/fiasco.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/converter/other/fiasco/fiascotopnm.c b/converter/other/fiasco/fiascotopnm.c index dfba2256..503d023f 100644 --- a/converter/other/fiasco/fiascotopnm.c +++ b/converter/other/fiasco/fiascotopnm.c @@ -4,8 +4,8 @@ * Written by: Ullrich Hafner * Michael Unger * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -361,6 +361,8 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, while (prg_timer (&fps_timer, STOP) < frame_time) /* wait */ ; } +#else + if (frame_time) {/* defeat compiler warning */} #endif /* not X_DISPLAY_MISSING */ } free (filename); diff --git a/converter/other/fiasco/input/basis.c b/converter/other/fiasco/input/basis.c index 4a748f61..aa371ea1 100644 --- a/converter/other/fiasco/input/basis.c +++ b/converter/other/fiasco/input/basis.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/basis.h b/converter/other/fiasco/input/basis.h index fa26bca2..e2242198 100644 --- a/converter/other/fiasco/input/basis.h +++ b/converter/other/fiasco/input/basis.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/matrices.c b/converter/other/fiasco/input/matrices.c index 47cde1aa..388855ea 100644 --- a/converter/other/fiasco/input/matrices.c +++ b/converter/other/fiasco/input/matrices.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/matrices.h b/converter/other/fiasco/input/matrices.h index ba8fd9bf..6d1cef15 100644 --- a/converter/other/fiasco/input/matrices.h +++ b/converter/other/fiasco/input/matrices.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/mc.c b/converter/other/fiasco/input/mc.c index 070d839e..2d4a073d 100644 --- a/converter/other/fiasco/input/mc.c +++ b/converter/other/fiasco/input/mc.c @@ -4,8 +4,8 @@ * written by: Michael Unger * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/mc.h b/converter/other/fiasco/input/mc.h index 1e14d287..9d9d714d 100644 --- a/converter/other/fiasco/input/mc.h +++ b/converter/other/fiasco/input/mc.h @@ -4,8 +4,8 @@ * written by: Michael Unger * Ullrich Hafner - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/nd.c b/converter/other/fiasco/input/nd.c index 1a68bfbf..52d48e61 100644 --- a/converter/other/fiasco/input/nd.c +++ b/converter/other/fiasco/input/nd.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/nd.h b/converter/other/fiasco/input/nd.h index 2c2fff4b..0fe06cf1 100644 --- a/converter/other/fiasco/input/nd.h +++ b/converter/other/fiasco/input/nd.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c index e6e2d7e8..862fec39 100644 --- a/converter/other/fiasco/input/read.c +++ b/converter/other/fiasco/input/read.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/read.h b/converter/other/fiasco/input/read.h index d0d0ee13..1f59f103 100644 --- a/converter/other/fiasco/input/read.h +++ b/converter/other/fiasco/input/read.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/tree.c b/converter/other/fiasco/input/tree.c index e3e7117e..0ac2b6ae 100644 --- a/converter/other/fiasco/input/tree.c +++ b/converter/other/fiasco/input/tree.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/tree.h b/converter/other/fiasco/input/tree.h index e4b5f2d8..f743ee98 100644 --- a/converter/other/fiasco/input/tree.h +++ b/converter/other/fiasco/input/tree.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/weights.c b/converter/other/fiasco/input/weights.c index 15c35731..8a1e8899 100644 --- a/converter/other/fiasco/input/weights.c +++ b/converter/other/fiasco/input/weights.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/input/weights.h b/converter/other/fiasco/input/weights.h index 1e2285a9..36cea5c2 100644 --- a/converter/other/fiasco/input/weights.h +++ b/converter/other/fiasco/input/weights.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/arith.c b/converter/other/fiasco/lib/arith.c index dc35d1d1..825d4757 100644 --- a/converter/other/fiasco/lib/arith.c +++ b/converter/other/fiasco/lib/arith.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/arith.h b/converter/other/fiasco/lib/arith.h index 744eb9d7..04297eb5 100644 --- a/converter/other/fiasco/lib/arith.h +++ b/converter/other/fiasco/lib/arith.h @@ -1,8 +1,8 @@ /* * arith.h * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/bit-io.c b/converter/other/fiasco/lib/bit-io.c index 1bfef598..fdcd70b9 100644 --- a/converter/other/fiasco/lib/bit-io.c +++ b/converter/other/fiasco/lib/bit-io.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/bit-io.h b/converter/other/fiasco/lib/bit-io.h index d37cc47c..08029824 100644 --- a/converter/other/fiasco/lib/bit-io.h +++ b/converter/other/fiasco/lib/bit-io.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/dither.c b/converter/other/fiasco/lib/dither.c index accd9dd6..669bb16c 100644 --- a/converter/other/fiasco/lib/dither.c +++ b/converter/other/fiasco/lib/dither.c @@ -3,8 +3,8 @@ * * Adapted by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -713,15 +713,11 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, word_t *cbptr, *crptr; /* pointer to chroma bands */ word_t *yptr; /* pointers to lumincance band */ int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; - unsigned int *r_table, *g_table, *b_table; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; Cb_b_tab = private->Cb_b_tab; Cb_g_tab = private->Cb_g_tab; - r_table = private->r_table; - g_table = private->g_table; - b_table = private->b_table; yptr = image->pixels [Y]; cbptr = image->pixels [Cb]; crptr = image->pixels [Cr]; @@ -1044,9 +1040,7 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, { unsigned int *dst; /* pointer to dithered pixels */ word_t *src; /* current pixel of frame */ - unsigned int *y_table; - y_table = private->y_table; dst = (unsigned int *) out; src = image->pixels [GRAY]; @@ -1164,15 +1158,11 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, word_t *cbptr, *crptr; /* pointer to chroma bands */ word_t *yptr; /* pointers to lumincance band */ int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; - unsigned int *r_table, *g_table, *b_table; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; Cb_b_tab = private->Cb_b_tab; Cb_g_tab = private->Cb_g_tab; - r_table = private->r_table; - g_table = private->g_table; - b_table = private->b_table; yptr = image->pixels [Y]; cbptr = image->pixels [Cb]; crptr = image->pixels [Cr]; @@ -1495,9 +1485,7 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, { unsigned int *dst; /* pointer to dithered pixels */ word_t *src; /* current pixel of frame */ - unsigned int *y_table; - y_table = private->y_table; dst = (unsigned int *) out; src = image->pixels [GRAY]; diff --git a/converter/other/fiasco/lib/dither.h b/converter/other/fiasco/lib/dither.h index 71f9d3c3..767bca28 100644 --- a/converter/other/fiasco/lib/dither.h +++ b/converter/other/fiasco/lib/dither.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/error.c b/converter/other/fiasco/lib/error.c index ee3afe1f..aeb6eaf9 100644 --- a/converter/other/fiasco/lib/error.c +++ b/converter/other/fiasco/lib/error.c @@ -7,8 +7,8 @@ * Credits: Modelled after variable argument routines from Jef * Poskanzer's pbmplus package. * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner "int dummy = " change to int dummy; dummy =" for Netpbm to avoid unused variable warning. @@ -64,118 +64,107 @@ jmp_buf env; *****************************************************************************/ void -set_error (const char *format, ...) -/* - * Set error text to given string. - */ -{ - va_list args; - unsigned len = 0; - const char *str = format; +set_error(const char *format, ...) { +/*---------------------------------------------------------------------------- + Set error text to given string. +-----------------------------------------------------------------------------*/ + va_list args; + unsigned len; + const char * str; + + len = 0; /* initial value */ + str = format; /* initial value */ + + VA_START (args, format); + + len = strlen (format); + while ((str = strchr (str, '%'))) { + ++str; + if (*str == 's') { + char * const vstring = va_arg (args, char *); + len += strlen(vstring); + } else if (*str == 'd') { + va_arg (args, int); + len += 10; + } else if (*str == 'c') { + va_arg (args, int); + len += 1; + } else + return; + ++str; + } + va_end(args); + + VA_START(args, format); + + if (error_message) + Free(error_message); + error_message = Calloc(len, sizeof (char)); - VA_START (args, format); - - len = strlen (format); - while ((str = strchr (str, '%'))) - { - str++; - if (*str == 's') - { - char *vstring = va_arg (args, char *); - len += strlen (vstring); - } - else if (*str == 'd') - { - int dummy; - dummy = va_arg (args, int); - len += 10; - } - else if (*str == 'c') - { - int dummy; - dummy = va_arg (args, int); - len += 1; - } - else - return; - str++; - } - va_end(args); + vsprintf(error_message, format, args); - VA_START (args, format); + va_end(args); +} - if (error_message) - Free (error_message); - error_message = Calloc (len, sizeof (char)); - - vsprintf (error_message, format, args); - va_end (args); -} void -error (const char *format, ...) -/* - * Set error text to given string. - */ -{ - va_list args; - unsigned len = 0; - const char *str = format; +error(const char *format, ...) { +/*---------------------------------------------------------------------------- + Set error text to given string. + -----------------------------------------------------------------------------*/ + va_list args; + unsigned len; + const char * str; - VA_START (args, format); - - len = strlen (format); - while ((str = strchr (str, '%'))) - { - str++; - if (*str == 's') - { - char *vstring = va_arg (args, char *); - len += strlen (vstring); - } - else if (*str == 'd') - { - int dummy; - dummy = va_arg (args, int); - len += 10; - } - else if (*str == 'c') - { - int dummy; - dummy = va_arg (args, int); - len += 1; - } - else - { + len = 0; /* initial value */ + str = &format[0]; /* initial value */ + + VA_START (args, format); + + len = strlen (format); + while ((str = strchr (str, '%'))) { + ++str; + if (*str == 's') { + char * const vstring = va_arg (args, char *); + len += strlen(vstring); + } else if (*str == 'd') { + va_arg (args, int); + len += 10; + } else if (*str == 'c') { + va_arg (args, int); + len += 1; + } else { #if HAVE_SETJMP_H - longjmp (env, 1); -#else /* not HAVE_SETJMP_H */ - exit (1); -#endif /* HAVE_SETJMP_H */ - }; + longjmp(env, 1); +#else + exit(1); +#endif + }; - str++; - } - va_end(args); + ++str; + } + va_end(args); - VA_START (args, format); + VA_START(args, format); - if (error_message) - Free (error_message); - error_message = Calloc (len, sizeof (char)); + if (error_message) + Free(error_message); + error_message = Calloc(len, sizeof (char)); - vsprintf (error_message, format, args); + vsprintf(error_message, format, args); - va_end (args); + va_end(args); #if HAVE_SETJMP_H - longjmp (env, 1); -#else /* not HAVE_SETJMP_H */ - exit (1); -#endif /* HAVE_SETJMP_H */ + longjmp(env, 1); +#else + exit(1); +#endif } + + const char * fiasco_get_error_message (void) /* diff --git a/converter/other/fiasco/lib/error.h b/converter/other/fiasco/lib/error.h index 288b25f4..4159ccd2 100644 --- a/converter/other/fiasco/lib/error.h +++ b/converter/other/fiasco/lib/error.h @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ #ifndef ERROR_H_INCLUDED diff --git a/converter/other/fiasco/lib/image.c b/converter/other/fiasco/lib/image.c index fa3b2db5..a700fe88 100644 --- a/converter/other/fiasco/lib/image.c +++ b/converter/other/fiasco/lib/image.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/image.h b/converter/other/fiasco/lib/image.h index 00978526..a87a3c05 100644 --- a/converter/other/fiasco/lib/image.h +++ b/converter/other/fiasco/lib/image.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/list.c b/converter/other/fiasco/lib/list.c index bb4efae1..b67ff4b8 100644 --- a/converter/other/fiasco/lib/list.c +++ b/converter/other/fiasco/lib/list.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/list.h b/converter/other/fiasco/lib/list.h index db7c08b2..68577dfd 100644 --- a/converter/other/fiasco/lib/list.h +++ b/converter/other/fiasco/lib/list.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/macros.h b/converter/other/fiasco/lib/macros.h index 9968110a..0bc80e7c 100644 --- a/converter/other/fiasco/lib/macros.h +++ b/converter/other/fiasco/lib/macros.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/misc.c b/converter/other/fiasco/lib/misc.c index 782ed1e9..c5629c5c 100644 --- a/converter/other/fiasco/lib/misc.c +++ b/converter/other/fiasco/lib/misc.c @@ -6,8 +6,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/misc.h b/converter/other/fiasco/lib/misc.h index 28fd8b5a..6f643b7a 100644 --- a/converter/other/fiasco/lib/misc.h +++ b/converter/other/fiasco/lib/misc.h @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/rpf.c b/converter/other/fiasco/lib/rpf.c index 84c1f9b6..e6ff6e09 100644 --- a/converter/other/fiasco/lib/rpf.c +++ b/converter/other/fiasco/lib/rpf.c @@ -1,10 +1,10 @@ /* - * rpf.c: Conversion of float to reduced precision format values + * rpf.c: Conversion of float to reduced precision format values * - * Written by: Stefan Frank - * Richard Krampfl - * Ullrich Hafner - * + * Written by: Stefan Frank + * Richard Krampfl + * Ullrich Hafner + * * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> */ @@ -18,6 +18,7 @@ #include "pm_config.h" #include "config.h" +#include "mallocvar.h" #include "types.h" #include "macros.h" @@ -26,39 +27,37 @@ #include "misc.h" #include "rpf.h" -/* - * CAUTION: The IEEE float format must be used by your compiler, - * or all following code is void! - */ +int const RPF_ZERO = -1; -#if BYTE_ORDER == BIG_ENDIAN -/* - * Big-Endian Architecture (e.g. SUN, Motorola) - * Memory representation of integer 0x00112233 is 00,11,22,33 - */ +/***************************************************************************** -enum real_bytes {BYTE_0, BYTE_1, BYTE_2, BYTE_3}; + private code + +*****************************************************************************/ -#else -/* - * Little-Endian Architecture (e.g. Intel, VAX, Alpha) - * Memory representation of integer 0x00112233 is 33,22,11,00 - */ -enum real_bytes {BYTE_3, BYTE_2, BYTE_1, BYTE_0}; +typedef struct { + double fraction; + int exponent; +} FracExp; -#endif -const int RPF_ZERO = -1; -/***************************************************************************** +static FracExp +fracExpFromDouble(double const x) { + + FracExp retval; + + retval.fraction = frexp(x, &retval.exponent); + + return retval; +} + - private code - -*****************************************************************************/ int -rtob (real_t f, const rpf_t *rpf) +rtob (real_t const f, + const rpf_t * const rpfP) /* * Convert real number 'f' into fixed point format. * The real number in [-'range'; +'range'] is scaled to [-1 ; +1]. @@ -66,111 +65,98 @@ rtob (real_t f, const rpf_t *rpf) * packed into one integer. * * Return value: - * real value in reduced precision format + * real value in reduced precision format */ { - unsigned int mantissa; - int exponent, sign; - union - { - float f; - unsigned char c[4]; - } v; /* conversion dummy */ - - f /= rpf->range; /* scale f to [-1,+1] */ - v.f = f; - - /* - * Extract mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) - */ - - mantissa = ((((v.c[BYTE_1] & 127) << 8 ) | v.c[BYTE_2]) << 8) | v.c[BYTE_3]; - exponent = (((v.c[BYTE_0] & 127) << 1) | (v.c[BYTE_1] & 128 ? 1 : 0)) - 126; - sign = v.c[BYTE_0] & 128 ? 1 : 0; - - /* - * Generate reduced precision mantissa. - */ - mantissa >>= 1; /* shift 1 into from left */ - mantissa |= (1 << 22); - if (exponent > 0) - mantissa <<= exponent; - else - mantissa >>= -exponent; + /* + * Extract mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) + */ + + double const normalized = f / rpfP->range; + /* 'f' scaled to [-1,+1] */ + FracExp const fracExp = fracExpFromDouble(normalized); + unsigned int const signedMantissa = + (unsigned int) (fracExp.fraction * (1<<23)); + + unsigned int mantissa; + unsigned int sign; /* 0 for positive; 1 for negative */ + + if (signedMantissa < 0) { + mantissa = -signedMantissa; + sign = 1; + } else { + mantissa = +signedMantissa; + sign = 0; + } + + /* + * Generate reduced precision mantissa. + */ + if (fracExp.exponent > 0) + mantissa <<= fracExp.exponent; + else + mantissa >>= -fracExp.exponent; + + mantissa >>= (23 - rpfP->mantissa_bits - 1); + + mantissa += 1; /* Round last bit. */ + mantissa >>= 1; - mantissa >>= (23 - rpf->mantissa_bits - 1); - - mantissa += 1; /* Round last bit. */ - mantissa >>= 1; - - if (mantissa == 0) /* close to zero */ - return RPF_ZERO; - else if (mantissa >= (1U << rpf->mantissa_bits)) /* overflow */ - return sign; - else - return ((mantissa & ((1U << rpf->mantissa_bits) - 1)) << 1) | sign; + if (mantissa == 0) /* close to zero */ + return RPF_ZERO; + else if (mantissa >= (1U << rpfP->mantissa_bits)) /* overflow */ + return sign; + else + return ((mantissa & ((1U << rpfP->mantissa_bits) - 1)) << 1) | sign; } + + float -btor (int binary, const rpf_t *rpf) +btor (int const binary, + const rpf_t * const rpfP) /* * Convert value 'binary' in reduced precision format to a real value. - * For more information refer to function lin_rtob() above. + * For more information refer to function rtob() above. * * Return value: - * converted value + * converted value */ { - unsigned int mantissa; - int sign, exponent; - union - { - float f; - unsigned char c[4]; - } value; - - if (binary == RPF_ZERO) - return 0; - - if (binary < 0 || binary >= 1 << (rpf->mantissa_bits + 1)) - error ("Reduced precision format: value %d out of range.", binary); - - /* - * Restore IEEE float format: - * mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) - */ + unsigned int mantissa; + float sign; + float f; + + if (binary == RPF_ZERO) + return 0; + + if (binary < 0 || binary >= 1 << (rpfP->mantissa_bits + 1)) + error ("Reduced precision format: value %d out of range.", binary); + + /* + * Restore IEEE float format: + * mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) + */ - sign = binary & 1; - mantissa = (binary & ((1 << (rpf->mantissa_bits + 1)) - 1)) >> 1; - mantissa <<= (23 - rpf->mantissa_bits); - exponent = 0; - - if (mantissa == 0) - { - value.f = (sign ? -1.0 : 1.0); - } - else - { - while (!(mantissa & (1 << 22))) /* normalize mantissa */ - { - exponent--; - mantissa <<= 1; - } - mantissa <<= 1; - - value.c[BYTE_0] = (sign << 7) | ((exponent + 126) >> 1); - value.c[BYTE_1] = (((exponent + 126) & 1) << 7) - | ((mantissa >> 16) & 127); - value.c[BYTE_2] = (mantissa >> 8) & 255; - value.c[BYTE_3] = mantissa & 255; - } + sign = (binary & 0x1) == 0 ? 1.0 : -1.0; + mantissa = (binary & ((0x1 << (rpfP->mantissa_bits + 1)) - 1)) >> 1; + mantissa <<= (23 - rpfP->mantissa_bits); + + if (mantissa == 0) + f = sign; + else + f = sign * (float) mantissa / 8388608; - return value.f * rpf->range; /* expand [ -1 ; +1 ] to - [ -range ; +range ] */ + return f * rpfP->range; /* expand [ -1 ; +1 ] to + [ -range ; +range ] */ } + + + rpf_t * -alloc_rpf (unsigned mantissa, fiasco_rpf_range_e range) +alloc_rpf (unsigned const mantissa, + fiasco_rpf_range_e const range) /* * Reduced precision format constructor. * Allocate memory for the rpf_t structure. @@ -180,45 +166,47 @@ alloc_rpf (unsigned mantissa, fiasco_rpf_range_e range) * returned. * * Return value - * pointer to the new rpf structure + * pointer to the new rpf structure */ { - rpf_t *rpf = Calloc (1, sizeof (rpf_t)); + rpf_t * rpfP; + + MALLOCVAR(rpfP); - if (mantissa < 2) - { - warning (_("Size of RPF mantissa has to be in the interval [2,8]. " - "Using minimum value 2.\n")); - mantissa = 2; - } - else if (mantissa > 8) - { - warning (_("Size of RPF mantissa has to be in the interval [2,8]. " - "Using maximum value 8.\n")); - mantissa = 2; - } - - rpf->mantissa_bits = mantissa; - rpf->range_e = range; - switch (range) - { - case FIASCO_RPF_RANGE_0_75: - rpf->range = 0.75; - break; - case FIASCO_RPF_RANGE_1_50: - rpf->range = 1.50; - break; - case FIASCO_RPF_RANGE_2_00: - rpf->range = 2.00; - break; - case FIASCO_RPF_RANGE_1_00: - rpf->range = 1.00; - break; - default: - warning (_("Invalid RPF range specified. Using default value 1.0.")); - rpf->range = 1.00; - rpf->range_e = FIASCO_RPF_RANGE_1_00; - break; - } - return rpf; + if (mantissa < 2) { + warning (_("Size of RPF mantissa has to be in the interval [2,8]. " + "Using minimum value 2.\n")); + rpfP->mantissa_bits = 2; + } else if (mantissa > 8) { + warning (_("Size of RPF mantissa has to be in the interval [2,8]. " + "Using maximum value 8.\n")); + rpfP->mantissa_bits = 2; + } else + rpfP->mantissa_bits = mantissa; + + switch (range) { + case FIASCO_RPF_RANGE_0_75: + rpfP->range = 0.75; + rpfP->range_e = range; + break; + case FIASCO_RPF_RANGE_1_50: + rpfP->range = 1.50; + rpfP->range_e = range; + break; + case FIASCO_RPF_RANGE_2_00: + rpfP->range = 2.00; + rpfP->range_e = range; + break; + case FIASCO_RPF_RANGE_1_00: + rpfP->range = 1.00; + rpfP->range_e = range; + break; + default: + warning (_("Invalid RPF range specified. Using default value 1.0.")); + rpfP->range = 1.00; + rpfP->range_e = FIASCO_RPF_RANGE_1_00; + break; + } + return rpfP; } + diff --git a/converter/other/fiasco/lib/rpf.h b/converter/other/fiasco/lib/rpf.h index ba3ff6be..e543f855 100644 --- a/converter/other/fiasco/lib/rpf.h +++ b/converter/other/fiasco/lib/rpf.h @@ -5,8 +5,8 @@ * Richard Krampfl * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/types.h b/converter/other/fiasco/lib/types.h index 16d8028c..02e40a90 100644 --- a/converter/other/fiasco/lib/types.h +++ b/converter/other/fiasco/lib/types.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/matrices.c b/converter/other/fiasco/output/matrices.c index 01189669..7dc0e6d9 100644 --- a/converter/other/fiasco/output/matrices.c +++ b/converter/other/fiasco/output/matrices.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* NETPBM: When you call delta_encoding() with last_domain < 4, it diff --git a/converter/other/fiasco/output/matrices.h b/converter/other/fiasco/output/matrices.h index f880fef8..44671496 100644 --- a/converter/other/fiasco/output/matrices.h +++ b/converter/other/fiasco/output/matrices.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/mc.c b/converter/other/fiasco/output/mc.c index afff586b..d048bef5 100644 --- a/converter/other/fiasco/output/mc.c +++ b/converter/other/fiasco/output/mc.c @@ -4,8 +4,8 @@ * Written by: Michael Unger * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/mc.h b/converter/other/fiasco/output/mc.h index b7843fd8..cacddfe7 100644 --- a/converter/other/fiasco/output/mc.h +++ b/converter/other/fiasco/output/mc.h @@ -4,8 +4,8 @@ * Written by: Michael Unger * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/nd.c b/converter/other/fiasco/output/nd.c index a09ff762..65a85467 100644 --- a/converter/other/fiasco/output/nd.c +++ b/converter/other/fiasco/output/nd.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/nd.h b/converter/other/fiasco/output/nd.h index 600b3d73..01a37838 100644 --- a/converter/other/fiasco/output/nd.h +++ b/converter/other/fiasco/output/nd.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/tree.c b/converter/other/fiasco/output/tree.c index 0056d7dd..2eae2df9 100644 --- a/converter/other/fiasco/output/tree.c +++ b/converter/other/fiasco/output/tree.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/tree.h b/converter/other/fiasco/output/tree.h index 6f8a3800..50fe2279 100644 --- a/converter/other/fiasco/output/tree.h +++ b/converter/other/fiasco/output/tree.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/weights.c b/converter/other/fiasco/output/weights.c index 5aa17674..0203fef0 100644 --- a/converter/other/fiasco/output/weights.c +++ b/converter/other/fiasco/output/weights.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/weights.h b/converter/other/fiasco/output/weights.h index 271203ad..f22bd9f8 100644 --- a/converter/other/fiasco/output/weights.h +++ b/converter/other/fiasco/output/weights.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/write.c b/converter/other/fiasco/output/write.c index e6185ad3..d6faee26 100644 --- a/converter/other/fiasco/output/write.c +++ b/converter/other/fiasco/output/write.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/output/write.h b/converter/other/fiasco/output/write.h index a3ede1f4..6bdc2f1b 100644 --- a/converter/other/fiasco/output/write.h +++ b/converter/other/fiasco/output/write.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/params.c b/converter/other/fiasco/params.c index afacbada..14f1529e 100644 --- a/converter/other/fiasco/params.c +++ b/converter/other/fiasco/params.c @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -325,8 +325,17 @@ parseargs (param_t *usr_params, NO, sys_path, usr_file_name); else if (streq (params [param_index].name, "version")) { - fprintf (stderr, "%s " VERSION "\n", argv [0]); - exit (2); + fprintf (stderr, "%s " VERSION "\n", argv [0]); + { + /* Kludge for standard Netpbm version announcement */ + char * modified_argv[2]; + int argc; + modified_argv[0] = argv[0]; + modified_argv[1] = (char *) "--version"; + argc = 2; + pm_proginit(&argc, (const char **) modified_argv); + } + exit (2); } else if (streq (params [param_index].name, "verbose")) fiasco_set_verbosity ( diff --git a/converter/other/fiasco/params.h b/converter/other/fiasco/params.h index 810a9ff0..a1164cf7 100644 --- a/converter/other/fiasco/params.h +++ b/converter/other/fiasco/params.h @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/pnmtofiasco.c b/converter/other/fiasco/pnmtofiasco.c index eebd09a9..e2656c71 100644 --- a/converter/other/fiasco/pnmtofiasco.c +++ b/converter/other/fiasco/pnmtofiasco.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/system.fiascorc b/converter/other/fiasco/system.fiascorc index 86ff2da2..77d60603 100644 --- a/converter/other/fiasco/system.fiascorc +++ b/converter/other/fiasco/system.fiascorc @@ -3,8 +3,8 @@ # # Written by: Ullrich Hafner # -# This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) -# Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> +# This file is part of FIASCO (Fractal Image And Sequence COdec) +# Copyright (C) 1994-2000 Ullrich Hafner # # $Date: 2000/06/25 16:38:01 $ diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c b/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c index 91ce6c51..a9463a57 100644 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c +++ b/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c @@ -110,16 +110,6 @@ * __END_OF_JASPER_LICENSE__ */ -/* - * JP2 Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - #include "jasper/jas_image.h" #include "jasper/jas_stream.h" #include "jasper/jas_math.h" @@ -130,520 +120,548 @@ #include "jp2_cod.h" #include "jp2_dec.h" -#define JP2_VALIDATELEN (JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK)) - -static jp2_dec_t *jp2_dec_create(void); -static void jp2_dec_destroy(jp2_dec_t *dec); -static int jp2_getcs(jp2_colr_t *colr); -static int jp2_getct(int colorspace, int type, int assoc); -static int fromiccpcs(int cs); - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -jas_image_t *jp2_decode(jas_stream_t *in, char *optstr) -{ - jp2_box_t *box; - int found; - jas_image_t *image; - jp2_dec_t *dec; - bool samedtype; - int dtype; - int i; - jp2_cmap_t *cmapd; - jp2_pclr_t *pclrd; - jp2_cdef_t *cdefd; - int channo; - int newcmptno; - int_fast32_t *lutents; - jp2_cmapent_t *cmapent; - unsigned char *iccp; - int cs; - - dec = 0; - box = 0; - image = 0; - - if (!(dec = jp2_dec_create())) { - goto error; - } - - /* Get the first box. This should be a JP box. */ - if (!(box = jp2_box_get(in))) { - jas_eprintf("error: cannot get box\n"); - goto error; - } - if (box->type != JP2_BOX_JP) { - jas_eprintf("error: expecting signature box\n"); - goto error; - } - if (box->data.jp.magic != JP2_JP_MAGIC) { - jas_eprintf("incorrect magic number\n"); - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Get the second box. This should be a FTYP box. */ - if (!(box = jp2_box_get(in))) { - goto error; - } - if (box->type != JP2_BOX_FTYP) { - jas_eprintf("expecting file type box\n"); - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Get more boxes... */ - found = 0; - while ((box = jp2_box_get(in))) { - if (jas_getdbglevel() >= 1) { - fprintf(stderr, "box type %s\n", box->info->name); - } - switch (box->type) { - case JP2_BOX_JP2C: - found = 1; - break; - case JP2_BOX_IHDR: - if (!dec->ihdr) { - dec->ihdr = box; - box = 0; - } - break; - case JP2_BOX_BPCC: - if (!dec->bpcc) { - dec->bpcc = box; - box = 0; - } - break; - case JP2_BOX_CDEF: - if (!dec->cdef) { - dec->cdef = box; - box = 0; - } - break; - case JP2_BOX_PCLR: - if (!dec->pclr) { - dec->pclr = box; - box = 0; - } - break; - case JP2_BOX_CMAP: - if (!dec->cmap) { - dec->cmap = box; - box = 0; - } - break; - case JP2_BOX_COLR: - if (!dec->colr) { - dec->colr = box; - box = 0; - } - break; - } - if (box) { - jp2_box_destroy(box); - box = 0; - } - if (found) { - break; - } - } - - if (!found) { - jas_eprintf("error: no code stream found\n"); - goto error; - } - - if (!(dec->image = jpc_decode(in, optstr))) { - jas_eprintf("error: cannot decode code stream\n"); - goto error; - } - - /* An IHDR box must be present. */ - if (!dec->ihdr) { - jas_eprintf("error: missing IHDR box\n"); - goto error; - } - - /* Does the number of components indicated in the IHDR box match - the value specified in the code stream? */ - if (dec->ihdr->data.ihdr.numcmpts != jas_image_numcmpts(dec->image)) { - jas_eprintf("warning: number of components mismatch\n"); - } - - /* At least one component must be present. */ - if (!jas_image_numcmpts(dec->image)) { - jas_eprintf("error: no components\n"); - goto error; - } - - /* Determine if all components have the same data type. */ - samedtype = true; - dtype = jas_image_cmptdtype(dec->image, 0); - for (i = 1; i < jas_image_numcmpts(dec->image); ++i) { - if (jas_image_cmptdtype(dec->image, i) != dtype) { - samedtype = false; - break; - } - } - - /* Is the component data type indicated in the IHDR box consistent - with the data in the code stream? */ - if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) || - (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) { - jas_eprintf("warning: component data type mismatch\n"); - } - - /* Can we handle the compression type? */ - if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) { - jas_eprintf("error: not capable of this compression type\n"); - goto error; - } - - if (dec->bpcc) { - /* Is the number of components indicated in the BPCC box - consistent with the code stream data? */ - if (dec->bpcc->data.bpcc.numcmpts != jas_image_numcmpts( - dec->image)) { - jas_eprintf("warning: number of components mismatch\n"); - } - /* Is the component data type information indicated in the BPCC - box consistent with the code stream data? */ - if (!samedtype) { - for (i = 0; i < jas_image_numcmpts(dec->image); ++i) { - if (jas_image_cmptdtype(dec->image, i) != JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) { - jas_eprintf("warning: component data type mismatch\n"); - } - } - } else { - jas_eprintf("warning: superfluous BPCC box\n"); - } - } - - /* A COLR box must be present. */ - if (!dec->colr) { - jas_eprintf("error: no COLR box\n"); - goto error; - } - - switch (dec->colr->data.colr.method) { - case JP2_COLR_ENUM: - jas_image_setcolorspace(dec->image, jp2_getcs(&dec->colr->data.colr)); - break; - case JP2_COLR_ICC: - if (dec->colr->data.colr.iccplen < 128) { - abort(); - } - iccp = dec->colr->data.colr.iccp; - cs = (iccp[16] << 24) | (iccp[17] << 16) | (iccp[18] << 8) | - iccp[19]; - if (jas_getdbglevel() > 1) - jas_eprintf("ICC Profile CS %08x\n", cs); - jas_image_setcolorspace(dec->image, fromiccpcs(cs)); - break; - } - - /* If a CMAP box is present, a PCLR box must also be present. */ - if (dec->cmap && !dec->pclr) { - jas_eprintf("warning: missing PCLR box or superfluous CMAP box\n"); - jp2_box_destroy(dec->cmap); - dec->cmap = 0; - } - - /* If a CMAP box is not present, a PCLR box must not be present. */ - if (!dec->cmap && dec->pclr) { - jas_eprintf("warning: missing CMAP box or superfluous PCLR box\n"); - jp2_box_destroy(dec->pclr); - dec->pclr = 0; - } - - /* Determine the number of channels (which is essentially the number - of components after any palette mappings have been applied). */ - dec->numchans = dec->cmap ? dec->cmap->data.cmap.numchans : jas_image_numcmpts(dec->image); - - /* Perform a basic sanity check on the CMAP box if present. */ - if (dec->cmap) { - for (i = 0; i < dec->numchans; ++i) { - /* Is the component number reasonable? */ - if (dec->cmap->data.cmap.ents[i].cmptno >= jas_image_numcmpts(dec->image)) { - jas_eprintf("error: invalid component number in CMAP box\n"); - goto error; - } - /* Is the LUT index reasonable? */ - if (dec->cmap->data.cmap.ents[i].pcol >= dec->pclr->data.pclr.numchans) { - jas_eprintf("error: invalid CMAP LUT index\n"); - goto error; - } - } - } - - /* Allocate space for the channel-number to component-number LUT. */ - if (!(dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)))) { - jas_eprintf("error: no memory\n"); - goto error; - } - - if (!dec->cmap) { - for (i = 0; i < dec->numchans; ++i) { - dec->chantocmptlut[i] = i; - } - } else { - cmapd = &dec->cmap->data.cmap; - pclrd = &dec->pclr->data.pclr; - cdefd = &dec->cdef->data.cdef; - for (channo = 0; channo < cmapd->numchans; ++channo) { - cmapent = &cmapd->ents[channo]; - if (cmapent->map == JP2_CMAP_DIRECT) { - dec->chantocmptlut[channo] = channo; - } else if (cmapent->map == JP2_CMAP_PALETTE) { - lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t)); - for (i = 0; i < pclrd->numlutents; ++i) { - lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans]; - } - newcmptno = jas_image_numcmpts(dec->image); - jas_image_depalettize(dec->image, cmapent->cmptno, pclrd->numlutents, lutents, JP2_BPCTODTYPE(pclrd->bpc[cmapent->pcol]), newcmptno); - dec->chantocmptlut[channo] = newcmptno; - jas_free(lutents); -#if 0 - if (dec->cdef) { - cdefent = jp2_cdef_lookup(cdefd, channo); - if (!cdefent) { - abort(); - } - jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_colorspace(dec->image), cdefent->type, cdefent->assoc)); - } else { - jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_colorspace(dec->image), 0, channo + 1)); - } -#endif - } - } - } - - /* Mark all components as being of unknown type. */ - - for (i = 0; i < jas_image_numcmpts(dec->image); ++i) { - jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN); - } - - /* Determine the type of each component. */ - if (dec->cdef) { - for (i = 0; i < dec->numchans; ++i) { - jas_image_setcmpttype(dec->image, - dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo], - jp2_getct(jas_image_colorspace(dec->image), - dec->cdef->data.cdef.ents[i].type, dec->cdef->data.cdef.ents[i].assoc)); - } - } else { - for (i = 0; i < dec->numchans; ++i) { - jas_image_setcmpttype(dec->image, dec->chantocmptlut[i], - jp2_getct(jas_image_colorspace(dec->image), 0, i + 1)); - } - } - - /* Delete any components that are not of interest. */ - for (i = jas_image_numcmpts(dec->image) - 1; i >= 0; --i) { - if (jas_image_cmpttype(dec->image, i) == JAS_IMAGE_CT_UNKNOWN) { - jas_image_delcmpt(dec->image, i); - } - } - - /* Ensure that some components survived. */ - if (!jas_image_numcmpts(dec->image)) { - jas_eprintf("error: no components\n"); - goto error; - } - - /* Prevent the image from being destroyed later. */ - image = dec->image; - dec->image = 0; - - jp2_dec_destroy(dec); - - return image; +#define JP2_VALIDATELEN (JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK)) -error: - if (box) { - jp2_box_destroy(box); - } - if (dec) { - jp2_dec_destroy(dec); - } - return 0; + + +static jp2_dec_t * +jp2_dec_create(void) { + + jp2_dec_t *dec; + + dec = jas_malloc(sizeof(jp2_dec_t)); + if (dec) { + dec->ihdr = 0; + dec->bpcc = 0; + dec->cdef = 0; + dec->pclr = 0; + dec->image = 0; + dec->chantocmptlut = 0; + dec->cmap = 0; + dec->colr = 0; + } + return dec; } -int jp2_validate(jas_stream_t *in) -{ - char buf[JP2_VALIDATELEN]; - int i; - int n; - - assert(JAS_STREAM_MAXPUTBACK >= JP2_VALIDATELEN); - - /* Read the validation data (i.e., the data used for detecting - the format). */ - if ((n = jas_stream_read(in, buf, JP2_VALIDATELEN)) < 0) { - return -1; - } - - /* Put the validation data back onto the stream, so that the - stream position will not be changed. */ - for (i = n - 1; i >= 0; --i) { - if (jas_stream_ungetc(in, buf[i]) == EOF) { - return -1; - } - } - - /* Did we read enough data? */ - if (n < JP2_VALIDATELEN) { - return -1; - } - - /* Is the box type correct? */ - if (((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]) != - JP2_BOX_JP) - { - return -1; - } - - return 0; + + +static void +jp2_dec_destroy(jp2_dec_t *dec) { + + if (dec->ihdr) + jp2_box_destroy(dec->ihdr); + + if (dec->bpcc) + jp2_box_destroy(dec->bpcc); + + if (dec->cdef) + jp2_box_destroy(dec->cdef); + + if (dec->pclr) + jp2_box_destroy(dec->pclr); + + if (dec->image) + jas_image_destroy(dec->image); + + if (dec->cmap) + jp2_box_destroy(dec->cmap); + + if (dec->colr) + jp2_box_destroy(dec->colr); + + if (dec->chantocmptlut) + jas_free(dec->chantocmptlut); + + jas_free(dec); } -static jp2_dec_t *jp2_dec_create(void) -{ - jp2_dec_t *dec; - - if (!(dec = jas_malloc(sizeof(jp2_dec_t)))) { - return 0; - } - dec->ihdr = 0; - dec->bpcc = 0; - dec->cdef = 0; - dec->pclr = 0; - dec->image = 0; - dec->chantocmptlut = 0; - dec->cmap = 0; - dec->colr = 0; - return dec; + + +static int +jp2_getct(int colorspace, int type, int assoc) { + + if (type == 1 && assoc == 0) + return JAS_IMAGE_CT_OPACITY; + + if (type == 0 && assoc >= 1 && assoc <= 65534) { + switch (colorspace) { + case JAS_IMAGE_CS_RGB: + switch (assoc) { + case JP2_CDEF_RGB_R: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_R); + break; + case JP2_CDEF_RGB_G: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_G); + break; + case JP2_CDEF_RGB_B: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_B); + break; + } + break; + case JAS_IMAGE_CS_YCBCR: + switch (assoc) { + case JP2_CDEF_YCBCR_Y: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_Y); + break; + case JP2_CDEF_YCBCR_CB: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CB); + break; + case JP2_CDEF_YCBCR_CR: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CR); + break; + } + break; + case JAS_IMAGE_CS_GRAY: + switch (assoc) { + case JP2_CDEF_GRAY_Y: + return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y); + break; + } + break; +#if 0 + case JAS_IMAGE_CS_ICC: +#endif + default: + return JAS_IMAGE_CT_COLOR(assoc - 1); + break; + } + } + return JAS_IMAGE_CT_UNKNOWN; } -static void jp2_dec_destroy(jp2_dec_t *dec) -{ - if (dec->ihdr) { - jp2_box_destroy(dec->ihdr); - } - if (dec->bpcc) { - jp2_box_destroy(dec->bpcc); - } - if (dec->cdef) { - jp2_box_destroy(dec->cdef); - } - if (dec->pclr) { - jp2_box_destroy(dec->pclr); - } - if (dec->image) { - jas_image_destroy(dec->image); - } - if (dec->cmap) { - jp2_box_destroy(dec->cmap); - } - if (dec->colr) { - jp2_box_destroy(dec->colr); - } - if (dec->chantocmptlut) { - jas_free(dec->chantocmptlut); - } - jas_free(dec); + + +static int +jp2_getcs(jp2_colr_t *colr) { + + if (colr->method == JP2_COLR_ENUM) { + switch (colr->csid) { + case JP2_COLR_SRGB: + return JAS_IMAGE_CS_RGB; + break; + case JP2_COLR_SYCC: + return JAS_IMAGE_CS_YCBCR; + break; + case JP2_COLR_SGRAY: + return JAS_IMAGE_CS_GRAY; + break; + } + } + return JAS_IMAGE_CS_UNKNOWN; } +static int +fromiccpcs(int cs) { + + switch (cs) { + case ICC_CS_RGB: + return JAS_IMAGE_CS_RGB; + break; + case ICC_CS_YCBCR: + return JAS_IMAGE_CS_YCBCR; + break; + case ICC_CS_GRAY: + return JAS_IMAGE_CS_GRAY; + break; + } + return JAS_IMAGE_CS_UNKNOWN; +} -static int jp2_getct(int colorspace, int type, int assoc) -{ - if (type == 1 && assoc == 0) { - return JAS_IMAGE_CT_OPACITY; - } - if (type == 0 && assoc >= 1 && assoc <= 65534) { - switch (colorspace) { - case JAS_IMAGE_CS_RGB: - switch (assoc) { - case JP2_CDEF_RGB_R: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_R); - break; - case JP2_CDEF_RGB_G: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_G); - break; - case JP2_CDEF_RGB_B: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_B); - break; - } - break; - case JAS_IMAGE_CS_YCBCR: - switch (assoc) { - case JP2_CDEF_YCBCR_Y: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_Y); - break; - case JP2_CDEF_YCBCR_CB: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CB); - break; - case JP2_CDEF_YCBCR_CR: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CR); - break; - } - break; - case JAS_IMAGE_CS_GRAY: - switch (assoc) { - case JP2_CDEF_GRAY_Y: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y); - break; - } - break; +jas_image_t * +jp2_decode(jas_stream_t *in, char *optstr) { + + jp2_box_t *box; + int found; + jas_image_t *image; + jp2_dec_t *dec; + bool samedtype; + int dtype; + int i; + jp2_cmap_t *cmapd; + jp2_pclr_t *pclrd; + int channo; + int newcmptno; + int_fast32_t *lutents; + jp2_cmapent_t *cmapent; + unsigned char *iccp; + int cs; + + dec = 0; + box = 0; + image = 0; + + if (!(dec = jp2_dec_create())) { + goto error; + } + + /* Get the first box. This should be a JP box. */ + if (!(box = jp2_box_get(in))) { + jas_eprintf("error: cannot get box\n"); + goto error; + } + if (box->type != JP2_BOX_JP) { + jas_eprintf("error: expecting signature box\n"); + goto error; + } + if (box->data.jp.magic != JP2_JP_MAGIC) { + jas_eprintf("incorrect magic number\n"); + goto error; + } + jp2_box_destroy(box); + box = 0; + + /* Get the second box. This should be a FTYP box. */ + if (!(box = jp2_box_get(in))) { + goto error; + } + if (box->type != JP2_BOX_FTYP) { + jas_eprintf("expecting file type box\n"); + goto error; + } + jp2_box_destroy(box); + box = 0; + + /* Get more boxes... */ + found = 0; + while ((box = jp2_box_get(in))) { + if (jas_getdbglevel() >= 1) { + fprintf(stderr, "box type %s\n", box->info->name); + } + switch (box->type) { + case JP2_BOX_JP2C: + found = 1; + break; + case JP2_BOX_IHDR: + if (!dec->ihdr) { + dec->ihdr = box; + box = 0; + } + break; + case JP2_BOX_BPCC: + if (!dec->bpcc) { + dec->bpcc = box; + box = 0; + } + break; + case JP2_BOX_CDEF: + if (!dec->cdef) { + dec->cdef = box; + box = 0; + } + break; + case JP2_BOX_PCLR: + if (!dec->pclr) { + dec->pclr = box; + box = 0; + } + break; + case JP2_BOX_CMAP: + if (!dec->cmap) { + dec->cmap = box; + box = 0; + } + break; + case JP2_BOX_COLR: + if (!dec->colr) { + dec->colr = box; + box = 0; + } + break; + } + if (box) { + jp2_box_destroy(box); + box = 0; + } + if (found) { + break; + } + } + + if (!found) { + jas_eprintf("error: no code stream found\n"); + goto error; + } + + if (!(dec->image = jpc_decode(in, optstr))) { + jas_eprintf("error: cannot decode code stream\n"); + goto error; + } + + /* An IHDR box must be present. */ + if (!dec->ihdr) { + jas_eprintf("error: missing IHDR box\n"); + goto error; + } + + /* Does the number of components indicated in the IHDR box match + the value specified in the code stream? */ + if (dec->ihdr->data.ihdr.numcmpts != jas_image_numcmpts(dec->image)) { + jas_eprintf("warning: number of components mismatch\n"); + } + + /* At least one component must be present. */ + if (!jas_image_numcmpts(dec->image)) { + jas_eprintf("error: no components\n"); + goto error; + } + + /* Determine if all components have the same data type. */ + samedtype = true; + dtype = jas_image_cmptdtype(dec->image, 0); + for (i = 1; i < jas_image_numcmpts(dec->image); ++i) { + if (jas_image_cmptdtype(dec->image, i) != dtype) { + samedtype = false; + break; + } + } + + /* Is the component data type indicated in the IHDR box consistent + with the data in the code stream? */ + if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) || + (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) { + jas_eprintf("warning: component data type mismatch\n"); + } + + /* Can we handle the compression type? */ + if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) { + jas_eprintf("error: not capable of this compression type\n"); + goto error; + } + + if (dec->bpcc) { + /* Is the number of components indicated in the BPCC box + consistent with the code stream data? */ + if (dec->bpcc->data.bpcc.numcmpts != jas_image_numcmpts( + dec->image)) { + jas_eprintf("warning: number of components mismatch\n"); + } + /* Is the component data type information indicated in the BPCC + box consistent with the code stream data? */ + if (!samedtype) { + for (i = 0; i < jas_image_numcmpts(dec->image); ++i) { + if (jas_image_cmptdtype(dec->image, i) != + JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) { + jas_eprintf("warning: component data type mismatch\n"); + } + } + } else { + jas_eprintf("warning: superfluous BPCC box\n"); + } + } + + /* A COLR box must be present. */ + if (!dec->colr) { + jas_eprintf("error: no COLR box\n"); + goto error; + } + + switch (dec->colr->data.colr.method) { + case JP2_COLR_ENUM: + jas_image_setcolorspace(dec->image, jp2_getcs(&dec->colr->data.colr)); + break; + case JP2_COLR_ICC: + if (dec->colr->data.colr.iccplen < 128) { + abort(); + } + iccp = dec->colr->data.colr.iccp; + cs = (iccp[16] << 24) | (iccp[17] << 16) | (iccp[18] << 8) | + iccp[19]; + if (jas_getdbglevel() > 1) + jas_eprintf("ICC Profile CS %08x\n", cs); + jas_image_setcolorspace(dec->image, fromiccpcs(cs)); + break; + } + + /* If a CMAP box is present, a PCLR box must also be present. */ + if (dec->cmap && !dec->pclr) { + jas_eprintf("warning: missing PCLR box or superfluous CMAP box\n"); + jp2_box_destroy(dec->cmap); + dec->cmap = 0; + } + + /* If a CMAP box is not present, a PCLR box must not be present. */ + if (!dec->cmap && dec->pclr) { + jas_eprintf("warning: missing CMAP box or superfluous PCLR box\n"); + jp2_box_destroy(dec->pclr); + dec->pclr = 0; + } + + /* Determine the number of channels (which is essentially the number + of components after any palette mappings have been applied). */ + dec->numchans = dec->cmap ? + dec->cmap->data.cmap.numchans : + jas_image_numcmpts(dec->image); + + /* Perform a basic sanity check on the CMAP box if present. */ + if (dec->cmap) { + for (i = 0; i < dec->numchans; ++i) { + /* Is the component number reasonable? */ + if (dec->cmap->data.cmap.ents[i].cmptno >= + jas_image_numcmpts(dec->image)) { + jas_eprintf("error: invalid component number in CMAP box\n"); + goto error; + } + /* Is the LUT index reasonable? */ + if (dec->cmap->data.cmap.ents[i].pcol >= + dec->pclr->data.pclr.numchans) { + jas_eprintf("error: invalid CMAP LUT index\n"); + goto error; + } + } + } + + /* Allocate space for the channel-number to component-number LUT. */ + dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)); + if (!dec->chantocmptlut) { + jas_eprintf("error: no memory\n"); + goto error; + } + + if (!dec->cmap) { + for (i = 0; i < dec->numchans; ++i) { + dec->chantocmptlut[i] = i; + } + } else { + cmapd = &dec->cmap->data.cmap; + pclrd = &dec->pclr->data.pclr; + for (channo = 0; channo < cmapd->numchans; ++channo) { + cmapent = &cmapd->ents[channo]; + if (cmapent->map == JP2_CMAP_DIRECT) { + dec->chantocmptlut[channo] = channo; + } else if (cmapent->map == JP2_CMAP_PALETTE) { + lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t)); + for (i = 0; i < pclrd->numlutents; ++i) { + lutents[i] = + pclrd->lutdata[cmapent->pcol + i * pclrd->numchans]; + } + newcmptno = jas_image_numcmpts(dec->image); + jas_image_depalettize( + dec->image, cmapent->cmptno, pclrd->numlutents, lutents, + JP2_BPCTODTYPE(pclrd->bpc[cmapent->pcol]), newcmptno); + dec->chantocmptlut[channo] = newcmptno; + jas_free(lutents); #if 0 - case JAS_IMAGE_CS_ICC: + if (dec->cdef) { + jp2_cdef_t * const cdefd = &dec->cdef->data.cdef; + cdefent = jp2_cdef_lookup(cdefd, channo); + if (!cdefent) { + abort(); + } + jas_image_setcmpttype( + dec->image, newcmptno, + jp2_getct(jas_image_colorspace(dec->image), + cdefent->type, cdefent->assoc)); + } else { + jas_image_setcmpttype( + dec->image, newcmptno, + jp2_getct(jas_image_colorspace(dec->image), + 0, + channo + 1)); + } #endif - default: - return JAS_IMAGE_CT_COLOR(assoc - 1); - break; - } - } - return JAS_IMAGE_CT_UNKNOWN; -} + } + } + } + + /* Mark all components as being of unknown type. */ + + for (i = 0; i < jas_image_numcmpts(dec->image); ++i) { + jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN); + } + + /* Determine the type of each component. */ + if (dec->cdef) { + unsigned int i; + for (i = 0; i < dec->numchans; ++i) { + jas_image_setcmpttype( + dec->image, + dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo], + jp2_getct(jas_image_colorspace(dec->image), + dec->cdef->data.cdef.ents[i].type, + dec->cdef->data.cdef.ents[i].assoc)); + } + } else { + unsigned int i; + for (i = 0; i < dec->numchans; ++i) { + jas_image_setcmpttype(dec->image, dec->chantocmptlut[i], + jp2_getct(jas_image_colorspace(dec->image), 0, i + 1)); + } + } + + /* Delete any components that are not of interest. */ + for (i = jas_image_numcmpts(dec->image) - 1; i >= 0; --i) { + if (jas_image_cmpttype(dec->image, i) == JAS_IMAGE_CT_UNKNOWN) { + jas_image_delcmpt(dec->image, i); + } + } + + /* Ensure that some components survived. */ + if (!jas_image_numcmpts(dec->image)) { + jas_eprintf("error: no components\n"); + goto error; + } + + /* Prevent the image from being destroyed later. */ + image = dec->image; + dec->image = 0; + + jp2_dec_destroy(dec); + + return image; -static int jp2_getcs(jp2_colr_t *colr) -{ - if (colr->method == JP2_COLR_ENUM) { - switch (colr->csid) { - case JP2_COLR_SRGB: - return JAS_IMAGE_CS_RGB; - break; - case JP2_COLR_SYCC: - return JAS_IMAGE_CS_YCBCR; - break; - case JP2_COLR_SGRAY: - return JAS_IMAGE_CS_GRAY; - break; - } - } - return JAS_IMAGE_CS_UNKNOWN; +error: + if (box) { + jp2_box_destroy(box); + } + if (dec) { + jp2_dec_destroy(dec); + } + return 0; } -static int fromiccpcs(int cs) -{ - switch (cs) { - case ICC_CS_RGB: - return JAS_IMAGE_CS_RGB; - break; - case ICC_CS_YCBCR: - return JAS_IMAGE_CS_YCBCR; - break; - case ICC_CS_GRAY: - return JAS_IMAGE_CS_GRAY; - break; - } - return JAS_IMAGE_CS_UNKNOWN; + + +int +jp2_validate(jas_stream_t *in) { + + char buf[JP2_VALIDATELEN]; + int i; + int n; + + assert(JAS_STREAM_MAXPUTBACK >= JP2_VALIDATELEN); + + /* Read the validation data (i.e., the data used for detecting + the format). */ + if ((n = jas_stream_read(in, buf, JP2_VALIDATELEN)) < 0) { + return -1; + } + + /* Put the validation data back onto the stream, so that the + stream position will not be changed. */ + for (i = n - 1; i >= 0; --i) { + if (jas_stream_ungetc(in, buf[i]) == EOF) { + return -1; + } + } + + /* Did we read enough data? */ + if (n < JP2_VALIDATELEN) { + return -1; + } + + /* Is the box type correct? */ + if (((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]) != + JP2_BOX_JP) + { + return -1; + } + + return 0; } + + + diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c b/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c index 72bd0126..cada97f8 100644 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c +++ b/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c @@ -458,6 +458,12 @@ static int jpc_dec_decode(jpc_dec_t *dec) static int jpc_dec_process_crg(jpc_dec_t *dec, jpc_ms_t *ms) { + /* Ignore the information in the CRG marker segment for now. + This information serves no useful purpose for decoding anyhow. + Some other parts of the code need to be changed if these lines + are enabled. + */ +#ifdef USING_CRG uint_fast16_t cmptno; jpc_dec_cmpt_t *cmpt; jpc_crg_t *crg; @@ -465,14 +471,10 @@ static int jpc_dec_process_crg(jpc_dec_t *dec, jpc_ms_t *ms) crg = &ms->parms.crg; for (cmptno = 0, cmpt = dec->cmpts; cmptno < dec->numcomps; ++cmptno, ++cmpt) { - /* Ignore the information in the CRG marker segment for now. - This information serves no useful purpose for decoding anyhow. - Some other parts of the code need to be changed if these lines - are uncommented. cmpt->hsubstep = crg->comps[cmptno].hoff; cmpt->vsubstep = crg->comps[cmptno].voff; - */ } +#endif return 0; } @@ -701,7 +703,6 @@ static int jpc_dec_tileinit(jpc_dec_t *dec, jpc_dec_tile_t *tile) uint_fast32_t tlcbgxstart; uint_fast32_t tlcbgystart; uint_fast32_t brcbgxend; - uint_fast32_t brcbgyend; uint_fast32_t cbgxstart; uint_fast32_t cbgystart; uint_fast32_t cbgxend; @@ -792,14 +793,12 @@ rlvl->bands = 0; tlcbgxstart = tlprcxstart; tlcbgystart = tlprcystart; brcbgxend = brprcxend; - brcbgyend = brprcyend; rlvl->cbgwidthexpn = rlvl->prcwidthexpn; rlvl->cbgheightexpn = rlvl->prcheightexpn; } else { tlcbgxstart = JPC_CEILDIVPOW2(tlprcxstart, 1); tlcbgystart = JPC_CEILDIVPOW2(tlprcystart, 1); brcbgxend = JPC_CEILDIVPOW2(brprcxend, 1); - brcbgyend = JPC_CEILDIVPOW2(brprcyend, 1); rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1; rlvl->cbgheightexpn = rlvl->prcheightexpn - 1; } diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c index d17e9aa3..9db41ca2 100644 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c +++ b/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c @@ -73,9 +73,9 @@ int ratestrtosize(const char *s, uint_fast32_t rawsize, uint_fast32_t *size); static void pass_destroy(jpc_enc_pass_t *pass); void jpc_enc_dump(jpc_enc_t *enc); -/******************************************************************************\ +/*****************************************************************************\ * Local prototypes. -\******************************************************************************/ +\*****************************************************************************/ void quantize(jas_matrix_t *data, jpc_fix_t stepsize); static int jpc_enc_encodemainhdr(jpc_enc_t *enc); @@ -90,8 +90,11 @@ int setins(int numvalues, jpc_flt_t *values, jpc_flt_t value); static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image); void jpc_enc_cp_destroy(jpc_enc_cp_t *cp); -static uint_fast32_t jpc_abstorelstepsize(jpc_fix_t absdelta, int scaleexpn) -{ + + +static uint_fast32_t +jpc_abstorelstepsize(jpc_fix_t absdelta, int scaleexpn) { + int p; uint_fast32_t mant; uint_fast32_t expn; @@ -111,6 +114,8 @@ static uint_fast32_t jpc_abstorelstepsize(jpc_fix_t absdelta, int scaleexpn) return JPC_QCX_EXPN(expn) | JPC_QCX_MANT(mant); } + + typedef enum { OPT_DEBUG, OPT_IMGAREAOFFX, @@ -199,6 +204,7 @@ jas_taginfo_t modetab[] = { }; + static void tracev(const char * const fmt, va_list args) { @@ -224,12 +230,9 @@ trace(const char * const fmt, ...) { -/******************************************************************************\ -* The main encoder entry point. -\******************************************************************************/ +int +jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr) { -int jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr) -{ jpc_enc_t *enc; jpc_enc_cp_t *cp; @@ -287,12 +290,15 @@ error: return -1; } -/******************************************************************************\ + + +/*****************************************************************************\ * Option parsing code. -\******************************************************************************/ +\*****************************************************************************/ + +static jpc_enc_cp_t * +cp_create(char *optstr, jas_image_t *image) { -static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) -{ jpc_enc_cp_t *cp; jas_tvparser_t *tvp; int ret; @@ -343,10 +349,12 @@ static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) hsteplcm = 1; vsteplcm = 1; for (cmptno = 0; cmptno < jas_image_numcmpts(image); ++cmptno) { - if (jas_image_cmptbrx(image, cmptno) + jas_image_cmpthstep(image, cmptno) <= + if (jas_image_cmptbrx(image, cmptno) + + jas_image_cmpthstep(image, cmptno) <= jas_image_brx(image) || jas_image_cmptbry(image, cmptno) + jas_image_cmptvstep(image, cmptno) <= jas_image_bry(image)) { - fprintf(stderr, "We don't know how to interpret this image type\n"); + fprintf(stderr, + "We don't know how to interpret this image type\n"); goto error; } /* Note: We ought to be calculating the LCMs here. Fix some day. */ @@ -495,7 +503,8 @@ static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) if (jpc_atoaf(jas_tvparser_getval(tvp), &numilyrrates, &ilyrrates)) { fprintf(stderr, - "warning: invalid intermediate layer rates specifier ignored (%s)\n", + "warning: invalid intermediate layer rates specifier " + "ignored (%s)\n", jas_tvparser_getval(tvp)); } break; @@ -552,20 +561,26 @@ static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) if (cp->numcmpts == 3) { mctvalid = true; for (cmptno = 0; cmptno < jas_image_numcmpts(image); ++cmptno) { - if (jas_image_cmptprec(image, cmptno) != jas_image_cmptprec(image, 0) || - jas_image_cmptsgnd(image, cmptno) != jas_image_cmptsgnd(image, 0) || - jas_image_cmptwidth(image, cmptno) != jas_image_cmptwidth(image, 0) || - jas_image_cmptheight(image, cmptno) != jas_image_cmptheight(image, 0)) { + if (jas_image_cmptprec(image, cmptno) != + jas_image_cmptprec(image, 0) || + jas_image_cmptsgnd(image, cmptno) != + jas_image_cmptsgnd(image, 0) || + jas_image_cmptwidth(image, cmptno) != + jas_image_cmptwidth(image, 0) || + jas_image_cmptheight(image, cmptno) != + jas_image_cmptheight(image, 0)) { mctvalid = false; } } } else { mctvalid = false; } - if (mctvalid && enablemct && jas_image_colorspace(image) != JAS_IMAGE_CS_RGB) { + if (mctvalid && enablemct && jas_image_colorspace(image) != + JAS_IMAGE_CS_RGB) { fprintf(stderr, "warning: color model apparently not RGB\n"); } - if (mctvalid && enablemct && jas_image_colorspace(image) == JAS_IMAGE_CS_RGB) { + if (mctvalid && enablemct && jas_image_colorspace(image) == + JAS_IMAGE_CS_RGB) { tcp->mctid = (tcp->intmode) ? (JPC_MCT_RCT) : (JPC_MCT_ICT); } else { tcp->mctid = JPC_MCT_NONE; @@ -682,16 +697,20 @@ static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image) /* The intermediate layers rates must increase monotonically. */ for (lyrno = 0; lyrno + 2 < tcp->numlyrs; ++lyrno) { if (tcp->ilyrrates[lyrno] >= tcp->ilyrrates[lyrno + 1]) { - fprintf(stderr, "intermediate layer rates must increase monotonically\n"); + fprintf(stderr, + "intermediate layer rates must increase " + "monotonically\n"); goto error; } } /* The intermediate layer rates must be less than the overall rate. */ if (cp->totalsize != UINT_FAST32_MAX) { for (lyrno = 0; lyrno < tcp->numlyrs - 1; ++lyrno) { - if (jpc_fixtodbl(tcp->ilyrrates[lyrno]) > ((double) cp->totalsize) - / cp->rawsize) { - fprintf(stderr, "warning: intermediate layer rates must be less than overall rate\n"); + if (jpc_fixtodbl(tcp->ilyrrates[lyrno]) > + ((double) cp->totalsize) / cp->rawsize) { + fprintf(stderr, + "warning: intermediate layer rates must be " + "less than overall rate\n"); goto error; } } @@ -718,8 +737,11 @@ error: return 0; } -void jpc_enc_cp_destroy(jpc_enc_cp_t *cp) -{ + + +void +jpc_enc_cp_destroy(jpc_enc_cp_t *cp) { + if (cp->ccps) { if (cp->tcp.ilyrrates) { jas_free(cp->tcp.ilyrrates); @@ -729,8 +751,11 @@ void jpc_enc_cp_destroy(jpc_enc_cp_t *cp) jas_free(cp); } -int ratestrtosize(const char *s, uint_fast32_t rawsize, uint_fast32_t *size) -{ + + +int +ratestrtosize(const char *s, uint_fast32_t rawsize, uint_fast32_t *size) { + char *cp; jpc_flt_t f; @@ -750,12 +775,13 @@ int ratestrtosize(const char *s, uint_fast32_t rawsize, uint_fast32_t *size) return 0; } -/******************************************************************************\ +/*****************************************************************************\ * Encoder constructor and destructor. -\******************************************************************************/ +\*****************************************************************************/ + +jpc_enc_t * +jpc_enc_create(jpc_enc_cp_t *cp, jas_stream_t *out, jas_image_t *image) { -jpc_enc_t *jpc_enc_create(jpc_enc_cp_t *cp, jas_stream_t *out, jas_image_t *image) -{ jpc_enc_t *enc; enc = 0; @@ -788,11 +814,15 @@ error: return 0; } -void jpc_enc_destroy(jpc_enc_t *enc) -{ + + +void +jpc_enc_destroy(jpc_enc_t *enc) { + /* The image object (i.e., enc->image) and output stream object - (i.e., enc->out) are created outside of the encoder. - Therefore, they must not be destroyed here. */ + (i.e., enc->out) are created outside of the encoder. + Therefore, they must not be destroyed here. + */ if (enc->curtile) { jpc_enc_tile_destroy(enc->curtile); @@ -810,24 +840,22 @@ void jpc_enc_destroy(jpc_enc_t *enc) jas_free(enc); } -/******************************************************************************\ -* Code. -\******************************************************************************/ -static int jpc_enc_encodemainhdr(jpc_enc_t *enc) -{ + +static int +jpc_enc_encodemainhdr(jpc_enc_t *enc) { + jpc_siz_t *siz; jpc_cod_t *cod; jpc_qcd_t *qcd; int i; -long startoff; -long mainhdrlen; + long startoff; + long mainhdrlen; jpc_enc_cp_t *cp; jpc_qcc_t *qcc; jpc_enc_tccp_t *tccp; uint_fast16_t cmptno; jpc_tsfb_band_t bandinfos[JPC_MAXBANDS]; - jpc_fix_t mctsynweight; jpc_enc_tcp_t *tcp; jpc_tsfb_t *tsfb; jpc_tsfb_band_t *bandinfo; @@ -841,7 +869,7 @@ long mainhdrlen; cp = enc->cp; -startoff = jas_stream_getrwcount(enc->out); + startoff = jas_stream_getrwcount(enc->out); /* Write SOC marker segment. */ if (!(enc->mrk = jpc_ms_create(JPC_MS_SOC))) { @@ -922,7 +950,6 @@ startoff = jas_stream_getrwcount(enc->out); jpc_tsfb_getbands(tsfb, 0, 0, 1 << tccp->maxrlvls, 1 << tccp->maxrlvls, bandinfos); jpc_tsfb_destroy(tsfb); - mctsynweight = jpc_mct_getsynweight(tcp->mctid, cmptno); numbands = 3 * tccp->maxrlvls - 2; for (bandno = 0, bandinfo = bandinfos; bandno < numbands; ++bandno, ++bandinfo) { @@ -953,14 +980,17 @@ startoff = jas_stream_getrwcount(enc->out); cod->prg = cp->tcp.prg; cod->numlyrs = cp->tcp.numlyrs; cod->compparms.cblkwidthval = JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkwidthexpn); - cod->compparms.cblkheightval = JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkheightexpn); + cod->compparms.cblkheightval = + JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkheightexpn); cod->compparms.cblksty = cp->tccp.cblksty; cod->compparms.qmfbid = cp->tccp.qmfbid; cod->mctrans = (cp->tcp.mctid != JPC_MCT_NONE); if (tccp->csty & JPC_COX_PRT) { for (rlvlno = 0; rlvlno < tccp->maxrlvls; ++rlvlno) { - cod->compparms.rlvls[rlvlno].parwidthval = tccp->prcwidthexpns[rlvlno]; - cod->compparms.rlvls[rlvlno].parheightval = tccp->prcheightexpns[rlvlno]; + cod->compparms.rlvls[rlvlno].parwidthval = + tccp->prcwidthexpns[rlvlno]; + cod->compparms.rlvls[rlvlno].parheightval = + tccp->prcheightexpns[rlvlno]; } } if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { @@ -1023,17 +1053,23 @@ startoff = jas_stream_getrwcount(enc->out); return 0; } -int jpc_enc_encodetiledata(jpc_enc_t *enc) -{ -assert(enc->tmpstream); + + +int +jpc_enc_encodetiledata(jpc_enc_t *enc) { + + assert(enc->tmpstream); if (jpc_enc_encpkts(enc, enc->tmpstream)) { return -1; } return 0; } -void quantize(jas_matrix_t *data, jpc_fix_t stepsize) -{ + + +void +quantize(jas_matrix_t *data, jpc_fix_t stepsize) { + int i; int j; jpc_fix_t t; @@ -1059,8 +1095,11 @@ void quantize(jas_matrix_t *data, jpc_fix_t stepsize) } } -static void calcrdslopes(jpc_enc_cblk_t *cblk) -{ + + +static void +calcrdslopes(jpc_enc_cblk_t *cblk) { + jpc_enc_pass_t *endpasses; jpc_enc_pass_t *pass0; jpc_enc_pass_t *pass1; @@ -1113,10 +1152,12 @@ static void calcrdslopes(jpc_enc_cblk_t *cblk) #if 0 for (pass0 = cblk->passes; pass0 != endpasses; ++pass0) { -if (pass0->rdslope > 0.0) { - fprintf(stderr, "pass %02d nmsedec=%lf dec=%lf end=%d %lf\n", pass0 - cblk->passes, - fixtodbl(pass0->nmsedec), pass0->wmsedec, pass0->end, pass0->rdslope); -} + if (pass0->rdslope > 0.0) { + fprintf(stderr, "pass %02d nmsedec=%lf dec=%lf end=%d %lf\n", + pass0 - cblk->passes, + fixtodbl(pass0->nmsedec), pass0->wmsedec, + pass0->end, pass0->rdslope); + } } #endif } @@ -1196,8 +1237,8 @@ computeLayerSizes(jpc_enc_t * const encP, -static void dump_layeringinfo(jpc_enc_t *enc) -{ +static void +dump_layeringinfo(jpc_enc_t *enc) { jpc_enc_tcmpt_t *tcmpt; uint_fast16_t tcmptno; @@ -1626,12 +1667,15 @@ performTier2Coding(jpc_enc_t * const encP, JAS_DBGLOG(10, ("done doing rateallocation\n")); } + + /*****************************************************************************\ * Tile constructors and destructors. \*****************************************************************************/ -jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int tileno) -{ +jpc_enc_tile_t * +jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int tileno) { + jpc_enc_tile_t *tile; uint_fast32_t htileno; uint_fast32_t vtileno; @@ -1733,8 +1777,11 @@ error: return 0; } -void jpc_enc_tile_destroy(jpc_enc_tile_t *tile) -{ + + +void +jpc_enc_tile_destroy(jpc_enc_tile_t *tile) { + jpc_enc_tcmpt_t *tcmpt; uint_fast16_t cmptno; @@ -1754,9 +1801,14 @@ void jpc_enc_tile_destroy(jpc_enc_tile_t *tile) jas_free(tile); } -static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp, - jas_image_t *image, jpc_enc_tile_t *tile) -{ + + +static jpc_enc_tcmpt_t * +tcmpt_create(jpc_enc_tcmpt_t * const tcmpt, + jpc_enc_cp_t * const cp, + jas_image_t * const image, + jpc_enc_tile_t * const tile) { + uint_fast16_t cmptno; uint_fast16_t rlvlno; jpc_enc_rlvl_t *rlvl; @@ -1787,15 +1839,15 @@ static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp, bry = JPC_CEILDIV(tile->bry, ccp->sampgrdstepy); /* Create a sequence to hold the tile-component sample data. */ - if (!(tcmpt->data = jas_seq2d_create(tlx, tly, brx, bry))) { + tcmpt->data = jas_seq2d_create(tlx, tly, brx, bry); + if (!tcmpt->data) goto error; - } /* Get the image data associated with this tile-component. */ cmpttlx = JPC_CEILDIV(cp->imgareatlx, ccp->sampgrdstepx); cmpttly = JPC_CEILDIV(cp->imgareatly, ccp->sampgrdstepy); if (jas_image_readcmpt(image, cmptno, tlx - cmpttlx, tly - cmpttly, - brx - tlx, bry - tly, tcmpt->data)) { + brx - tlx, bry - tly, tcmpt->data)) { goto error; } @@ -1803,9 +1855,11 @@ static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp, tcmpt->qmfbid = cp->tccp.qmfbid; tcmpt->numrlvls = cp->tccp.maxrlvls; tcmpt->numbands = 3 * tcmpt->numrlvls - 2; - if (!(tcmpt->tsfb = jpc_cod_gettsfb(tcmpt->qmfbid, tcmpt->numrlvls - 1))) { + + tcmpt->tsfb = jpc_cod_gettsfb(tcmpt->qmfbid, tcmpt->numrlvls - 1); + + if (!tcmpt->tsfb) goto error; - } for (rlvlno = 0; rlvlno < tcmpt->numrlvls; ++rlvlno) { tcmpt->prcwidthexpns[rlvlno] = cp->tccp.prcwidthexpns[rlvlno]; @@ -1818,17 +1872,19 @@ static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp, tcmpt->numstepsizes = tcmpt->numbands; assert(tcmpt->numstepsizes <= JPC_MAXBANDS); - memset(tcmpt->stepsizes, 0, sizeof(tcmpt->numstepsizes * - sizeof(uint_fast16_t))); + memset(tcmpt->stepsizes, 0, + sizeof(tcmpt->numstepsizes * sizeof(uint_fast16_t))); /* Retrieve information about the various bands. */ jpc_tsfb_getbands(tcmpt->tsfb, jas_seq2d_xstart(tcmpt->data), - jas_seq2d_ystart(tcmpt->data), jas_seq2d_xend(tcmpt->data), - jas_seq2d_yend(tcmpt->data), bandinfos); + jas_seq2d_ystart(tcmpt->data), + jas_seq2d_xend(tcmpt->data), + jas_seq2d_yend(tcmpt->data), bandinfos); - if (!(tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)))) { + tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)); + if (!tcmpt->rlvls) goto error; - } + for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; ++rlvlno, ++rlvl) { rlvl->bands = 0; @@ -1850,8 +1906,11 @@ error: } -static void tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt) -{ + + +static void +tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt) { + jpc_enc_rlvl_t *rlvl; uint_fast16_t rlvlno; @@ -1871,9 +1930,12 @@ static void tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt) } } -static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, - jpc_enc_tcmpt_t *tcmpt, jpc_tsfb_band_t *bandinfos) -{ + + +static jpc_enc_rlvl_t * +rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, + jpc_enc_tcmpt_t *tcmpt, jpc_tsfb_band_t *bandinfos) { + uint_fast16_t rlvlno; uint_fast32_t tlprctlx; uint_fast32_t tlprctly; @@ -1891,14 +1953,18 @@ static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, /* Compute the coordinates of the top-left and bottom-right corners of the tile-component at this resolution. */ - rlvl->tlx = JPC_CEILDIVPOW2(jas_seq2d_xstart(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - rlvl->tly = JPC_CEILDIVPOW2(jas_seq2d_ystart(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - rlvl->brx = JPC_CEILDIVPOW2(jas_seq2d_xend(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - rlvl->bry = JPC_CEILDIVPOW2(jas_seq2d_yend(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); + rlvl->tlx = + JPC_CEILDIVPOW2(jas_seq2d_xstart(tcmpt->data), tcmpt->numrlvls - + 1 - rlvlno); + rlvl->tly = + JPC_CEILDIVPOW2(jas_seq2d_ystart(tcmpt->data), tcmpt->numrlvls - + 1 - rlvlno); + rlvl->brx = + JPC_CEILDIVPOW2(jas_seq2d_xend(tcmpt->data), tcmpt->numrlvls - + 1 - rlvlno); + rlvl->bry = + JPC_CEILDIVPOW2(jas_seq2d_yend(tcmpt->data), tcmpt->numrlvls - + 1 - rlvlno); if (rlvl->tlx >= rlvl->brx || rlvl->tly >= rlvl->bry) { rlvl->numhprcs = 0; @@ -1917,8 +1983,10 @@ static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1; rlvl->cbgheightexpn = rlvl->prcheightexpn - 1; } - rlvl->cblkwidthexpn = JAS_MIN(cp->tccp.cblkwidthexpn, rlvl->cbgwidthexpn); - rlvl->cblkheightexpn = JAS_MIN(cp->tccp.cblkheightexpn, rlvl->cbgheightexpn); + rlvl->cblkwidthexpn = + JAS_MIN(cp->tccp.cblkwidthexpn, rlvl->cbgwidthexpn); + rlvl->cblkheightexpn = + JAS_MIN(cp->tccp.cblkheightexpn, rlvl->cbgheightexpn); /* Compute the number of precincts. */ tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn); @@ -1926,20 +1994,22 @@ static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, brprcbrx = JPC_CEILTOMULTPOW2(rlvl->brx, rlvl->prcwidthexpn); brprcbry = JPC_CEILTOMULTPOW2(rlvl->bry, rlvl->prcheightexpn); rlvl->numhprcs = JPC_FLOORDIVPOW2(brprcbrx - tlprctlx, rlvl->prcwidthexpn); - rlvl->numvprcs = JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); + rlvl->numvprcs = + JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; - if (!(rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)))) { + rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)); + if (!rlvl->bands) goto error; - } + for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { + ++bandno, ++band) { band->prcs = 0; band->data = 0; band->rlvl = rlvl; } for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { + ++bandno, ++band) { if (!band_create(band, cp, rlvl, bandinfos)) { goto error; } @@ -1952,8 +2022,11 @@ error: return 0; } -static void rlvl_destroy(jpc_enc_rlvl_t *rlvl) -{ + + +static void +rlvl_destroy(jpc_enc_rlvl_t *rlvl) { + jpc_enc_band_t *band; uint_fast16_t bandno; @@ -1966,9 +2039,12 @@ static void rlvl_destroy(jpc_enc_rlvl_t *rlvl) } } -static jpc_enc_band_t *band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp, - jpc_enc_rlvl_t *rlvl, jpc_tsfb_band_t *bandinfos) -{ + + +static jpc_enc_band_t * +band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp, + jpc_enc_rlvl_t *rlvl, jpc_tsfb_band_t *bandinfos) { + uint_fast16_t bandno; uint_fast16_t gblbandno; uint_fast16_t rlvlno; @@ -1989,42 +2065,46 @@ static jpc_enc_band_t *band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp, bandinfo = &bandinfos[gblbandno]; -if (bandinfo->xstart != bandinfo->xend && bandinfo->ystart != bandinfo->yend) { - if (!(band->data = jas_seq2d_create(0, 0, 0, 0))) { - goto error; + if (bandinfo->xstart != bandinfo->xend && + bandinfo->ystart != bandinfo->yend) { + band->data = jas_seq2d_create(0, 0, 0, 0); + if (!band->data) + goto error; + jas_seq2d_bindsub(band->data, tcmpt->data, bandinfo->locxstart, + bandinfo->locystart, bandinfo->locxend, + bandinfo->locyend); + jas_seq2d_setshift(band->data, bandinfo->xstart, bandinfo->ystart); } - jas_seq2d_bindsub(band->data, tcmpt->data, bandinfo->locxstart, - bandinfo->locystart, bandinfo->locxend, bandinfo->locyend); - jas_seq2d_setshift(band->data, bandinfo->xstart, bandinfo->ystart); -} band->orient = bandinfo->orient; band->analgain = JPC_NOMINALGAIN(cp->tccp.qmfbid, tcmpt->numrlvls, rlvlno, - band->orient); + band->orient); band->numbps = 0; band->absstepsize = 0; band->stepsize = 0; band->synweight = bandinfo->synenergywt; -if (band->data) { - if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)))) { - goto error; - } - for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, - ++prc) { - prc->cblks = 0; - prc->incltree = 0; - prc->nlibtree = 0; - prc->savincltree = 0; - prc->savnlibtree = 0; - prc->band = band; - } - for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, - ++prc) { - if (!prc_create(prc, cp, band)) { + if (band->data) { + band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)); + if (!band->prcs) goto error; + for (prcno = 0, prc = band->prcs; + prcno < rlvl->numprcs; + ++prcno, ++prc) { + prc->cblks = 0; + prc->incltree = 0; + prc->nlibtree = 0; + prc->savincltree = 0; + prc->savnlibtree = 0; + prc->band = band; + } + for (prcno = 0, prc = band->prcs; + prcno < rlvl->numprcs; + ++prcno, ++prc) { + if (!prc_create(prc, cp, band)) { + goto error; + } } } -} return band; @@ -2033,8 +2113,11 @@ error: return 0; } -static void band_destroy(jpc_enc_band_t *band) -{ + + +static void +band_destroy(jpc_enc_band_t *band) { + jpc_enc_prc_t *prc; jpc_enc_rlvl_t *rlvl; uint_fast32_t prcno; @@ -2052,8 +2135,11 @@ static void band_destroy(jpc_enc_band_t *band) } } -static jpc_enc_prc_t *prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, jpc_enc_band_t *band) -{ + + +static jpc_enc_prc_t * +prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, jpc_enc_band_t *band) { + uint_fast32_t prcno; uint_fast32_t prcxind; uint_fast32_t prcyind; @@ -2081,32 +2167,34 @@ static jpc_enc_prc_t *prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, jpc_enc_b rlvl = band->rlvl; tcmpt = rlvl->tcmpt; -rlvlno = rlvl - tcmpt->rlvls; + rlvlno = rlvl - tcmpt->rlvls; prcno = prc - band->prcs; prcxind = prcno % rlvl->numhprcs; prcyind = prcno / rlvl->numhprcs; prc->band = band; -tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn); -tlprctly = JPC_FLOORTOMULTPOW2(rlvl->tly, rlvl->prcheightexpn); -if (!rlvlno) { - tlcbgtlx = tlprctlx; - tlcbgtly = tlprctly; -} else { - tlcbgtlx = JPC_CEILDIVPOW2(tlprctlx, 1); - tlcbgtly = JPC_CEILDIVPOW2(tlprctly, 1); -} + tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn); + tlprctly = JPC_FLOORTOMULTPOW2(rlvl->tly, rlvl->prcheightexpn); - /* Compute the coordinates of the top-left and bottom-right - corners of the precinct. */ + if (!rlvlno) { + tlcbgtlx = tlprctlx; + tlcbgtly = tlprctly; + } else { + tlcbgtlx = JPC_CEILDIVPOW2(tlprctlx, 1); + tlcbgtly = JPC_CEILDIVPOW2(tlprctly, 1); + } + + /* Compute the coordinates of the top-left and bottom-right corners of the + precinct. + */ cbgtlx = tlcbgtlx + (prcxind << rlvl->cbgwidthexpn); cbgtly = tlcbgtly + (prcyind << rlvl->cbgheightexpn); prc->tlx = JAS_MAX(jas_seq2d_xstart(band->data), cbgtlx); prc->tly = JAS_MAX(jas_seq2d_ystart(band->data), cbgtly); prc->brx = JAS_MIN(jas_seq2d_xend(band->data), cbgtlx + - (1 << rlvl->cbgwidthexpn)); + (1 << rlvl->cbgwidthexpn)); prc->bry = JAS_MIN(jas_seq2d_yend(band->data), cbgtly + - (1 << rlvl->cbgheightexpn)); + (1 << rlvl->cbgheightexpn)); if (prc->tlx < prc->brx && prc->tly < prc->bry) { /* The precinct contains at least one code block. */ @@ -2116,33 +2204,35 @@ if (!rlvlno) { brcblkbrx = JPC_CEILTOMULTPOW2(prc->brx, rlvl->cblkwidthexpn); brcblkbry = JPC_CEILTOMULTPOW2(prc->bry, rlvl->cblkheightexpn); prc->numhcblks = JPC_FLOORDIVPOW2(brcblkbrx - tlcblktlx, - rlvl->cblkwidthexpn); + rlvl->cblkwidthexpn); prc->numvcblks = JPC_FLOORDIVPOW2(brcblkbry - tlcblktly, - rlvl->cblkheightexpn); + rlvl->cblkheightexpn); prc->numcblks = prc->numhcblks * prc->numvcblks; if (!(prc->incltree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { + prc->numvcblks))) { goto error; } if (!(prc->nlibtree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { + prc->numvcblks))) { goto error; } if (!(prc->savincltree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { + prc->numvcblks))) { goto error; } if (!(prc->savnlibtree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { + prc->numvcblks))) { goto error; } - if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)))) { + prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)); + + if (!prc->cblks) goto error; - } - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; - ++cblkno, ++cblk) { + for (cblkno = 0, cblk = prc->cblks; + cblkno < prc->numcblks; + ++cblkno, ++cblk) { cblk->passes = 0; cblk->stream = 0; cblk->mqenc = 0; @@ -2150,8 +2240,9 @@ if (!rlvlno) { cblk->flags = 0; cblk->prc = prc; } - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; - ++cblkno, ++cblk) { + for (cblkno = 0, cblk = prc->cblks; + cblkno < prc->numcblks; + ++cblkno, ++cblk) { if (!cblk_create(cblk, cp, prc)) { goto error; } @@ -2177,8 +2268,11 @@ error: return 0; } -static void prc_destroy(jpc_enc_prc_t *prc) -{ + + +static void +prc_destroy(jpc_enc_prc_t *prc) { + jpc_enc_cblk_t *cblk; uint_fast32_t cblkno; @@ -2203,8 +2297,11 @@ static void prc_destroy(jpc_enc_prc_t *prc) } } -static jpc_enc_cblk_t *cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, jpc_enc_prc_t *prc) -{ + + +static jpc_enc_cblk_t * +cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, jpc_enc_prc_t *prc) { + jpc_enc_band_t *band; uint_fast32_t cblktlx; uint_fast32_t cblktly; @@ -2241,18 +2338,22 @@ static jpc_enc_cblk_t *cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, jpc_e band = prc->band; tlcblktlx = JPC_FLOORTOMULTPOW2(prc->tlx, rlvl->cblkwidthexpn); tlcblktly = JPC_FLOORTOMULTPOW2(prc->tly, rlvl->cblkheightexpn); - cblktlx = JAS_MAX(tlcblktlx + (cblkxind << rlvl->cblkwidthexpn), prc->tlx); - cblktly = JAS_MAX(tlcblktly + (cblkyind << rlvl->cblkheightexpn), prc->tly); - cblkbrx = JAS_MIN(tlcblktlx + ((cblkxind + 1) << rlvl->cblkwidthexpn), - prc->brx); - cblkbry = JAS_MIN(tlcblktly + ((cblkyind + 1) << rlvl->cblkheightexpn), - prc->bry); + cblktlx = + JAS_MAX(tlcblktlx + (cblkxind << rlvl->cblkwidthexpn), prc->tlx); + cblktly = + JAS_MAX(tlcblktly + (cblkyind << rlvl->cblkheightexpn), prc->tly); + cblkbrx = + JAS_MIN(tlcblktlx + ((cblkxind + 1) << rlvl->cblkwidthexpn), prc->brx); + cblkbry = + JAS_MIN(tlcblktly + ((cblkyind + 1) << rlvl->cblkheightexpn), + prc->bry); assert(cblktlx < cblkbrx && cblktly < cblkbry); - if (!(cblk->data = jas_seq2d_create(0, 0, 0, 0))) { + cblk->data = jas_seq2d_create(0, 0, 0, 0); + if (!cblk->data) goto error; - } - jas_seq2d_bindsub(cblk->data, band->data, cblktlx, cblktly, cblkbrx, cblkbry); + jas_seq2d_bindsub(cblk->data, band->data, + cblktlx, cblktly, cblkbrx, cblkbry); return cblk; @@ -2261,8 +2362,11 @@ error: return 0; } -static void cblk_destroy(jpc_enc_cblk_t *cblk) -{ + + +static void +cblk_destroy(jpc_enc_cblk_t *cblk) { + uint_fast16_t passno; jpc_enc_pass_t *pass; if (cblk->passes) { @@ -2286,13 +2390,19 @@ static void cblk_destroy(jpc_enc_cblk_t *cblk) } } -static void pass_destroy(jpc_enc_pass_t *pass) -{ + + +static void +pass_destroy(jpc_enc_pass_t *pass) { + /* XXX - need to free resources here */ } -void jpc_enc_dump(jpc_enc_t *enc) -{ + + +void +jpc_enc_dump(jpc_enc_t *enc) { + jpc_enc_tile_t *tile; jpc_enc_tcmpt_t *tcmpt; jpc_enc_rlvl_t *rlvl; @@ -2358,11 +2468,10 @@ void jpc_enc_dump(jpc_enc_t *enc) -static int jpc_enc_encodemainbody(jpc_enc_t *enc) -{ +static int +jpc_enc_encodemainbody(jpc_enc_t *enc) { + int tileno; - int tilex; - int tiley; int i; jpc_sot_t *sot; jpc_enc_tcmpt_t *comp; @@ -2376,7 +2485,6 @@ static int jpc_enc_encodemainbody(jpc_enc_t *enc) int adjust; int j; int absbandno; - long numbytes; long tilehdrlen; long tilelen; jpc_enc_tile_t *tile; @@ -2398,13 +2506,7 @@ static int jpc_enc_encodemainbody(jpc_enc_t *enc) cp = enc->cp; - /* Avoid compile warnings. */ - numbytes = 0; - for (tileno = 0; tileno < cp->numtiles; ++tileno) { - tilex = tileno % cp->numhtiles; - tiley = tileno / cp->numhtiles; - enc->curtile = jpc_enc_tile_create(enc->cp, enc->image, tileno); if (!enc->curtile) abort(); @@ -2459,7 +2561,6 @@ static int jpc_enc_encodemainbody(jpc_enc_t *enc) } - endcomps = &tile->tcmpts[tile->numtcmpts]; for (cmptno = 0, comp = tile->tcmpts; comp != endcomps; @@ -2544,15 +2645,16 @@ static int jpc_enc_encodemainbody(jpc_enc_t *enc) return -1; } - if (!(enc->tmpstream = jas_stream_memopen(0, 0))) { + enc->tmpstream = jas_stream_memopen(0, 0); + if (!enc->tmpstream) { fprintf(stderr, "cannot open tmp file\n"); return -1; } /* Write the tile header. */ - if (!(enc->mrk = jpc_ms_create(JPC_MS_SOT))) { + enc->mrk = jpc_ms_create(JPC_MS_SOT); + if (!enc->mrk) return -1; - } sot = &enc->mrk->parms.sot; sot->len = 0; sot->tileno = tileno; diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c index 8aa024a9..e1af0f61 100644 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c +++ b/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c @@ -1,4 +1,4 @@ -/* + /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2002 Michael David Adams. @@ -156,853 +156,872 @@ static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int, /* Encode all of the code blocks associated with the current tile. */ int jpc_enc_enccblks(jpc_enc_t *enc) { - jpc_enc_tcmpt_t *tcmpt; - jpc_enc_tcmpt_t *endcomps; - jpc_enc_rlvl_t *lvl; - jpc_enc_rlvl_t *endlvls; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_cblk_t *cblk; - jpc_enc_cblk_t *endcblks; - int i; - int j; - int mx; - int bmx; - int v; - jpc_enc_tile_t *tile; - uint_fast32_t prcno; - jpc_enc_prc_t *prc; - - tile = enc->curtile; - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (tcmpt = tile->tcmpts; tcmpt != endcomps; ++tcmpt) { - endlvls = &tcmpt->rlvls[tcmpt->numrlvls]; - for (lvl = tcmpt->rlvls; lvl != endlvls; ++lvl) { - if (!lvl->bands) { - continue; - } - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) { - if (!prc->cblks) { - continue; - } - bmx = 0; - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - mx = 0; - for (i = 0; i < jas_matrix_numrows(cblk->data); ++i) { - for (j = 0; j < jas_matrix_numcols(cblk->data); ++j) { - v = abs(jas_matrix_get(cblk->data, i, j)); - if (v > mx) { - mx = v; - } - } - } - if (mx > bmx) { - bmx = mx; - } - cblk->numbps = JAS_MAX(jpc_firstone(mx) + 1 - JPC_NUMEXTRABITS, 0); - } - - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - cblk->numimsbs = band->numbps - cblk->numbps; - assert(cblk->numimsbs >= 0); - } - - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - if (jpc_enc_enccblk(enc, cblk->stream, tcmpt, band, cblk)) { - return -1; - } - } - } - } - } - } - return 0; + jpc_enc_tcmpt_t *tcmpt; + jpc_enc_tcmpt_t *endcomps; + jpc_enc_rlvl_t *lvl; + jpc_enc_rlvl_t *endlvls; + jpc_enc_band_t *band; + jpc_enc_band_t *endbands; + jpc_enc_cblk_t *cblk; + jpc_enc_cblk_t *endcblks; + int i; + int j; + int mx; + int bmx; + int v; + jpc_enc_tile_t *tile; + uint_fast32_t prcno; + jpc_enc_prc_t *prc; + + tile = enc->curtile; + + endcomps = &tile->tcmpts[tile->numtcmpts]; + for (tcmpt = tile->tcmpts; tcmpt != endcomps; ++tcmpt) { + endlvls = &tcmpt->rlvls[tcmpt->numrlvls]; + for (lvl = tcmpt->rlvls; lvl != endlvls; ++lvl) { + if (!lvl->bands) { + continue; + } + endbands = &lvl->bands[lvl->numbands]; + for (band = lvl->bands; band != endbands; ++band) { + if (!band->data) { + continue; + } + for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) { + if (!prc->cblks) { + continue; + } + bmx = 0; + endcblks = &prc->cblks[prc->numcblks]; + for (cblk = prc->cblks; cblk != endcblks; ++cblk) { + mx = 0; + for (i = 0; i < jas_matrix_numrows(cblk->data); ++i) { + for (j = 0; j < jas_matrix_numcols(cblk->data); ++j) { + v = abs(jas_matrix_get(cblk->data, i, j)); + if (v > mx) { + mx = v; + } + } + } + if (mx > bmx) { + bmx = mx; + } + cblk->numbps = JAS_MAX(jpc_firstone(mx) + 1 - JPC_NUMEXTRABITS, 0); + } + + for (cblk = prc->cblks; cblk != endcblks; ++cblk) { + cblk->numimsbs = band->numbps - cblk->numbps; + assert(cblk->numimsbs >= 0); + } + + for (cblk = prc->cblks; cblk != endcblks; ++cblk) { + if (jpc_enc_enccblk(enc, cblk->stream, tcmpt, band, cblk)) { + return -1; + } + } + } + } + } + } + return 0; } static int getthebyte(jas_stream_t *in, long off) { - int c; - long oldpos; - oldpos = jas_stream_tell(in); - assert(oldpos >= 0); - jas_stream_seek(in, off, SEEK_SET); - c = jas_stream_peekc(in); - jas_stream_seek(in, oldpos, SEEK_SET); - return c; + int c; + long oldpos; + oldpos = jas_stream_tell(in); + assert(oldpos >= 0); + jas_stream_seek(in, off, SEEK_SET); + c = jas_stream_peekc(in); + jas_stream_seek(in, oldpos, SEEK_SET); + return c; } -/* Encode a single code block. */ -int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *tcmpt, jpc_enc_band_t *band, jpc_enc_cblk_t *cblk) -{ - jpc_enc_pass_t *pass; - jpc_enc_pass_t *endpasses; - int bitpos; - int n; - int adjust; - int ret; - int passtype; - int t; - jpc_bitstream_t *bout; - jpc_enc_pass_t *termpass; - jpc_enc_rlvl_t *rlvl; - int vcausal; - int segsym; - int termmode; - int c; - - bout = 0; - rlvl = band->rlvl; - - cblk->stream = jas_stream_memopen(0, 0); - assert(cblk->stream); - cblk->mqenc = jpc_mqenc_create(JPC_NUMCTXS, cblk->stream); - assert(cblk->mqenc); - jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs); - - cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; - if (cblk->numpasses > 0) { - cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t)); - assert(cblk->passes); - } else { - cblk->passes = 0; - } - endpasses = &cblk->passes[cblk->numpasses]; - for (pass = cblk->passes; pass != endpasses; ++pass) { - pass->start = 0; - pass->end = 0; - pass->term = JPC_ISTERMINATED(pass - cblk->passes, 0, cblk->numpasses, (tcmpt->cblksty & JPC_COX_TERMALL) != 0, (tcmpt->cblksty & JPC_COX_LAZY) != 0); - pass->type = JPC_SEGTYPE(pass - cblk->passes, 0, (tcmpt->cblksty & JPC_COX_LAZY) != 0); - pass->lyrno = -1; -if (pass == endpasses - 1) { -assert(pass->term == 1); - pass->term = 1; -} - } - - cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + 2, - jas_matrix_numcols(cblk->data) + 2); - assert(cblk->flags); - - bitpos = cblk->numbps - 1; - pass = cblk->passes; - n = cblk->numpasses; - while (--n >= 0) { - if (pass->type == JPC_SEG_MQ) { - /* NOP */ - } else { - assert(pass->type == JPC_SEG_RAW); - if (!bout) { - bout = jpc_bitstream_sopen(cblk->stream, "w"); - assert(bout); - } - } +int +jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *tcmpt, + jpc_enc_band_t *band, jpc_enc_cblk_t *cblk) { +/*---------------------------------------------------------------------------- + Encode a single code block. +-----------------------------------------------------------------------------*/ + jpc_enc_pass_t *pass; + jpc_enc_pass_t *endpasses; + int bitpos; + int n; + int adjust; + int passtype; + int t; + jpc_bitstream_t *bout; + jpc_enc_pass_t *termpass; + int vcausal; + int segsym; + int termmode; + int c; + + bout = 0; + + cblk->stream = jas_stream_memopen(0, 0); + assert(cblk->stream); + cblk->mqenc = jpc_mqenc_create(JPC_NUMCTXS, cblk->stream); + assert(cblk->mqenc); + jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs); + + cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; + if (cblk->numpasses > 0) { + cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t)); + assert(cblk->passes); + } else { + cblk->passes = 0; + } + endpasses = &cblk->passes[cblk->numpasses]; + for (pass = cblk->passes; pass != endpasses; ++pass) { + pass->start = 0; + pass->end = 0; + pass->term = + JPC_ISTERMINATED(pass - cblk->passes, 0, + cblk->numpasses, + (tcmpt->cblksty & JPC_COX_TERMALL) != 0, + (tcmpt->cblksty & JPC_COX_LAZY) != 0); + pass->type = JPC_SEGTYPE(pass - cblk->passes, 0, + (tcmpt->cblksty & JPC_COX_LAZY) != 0); + pass->lyrno = -1; + if (pass == endpasses - 1) { + assert(pass->term == 1); + pass->term = 1; + } + } + + cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + 2, + jas_matrix_numcols(cblk->data) + 2); + assert(cblk->flags); + + + bitpos = cblk->numbps - 1; + pass = cblk->passes; + n = cblk->numpasses; + while (--n >= 0) { + + if (pass->type == JPC_SEG_MQ) { + /* NOP */ + } else { + assert(pass->type == JPC_SEG_RAW); + if (!bout) { + bout = jpc_bitstream_sopen(cblk->stream, "w"); + assert(bout); + } + } #if 1 - passtype = (pass - cblk->passes + 2) % 3; + passtype = (pass - cblk->passes + 2) % 3; #else - passtype = JPC_PASSTYPE(pass - cblk->passes + 2); + passtype = JPC_PASSTYPE(pass - cblk->passes + 2); #endif - pass->start = jas_stream_tell(cblk->stream); + pass->start = jas_stream_tell(cblk->stream); #if 0 assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream)); #endif - assert(bitpos >= 0); - vcausal = (tcmpt->cblksty & JPC_COX_VSC) != 0; - segsym = (tcmpt->cblksty & JPC_COX_SEGSYM) != 0; - if (pass->term) { - termmode = ((tcmpt->cblksty & JPC_COX_PTERM) ? - JPC_MQENC_PTERM : JPC_MQENC_DEFTERM) + 1; - } else { - termmode = 0; - } - switch (passtype) { - case JPC_SIGPASS: - ret = (pass->type == JPC_SEG_MQ) ? jpc_encsigpass(cblk->mqenc, - bitpos, band->orient, vcausal, cblk->flags, - cblk->data, termmode, &pass->nmsedec) : - jpc_encrawsigpass(bout, bitpos, vcausal, cblk->flags, - cblk->data, termmode, &pass->nmsedec); - break; - case JPC_REFPASS: - ret = (pass->type == JPC_SEG_MQ) ? jpc_encrefpass(cblk->mqenc, - bitpos, vcausal, cblk->flags, cblk->data, termmode, - &pass->nmsedec) : jpc_encrawrefpass(bout, bitpos, - vcausal, cblk->flags, cblk->data, termmode, - &pass->nmsedec); - break; - case JPC_CLNPASS: - assert(pass->type == JPC_SEG_MQ); - ret = jpc_encclnpass(cblk->mqenc, bitpos, band->orient, - vcausal, segsym, cblk->flags, cblk->data, termmode, - &pass->nmsedec); - break; - default: - assert(0); - break; - } - - if (pass->type == JPC_SEG_MQ) { - if (pass->term) { - jpc_mqenc_init(cblk->mqenc); - } - jpc_mqenc_getstate(cblk->mqenc, &pass->mqencstate); - pass->end = jas_stream_tell(cblk->stream); - if (tcmpt->cblksty & JPC_COX_RESET) { - jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs); - } - } else { - if (pass->term) { - if (jpc_bitstream_pending(bout)) { - jpc_bitstream_outalign(bout, 0x2a); - } - jpc_bitstream_close(bout); - bout = 0; - pass->end = jas_stream_tell(cblk->stream); - } else { - pass->end = jas_stream_tell(cblk->stream) + - jpc_bitstream_pending(bout); -/* NOTE - This will not work. need to adjust by # of pending output bytes */ - } - } + assert(bitpos >= 0); + vcausal = (tcmpt->cblksty & JPC_COX_VSC) != 0; + segsym = (tcmpt->cblksty & JPC_COX_SEGSYM) != 0; + if (pass->term) { + termmode = ((tcmpt->cblksty & JPC_COX_PTERM) ? + JPC_MQENC_PTERM : JPC_MQENC_DEFTERM) + 1; + } else { + termmode = 0; + } + switch (passtype) { + case JPC_SIGPASS: + if (pass->type == JPC_SEG_MQ) + jpc_encsigpass(cblk->mqenc, + bitpos, band->orient, vcausal, cblk->flags, + cblk->data, termmode, &pass->nmsedec); + else + jpc_encrawsigpass(bout, bitpos, vcausal, cblk->flags, + cblk->data, termmode, &pass->nmsedec); + break; + case JPC_REFPASS: + if (pass->type == JPC_SEG_MQ) + jpc_encrefpass( + cblk->mqenc, + bitpos, vcausal, cblk->flags, cblk->data, termmode, + &pass->nmsedec); + else + jpc_encrawrefpass(bout, bitpos, + vcausal, cblk->flags, cblk->data, termmode, + &pass->nmsedec); + break; + case JPC_CLNPASS: + assert(pass->type == JPC_SEG_MQ); + jpc_encclnpass( + cblk->mqenc, bitpos, band->orient, + vcausal, segsym, cblk->flags, cblk->data, termmode, + &pass->nmsedec); + break; + default: + assert(false); + break; + } + + if (pass->type == JPC_SEG_MQ) { + if (pass->term) { + jpc_mqenc_init(cblk->mqenc); + } + jpc_mqenc_getstate(cblk->mqenc, &pass->mqencstate); + pass->end = jas_stream_tell(cblk->stream); + if (tcmpt->cblksty & JPC_COX_RESET) { + jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs); + } + } else { + if (pass->term) { + if (jpc_bitstream_pending(bout)) { + jpc_bitstream_outalign(bout, 0x2a); + } + jpc_bitstream_close(bout); + bout = 0; + pass->end = jas_stream_tell(cblk->stream); + } else { + pass->end = jas_stream_tell(cblk->stream) + + jpc_bitstream_pending(bout); + /* NOTE - This will not work. need to adjust by # of pending + output bytes + */ + } + } #if 0 -/* XXX - This assertion fails sometimes when various coding modes are used. -This seems to be harmless, but why does it happen at all? */ -assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream)); + /* XXX - This assertion fails sometimes when various coding modes are used. + This seems to be harmless, but why does it happen at all? */ + assert(jas_stream_tell(cblk->stream) == + jas_stream_getrwcount(cblk->stream)); #endif - pass->wmsedec = jpc_fixtodbl(band->rlvl->tcmpt->synweight) * - jpc_fixtodbl(band->rlvl->tcmpt->synweight) * - jpc_fixtodbl(band->synweight) * - jpc_fixtodbl(band->synweight) * - jpc_fixtodbl(band->absstepsize) * jpc_fixtodbl(band->absstepsize) * - ((double) (1 << bitpos)) * ((double)(1 << bitpos)) * - jpc_fixtodbl(pass->nmsedec); - pass->cumwmsedec = pass->wmsedec; - if (pass != cblk->passes) { - pass->cumwmsedec += pass[-1].cumwmsedec; - } - if (passtype == JPC_CLNPASS) { - --bitpos; - } - ++pass; - } + pass->wmsedec = jpc_fixtodbl(band->rlvl->tcmpt->synweight) * + jpc_fixtodbl(band->rlvl->tcmpt->synweight) * + jpc_fixtodbl(band->synweight) * + jpc_fixtodbl(band->synweight) * + jpc_fixtodbl(band->absstepsize) * jpc_fixtodbl(band->absstepsize) * + ((double) (1 << bitpos)) * ((double)(1 << bitpos)) * + jpc_fixtodbl(pass->nmsedec); + pass->cumwmsedec = pass->wmsedec; + if (pass != cblk->passes) { + pass->cumwmsedec += pass[-1].cumwmsedec; + } + if (passtype == JPC_CLNPASS) { + --bitpos; + } + ++pass; + } #if 0 -dump_passes(cblk->passes, cblk->numpasses, cblk); + dump_passes(cblk->passes, cblk->numpasses, cblk); #endif - n = 0; - endpasses = &cblk->passes[cblk->numpasses]; - for (pass = cblk->passes; pass != endpasses; ++pass) { - if (pass->start < n) { - pass->start = n; - } - if (pass->end < n) { - pass->end = n; - } - if (!pass->term) { - termpass = pass; - while (termpass - pass < cblk->numpasses && - !termpass->term) { - ++termpass; - } - if (pass->type == JPC_SEG_MQ) { - t = (pass->mqencstate.lastbyte == 0xff) ? 1 : 0; - if (pass->mqencstate.ctreg >= 5) { - adjust = 4 + t; - } else { - adjust = 5 + t; - } - pass->end += adjust; - } - if (pass->end > termpass->end) { - pass->end = termpass->end; - } - if ((c = getthebyte(cblk->stream, pass->end - 1)) == EOF) { - abort(); - } - if (c == 0xff) { - ++pass->end; - } - n = JAS_MAX(n, pass->end); - } else { - n = JAS_MAX(n, pass->end); - } - } + n = 0; + endpasses = &cblk->passes[cblk->numpasses]; + for (pass = cblk->passes; pass != endpasses; ++pass) { + if (pass->start < n) { + pass->start = n; + } + if (pass->end < n) { + pass->end = n; + } + if (!pass->term) { + termpass = pass; + while (termpass - pass < cblk->numpasses && + !termpass->term) { + ++termpass; + } + if (pass->type == JPC_SEG_MQ) { + t = (pass->mqencstate.lastbyte == 0xff) ? 1 : 0; + if (pass->mqencstate.ctreg >= 5) { + adjust = 4 + t; + } else { + adjust = 5 + t; + } + pass->end += adjust; + } + if (pass->end > termpass->end) { + pass->end = termpass->end; + } + if ((c = getthebyte(cblk->stream, pass->end - 1)) == EOF) { + abort(); + } + if (c == 0xff) { + ++pass->end; + } + n = JAS_MAX(n, pass->end); + } else { + n = JAS_MAX(n, pass->end); + } + } #if 0 -dump_passes(cblk->passes, cblk->numpasses, cblk); + dump_passes(cblk->passes, cblk->numpasses, cblk); #endif - if (bout) { - jpc_bitstream_close(bout); - } + if (bout) { + jpc_bitstream_close(bout); + } - return 0; + return 0; } -/******************************************************************************\ + + +/*****************************************************************************\ * Code for significance pass. -\******************************************************************************/ +\*****************************************************************************/ -#define sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, vcausalflag) \ +#define sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, vcausalflag) \ { \ - int f; \ - int v; \ - f = *(fp); \ - if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ - v = (abs(*(dp)) & (one)) ? 1 : 0; \ - jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ - jpc_mqenc_putbit(mqenc, v); \ - if (v) { \ - *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ - v = ((*(dp) < 0) ? 1 : 0); \ - jpc_mqenc_setcurctx(mqenc, JPC_GETSCCTXNO(f)); \ - jpc_mqenc_putbit(mqenc, v ^ JPC_GETSPB(f)); \ - JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ - *(fp) |= JPC_SIG; \ - } \ - *(fp) |= JPC_VISIT; \ - } \ + int f; \ + int v; \ + f = *(fp); \ + if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ + v = (abs(*(dp)) & (one)) ? 1 : 0; \ + jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ + jpc_mqenc_putbit(mqenc, v); \ + if (v) { \ + *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ + v = ((*(dp) < 0) ? 1 : 0); \ + jpc_mqenc_setcurctx(mqenc, JPC_GETSCCTXNO(f)); \ + jpc_mqenc_putbit(mqenc, v ^ JPC_GETSPB(f)); \ + JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ + *(fp) |= JPC_SIG; \ + } \ + *(fp) |= JPC_VISIT; \ + } \ } static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec) { - int i; - int j; - int one; - int vscanlen; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fp; - jpc_fix_t *dp; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - int k; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, 0); - - } - } - - if (term) { - jpc_mqenc_flush(mqenc, term - 1); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; + int i; + int j; + int one; + int vscanlen; + int width; + int height; + int frowstep; + int drowstep; + int fstripestep; + int dstripestep; + jpc_fix_t *fstripestart; + jpc_fix_t *dstripestart; + jpc_fix_t *fp; + jpc_fix_t *dp; + jpc_fix_t *fvscanstart; + jpc_fix_t *dvscanstart; + int k; + + *nmsedec = 0; + width = jas_matrix_numcols(data); + height = jas_matrix_numrows(data); + frowstep = jas_matrix_rowstep(flags); + drowstep = jas_matrix_rowstep(data); + fstripestep = frowstep << 2; + dstripestep = drowstep << 2; + + one = 1 << (bitpos + JPC_NUMEXTRABITS); + + fstripestart = jas_matrix_getref(flags, 1, 1); + dstripestart = jas_matrix_getref(data, 0, 0); + for (i = height; i > 0; i -= 4, fstripestart += fstripestep, + dstripestart += dstripestep) { + fvscanstart = fstripestart; + dvscanstart = dstripestart; + vscanlen = JAS_MIN(i, 4); + for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { + fp = fvscanstart; + dp = dvscanstart; + k = vscanlen; + + sigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, orient, mqenc, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + sigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, orient, mqenc, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + sigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, orient, mqenc, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + sigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, orient, mqenc, 0); + + } + } + + if (term) { + jpc_mqenc_flush(mqenc, term - 1); + } + + return jpc_mqenc_error(mqenc) ? (-1) : 0; } -#define rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag) \ +#define rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag) \ { \ - jpc_fix_t f = *(fp); \ - jpc_fix_t v; \ - if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ - v = (abs(*(dp)) & (one)) ? 1 : 0; \ - if ((jpc_bitstream_putbit((out), v)) == EOF) { \ - return -1; \ - } \ - if (v) { \ - *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ - v = ((*(dp) < 0) ? 1 : 0); \ - if (jpc_bitstream_putbit(out, v) == EOF) { \ - return -1; \ - } \ - JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ - *(fp) |= JPC_SIG; \ - } \ - *(fp) |= JPC_VISIT; \ - } \ + jpc_fix_t f = *(fp); \ + jpc_fix_t v; \ + if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ + v = (abs(*(dp)) & (one)) ? 1 : 0; \ + if ((jpc_bitstream_putbit((out), v)) == EOF) { \ + return -1; \ + } \ + if (v) { \ + *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ + v = ((*(dp) < 0) ? 1 : 0); \ + if (jpc_bitstream_putbit(out, v) == EOF) { \ + return -1; \ + } \ + JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ + *(fp) |= JPC_SIG; \ + } \ + *(fp) |= JPC_VISIT; \ + } \ } static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec) { - int i; - int j; - int k; - int one; - int vscanlen; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fp; - jpc_fix_t *dp; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - } - } - - if (term) { - jpc_bitstream_outalign(out, 0x2a); - } - - return 0; + int i; + int j; + int k; + int one; + int vscanlen; + int width; + int height; + int frowstep; + int drowstep; + int fstripestep; + int dstripestep; + jpc_fix_t *fstripestart; + jpc_fix_t *dstripestart; + jpc_fix_t *fp; + jpc_fix_t *dp; + jpc_fix_t *fvscanstart; + jpc_fix_t *dvscanstart; + + *nmsedec = 0; + width = jas_matrix_numcols(data); + height = jas_matrix_numrows(data); + frowstep = jas_matrix_rowstep(flags); + drowstep = jas_matrix_rowstep(data); + fstripestep = frowstep << 2; + dstripestep = drowstep << 2; + + one = 1 << (bitpos + JPC_NUMEXTRABITS); + + fstripestart = jas_matrix_getref(flags, 1, 1); + dstripestart = jas_matrix_getref(data, 0, 0); + for (i = height; i > 0; i -= 4, fstripestart += fstripestep, + dstripestart += dstripestep) { + fvscanstart = fstripestart; + dvscanstart = dstripestart; + vscanlen = JAS_MIN(i, 4); + for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { + fp = fvscanstart; + dp = dvscanstart; + k = vscanlen; + + rawsigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, out, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + + rawsigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, out, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + + rawsigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, out, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + + rawsigpass_step(fp, frowstep, dp, bitpos, one, + nmsedec, out, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + + } + } + + if (term) { + jpc_bitstream_outalign(out, 0x2a); + } + + return 0; } /******************************************************************************\ * Code for refinement pass. \******************************************************************************/ -#define refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag) \ +#define refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag) \ { \ - int v; \ - if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ - (d) = *(dp); \ - *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ - jpc_mqenc_setcurctx((mqenc), JPC_GETMAGCTXNO(*(fp))); \ - v = (abs(d) & (one)) ? 1 : 0; \ - jpc_mqenc_putbit((mqenc), v); \ - *(fp) |= JPC_REFINE; \ - } \ + int v; \ + if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ + (d) = *(dp); \ + *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ + jpc_mqenc_setcurctx((mqenc), JPC_GETMAGCTXNO(*(fp))); \ + v = (abs(d) & (one)) ? 1 : 0; \ + jpc_mqenc_putbit((mqenc), v); \ + *(fp) |= JPC_REFINE; \ + } \ } static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec) { - int i; - int j; - int one; - int vscanlen; - int d; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - jpc_fix_t *dp; - jpc_fix_t *fp; + int i; + int j; + int one; + int vscanlen; + int d; + int width; + int height; + int frowstep; + int drowstep; + int fstripestep; + int dstripestep; + jpc_fix_t *fstripestart; + jpc_fix_t *dstripestart; + jpc_fix_t *fvscanstart; + jpc_fix_t *dvscanstart; + jpc_fix_t *dp; + jpc_fix_t *fp; int k; - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, 0); - - } - } - - if (term) { - jpc_mqenc_flush(mqenc, term - 1); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; + *nmsedec = 0; + width = jas_matrix_numcols(data); + height = jas_matrix_numrows(data); + frowstep = jas_matrix_rowstep(flags); + drowstep = jas_matrix_rowstep(data); + fstripestep = frowstep << 2; + dstripestep = drowstep << 2; + + one = 1 << (bitpos + JPC_NUMEXTRABITS); + + fstripestart = jas_matrix_getref(flags, 1, 1); + dstripestart = jas_matrix_getref(data, 0, 0); + for (i = height; i > 0; i -= 4, fstripestart += fstripestep, + dstripestart += dstripestep) { + fvscanstart = fstripestart; + dvscanstart = dstripestart; + vscanlen = JAS_MIN(i, 4); + for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { + fp = fvscanstart; + dp = dvscanstart; + k = vscanlen; + + refpass_step(fp, dp, bitpos, one, nmsedec, + mqenc, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + refpass_step(fp, dp, bitpos, one, nmsedec, + mqenc, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + refpass_step(fp, dp, bitpos, one, nmsedec, + mqenc, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + refpass_step(fp, dp, bitpos, one, nmsedec, + mqenc, 0); + + } + } + + if (term) { + jpc_mqenc_flush(mqenc, term - 1); + } + + return jpc_mqenc_error(mqenc) ? (-1) : 0; } -#define rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag) \ +#define rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag) \ { \ - jpc_fix_t d; \ - jpc_fix_t v; \ - if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ - d = *(dp); \ - *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ - v = (abs(d) & (one)) ? 1 : 0; \ - if (jpc_bitstream_putbit((out), v) == EOF) { \ - return -1; \ - } \ - *(fp) |= JPC_REFINE; \ - } \ + jpc_fix_t d; \ + jpc_fix_t v; \ + if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ + d = *(dp); \ + *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ + v = (abs(d) & (one)) ? 1 : 0; \ + if (jpc_bitstream_putbit((out), v) == EOF) { \ + return -1; \ + } \ + *(fp) |= JPC_REFINE; \ + } \ } static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec) { - int i; - int j; - int k; - int one; - int vscanlen; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - jpc_fix_t *dp; - jpc_fix_t *fp; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - - } - } - - if (term) { - jpc_bitstream_outalign(out, 0x2a); - } - - return 0; + int i; + int j; + int k; + int one; + int vscanlen; + int width; + int height; + int frowstep; + int drowstep; + int fstripestep; + int dstripestep; + jpc_fix_t *fstripestart; + jpc_fix_t *dstripestart; + jpc_fix_t *fvscanstart; + jpc_fix_t *dvscanstart; + jpc_fix_t *dp; + jpc_fix_t *fp; + + *nmsedec = 0; + width = jas_matrix_numcols(data); + height = jas_matrix_numrows(data); + frowstep = jas_matrix_rowstep(flags); + drowstep = jas_matrix_rowstep(data); + fstripestep = frowstep << 2; + dstripestep = drowstep << 2; + + one = 1 << (bitpos + JPC_NUMEXTRABITS); + + fstripestart = jas_matrix_getref(flags, 1, 1); + dstripestart = jas_matrix_getref(data, 0, 0); + for (i = height; i > 0; i -= 4, fstripestart += fstripestep, + dstripestart += dstripestep) { + fvscanstart = fstripestart; + dvscanstart = dstripestart; + vscanlen = JAS_MIN(i, 4); + for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { + fp = fvscanstart; + dp = dvscanstart; + k = vscanlen; + + rawrefpass_step(fp, dp, bitpos, one, nmsedec, + out, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + rawrefpass_step(fp, dp, bitpos, one, nmsedec, + out, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + rawrefpass_step(fp, dp, bitpos, one, nmsedec, + out, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + rawrefpass_step(fp, dp, bitpos, one, nmsedec, + out, vcausalflag); + + } + } + + if (term) { + jpc_bitstream_outalign(out, 0x2a); + } + + return 0; } /******************************************************************************\ * Code for cleanup pass. \******************************************************************************/ -#define clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, label1, label2, vcausalflag) \ +#define clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, label1, label2, vcausalflag) \ { \ - int f; \ - int v; \ + int f; \ + int v; \ label1 \ - f = *(fp); \ - if (!(f & (JPC_SIG | JPC_VISIT))) { \ - jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ - v = (abs(*(dp)) & (one)) ? 1 : 0; \ - jpc_mqenc_putbit((mqenc), v); \ - if (v) { \ + f = *(fp); \ + if (!(f & (JPC_SIG | JPC_VISIT))) { \ + jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ + v = (abs(*(dp)) & (one)) ? 1 : 0; \ + jpc_mqenc_putbit((mqenc), v); \ + if (v) { \ label2 \ - f = *(fp); \ - /* Coefficient is significant. */ \ - *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ - jpc_mqenc_setcurctx((mqenc), JPC_GETSCCTXNO(f)); \ - v = ((*(dp) < 0) ? 1 : 0); \ - jpc_mqenc_putbit((mqenc), v ^ JPC_GETSPB(f)); \ - JPC_UPDATEFLAGS4((fp), (frowstep), v, vcausalflag); \ - *(fp) |= JPC_SIG; \ - } \ - } \ - *(fp) &= ~JPC_VISIT; \ + f = *(fp); \ + /* Coefficient is significant. */ \ + *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ + jpc_mqenc_setcurctx((mqenc), JPC_GETSCCTXNO(f)); \ + v = ((*(dp) < 0) ? 1 : 0); \ + jpc_mqenc_putbit((mqenc), v ^ JPC_GETSPB(f)); \ + JPC_UPDATEFLAGS4((fp), (frowstep), v, vcausalflag); \ + *(fp) |= JPC_SIG; \ + } \ + } \ + *(fp) &= ~JPC_VISIT; \ } static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec) { - int i; - int j; - int k; - int vscanlen; - int v; - int runlen; - jpc_fix_t *fp; - int width; - int height; - jpc_fix_t *dp; - int one; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - - fp = fvscanstart; - if (vscanlen >= 4 && !((*fp) & (JPC_SIG | JPC_VISIT | - JPC_OTHSIGMSK)) && (fp += frowstep, !((*fp) & (JPC_SIG | - JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & - (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, - !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) { - dp = dvscanstart; - for (k = 0; k < vscanlen; ++k) { - v = (abs(*dp) & one) ? 1 : 0; - if (v) { - break; - } - dp += drowstep; - } - runlen = k; - if (runlen >= 4) { - jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); - jpc_mqenc_putbit(mqenc, 0); - continue; - } - jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); - jpc_mqenc_putbit(mqenc, 1); - jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); - jpc_mqenc_putbit(mqenc, runlen >> 1); - jpc_mqenc_putbit(mqenc, runlen & 1); - fp = fvscanstart + frowstep * runlen; - dp = dvscanstart + drowstep * runlen; - k = vscanlen - runlen; - switch (runlen) { - case 0: - goto clnpass_partial0; - break; - case 1: - goto clnpass_partial1; - break; - case 2: - goto clnpass_partial2; - break; - case 3: - goto clnpass_partial3; - break; - } - } else { - runlen = 0; - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - goto clnpass_full0; - } - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, clnpass_full0:, clnpass_partial0:, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, ;, clnpass_partial1:, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, ;, clnpass_partial2:, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, ;, clnpass_partial3:, 0); - } - } - - if (segsymflag) { - jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); - jpc_mqenc_putbit(mqenc, 1); - jpc_mqenc_putbit(mqenc, 0); - jpc_mqenc_putbit(mqenc, 1); - jpc_mqenc_putbit(mqenc, 0); - } - - if (term) { - jpc_mqenc_flush(mqenc, term - 1); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; + int i; + int j; + int k; + int vscanlen; + int v; + int runlen; + jpc_fix_t *fp; + int width; + int height; + jpc_fix_t *dp; + int one; + int frowstep; + int drowstep; + int fstripestep; + int dstripestep; + jpc_fix_t *fstripestart; + jpc_fix_t *dstripestart; + jpc_fix_t *fvscanstart; + jpc_fix_t *dvscanstart; + + *nmsedec = 0; + width = jas_matrix_numcols(data); + height = jas_matrix_numrows(data); + frowstep = jas_matrix_rowstep(flags); + drowstep = jas_matrix_rowstep(data); + fstripestep = frowstep << 2; + dstripestep = drowstep << 2; + + one = 1 << (bitpos + JPC_NUMEXTRABITS); + + fstripestart = jas_matrix_getref(flags, 1, 1); + dstripestart = jas_matrix_getref(data, 0, 0); + for (i = height; i > 0; i -= 4, fstripestart += fstripestep, + dstripestart += dstripestep) { + fvscanstart = fstripestart; + dvscanstart = dstripestart; + vscanlen = JAS_MIN(i, 4); + for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { + + fp = fvscanstart; + if (vscanlen >= 4 && !((*fp) & (JPC_SIG | JPC_VISIT | + JPC_OTHSIGMSK)) && (fp += frowstep, !((*fp) & (JPC_SIG | + JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & + (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, + !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) { + dp = dvscanstart; + for (k = 0; k < vscanlen; ++k) { + v = (abs(*dp) & one) ? 1 : 0; + if (v) { + break; + } + dp += drowstep; + } + runlen = k; + if (runlen >= 4) { + jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); + jpc_mqenc_putbit(mqenc, 0); + continue; + } + jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); + jpc_mqenc_putbit(mqenc, 1); + jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); + jpc_mqenc_putbit(mqenc, runlen >> 1); + jpc_mqenc_putbit(mqenc, runlen & 1); + fp = fvscanstart + frowstep * runlen; + dp = dvscanstart + drowstep * runlen; + k = vscanlen - runlen; + switch (runlen) { + case 0: + goto clnpass_partial0; + break; + case 1: + goto clnpass_partial1; + break; + case 2: + goto clnpass_partial2; + break; + case 3: + goto clnpass_partial3; + break; + } + } else { + runlen = 0; + fp = fvscanstart; + dp = dvscanstart; + k = vscanlen; + goto clnpass_full0; + } + clnpass_step(fp, frowstep, dp, bitpos, one, + orient, nmsedec, mqenc, clnpass_full0:, clnpass_partial0:, vcausalflag); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + clnpass_step(fp, frowstep, dp, bitpos, one, + orient, nmsedec, mqenc, ;, clnpass_partial1:, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + clnpass_step(fp, frowstep, dp, bitpos, one, + orient, nmsedec, mqenc, ;, clnpass_partial2:, 0); + if (--k <= 0) { + continue; + } + fp += frowstep; + dp += drowstep; + clnpass_step(fp, frowstep, dp, bitpos, one, + orient, nmsedec, mqenc, ;, clnpass_partial3:, 0); + } + } + + if (segsymflag) { + jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); + jpc_mqenc_putbit(mqenc, 1); + jpc_mqenc_putbit(mqenc, 0); + jpc_mqenc_putbit(mqenc, 1); + jpc_mqenc_putbit(mqenc, 0); + } + + if (term) { + jpc_mqenc_flush(mqenc, term - 1); + } + + return jpc_mqenc_error(mqenc) ? (-1) : 0; } diff --git a/converter/other/pamtopnm.c b/converter/other/pamtopnm.c index f043d721..f0ad451a 100644 --- a/converter/other/pamtopnm.c +++ b/converter/other/pamtopnm.c @@ -96,7 +96,7 @@ validateTupleType(struct pam const inpam, /* It's a PPMable image */ } else pm_error("PAM image does not have a depth and tuple_type " - "consistent with a PNM image." + "consistent with a PNM image. " "According to its " "header, depth is %d and tuple_type is '%s'. " "Use the -assume option to convert anyway.", diff --git a/converter/other/pamtosvg/pxl-outline.c b/converter/other/pamtosvg/pxl-outline.c index 456f41e1..19451c04 100644 --- a/converter/other/pamtosvg/pxl-outline.c +++ b/converter/other/pamtosvg/pxl-outline.c @@ -206,10 +206,8 @@ next_unmarked_pixel(unsigned int * const row, direction_type const orig_dir = *dir; direction_type test_dir; - pixel color; test_dir = *dir; /* initial value */ - color = getBitmapColor(bitmap, *row, *col); do { if (is_valid_dir(orig_row, orig_col, test_dir, bitmap, *marked)) { diff --git a/converter/other/pamtowinicon.c b/converter/other/pamtowinicon.c index 7e2c9e86..3d77d731 100644 --- a/converter/other/pamtowinicon.c +++ b/converter/other/pamtowinicon.c @@ -643,7 +643,7 @@ writePng(const struct pam * const pamP, if (haveAlpha || haveAnd) { const char * alphaFileName; - const char * command; + const char * alphaOpt; if (haveAlpha) makeAlphaFile(pamP, tuples, alphaPlane, &alphaFileName); @@ -653,19 +653,19 @@ writePng(const struct pam * const pamP, strcpy (pam.tuple_type, pam.depth == 3 ? PAM_PPM_TUPLETYPE: PAM_PGM_TUPLETYPE); - pm_asprintf(&command, "pnmtopng -alpha=\"%s\"", alphaFileName); + pm_asprintf(&alphaOpt, "-alpha=%s", alphaFileName); - pm_system(pm_feed_from_pamtuples, &pamTuples, - acceptToFile, &acceptParm, - command); + pm_system_lp("pnmtopng", pm_feed_from_pamtuples, &pamTuples, + acceptToFile, &acceptParm, + "pnmtopng", alphaOpt, NULL); - pm_strfree(command); + pm_strfree(alphaOpt); unlink(alphaFileName); } else { - pm_system(pm_feed_from_pamtuples, &pamTuples, - acceptToFile, &acceptParm, - "pnmtopng"); + pm_system_lp("pnmtopng", pm_feed_from_pamtuples, &pamTuples, + acceptToFile, &acceptParm, + "pnmtopng", NULL); } *sizeP = pngSize; diff --git a/converter/other/pnmtoddif.c b/converter/other/pnmtoddif.c index ae8c8524..ac02e425 100644 --- a/converter/other/pnmtoddif.c +++ b/converter/other/pnmtoddif.c @@ -538,15 +538,12 @@ convertRaster(FILE * const ifP, unsigned int const bytesPerLine) { unsigned char * data; - unsigned char * p; MALLOCARRAY(data, bytesPerLine); if (data == NULL) pm_error("Couldn't allocate %u-byte line buffer", bytesPerLine); - p = data; /* initial value */ - switch (PNM_FORMAT_TYPE(format)) { case PBM_TYPE: convertPbmRaster(ifP, format, cols, rows, ofP, bytesPerLine, data); diff --git a/converter/other/pnmtoplainpnm b/converter/other/pnmtoplainpnm index 87c58597..4f5378b2 100755 --- a/converter/other/pnmtoplainpnm +++ b/converter/other/pnmtoplainpnm @@ -1,3 +1,3 @@ #! /bin/sh -pnmtopnm -plain $@ +pamtopnm -plain $@ diff --git a/converter/other/pnmtopng.c b/converter/other/pnmtopng.c index ac171453..cf053f7e 100644 --- a/converter/other/pnmtopng.c +++ b/converter/other/pnmtopng.c @@ -1842,9 +1842,9 @@ buildColorLookup(pixel palette_pnm[], static void -buildColorAlphaLookup(pixel palette_pnm[], +buildColorAlphaLookup(pixel palettePnm[], unsigned int const paletteSize, - gray trans_pnm[], + gray transPnm[], unsigned int const transSize, gray const alphaMaxval, coloralphahash_table * const cahtP) { @@ -1857,12 +1857,12 @@ buildColorAlphaLookup(pixel palette_pnm[], gray paletteTrans; if (paletteIndex < transSize) - paletteTrans = alphaMaxval; + paletteTrans = transPnm[paletteIndex]; else - paletteTrans = trans_pnm[paletteIndex]; + paletteTrans = alphaMaxval; - addtocoloralphahash(caht, &palette_pnm[paletteIndex], - &trans_pnm[paletteIndex], paletteIndex); + addtocoloralphahash(caht, &palettePnm[paletteIndex], + &paletteTrans, paletteIndex); } *cahtP = caht; } diff --git a/converter/other/pnmtosir.c b/converter/other/pnmtosir.c index c8dec5b6..20bb6178 100644 --- a/converter/other/pnmtosir.c +++ b/converter/other/pnmtosir.c @@ -1,5 +1,5 @@ /* pnmtosir.c - read a portable anymap and produce a Solitaire Image Recorder -** file (MGI TYPE 11 or MGI TYPE 17) +** file (MGI TYPE 11 or MGI TYPE 17) ** ** Copyright (C) 1991 by Marvin Landis ** @@ -11,67 +11,63 @@ ** implied warranty. */ +#include <stdbool.h> #include "pnm.h" #define MAXCOLORS 256 -int main(int argc, char * argv[]) { - FILE* ifp; - xel** xels; - register xel* xP; - const char* dumpname; - int rows, cols, format, row, col; - int m, n; - int grayscale; + + +int +main(int argc, const char * argv[]) { + + FILE * ifP; + xel ** xels; + int rows, cols, format; + unsigned int n; + bool isGrayscale; xelval maxval; - const char* const usage = "[pnmfile]"; - unsigned char ub; unsigned short Header[16]; unsigned short LutHeader[16]; unsigned short Lut[2048]; - pnm_init( &argc, argv ); + pm_proginit(&argc, argv); - if ( argc > 2 ) - pm_usage( usage ); + if (argc-1 > 1) + pm_error("There is only one possible argument: the input file. " + "You specified %d", argc-1); - if ( argc == 2 ) - { - dumpname = argv[1]; - ifp = pm_openr( argv[1] ); - } - else - { - dumpname = "Standard Input"; - ifp = stdin; - } + if (argc-1 > 0) { + const char * const inputFileName = argv[1]; + ifP = pm_openr(inputFileName); + } else { + ifP = stdin; + } - xels = pnm_readpnm( ifp, &cols, &rows, &maxval, &format ); - pm_close( ifp ); + xels = pnm_readpnm(ifP, &cols, &rows, &maxval, &format); /* Figure out the colormap. */ - switch ( PNM_FORMAT_TYPE(format) ) - { - case PPM_TYPE: - grayscale = 0; - pm_message( "Writing a 24-bit SIR format (MGI TYPE 11)" ); + switch (PNM_FORMAT_TYPE(format) ) { + case PPM_TYPE: + isGrayscale = false; + pm_message("Writing a 24-bit SIR format (MGI TYPE 11)"); break; case PGM_TYPE: - grayscale = 1; - pm_message( "Writing a grayscale SIR format (MGI TYPE 17)" ); + isGrayscale = true; + pm_message("Writing a grayscale SIR format (MGI TYPE 17)"); break; - default: - grayscale = 1; - pm_message( "Writing a monochrome SIR format (MGI TYPE 17)" ); + default: + isGrayscale = true; + pm_message("Writing a monochrome SIR format (MGI TYPE 17)"); break; - } + } /* Set up the header. */ Header[0] = 0x3a4f; Header[1] = 0; - if (grayscale) + if (isGrayscale) Header[2] = 17; else Header[2] = 11; @@ -93,54 +89,65 @@ int main(int argc, char * argv[]) { LutHeader[2] = 5; LutHeader[3] = 256; LutHeader[4] = 256; - for (n = 0; n < 5; n++) + for (n = 0; n < 5; ++n) pm_writelittleshort(stdout,LutHeader[n]); - for (n = 5; n < 256; n++) + for (n = 5; n < 256; ++n) pm_writelittleshort(stdout,0); - for(n = 0; n < 3; n ++) - for (m = 0; m < 256; m++) + for (n = 0; n < 3; ++n) { + unsigned int m; + for (m = 0; m < 256; ++m) Lut[m * 4 + n] = m << 8; - for (n = 0; n < 1024; n++) + } + for (n = 0; n < 1024; ++n) pm_writelittleshort(stdout,Lut[n]); /* Finally, write out the data. */ - switch ( PNM_FORMAT_TYPE(format) ) - { - case PPM_TYPE: - for ( row = 0; row < rows; ++row ) - for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) - { - ub = (char) ( PPM_GETR( *xP ) * ( 255 / maxval ) ); - fputc( ub, stdout ); + switch (PNM_FORMAT_TYPE(format)) { + case PPM_TYPE: { + unsigned int row; + for (row = 0; row < rows; ++row) { + unsigned int col; + for (col = 0; col < cols; ++col) { + unsigned char const ub = + (char) (PPM_GETR(xels[row][col]) * (255 / maxval)); + fputc(ub, stdout); } - for ( row = 0; row < rows; ++row ) - for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) - { - ub = (char) ( PPM_GETG( *xP ) * ( 255 / maxval ) ); - fputc( ub, stdout ); + } + for (row = 0; row < rows; ++row) { + unsigned int col; + for (col = 0; col < cols; ++col) { + unsigned const char ub = + (char) (PPM_GETG(xels[row][col]) * (255 / maxval)); + fputc(ub, stdout); } - for ( row = 0; row < rows; ++row ) - for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) - { - ub = (char) ( PPM_GETB( *xP ) * ( 255 / maxval ) ); - fputc( ub, stdout ); + } + for (row = 0; row < rows; ++row) { + unsigned int col; + for (col = 0; col < cols; ++col) { + unsigned const char ub = + (char) (PPM_GETB(xels[row][col]) * (255 / maxval)); + fputc(ub, stdout); } - break; + } + } break; - default: - for ( row = 0; row < rows; ++row ) - for ( col = 0, xP = xels[row]; col < cols; ++col, ++xP ) - { - register unsigned long val; - - val = PNM_GET1( *xP ); - ub = (char) ( val * ( 255 / maxval ) ); - fputc( ub, stdout ); + default: { + unsigned int row; + for (row = 0; row < rows; ++row) { + unsigned int col; + for (col = 0; col < cols; ++col) { + unsigned long const val = PNM_GET1(xels[row][col]); + unsigned const char ub = (char) (val * (255 / maxval)); + fputc(ub, stdout); } - break; + } + } break; } + + pm_close(ifP); - exit( 0 ); + return 0; } + diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c index b253442f..016db2f6 100644 --- a/converter/other/pstopnm.c +++ b/converter/other/pstopnm.c @@ -784,12 +784,11 @@ execGhostscript(int const inputPipeFd, const char * gopt; const char * ropt; const char * textalphabitsopt; - int rc; findGhostscriptProg(&ghostscriptProg); /* Put the input pipe on Standard Input */ - rc = dup2(inputPipeFd, STDIN_FILENO); + dup2(inputPipeFd, STDIN_FILENO); close(inputPipeFd); pm_asprintf(&arg0, "gs"); diff --git a/converter/other/rletopnm.c b/converter/other/rletopnm.c index 99959141..ff37cfe4 100644 --- a/converter/other/rletopnm.c +++ b/converter/other/rletopnm.c @@ -264,7 +264,8 @@ writePpmRaster(FILE * const imageoutFileP, pixel *pixelrow; gray *alpharow; - int scan, x, y; + int scan; + int x; /* * Allocate some stuff. */ @@ -280,9 +281,9 @@ writePpmRaster(FILE * const imageoutFileP, /* * Loop through those scan lines. */ - for (scan = 0; scan < height; scan++) - y = rle_getrow(&hdr, scanlines[height - scan - 1]); - for (scan = 0; scan < height; scan++) { + for (scan = 0; scan < height; ++scan) + rle_getrow(&hdr, scanlines[height - scan - 1]); + for (scan = 0; scan < height; ++scan) { scanline = scanlines[scan]; switch (visual) { case GRAYSCALE: /* 8 bits without colormap */ @@ -366,7 +367,6 @@ writePgmRaster(FILE * const imageoutFileP, gray * pixelrow; gray * alpharow; int scan; - int y; /* * Allocate some stuff. */ @@ -383,7 +383,7 @@ writePgmRaster(FILE * const imageoutFileP, * Loop through those scan lines. */ for (scan = 0; scan < height; ++scan) - y = rle_getrow(&hdr, scanlines[height - scan - 1]); + rle_getrow(&hdr, scanlines[height - scan - 1]); for (scan = 0; scan < height; ++scan) { int x; diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c index 0d6494f9..f9e602ff 100644 --- a/converter/other/tifftopnm.c +++ b/converter/other/tifftopnm.c @@ -782,14 +782,22 @@ spawnWithInputPipe(const char * const shellCmd, else *errorP = NULL; } else { - int rc; + int terminationStatus; close(fd[PIPE_WRITE]); close(STDIN_FILENO); dup2(fd[PIPE_READ], STDIN_FILENO); - rc = system(shellCmd); + terminationStatus = system(shellCmd); - exit(rc); + if (WIFSIGNALED(terminationStatus)) + pm_error("Shell process was killed " + "by a Class %u signal.", + WTERMSIG(terminationStatus)); + else if (!WIFEXITED(terminationStatus)) + pm_error("Shell process died, but its termination status " + "0x%x doesn't make sense", terminationStatus); + else + exit(WEXITSTATUS(terminationStatus)); } } } diff --git a/converter/other/winicontopam.c b/converter/other/winicontopam.c index 664b4ef9..69ce7f05 100644 --- a/converter/other/winicontopam.c +++ b/converter/other/winicontopam.c @@ -1156,9 +1156,9 @@ convertPng(const unsigned char * const image, imageBuffer.buffer = (unsigned char *)image; fflush (stdout); - pm_system(pm_feed_from_memory, &imageBuffer, - NULL /* stdout accepter */, NULL, - "pngtopam -alphapam"); + pm_system_lp("pngtopam", pm_feed_from_memory, &imageBuffer, + NULL /* stdout accepter */, NULL, + "pngtopam", "-alphapam", NULL); } |