Commit 80586f1b authored by Emmanuel Bouthenot's avatar Emmanuel Bouthenot

Imported Upstream version 0.7.6

parent 1d8e7cec
# OptiPNG version 0.7.5
# Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
# OptiPNG version 0.7.6
# Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors.
# See the accompanying LICENSE file for details.
#
# A Contributing Author is a person or company who contributed code that
......@@ -19,8 +19,10 @@ Niels de Koning
Oliver Schneider
Petr Gajdos
Piotr Bandurski
Priit Laes
Ramona C. Truta
Sebastian Pipping
Stefan Brüns
Till Maas
Ville Skyttä
Vincent Lefèvre
Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors.
For the purpose of copyright and licensing, the list of Contributing
Authors is available in the accompanying AUTHORS file.
......
OptiPNG 0.7.5: Advanced PNG optimizer
=====================================
OptiPNG version 0.7.6: Advanced PNG optimizer
=============================================
Copyright and licensing
-----------------------
Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors.
See the accompanying AUTHORS file.
This program is distributed under the zlib license.
......@@ -30,14 +30,14 @@ Resources
Build instructions
------------------
On Unix, or under a Bourne-compatible shell, run ./configure and make:
cd optipng-0.7.5/
cd optipng-0.7.6/
./configure
make
make test
Alternatively, use a pre-configured makefile that matches your compiler;
e.g.:
cd optipng-0.7.5/
cd optipng-0.7.6/
nmake -f build/visualc.mk
nmake -f build/visualc.mk test
......
......@@ -2,6 +2,11 @@
trap "rm -f conftest* core a.out; exit 1" 1 2 3 15
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE
prefix="${prefix-/usr/local}"
exec_prefix="${exec_prefix-\$(prefix)}"
bindir="${bindir-\$(exec_prefix)/bin}"
......
This diff is collapsed.
<!-- Creator : groff version 1.22.2 -->
<!-- CreationDate: Mon Mar 24 12:45:00 2014 -->
<!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Sun Apr 3 11:39:00 2016 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
......@@ -623,7 +623,8 @@ RGBA) images.</p>
imported from the external image formats.</p>
<p style="margin-left:11%; margin-top: 1em">There is no
support for pipes or streams.</p>
support for pipes, streams, extended file attributes or
access control lists.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
......
No preview for this file type
......@@ -276,14 +276,15 @@ BUGS
Metadata is not imported from the external image formats.
There is no support for pipes or streams.
There is no support for pipes, streams, extended file attributes or
access control lists.
SEE ALSO
png(5), libpng(3), zlib(3), pngcrush(1), pngrewrite(1).
STANDARDS
The files produced by OptiPNG are compliant with PNG-2003:
Glenn Randers-Pehrson et al. Portable Network Graphics (PNG) Specifi-
Glenn Randers-Pehrson et al. Portable Network Graphics (PNG) Specifi-
cation, Second Edition.
W3C Recommendation 10 November 2003; ISO/IEC IS 15948:2003 (E).
http://www.w3.org/TR/PNG/
......@@ -291,8 +292,8 @@ STANDARDS
AUTHOR
OptiPNG is written and maintained by Cosmin Truta.
This manual page was originally written by Nelson A. de Oliveira for
the Debian Project. It was later updated by Cosmin Truta, and is now
This manual page was originally written by Nelson A. de Oliveira for
the Debian Project. It was later updated by Cosmin Truta, and is now
part of the OptiPNG distribution.
OptiPNG version 0.7.5 2014-Mar-24 OPTIPNG(1)
OptiPNG version 0.7.6 2016-Apr-03 OPTIPNG(1)
......@@ -5,14 +5,14 @@
* @author Cosmin Truta
*
* @section Copyright
* Copyright (C) 2003-2011 Cosmin Truta.
* Copyright (C) 2003-2015 Cosmin Truta.
* This software was derived from "giftopnm.c" by David Koblas,
* and is distributed under the same copyright and warranty terms.
*
* The original copyright notice is provided below.
* <pre>
* +-------------------------------------------------------------------+
* | Copyright 1990, 1991, 1993, David Koblas. (koblas@netcom.com) |
* | Copyright 1990 - 1994, David Koblas. (koblas@netcom.com) |
* | Permission to use, copy, modify, and distribute this software |
* | and its documentation for any purpose and without fee is hereby |
* | granted, provided that the above copyright notice appear in all |
......@@ -357,6 +357,7 @@ static int LZWGetCode(int code_size, int init_flag, FILE *stream)
{
curbit = 0;
lastbit = 0;
last_byte = 2;
done = LZW_FALSE;
return 0;
}
......@@ -369,8 +370,8 @@ static int LZWGetCode(int code_size, int init_flag, FILE *stream)
GIFError("GIF/LZW error: ran off the end of my bits");
return -1;
}
buffer[0] = buffer[last_byte-2];
buffer[1] = buffer[last_byte-1];
buffer[0] = buffer[last_byte - 2];
buffer[1] = buffer[last_byte - 1];
if ((count = GIFReadDataBlock(&buffer[2], stream)) == 0)
done = LZW_TRUE;
......@@ -382,7 +383,7 @@ static int LZWGetCode(int code_size, int init_flag, FILE *stream)
ret = 0;
for (i = curbit, j = 0; j < code_size; ++i, ++j)
ret |= ((buffer[ i / 8 ] & (1 << (i % 8))) != 0) << j;
ret |= ((buffer[i / 8] & (1 << (i % 8))) != 0) << j;
curbit += code_size;
return ret;
......@@ -403,7 +404,7 @@ static int LZWReadByte(int init_flag, int input_code_size, FILE *stream)
if (init_flag)
{
set_code_size = input_code_size;
code_size = set_code_size+1;
code_size = set_code_size + 1;
clear_code = 1 << set_code_size;
end_code = clear_code + 1;
max_code_size = 2 * clear_code;
......@@ -456,9 +457,9 @@ static int LZWReadByte(int init_flag, int input_code_size, FILE *stream)
table[1][i] = 0;
}
code_size = set_code_size+1;
max_code_size = 2*clear_code;
max_code = clear_code+2;
code_size = set_code_size + 1;
max_code_size = 2 * clear_code;
max_code = clear_code + 2;
sp = stack;
firstcode = oldcode =
LZWGetCode(code_size, LZW_FALSE, stream);
......@@ -583,7 +584,7 @@ void GIFInitExtension(struct GIFExtension *ext,
{
unsigned char *newBuffer;
ext->Screen = screen;
ext->Screen = screen;
if (initBufferSize > 0)
{
newBuffer = (unsigned char *)malloc(initBufferSize);
......@@ -720,4 +721,3 @@ void (*GIFError)(const char *message) = DefaultError;
* The warning handling callback.
*/
void (*GIFWarning)(const char *message) = DefaultWarning;
......@@ -5,14 +5,14 @@
* @author Cosmin Truta
*
* @section Copyright
* Copyright (C) 2003-2011 Cosmin Truta.
* Copyright (C) 2003-2015 Cosmin Truta.
* This software was derived from "giftopnm.c" by David Koblas,
* and is distributed under the same copyright and warranty terms.
*
* The original copyright notice is provided below.
* <pre>
* +-------------------------------------------------------------------+
* | Copyright 1990, 1991, 1993, David Koblas. (koblas@netcom.com) |
* | Copyright 1990 - 1994, David Koblas. (koblas@netcom.com) |
* | Permission to use, copy, modify, and distribute this software |
* | and its documentation for any purpose and without fee is hereby |
* | granted, provided that the above copyright notice appear in all |
......
......@@ -149,7 +149,7 @@ $(TIFF_DIR)/$(TIFF_LIB):
$(MAKE) -f $(TIFF_MK) $(TIFF_LIB) && \
cd $(OPTIPNG_DIR)
test: local-test test-libpng test-gifread test-minitiff
test: local-test test-gifread test-minitiff
.PHONY: local-test
local-test: optipng$(EXEEXT) $(OPTIPNG_TESTS)
......@@ -176,20 +176,6 @@ test/bitset_test.o: test/bitset_test.c bitset.h
test/ratio_test.o: test/ratio_test.c ratio.h
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
.PHONY: test-libpng
test-libpng: test-zlib
@USE_SYSTEM_LIBPNG_FALSE@ cd $(LIBPNG_DIR) && \
@USE_SYSTEM_LIBPNG_FALSE@ $(MAKE) -f $(LIBPNG_MK) $(LIBPNG_MK_DEF) test && \
@USE_SYSTEM_LIBPNG_FALSE@ cd $(OPTIPNG_DIR)
# FIXME:
# Can't test zlib if NO_GZCOMPRES and NO_GZIP are enabled.
.PHONY: test-zlib
test-zlib:
#@USE_SYSTEM_ZLIB_FALSE@ cd $(ZLIB_DIR) && \
#@USE_SYSTEM_ZLIB_FALSE@ $(MAKE) -f $(ZLIB_MK) test && \
#@USE_SYSTEM_ZLIB_FALSE@ cd $(OPTIPNG_DIR)
.PHONY: test-gifread
test-gifread:
cd $(GIF_DIR) && \
......
......@@ -95,21 +95,21 @@ inline void
opng_bitset_set_range(opng_bitset_t *set, int start_elt, int stop_elt)
{
if (start_elt <= stop_elt)
*set |= (((1U << (stop_elt - start_elt) << 1) - 1) << start_elt);
*set |= opng_bitset__range__(start_elt, stop_elt);
}
inline void
opng_bitset_reset_range(opng_bitset_t *set, int start_elt, int stop_elt)
{
if (start_elt <= stop_elt)
*set &= ~(((1U << (stop_elt - start_elt) << 1) - 1) << start_elt);
*set &= ~opng_bitset__range__(start_elt, stop_elt);
}
inline void
opng_bitset_flip_range(opng_bitset_t *set, int start_elt, int stop_elt)
{
if (start_elt <= stop_elt)
*set ^= (((1U << (stop_elt - start_elt) << 1) - 1) << start_elt);
*set ^= opng_bitset__range__(start_elt, stop_elt);
}
#else /* !__cplusplus */
......
......@@ -137,7 +137,7 @@ $(TIFF_DIR)\$(TIFF_LIB):
$(MAKE) -f $(TIFF_MK) $(TIFF_LIB)
cd $(OPTIPNG_DIR)
test: local-test test-libpng test-gifread test-minitiff
test: local-test test-gifread test-minitiff
local-test: optipng.exe $(OPTIPNG_TESTS)
-@$(RM_F) pngtest.out.png
......@@ -163,18 +163,6 @@ test\bitset_test.obj: test\bitset_test.c bitset.h
test\ratio_test.obj: test\ratio_test.c ratio.h
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) -o$@ $*.c
test-libpng: test-zlib
cd $(LIBPNG_DIR)
$(MAKE) -f $(LIBPNG_MK) $(LIBPNG_MK_DEF) test
cd $(OPTIPNG_DIR)
# FIXME:
# Can't test zlib if NO_GZCOMPRES and NO_GZIP are enabled.
test-zlib:
# cd $(ZLIB_DIR)
# $(MAKE) -f $(ZLIB_MK) test
# cd $(OPTIPNG_DIR)
test-gifread:
cd $(GIF_DIR)
$(MAKE) -f $(GIF_MK) test
......
......@@ -155,7 +155,7 @@ $(TIFF_DIR)/$(TIFF_LIB):
$(MAKE) -f $(TIFF_MK) $(TIFF_LIB) && \
cd $(OPTIPNG_DIR)
test: local-test test-libpng test-gifread test-minitiff
test: local-test test-gifread test-minitiff
.PHONY: local-test
local-test: optipng$(EXEEXT) $(OPTIPNG_TESTS)
......@@ -182,20 +182,6 @@ test/bitset_test.o: test/bitset_test.c bitset.h
test/ratio_test.o: test/ratio_test.c ratio.h
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
.PHONY: test-libpng
test-libpng: test-zlib
cd $(LIBPNG_DIR) && \
$(MAKE) -f $(LIBPNG_MK) $(LIBPNG_MK_DEF) test && \
cd $(OPTIPNG_DIR)
# FIXME:
# Can't test zlib if NO_GZCOMPRES and NO_GZIP are enabled.
.PHONY: test-zlib
test-zlib:
# cd $(ZLIB_DIR) && \
# $(MAKE) -f $(ZLIB_MK) test && \
# cd $(OPTIPNG_DIR)
.PHONY: test-gifread
test-gifread:
cd $(GIF_DIR) && \
......
......@@ -155,7 +155,7 @@ $(TIFF_DIR)/$(TIFF_LIB):
$(MAKE) -f $(TIFF_MK) $(TIFF_LIB) && \
cd $(OPTIPNG_DIR)
test: local-test test-libpng test-gifread test-minitiff
test: local-test test-gifread test-minitiff
.PHONY: local-test
local-test: optipng$(EXEEXT) $(OPTIPNG_TESTS)
......@@ -182,20 +182,6 @@ test/bitset_test.o: test/bitset_test.c bitset.h
test/ratio_test.o: test/ratio_test.c ratio.h
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
.PHONY: test-libpng
test-libpng: test-zlib
cd $(LIBPNG_DIR) && \
$(MAKE) -f $(LIBPNG_MK) $(LIBPNG_MK_DEF) test && \
cd $(OPTIPNG_DIR)
# FIXME:
# Can't test zlib if NO_GZCOMPRES and NO_GZIP are enabled.
.PHONY: test-zlib
test-zlib:
# cd $(ZLIB_DIR) && \
# $(MAKE) -f $(ZLIB_MK) test && \
# cd $(OPTIPNG_DIR)
.PHONY: test-gifread
test-gifread:
cd $(GIF_DIR) && \
......
......@@ -155,7 +155,7 @@ $(TIFF_DIR)/$(TIFF_LIB):
$(MAKE) -f $(TIFF_MK) $(TIFF_LIB) && \
cd $(OPTIPNG_DIR)
test: local-test test-libpng test-gifread test-minitiff
test: local-test test-gifread test-minitiff
.PHONY: local-test
local-test: optipng$(EXEEXT) $(OPTIPNG_TESTS)
......@@ -182,20 +182,6 @@ test/bitset_test.o: test/bitset_test.c bitset.h
test/ratio_test.o: test/ratio_test.c ratio.h
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) -o $@ $*.c
.PHONY: test-libpng
test-libpng: test-zlib
cd $(LIBPNG_DIR) && \
$(MAKE) -f $(LIBPNG_MK) $(LIBPNG_MK_DEF) test && \
cd $(OPTIPNG_DIR)
# FIXME:
# Can't test zlib if NO_GZCOMPRES and NO_GZIP are enabled.
.PHONY: test-zlib
test-zlib:
# cd $(ZLIB_DIR) && \
# $(MAKE) -f $(ZLIB_MK) test && \
# cd $(OPTIPNG_DIR)
.PHONY: test-gifread
test-gifread:
cd $(GIF_DIR) && \
......
......@@ -137,7 +137,7 @@ $(TIFF_DIR)\$(TIFF_LIB):
$(MAKE) -f $(TIFF_MK) $(TIFF_LIB)
cd $(OPTIPNG_DIR)
test: local-test test-libpng test-gifread test-minitiff
test: local-test test-gifread test-minitiff
local-test: optipng.exe $(OPTIPNG_TESTS)
-@$(RM_F) pngtest.out.png
......@@ -163,18 +163,6 @@ test\bitset_test.obj: test\bitset_test.c bitset.h
test\ratio_test.obj: test\ratio_test.c ratio.h
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) -Fo$@ $*.c
test-libpng: test-zlib
cd $(LIBPNG_DIR)
$(MAKE) -f $(LIBPNG_MK) $(LIBPNG_MK_DEF) test
cd $(OPTIPNG_DIR)
# FIXME:
# Can't test zlib if NO_GZCOMPRES and NO_GZIP are enabled.
test-zlib:
# cd $(ZLIB_DIR)
# $(MAKE) -f $(ZLIB_MK) test
# cd $(OPTIPNG_DIR)
test-gifread:
cd $(GIF_DIR)
$(MAKE) -f $(GIF_MK) test
......
.TH OPTIPNG 1 "2014-Mar-24" "OptiPNG version 0.7.5"
.TH OPTIPNG 1 "2016-Apr-03" "OptiPNG version 0.7.6"
.SH NAME
.B OptiPNG
......@@ -315,7 +315,8 @@ RGBA) images.
.P
Metadata is not imported from the external image formats.
.P
There is no support for pipes or streams.
There is no support for pipes, streams, extended file attributes or access
control lists.
.SH "SEE ALSO"
\fBpng\fP(5),
......
......@@ -2,7 +2,7 @@
* optim.c
* The main PNG optimization engine.
*
* Copyright (C) 2001-2014 Cosmin Truta.
* Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
*
* This software is distributed under the zlib license.
* Please see the accompanying LICENSE file.
......@@ -1646,7 +1646,7 @@ opng_optimize_impl(const char *infile_name)
if (new_outfile && !options.backup && !options.clobber)
{
usr_printf("The output file exists. "
"Rerun " PROGRAM_NAME " with -backup enabled\n");
"Rerun " PROGRAM_NAME " with -backup enabled.\n");
Throw "Can't overwrite the output file";
}
if (osys_test(outfile_name, "fw") != 0 ||
......
......@@ -2,7 +2,7 @@
* OptiPNG: Advanced PNG optimization program.
* http://optipng.sourceforge.net/
*
* Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
* Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors.
*
* This software is distributed under the zlib license.
* Please see the accompanying LICENSE file.
......
......@@ -2,7 +2,7 @@
* optipng.h
* The OptiPNG programming interface.
*
* Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
* Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors.
*
* This software is distributed under the zlib license.
* Please see the accompanying LICENSE file.
......
......@@ -19,9 +19,17 @@
* Auto-configuration.
*/
#if defined UNIX || defined __UNIX__ || defined __unix || defined __unix__ || \
defined _BSD_SOURCE || defined _GNU_SOURCE || defined _SVID_SOURCE || \
defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE
# define OSYS_UNIX
/* To be continued. */
#endif
#if defined __APPLE__ && defined __MACH__
# define OSYS_DARWIN
# ifndef OSYS_UNIX
/* The macros __unix and __unix__ are not predefined on Darwin. */
# define OSYS_UNIX
# endif
#endif
#if defined WIN32 || defined _WIN32 || defined _WIN32_WCE || \
......@@ -50,20 +58,10 @@
# define OSYS_DOSISH
#endif
#if defined __APPLE__
# define OSYS_MACOS
# if defined __MACH__
# define OSYS_MACOSX
# ifndef OSYS_UNIX
# define OSYS_UNIX
# endif
# endif
#endif
#if defined __CYGWIN__ || defined __DJGPP__ || defined __EMX__
# define OSYS_UNIXISH
/* Strictly speaking, this is not entirely correct, but "it works". */
# ifndef OSYS_UNIX
/* Strictly speaking, this is not correct, but "it works". */
# define OSYS_UNIX
# endif
#endif
......@@ -77,13 +75,6 @@
# endif
#endif
#if defined OSYS_UNIX
# ifndef _BSD_SOURCE
# define _BSD_SOURCE 1
# endif
# include <strings.h>
#endif
#if defined OSYS_UNIX || defined OSYS_WINDOWS || defined OSYS_DOSISH
# include <fcntl.h>
# include <sys/stat.h>
......@@ -120,7 +111,7 @@
# define OSYS_PATH_PATHSEP_STR "/"
# if defined OSYS_UNIXISH
# define OSYS_PATH_PATHSEP_ALL_STR "/\\"
# elif defined OSYS_MACOSX
# elif defined OSYS_DARWIN
# define OSYS_PATH_PATHSEP_ALL_STR "/:"
# else /* OSYS_UNIX and others */
# define OSYS_PATH_PATHSEP_ALL_STR "/"
......@@ -128,7 +119,6 @@
#endif
#define OSYS_PATH_EXTSEP '.'
#define OSYS_PATH_EXTSEP_STR "."
/* TODO: Support more systems (e.g. OSYS_RISCOS). */
#if defined OSYS_WINDOWS || defined OSYS_DOSISH || defined OSYS_UNIXISH
# define OSYS_PATH_DOS
......@@ -167,7 +157,7 @@
#endif
#ifdef OSYS_WINDOWS
# if defined OSYS_WIN64
# if defined OSYS_WIN64 || (defined _MSC_VER && _MSC_VER >= 1500)
# define OSYS_HAVE_STDIO__I64
# define OSYS_WINDOWS_IS_WIN9X() 0
# else
......@@ -518,7 +508,7 @@ osys_copy_attr(const char *src_path, const char *dest_path)
if (chmod(dest_path, sbuf.st_mode) != 0)
result = -1;
#ifdef AT_FDCWD
#if defined AT_FDCWD && defined UTIME_NOW && defined UTIME_OMIT
{
struct timespec times[2];
......
......@@ -2,7 +2,7 @@
* proginfo.h
* OptiPNG program information.
*
* Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors.
* Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors.
*
* This software is distributed under the zlib license.
* Please see the accompanying LICENSE file.
......@@ -16,9 +16,9 @@
#define PROGRAM_SUMMARY \
"Portable Network Graphics optimizer"
#define PROGRAM_VERSION \
"0.7.5"
"0.7.6"
#define PROGRAM_COPYRIGHT \
"Copyright (C) 2001-2014 Cosmin Truta and the Contributing Authors"
"Copyright (C) 2001-2016 Cosmin Truta and the Contributing Authors"
#define PROGRAM_URI \
"http://optipng.sourceforge.net/"
......
......@@ -22,7 +22,7 @@ typedef opng_ullong_t opng_ulongest_impl_t;
#define OPNG_LONGEST_IMPL_FORMAT OPNG_LLONG_FORMAT
#else
typedef long opng_longest_impl_t;
typedef unsigned long opng_longest_impl_t;
typedef unsigned long opng_ulongest_impl_t;
#define OPNG_LONGEST_IMPL_FORMAT "l"
#endif
......
......@@ -14,7 +14,8 @@
#include <stddef.h>
/* The following definitions exist for the benefit of pre-C99 and pre-C++11
/*
* The following definitions exist for the benefit of pre-C99 and pre-C++11
* compilers and runtimes that are unable to grok the long long type.
*/
#ifndef OPNG_LLONG_T_DEFINED
......
/*
* pngxrbmp.c - libpng external I/O: BMP reader.
* Copyright (C) 2003-2014 Cosmin Truta.
* Copyright (C) 2003-2016 Cosmin Truta and the Contributing Authors.
*
* This code was derived from "bmp2png.c" by MIYASAKA Masaru, and
* is distributed under the same copyright and warranty terms as libpng.
......@@ -108,17 +108,17 @@ bmp_get_dword(png_bytep ptr)
/*****************************************************************************/
/* BMP RLE helpers */
/* BMP helpers */
/*****************************************************************************/
static void
bmp_rle8_memset(png_bytep ptr, size_t offset, int ch, size_t len)
bmp_memset_bytes(png_bytep ptr, size_t offset, int ch, size_t len)
{
memset(ptr + offset, ch, len);
}
static void
bmp_rle4_memset(png_bytep ptr, size_t offset, int ch, size_t len)
bmp_memset_halfbytes(png_bytep ptr, size_t offset, int ch, size_t len)
{
if (len == 0)
return;
......@@ -136,7 +136,7 @@ bmp_rle4_memset(png_bytep ptr, size_t offset, int ch, size_t len)
}
static size_t
bmp_rle8_fread(png_bytep ptr, size_t offset, size_t len, FILE *stream)
bmp_fread_bytes(png_bytep ptr, size_t offset, size_t len, FILE *stream)
{
size_t result;
......@@ -147,15 +147,17 @@ bmp_rle8_fread(png_bytep ptr, size_t offset, size_t len, FILE *stream)
}
static size_t
bmp_rle4_fread(png_bytep ptr, size_t offset, size_t len, FILE *stream)
bmp_fread_halfbytes(png_bytep ptr, size_t offset, size_t len, FILE *stream)
{
size_t result;
int ch;
if (len == 0)
return 0;
ptr += offset / 2;
if (offset & 1) /* use half-byte operations at odd offset */
{
for (result = 0; result < len; result += 2)
for (result = 0; result < len - 1; result += 2)
{
ch = getc(stream);
if (ch == EOF)
......@@ -231,14 +233,14 @@ bmp_read_rows(png_bytepp begin_row, png_bytepp end_row, size_t row_size,
endn = row_size * 2;
if (endn <= row_size)
return 0; /* overflow */
bmp_memset_fn = bmp_rle4_memset;
bmp_fread_fn = bmp_rle4_fread;
bmp_memset_fn = bmp_memset_halfbytes;
bmp_fread_fn = bmp_fread_halfbytes;
}
else
{
endn = row_size;
bmp_memset_fn = bmp_rle8_memset;
bmp_fread_fn = bmp_rle8_fread;
bmp_memset_fn = bmp_memset_bytes;
bmp_fread_fn = bmp_fread_bytes;
}
if (compression == BI_RGB || compression == BI_BITFIELDS)
......@@ -258,19 +260,14 @@ bmp_read_rows(png_bytepp begin_row, png_bytepp end_row, size_t row_size,
if (compression == BI_RLE8)
{
endn = row_size;
bmp_memset_fn = bmp_rle8_memset;
bmp_fread_fn = bmp_rle8_fread;
}
else /* BI_RLE4 */
else /* BI_RLE4 */
{
endn = row_size * 2;
if (endn <= row_size)
return 0; /* overflow */
bmp_memset_fn = bmp_rle4_memset;
bmp_fread_fn = bmp_rle4_fread;
}
crt_row = begin_row;
for ( ; ; )
for (crt_row = begin_row; crt_row != end_row; )
{
ch = getc(stream); b1 = (unsigned int)ch;
ch = getc(stream); b2 = (unsigned int)ch;
......@@ -300,6 +297,7 @@ bmp_read_rows(png_bytepp begin_row, png_bytepp end_row, size_t row_size,
{
bmp_memset_fn(*crt_row, crtn, 0, endn - crtn);
crt_row += inc;
crtn = 0;
result = (begin_row <= end_row) ?
(end_row - begin_row) : (begin_row - end_row);
break; /* the rest is wiped out at the end */
......@@ -311,16 +309,17 @@ bmp_read_rows(png_bytepp begin_row, png_bytepp end_row, size_t row_size,
if (ch == EOF)
break;
dcrtn = (b1 < endn - crtn) ? (crtn + b1) : endn;
if (b2 > (size_t)((end_row - crt_row) * inc))
b2 = (unsigned int)((end_row - crt_row) * inc);
for ( ; b2 > 0; --b2)
{
bmp_memset_fn(*crt_row, crtn, 0, endn - crtn);
crt_row += inc;
crtn = 0;
++result;
if (crt_row == end_row)
break;
}
bmp_memset_fn(*crt_row, crtn, 0, dcrtn - crtn);
if (crt_row != end_row)
bmp_memset_fn(*crt_row, crtn, 0, dcrtn - crtn);
}
else /* b2 >= 3 bytes in absolute mode */
{
......@@ -566,7 +565,7 @@ pngx_read_bmp(png_structp png_ptr, png_infop info_ptr, FILE *stream)
rgba_mask[1] = 0x03e0;
rgba_mask[2] = 0x001f;
}
else /* pixdepth == 24 || pixdepth == 32 */
else /* pixdepth == 24 || pixdepth == 32 */
{
rgba_mask[0] = (png_uint_32)0x00ff0000L;
rgba_mask[1] = (png_uint_32)0x0000ff00L;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment