Merge branch 'port/switch'

This commit is contained in:
Vicki Pfau 2018-09-15 12:15:27 -07:00
commit 9de8f084ba
335 changed files with 20136 additions and 6076 deletions

View File

@ -6,7 +6,9 @@ project(mGBA)
set(BINARY_NAME mgba CACHE INTERNAL "Name of output binaries")
if(NOT MSVC)
set(GCC_STD "c99")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_COMPILER_VERSION VERSION_LESS "4.3")
if(SWITCH)
set(GCC_STD "gnu11")
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_COMPILER_VERSION VERSION_LESS "4.3")
set(GCC_STD "gnu99")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-missing-field-initializers -std=${GCC_STD}")
@ -44,8 +46,8 @@ set(BUILD_PYTHON OFF CACHE BOOL "Build Python bindings")
set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
set(SKIP_LIBRARY OFF CACHE BOOL "Skip building the library (useful for only building libretro or OpenEmu cores)")
set(BUILD_GL ON CACHE STRING "Build with OpenGL")
set(BUILD_GLES2 OFF CACHE STRING "Build with OpenGL|ES 2")
set(BUILD_GL ON CACHE BOOL "Build with OpenGL")
set(BUILD_GLES2 OFF CACHE BOOL "Build with OpenGL|ES 2")
set(USE_EPOXY ON CACHE STRING "Build with libepoxy")
set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies")
set(DISTBUILD OFF CACHE BOOL "Build distribution packages")
@ -65,7 +67,7 @@ file(GLOB GBA_CHEATS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/cheats/*.c)
file(GLOB GBA_RR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/rr/*.c)
file(GLOB CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/core/*.c)
file(GLOB CORE_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/core/test/*.c)
file(GLOB UTIL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.[cSs])
file(GLOB UTIL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/*.c)
file(GLOB UTIL_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/test/*.c)
file(GLOB GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_CURRENT_SOURCE_DIR}/src/feature/gui/*.c)
file(GLOB GBA_RENDERER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/renderers/*.c)
@ -283,7 +285,7 @@ if(PSP2 OR WII)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
endif()
if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII)
if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII OR DEFINED SWITCH)
set(IS_EMBEDDED ON)
set(USE_DEBUGGERS OFF)
set(USE_SQLITE3 OFF)
@ -293,6 +295,10 @@ if(DEFINED 3DS)
add_definitions(-DFIXED_ROM_BUFFER)
endif()
if(DEFINED SWITCH)
set(BUILD_GLES2 ON CACHE BOOL "Build with OpenGL|ES 2" FORCE)
endif()
if(NOT M_CORE_GBA)
set(USE_GDB_STUB OFF)
endif()
@ -331,7 +337,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
check_function_exists(uselocale HAVE_USELOCALE)
check_function_exists(setlocale HAVE_SETLOCALE)
else()
if(DEFINED 3DS OR DEFINED WII)
if(DEFINED 3DS OR DEFINED WII OR DEFINED SWITCH)
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,snprintf_l)
check_function_exists(snprintf_l HAVE_SNPRINTF_L)
set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,strtof_l)
@ -583,10 +589,13 @@ if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
set(PNG_SHARED OFF CACHE BOOL "" FORCE)
set(PNG_TESTS OFF CACHE BOOL "" FORCE)
set(SKIP_INSTALL_ALL ON)
if (SWITCH)
set(PNG_ARM_NEON "off" CACHE STRING "" FORCE)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng libpng)
set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/libpng;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
set_property(TARGET png_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/libpng;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
set(PNG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng ${CMAKE_CURRENT_BINARY_DIR}/libpng)
list(APPEND DEPENDENCY_LIB png16_static)
list(APPEND DEPENDENCY_LIB png_static)
set(USE_PNG ON)
endif()
@ -775,6 +784,10 @@ if(DEFINED PSP2)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/psp2 ${CMAKE_CURRENT_BINARY_DIR}/psp2)
endif()
if(DEFINED SWITCH)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/switch ${CMAKE_CURRENT_BINARY_DIR}/switch)
endif()
# Binaries
list(APPEND CORE_SRC
${UTIL_SRC}

View File

@ -42,6 +42,8 @@ png_structp PNGReadOpen(struct VFile* source, unsigned offset);
bool PNGInstallChunkHandler(png_structp png, void* context, ChunkHandler handler, const char* chunkName);
bool PNGReadHeader(png_structp png, png_infop info);
bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
bool PNGReadPixelsA(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
bool PNGReadPixels8(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
bool PNGIgnorePixels(png_structp png, png_infop info);
bool PNGReadFooter(png_structp png, png_infop end);
void PNGReadClose(png_structp png, png_infop info, png_infop end);

View File

@ -55,6 +55,9 @@ struct Address {
extern u32* SOCUBuffer;
#endif
#ifdef __SWITCH__
#include <switch.h>
#endif
static inline void SocketSubsystemInit() {
#ifdef _WIN32
@ -65,6 +68,8 @@ static inline void SocketSubsystemInit() {
SOCUBuffer = memalign(SOCU_ALIGN, SOCU_BUFFERSIZE);
socInit(SOCUBuffer, SOCU_BUFFERSIZE);
}
#elif defined(__SWITCH__)
socketInitializeDefault();
#endif
}
@ -75,6 +80,8 @@ static inline void SocketSubsystemDeinit() {
socExit();
free(SOCUBuffer);
SOCUBuffer = NULL;
#elif defined(__SWITCH__)
socketExit();
#endif
}
@ -103,7 +110,7 @@ static inline ssize_t SocketSend(Socket socket, const void* buffer, size_t size)
}
static inline ssize_t SocketRecv(Socket socket, void* buffer, size_t size) {
#ifdef _WIN32
#if defined(_WIN32) || defined(__SWITCH__)
return recv(socket, (char*) buffer, size, 0);
#else
return read(socket, buffer, size);

View File

@ -13,12 +13,14 @@ CXX_GUARD_START
#ifndef DISABLE_THREADING
#ifdef USE_PTHREADS
#include <mgba-util/platform/posix/threading.h>
#elif _WIN32
#elif defined(_WIN32)
#include <mgba-util/platform/windows/threading.h>
#elif PSP2
#elif defined(PSP2)
#include <mgba-util/platform/psp2/threading.h>
#elif _3DS
#elif defined(_3DS)
#include <mgba-util/platform/3ds/threading.h>
#elif defined(__SWITCH__)
#include <mgba-util/platform/switch/threading.h>
#else
#define DISABLE_THREADING
#endif

BIN
res/font-new.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -179,7 +179,7 @@ void mCoreConfigMakePortable(const struct mCoreConfig* config) {
WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, MAX_PATH, 0, 0);
StringCchCatA(out, MAX_PATH, "\\portable.ini");
portable = VFileOpen(out, O_WRONLY | O_CREAT);
#elif defined(PSP2) || defined(_3DS) || defined(GEKKO)
#elif defined(PSP2) || defined(_3DS) || defined(__SWITCH__) || defined(GEKKO)
// Already portable
#else
char out[PATH_MAX];
@ -219,7 +219,7 @@ void mCoreConfigDirectory(char* out, size_t outLength) {
UNUSED(portable);
snprintf(out, outLength, "ux0:data/%s", projectName);
sceIoMkdir(out, 0777);
#elif defined(GEKKO)
#elif defined(GEKKO) || defined(__SWITCH__)
UNUSED(portable);
snprintf(out, outLength, "/%s", projectName);
mkdir(out, 0777);

View File

@ -0,0 +1,51 @@
find_program(ELF2NRO elf2nro)
find_program(NACPTOOL nacptool)
find_program(BUILD_ROMFS build_romfs)
find_library(GLAPI_LIBRARY glapi REQUIRED)
find_library(EGL_LIBRARY EGL REQUIRED)
set(OS_DEFINES USE_VFS_FILE IOAPI_NO_64)
list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c)
include_directories(AFTER ${OPENGLES2_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIR})
file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/wii/wii-*.c)
if(${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
find_library(NOUVEAU_LIBRARY drm_nouveaud REQUIRED)
list(APPEND OS_LIB nxd)
else()
find_library(NOUVEAU_LIBRARY drm_nouveau REQUIRED)
list(APPEND OS_LIB nx)
endif()
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE)
set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE)
set(OS_SRC ${OS_SRC} PARENT_SCOPE)
set(OS_LIB ${OS_LIB} PARENT_SCOPE)
if(BUILD_PERF)
add_custom_target(${BINARY_NAME}-perf.nro ALL
${ELF2NRO} ../${BINARY_NAME}-perf ${BINARY_NAME}-perf.nro
DEPENDS ${BINARY_NAME}-perf)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}-perf.nro
DESTINATION . COMPONENT ${BINARY_NAME}-perf)
endif()
add_executable(${BINARY_NAME}.elf ${GUI_SRC} ${PLATFORM_SRC} main.c)
set_target_properties(${BINARY_NAME}.elf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
target_link_libraries(${BINARY_NAME}.elf ${BINARY_NAME} ${M_LIBRARY} ${EGL_LIBRARY} ${OPENGLES2_LIBRARY} ${GLAPI_LIBRARY} ${NOUVEAU_LIBRARY} stdc++ ${OS_LIB})
add_custom_command(OUTPUT control.nacp
COMMAND ${NACPTOOL} --create "${PROJECT_NAME}" "endrift" "${VERSION_STRING}" control.nacp)
add_custom_command(OUTPUT romfs.bin
COMMAND ${CMAKE_COMMAND} -E make_directory romfs
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/res/font-new.png" romfs/
COMMAND ${BUILD_ROMFS} romfs romfs.bin
COMMAND ${CMAKE_COMMAND} -E remove_directory romfs
DEPENDS "${CMAKE_SOURCE_DIR}/res/font-new.png")
add_custom_target(${BINARY_NAME}.nro ALL
${ELF2NRO} ${BINARY_NAME}.elf ${BINARY_NAME}.nro --romfs=romfs.bin --nacp=control.nacp --icon="${CMAKE_CURRENT_SOURCE_DIR}/icon.jpg"
DEPENDS ${BINARY_NAME}.elf control.nacp ${CMAKE_CURRENT_SOURCE_DIR}/icon.jpg romfs.bin)

View File

@ -0,0 +1,56 @@
if(DEFINED ENV{DEVKITPRO})
set(DEVKITPRO $ENV{DEVKITPRO})
else()
message(FATAL_ERROR "Could not find DEVKITPRO in environment")
endif()
if(DEFINED ENV{DEVKITA64})
set(DEVKITA64 $ENV{DEVKITA64})
else()
set(DEVKITA64 ${DEVKITPRO}/devkitA64)
endif()
if(DEFINED ENV{LIBNX})
set(LIBNX $ENV{LIBNX})
else()
set(LIBNX ${DEVKITPRO}/libnx)
endif()
set(extension)
if (CMAKE_HOST_WIN32)
set(extension .exe)
endif()
set(CMAKE_PROGRAM_PATH ${DEVKITA64}/bin)
set(cross_prefix aarch64-none-elf-)
set(arch_flags "-mtune=cortex-a57 -ffunction-sections -march=armv8-a -mtp=soft -fPIC -ftls-model=local-exec")
set(inc_flags "-I${LIBNX}/include ${arch_flags}")
set(link_flags "-L${LIBNX}/lib -lnx -specs=${LIBNX}/switch.specs ${arch_flags}")
set(CMAKE_SYSTEM_NAME Generic CACHE INTERNAL "system name")
set(CMAKE_SYSTEM_PROCESSOR aarch64 CACHE INTERNAL "processor")
set(CMAKE_LIBRARY_ARCHITECTURE aarch64-none-elf CACHE INTERNAL "abi")
find_program(CMAKE_AR ${cross_prefix}gcc-ar${extension})
find_program(CMAKE_RANLIB ${cross_prefix}gcc-ranlib${extension})
find_program(CMAKE_C_COMPILER ${cross_prefix}gcc${extension})
find_program(CMAKE_CXX_COMPILER ${cross_prefix}g++${extension})
find_program(CMAKE_ASM_COMPILER ${cross_prefix}gcc${extension})
find_program(CMAKE_LINKER ${cross_prefix}ld${extension})
set(CMAKE_C_FLAGS ${inc_flags} CACHE INTERNAL "c compiler flags")
set(CMAKE_ASM_FLAGS ${inc_flags} CACHE INTERNAL "assembler flags")
set(CMAKE_CXX_FLAGS ${inc_flags} CACHE INTERNAL "cxx compiler flags")
SET(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags")
set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags")
set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared link flags")
set(CMAKE_FIND_ROOT_PATH ${DEVKITARM}/aarch64-none-elf ${DEVKITPRO}/portlibs/switch)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "")
set(PKG_CONFIG_EXECUTABLE "/dev/null" CACHE INTERNAL "" FORCE)
set(SWITCH ON)
add_definitions(-D__SWITCH__)

View File

@ -0,0 +1,364 @@
/* Copyright (c) 2013-2018 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba-util/gui/font.h>
#include <mgba-util/gui/font-metrics.h>
#include <mgba-util/png-io.h>
#include <mgba-util/string.h>
#include <mgba-util/vfs.h>
#include <GLES2/gl2.h>
#define GLYPH_HEIGHT 24
#define CELL_HEIGHT 32
#define CELL_WIDTH 32
static const GLfloat _offsets[] = {
0.f, 0.f,
1.f, 0.f,
1.f, 1.f,
0.f, 1.f,
};
static const GLchar* const _gles2Header =
"#version 100\n"
"precision mediump float;\n";
static const char* const _vertexShader =
"attribute vec2 offset;\n"
"uniform vec3 origin;\n"
"uniform vec2 glyph;\n"
"uniform vec2 dims;\n"
"uniform mat2 transform;\n"
"varying vec2 texCoord;\n"
"void main() {\n"
" texCoord = (glyph + offset * dims) / 512.0;\n"
" vec2 scaledOffset = (transform * (offset * 2.0 - vec2(1.0)) + vec2(1.0)) / 2.0 * dims;\n"
" gl_Position = vec4((origin.x + scaledOffset.x) / 640.0 - 1.0, -(origin.y + scaledOffset.y) / 360.0 + 1.0, origin.z, 1.0);\n"
"}";
static const char* const _fragmentShader =
"varying vec2 texCoord;\n"
"uniform sampler2D tex;\n"
"uniform vec4 color;\n"
"uniform float cutoff;\n"
"void main() {\n"
" vec4 texColor = texture2D(tex, texCoord);\n"
" texColor.a = clamp((texColor.a - cutoff) / (1.0 - cutoff), 0.0, 1.0);\n"
" texColor.rgb = color.rgb;\n"
" texColor.a *= color.a;\n"
" gl_FragColor = texColor;\n"
"}";
struct GUIFont {
GLuint font;
GLuint program;
GLuint vbo;
GLuint offsetLocation;
GLuint texLocation;
GLuint dimsLocation;
GLuint transformLocation;
GLuint colorLocation;
GLuint originLocation;
GLuint glyphLocation;
GLuint cutoffLocation;
};
static bool _loadTexture(const char* path) {
struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) {
return false;
}
png_structp png = PNGReadOpen(vf, 0);
png_infop info = png_create_info_struct(png);
png_infop end = png_create_info_struct(png);
bool success = false;
if (png && info && end) {
success = PNGReadHeader(png, info);
}
void* pixels = NULL;
if (success) {
unsigned height = png_get_image_height(png, info);
unsigned width = png_get_image_width(png, info);
pixels = malloc(width * height);
if (pixels) {
success = PNGReadPixels8(png, info, pixels, width, height, width);
success = success && PNGReadFooter(png, end);
} else {
success = false;
}
if (success) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);
}
}
PNGReadClose(png, info, end);
if (pixels) {
free(pixels);
}
vf->close(vf);
return success;
}
struct GUIFont* GUIFontCreate(void) {
struct GUIFont* font = malloc(sizeof(struct GUIFont));
if (!font) {
return NULL;
}
glGenTextures(1, &font->font);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, font->font);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (!_loadTexture("romfs:/font-new.png")) {
GUIFontDestroy(font);
return NULL;
}
font->program = glCreateProgram();
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
const GLchar* shaderBuffer[2];
shaderBuffer[0] = _gles2Header;
shaderBuffer[1] = _vertexShader;
glShaderSource(vertexShader, 2, shaderBuffer, NULL);
shaderBuffer[1] = _fragmentShader;
glShaderSource(fragmentShader, 2, shaderBuffer, NULL);
glAttachShader(font->program, vertexShader);
glAttachShader(font->program, fragmentShader);
glCompileShader(fragmentShader);
GLint success;
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success) {
GLchar msg[512];
glGetShaderInfoLog(fragmentShader, sizeof(msg), NULL, msg);
puts(msg);
}
glCompileShader(vertexShader);
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success) {
GLchar msg[512];
glGetShaderInfoLog(vertexShader, sizeof(msg), NULL, msg);
puts(msg);
}
glLinkProgram(font->program);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
font->texLocation = glGetUniformLocation(font->program, "tex");
font->colorLocation = glGetUniformLocation(font->program, "color");
font->dimsLocation = glGetUniformLocation(font->program, "dims");
font->transformLocation = glGetUniformLocation(font->program, "transform");
font->originLocation = glGetUniformLocation(font->program, "origin");
font->glyphLocation = glGetUniformLocation(font->program, "glyph");
font->cutoffLocation = glGetUniformLocation(font->program, "cutoff");
font->offsetLocation = glGetAttribLocation(font->program, "offset");
glGenBuffers(1, &font->vbo);
glBindBuffer(GL_ARRAY_BUFFER, font->vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(_offsets), _offsets, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return font;
}
void GUIFontDestroy(struct GUIFont* font) {
glDeleteBuffers(1, &font->vbo);
glDeleteProgram(font->program);
glDeleteTextures(1, &font->font);
free(font);
}
unsigned GUIFontHeight(const struct GUIFont* font) {
UNUSED(font);
return GLYPH_HEIGHT;
}
unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
UNUSED(font);
if (glyph > 0x7F) {
glyph = '?';
}
return defaultFontMetrics[glyph].width * 2;
}
void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned* w, unsigned* h) {
UNUSED(font);
if (icon >= GUI_ICON_MAX) {
if (w) {
*w = 0;
}
if (h) {
*h = 0;
}
} else {
if (w) {
*w = defaultIconMetrics[icon].width * 2;
}
if (h) {
*h = defaultIconMetrics[icon].height * 2;
}
}
}
void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
if (glyph > 0x7F) {
glyph = '?';
}
struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph];
glUseProgram(font->program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, font->font);
glBindBuffer(GL_ARRAY_BUFFER, font->vbo);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUniform1i(font->texLocation, 0);
glUniform2f(font->glyphLocation, (glyph & 15) * CELL_WIDTH + metric.padding.left * 2, (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2);
glUniform2f(font->dimsLocation, CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2, CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2);
glUniform3f(font->originLocation, x, y - GLYPH_HEIGHT + metric.padding.top * 2, 0);
glUniformMatrix2fv(font->transformLocation, 1, GL_FALSE, (float[4]) {1.0, 0.0, 0.0, 1.0});
glVertexAttribPointer(font->offsetLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(font->offsetLocation);
glUniform1f(font->cutoffLocation, 0.1f);
glUniform4f(font->colorLocation, 0.0, 0.0, 0.0, ((color >> 24) & 0xFF) / 128.0f);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glUniform1f(font->cutoffLocation, 0.7f);
glUniform4f(font->colorLocation, ((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(font->offsetLocation);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
}
void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) {
if (icon >= GUI_ICON_MAX) {
return;
}
struct GUIIconMetric metric = defaultIconMetrics[icon];
float hFlip = 1.0f;
float vFlip = 1.0f;
switch (align & GUI_ALIGN_HCENTER) {
case GUI_ALIGN_HCENTER:
x -= metric.width;
break;
case GUI_ALIGN_RIGHT:
x -= metric.width * 2;
break;
}
switch (align & GUI_ALIGN_VCENTER) {
case GUI_ALIGN_VCENTER:
y -= metric.height;
break;
case GUI_ALIGN_BOTTOM:
y -= metric.height * 2;
break;
}
glUseProgram(font->program);
switch (orient) {
case GUI_ORIENT_HMIRROR:
hFlip = -1.0;
break;
case GUI_ORIENT_VMIRROR:
vFlip = -1.0;
break;
case GUI_ORIENT_0:
default:
// TODO: Rotate
break;
}
glUseProgram(font->program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, font->font);
glBindBuffer(GL_ARRAY_BUFFER, font->vbo);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUniform1i(font->texLocation, 0);
glUniform2f(font->glyphLocation, metric.x * 2, metric.y * 2 + 256);
glUniform2f(font->dimsLocation, metric.width * 2, metric.height * 2);
glUniform3f(font->originLocation, x, y, 0);
glUniformMatrix2fv(font->transformLocation, 1, GL_FALSE, (float[4]) {hFlip, 0.0, 0.0, vFlip});
glVertexAttribPointer(font->offsetLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(font->offsetLocation);
glUniform1f(font->cutoffLocation, 0.1f);
glUniform4f(font->colorLocation, 0.0, 0.0, 0.0, ((color >> 24) & 0xFF) / 128.0f);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glUniform1f(font->cutoffLocation, 0.7f);
glUniform4f(font->colorLocation, ((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(font->offsetLocation);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
}
void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) {
if (icon >= GUI_ICON_MAX) {
return;
}
struct GUIIconMetric metric = defaultIconMetrics[icon];
if (!w) {
w = metric.width * 2;
}
if (!h) {
h = metric.height * 2;
}
glUseProgram(font->program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, font->font);
glBindBuffer(GL_ARRAY_BUFFER, font->vbo);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUniform1i(font->texLocation, 0);
glUniform2f(font->glyphLocation, metric.x * 2, metric.y * 2 + 256);
glUniform2f(font->dimsLocation, metric.width * 2, metric.height * 2);
glUniform3f(font->originLocation, x + w / 2 - metric.width, y + h / 2 - metric.height, 0);
glUniformMatrix2fv(font->transformLocation, 1, GL_FALSE, (float[4]) {w * 0.5f / metric.width, 0.0, 0.0, h * 0.5f / metric.height});
glVertexAttribPointer(font->offsetLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(font->offsetLocation);
glUniform1f(font->cutoffLocation, 0.1f);
glUniform4f(font->colorLocation, 0.0, 0.0, 0.0, ((color >> 24) & 0xFF) / 128.0f);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glUniform1f(font->cutoffLocation, 0.7f);
glUniform4f(font->colorLocation, ((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color & 0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(font->offsetLocation);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

476
src/platform/switch/main.c Normal file
View File

@ -0,0 +1,476 @@
/* Copyright (c) 2013-2018 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "feature/gui/gui-runner.h"
#include <mgba/core/blip_buf.h>
#include <mgba/core/core.h>
#include <mgba/internal/gba/audio.h>
#include <mgba/internal/gba/input.h>
#include <mgba-util/gui.h>
#include <mgba-util/gui/font.h>
#include <switch.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#define AUTO_INPUT 0x4E585031
#define SAMPLES 0x400
#define BUFFER_SIZE 0x1000
#define N_BUFFERS 3
TimeType __nx_time_type = TimeType_UserSystemClock;
static EGLDisplay s_display;
static EGLContext s_context;
static EGLSurface s_surface;
static const GLfloat _offsets[] = {
0.f, 0.f,
1.f, 0.f,
1.f, 1.f,
0.f, 1.f,
};
static const GLchar* const _gles2Header =
"#version 100\n"
"precision mediump float;\n";
static const char* const _vertexShader =
"attribute vec2 offset;\n"
"uniform vec2 dims;\n"
"uniform vec2 insize;\n"
"varying vec2 texCoord;\n"
"void main() {\n"
" vec2 ratio = insize / 256.0;\n"
" vec2 scaledOffset = offset * dims;\n"
" gl_Position = vec4(scaledOffset.x * 2.0 - dims.x, scaledOffset.y * -2.0 + dims.y, 0.0, 1.0);\n"
" texCoord = offset * ratio;\n"
"}";
static const char* const _fragmentShader =
"varying vec2 texCoord;\n"
"uniform sampler2D tex;\n"
"uniform vec4 color;\n"
"void main() {\n"
" vec4 texColor = vec4(texture2D(tex, texCoord).rgb, 1.0);\n"
" texColor *= color;\n"
" gl_FragColor = texColor;\n"
"}";
static GLuint program;
static GLuint vbo;
static GLuint offsetLocation;
static GLuint texLocation;
static GLuint dimsLocation;
static GLuint insizeLocation;
static GLuint colorLocation;
static GLuint tex;
static color_t frameBuffer[256 * 256];
static struct mAVStream stream;
static int audioBufferActive;
static struct GBAStereoSample audioBuffer[N_BUFFERS][SAMPLES] __attribute__((__aligned__(0x1000)));
static AudioOutBuffer audoutBuffer[N_BUFFERS];
static int enqueuedBuffers;
static bool frameLimiter = true;
static int framecount = 0;
static bool initEgl() {
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (!s_display) {
goto _fail0;
}
eglInitialize(s_display, NULL, NULL);
EGLConfig config;
EGLint numConfigs;
static const EGLint attributeList[] = {
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_NONE
};
eglChooseConfig(s_display, attributeList, &config, 1, &numConfigs);
if (!numConfigs) {
goto _fail1;
}
s_surface = eglCreateWindowSurface(s_display, config, "", NULL);
if (!s_surface) {
goto _fail1;
}
//EGLint contextAttributeList[] = {
// EGL_CONTEXT_CLIENT_VERSION, 2,
// EGL_NONE
//};
s_context = eglCreateContext(s_display, config, EGL_NO_CONTEXT, NULL);
if (!s_context) {
goto _fail2;
}
eglMakeCurrent(s_display, s_surface, s_surface, s_context);
return true;
_fail2:
eglDestroySurface(s_display, s_surface);
s_surface = NULL;
_fail1:
eglTerminate(s_display);
s_display = NULL;
_fail0:
return false;
}
static void deinitEgl() {
if (s_display) {
if (s_context) {
eglDestroyContext(s_display, s_context);
}
if (s_surface) {
eglDestroySurface(s_display, s_surface);
}
eglTerminate(s_display);
}
}
static void _mapKey(struct mInputMap* map, uint32_t binding, int nativeKey, enum GBAKey key) {
mInputBindKey(map, binding, __builtin_ctz(nativeKey), key);
}
static void _drawStart(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
static void _drawEnd(void) {
if (frameLimiter || (framecount & 2) == 0) {
eglSwapBuffers(s_display, s_surface);
}
}
static uint32_t _pollInput(const struct mInputMap* map) {
int keys = 0;
hidScanInput();
u32 padkeys = hidKeysHeld(CONTROLLER_P1_AUTO);
keys |= mInputMapKeyBits(map, AUTO_INPUT, padkeys, 0);
return keys;
}
static enum GUICursorState _pollCursor(unsigned* x, unsigned* y) {
hidScanInput();
if (hidTouchCount() < 1) {
return GUI_CURSOR_NOT_PRESENT;
}
touchPosition touch;
hidTouchRead(&touch, 0);
*x = touch.px;
*y = touch.py;
return GUI_CURSOR_DOWN;
}
static void _setup(struct mGUIRunner* runner) {
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_A, GBA_KEY_A);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_B, GBA_KEY_B);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_PLUS, GBA_KEY_START);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_MINUS, GBA_KEY_SELECT);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_DUP, GBA_KEY_UP);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_DDOWN, GBA_KEY_DOWN);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_DLEFT, GBA_KEY_LEFT);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_DRIGHT, GBA_KEY_RIGHT);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_L, GBA_KEY_L);
_mapKey(&runner->core->inputMap, AUTO_INPUT, KEY_R, GBA_KEY_R);
runner->core->setVideoBuffer(runner->core, frameBuffer, 256);
runner->core->setAVStream(runner->core, &stream);
}
static void _gameLoaded(struct mGUIRunner* runner) {
u32 samplerate = audoutGetSampleRate();
double ratio = GBAAudioCalculateRatio(1, 60.0, 1);
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), samplerate * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), samplerate * ratio);
}
static void _drawTex(struct mGUIRunner* runner, unsigned width, unsigned height, bool faded) {
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUseProgram(program);
float aspectX = width / (float) runner->params.width;
float aspectY = height / (float) runner->params.height;
float max;
if (aspectX > aspectY) {
max = floor(1.0 / aspectX);
} else {
max = floor(1.0 / aspectY);
}
aspectX *= max;
aspectY *= max;
glUniform1i(texLocation, 0);
glUniform2f(dimsLocation, aspectX, aspectY);
glUniform2f(insizeLocation, width, height);
if (!faded) {
glUniform4f(colorLocation, 1.0f, 1.0f, 1.0f, 1.0f);
} else {
glUniform4f(colorLocation, 0.8f, 0.8f, 0.8f, 0.8f);
}
glVertexAttribPointer(offsetLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(offsetLocation);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableVertexAttribArray(offsetLocation);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
}
static void _drawFrame(struct mGUIRunner* runner, bool faded) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, frameBuffer);
unsigned width, height;
runner->core->desiredVideoDimensions(runner->core, &width, &height);
_drawTex(runner, width, height, faded);
++framecount;
}
static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
_drawTex(runner, width, height, faded);
}
static uint16_t _pollGameInput(struct mGUIRunner* runner) {
int keys = 0;
hidScanInput();
u32 padkeys = hidKeysHeld(CONTROLLER_P1_AUTO);
keys |= mInputMapKeyBits(&runner->core->inputMap, AUTO_INPUT, padkeys, 0);
return keys;
}
static void _setFrameLimiter(struct mGUIRunner* runner, bool limit) {
UNUSED(runner);
frameLimiter = limit;
}
static bool _running(struct mGUIRunner* runner) {
UNUSED(runner);
return appletMainLoop();
}
static void _postAudioBuffer(struct mAVStream* stream, blip_t* left, blip_t* right) {
UNUSED(stream);
static AudioOutBuffer* releasedBuffers;
u32 audoutNReleasedBuffers;
audoutGetReleasedAudioOutBuffer(&releasedBuffers, &audoutNReleasedBuffers);
enqueuedBuffers -= audoutNReleasedBuffers;
if (!frameLimiter && enqueuedBuffers == N_BUFFERS) {
blip_clear(left);
blip_clear(right);
return;
}
struct GBAStereoSample* samples = audioBuffer[audioBufferActive];
blip_read_samples(left, &samples[0].left, SAMPLES, true);
blip_read_samples(right, &samples[0].right, SAMPLES, true);
audoutAppendAudioOutBuffer(&audoutBuffer[audioBufferActive]);
audioBufferActive += 1;
audioBufferActive %= N_BUFFERS;
++enqueuedBuffers;
}
static int _batteryState(void) {
u32 charge;
int state = 0;
if (R_SUCCEEDED(psmGetBatteryChargePercentage(&charge))) {
state = charge / 25;
}
return state;
}
int main(int argc, char* argv[]) {
socketInitializeDefault();
nxlinkStdio();
initEgl();
romfsInit();
audoutInitialize();
psmInitialize();
struct GUIFont* font = GUIFontCreate();
u32 width = 1280;
u32 height = 720;
glViewport(0, 0, width, height);
glClearColor(0.f, 0.f, 0.f, 1.f);
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
program = glCreateProgram();
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
const GLchar* shaderBuffer[2];
shaderBuffer[0] = _gles2Header;
shaderBuffer[1] = _vertexShader;
glShaderSource(vertexShader, 2, shaderBuffer, NULL);
shaderBuffer[1] = _fragmentShader;
glShaderSource(fragmentShader, 2, shaderBuffer, NULL);
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glCompileShader(fragmentShader);
GLint success;
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success) {
GLchar msg[512];
glGetShaderInfoLog(fragmentShader, sizeof(msg), NULL, msg);
puts(msg);
}
glCompileShader(vertexShader);
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success) {
GLchar msg[512];
glGetShaderInfoLog(vertexShader, sizeof(msg), NULL, msg);
puts(msg);
}
glLinkProgram(program);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
texLocation = glGetUniformLocation(program, "tex");
colorLocation = glGetUniformLocation(program, "color");
dimsLocation = glGetUniformLocation(program, "dims");
insizeLocation = glGetUniformLocation(program, "insize");
offsetLocation = glGetAttribLocation(program, "offset");
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(_offsets), _offsets, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
stream.videoDimensionsChanged = NULL;
stream.postVideoFrame = NULL;
stream.postAudioFrame = NULL;
stream.postAudioBuffer = _postAudioBuffer;
memset(audioBuffer, 0, sizeof(audioBuffer));
audioBufferActive = 0;
enqueuedBuffers = 0;
size_t i;
for (i = 0; i < N_BUFFERS; ++i) {
audoutBuffer[i].next = NULL;
audoutBuffer[i].buffer = audioBuffer[i];
audoutBuffer[i].buffer_size = BUFFER_SIZE;
audoutBuffer[i].data_size = BUFFER_SIZE;
audoutBuffer[i].data_offset = 0;
}
struct mGUIRunner runner = {
.params = {
width, height,
font, "/",
_drawStart, _drawEnd,
_pollInput, _pollCursor,
_batteryState,
NULL, NULL,
},
.keySources = (struct GUIInputKeys[]) {
{
.name = "Controller Input",
.id = AUTO_INPUT,
.keyNames = (const char*[]) {
"A",
"B",
"X",
"Y",
"L Stick",
"R Stick",
"L",
"R",
"ZL",
"ZR",
"+",
"-",
"Left",
"Up",
"Right",
"Down",
"L Left",
"L Up",
"L Right",
"L Down",
"R Left",
"R Up",
"R Right",
"R Down",
"SL",
"SR"
},
.nKeys = 26
},
{ .id = 0 }
},
.nConfigExtra = 0,
.setup = _setup,
.teardown = NULL,
.gameLoaded = _gameLoaded,
.gameUnloaded = NULL,
.prepareForFrame = NULL,
.drawFrame = _drawFrame,
.drawScreenshot = _drawScreenshot,
.paused = NULL,
.unpaused = _gameLoaded,
.incrementScreenMode = NULL,
.setFrameLimiter = _setFrameLimiter,
.pollGameInput = _pollGameInput,
.running = _running
};
mGUIInit(&runner, "switch");
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_A, GUI_INPUT_SELECT);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_B, GUI_INPUT_BACK);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_X, GUI_INPUT_CANCEL);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DUP, GUI_INPUT_UP);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DDOWN, GUI_INPUT_DOWN);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DLEFT, GUI_INPUT_LEFT);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DRIGHT, GUI_INPUT_RIGHT);
audoutStartAudioOut();
mGUIRunloop(&runner);
psmExit();
audoutExit();
deinitEgl();
socketExit();
return 0;
}

View File

@ -0,0 +1,15 @@
/* Copyright (c) 2013-2018 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba-util/memory.h>
void* anonymousMemoryMap(size_t size) {
return malloc(size);
}
void mappedMemoryFree(void* memory, size_t size) {
UNUSED(size);
free(memory);
}

View File

@ -19,6 +19,9 @@
#ifdef _3DS
#include <3ds.h>
#endif
#ifdef __SWITCH__
#include <switch.h>
#endif
#include <errno.h>
#include <fcntl.h>
@ -49,6 +52,9 @@ struct PerfOpts {
extern bool allocateRomBuffer(void);
FS_Archive sdmcArchive;
#endif
#ifdef __SWITCH__
TimeType __nx_time_type = TimeType_LocalSystemClock;
#endif
static void _mPerfRunloop(struct mCore* context, int* frames, bool quiet);
static void _mPerfShutdown(int signal);
@ -71,6 +77,10 @@ int main(int argc, char** argv) {
if (!allocateRomBuffer()) {
return 1;
}
#elif defined(__SWITCH__)
UNUSED(_mPerfShutdown);
gfxInitDefault();
consoleInit(NULL);
#else
signal(SIGINT, _mPerfShutdown);
#endif
@ -128,6 +138,8 @@ int main(int argc, char** argv) {
#ifdef _3DS
gfxExit();
acExit();
#elif defined(__SWITCH__)
gfxExit();
#endif
return didFail;
@ -254,7 +266,10 @@ static bool _mPerfRunServer(const char* listen, const struct mArguments* args, c
SocketSend(_socket, header, strlen(header));
}
char path[PATH_MAX];
while (SocketRecv(_socket, path, sizeof(path)) > 0) {
memset(path, 0, sizeof(path));
ssize_t i;
while ((i = SocketRecv(_socket, path, sizeof(path) - 1)) > 0) {
path[i] = '\0';
char* nl = strchr(path, '\n');
if (nl == path) {
break;
@ -265,6 +280,7 @@ static bool _mPerfRunServer(const char* listen, const struct mArguments* args, c
if (!_mPerfRunCore(path, args, perfOpts)) {
break;
}
memset(path, 0, sizeof(path));
}
SocketClose(_socket);
SocketClose(server);

View File

@ -1,4 +1,4 @@
Libpng 1.6.17 - March 26, 2015
Libpng 1.6.34 - September 29, 2017
This is a public release of libpng, intended for use in production codes.
@ -7,61 +7,24 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a
"configure" script
libpng-1.6.17.tar.xz (LZMA-compressed, recommended)
libpng-1.6.17.tar.gz
libpng-1.6.34.tar.xz (LZMA-compressed, recommended)
libpng-1.6.34.tar.gz
Source files with CRLF line endings (for Windows), without the
"configure" script
lpng1617.7z (LZMA-compressed, recommended)
lpng1617.zip
lpng1634.7z (LZMA-compressed, recommended)
lpng1634.zip
Other information:
libpng-1.6.17-README.txt
libpng-1.6.17-LICENSE.txt
libpng-1.6.17-*.asc (armored detached GPG signatures)
libpng-1.6.34-README.txt
libpng-1.6.34-LICENSE.txt
libpng-1.6.34-*.asc (armored detached GPG signatures)
Changes since the last public release (1.6.16):
Removed duplicate PNG_SAFE_LIMITS_SUPPORTED handling from pngconf.h
Corrected the width limit calculation in png_check_IHDR().
Removed user limits from pngfix. Also pass NULL pointers to
png_read_row to skip the unnecessary row de-interlace stuff.
Added testing of png_set_packing() to pngvalid.c
Regenerated configure scripts in the *.tar distributions with libtool-2.4.4
Implement previously untested cases of libpng transforms in pngvalid.c
Fixed byte order in 2-byte filler, in png_do_read_filler().
Made the check for out-of-range values in png_set_tRNS() detect
values that are exactly 2^bit_depth, and work on 16-bit platforms.
Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.
Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and
pngset.c to avoid warnings about dead code.
Do not build png_product2() when it is unused.
Display user limits in the output from pngtest.
Eliminated the PNG_SAFE_LIMITS macro and restored the 1-million-column
and 1-million-row default limits in pnglibconf.dfa, that can be reset
by the user at build time or run time. This provides a more robust
defense against DOS and as-yet undiscovered overflows.
Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.
Allow user to call png_get_IHDR() with NULL arguments (Reuben Hawkins).
Rebuilt configure scripts with automake-1.15 and libtool-2.4.6
Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block
of png.h.
Avoid runtime checks when converting integer to png_byte with
Visual Studio (Sergey Kosarevsky)
Removed some comments that the configure script did not handle
properly from scripts/pnglibconf.dfa and pnglibconf.h.prebuilt.
Free the unknown_chunks structure even when it contains no data.
Updated CMakeLists.txt to add OSX framework, change YES/NO to ON/OFF
for consistency, and remove some useless tests (Alexey Petruchik).
Remove pnglibconf.h, pnglibconf.c, pnglibconf.pre, pnglibconf.dfn,
and pnglibconf.out instead of pnglibconf.* in "make clean" (Cosmin).
Fixed simplified 8-bit-linear to sRGB alpha. The calculated alpha
value was wrong. It's not clear if this affected the final stored
value; in the obvious code path the upper and lower 8-bits of the
alpha value were identical and the alpha was truncated to 8-bits
rather than dividing by 257 (John Bowler).
Changes since the last public release (1.6.33):
Removed contrib/pngsuite/i*.png; some of these were incorrect and caused
test failures.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +1,57 @@
# CMakeLists.txt
# Copyright (C) 2007-2015 Glenn Randers-Pehrson
# Copyright (C) 2007,2009-2017 Glenn Randers-Pehrson
# Written by Christian Ehrlicher, 2007
# Revised by Roger Lowman, 2009-2010
# Revised by Clifford Yapp, 2011-2012
# Revised by Roger Leigh, 2016
# Revised by Andreas Franek, 2016
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h
cmake_minimum_required(VERSION 2.4.4)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
cmake_minimum_required(VERSION 3.0.2)
cmake_policy(VERSION 3.0.2)
# Set MacOSX @rpath usage globally.
if (POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif(POLICY CMP0020)
if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif(POLICY CMP0042)
# Use new variable expansion policy.
if (POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
endif(POLICY CMP0053)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif(POLICY CMP0054)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
project(libpng C)
project(libpng ASM C)
enable_testing()
set(PNGLIB_MAJOR 1)
set(PNGLIB_MINOR 6)
set(PNGLIB_RELEASE 17)
set(PNGLIB_RELEASE 34)
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
include(GNUInstallDirs)
# needed packages
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
#Allow users to specify location of Zlib,
# Useful if zlib is being built alongside this as a sub-project
option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" OFF)
IF(NOT PNG_BUILD_ZLIB)
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
ENDIF(NOT PNG_BUILD_ZLIB)
if(NOT WIN32)
find_library(M_LIBRARY
@ -47,32 +76,391 @@ option(PNG_FRAMEWORK "Build OS X framework" OFF)
option(PNG_DEBUG "Build with debug output" OFF)
option(PNGARG "Disable ANSI-C prototypes" OFF)
option(PNG_HARDWARE_OPTIMIZATIONS "Enable Hardware Optimizations" ON)
set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names")
set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings")
if(PNG_HARDWARE_OPTIMIZATIONS)
# set definitions and sources for arm
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
set(PNG_ARM_NEON "check" CACHE STRING "Enable ARM NEON optimizations:
check: (default) use internal checking code;
off: disable the optimizations;
on: turn on unconditionally.")
set_property(CACHE PNG_ARM_NEON PROPERTY STRINGS
${PNG_ARM_NEON_POSSIBLE_VALUES})
list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index)
if(index EQUAL -1)
message(FATAL_ERROR
" PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]")
elseif(NOT ${PNG_ARM_NEON} STREQUAL "off")
set(libpng_arm_sources
arm/arm_init.c
arm/filter_neon.S
arm/filter_neon_intrinsics.c)
if(${PNG_ARM_NEON} STREQUAL "on")
add_definitions(-DPNG_ARM_NEON_OPT=2)
elseif(${PNG_ARM_NEON} STREQUAL "check")
add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED)
endif()
else()
add_definitions(-DPNG_ARM_NEON_OPT=0)
endif()
endif()
# set definitions and sources for powerpc
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*" )
set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off)
set(PNG_POWERPC_VSX "on" CACHE STRING "Enable POWERPC VSX optimizations:
off: disable the optimizations.")
set_property(CACHE PNG_POWERPC_VSX PROPERTY STRINGS
${PNG_POWERPC_VSX_POSSIBLE_VALUES})
list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index)
if(index EQUAL -1)
message(FATAL_ERROR
" PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]")
elseif(NOT ${PNG_POWERPC_VSX} STREQUAL "off")
set(libpng_powerpc_sources
powerpc/powerpc_init.c
powerpc/filter_vsx_intrinsics.c)
if(${PNG_POWERPC_VSX} STREQUAL "on")
add_definitions(-DPNG_POWERPC_VSX_OPT=2)
endif()
else()
add_definitions(-DPNG_POWERPC_VSX_OPT=0)
endif()
endif()
# set definitions and sources for intel
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*" )
set(PNG_INTEL_SSE_POSSIBLE_VALUES on off)
set(PNG_INTEL_SSE "on" CACHE STRING "Enable INTEL_SSE optimizations:
off: disable the optimizations")
set_property(CACHE PNG_INTEL_SSE PROPERTY STRINGS
${PNG_INTEL_SSE_POSSIBLE_VALUES})
list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index)
if(index EQUAL -1)
message(FATAL_ERROR
" PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]")
elseif(NOT ${PNG_INTEL_SSE} STREQUAL "off")
set(libpng_intel_sources
intel/intel_init.c
intel/filter_sse2_intrinsics.c)
if(${PNG_INTEL_SSE} STREQUAL "on")
add_definitions(-DPNG_INTEL_SSE_OPT=1)
endif()
else()
add_definitions(-DPNG_INTEL_SSE_OPT=0)
endif()
endif()
# set definitions and sources for MIPS
if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*" )
set(PNG_MIPS_MSA_POSSIBLE_VALUES on off)
set(PNG_MIPS_MSA "on" CACHE STRING "Enable MIPS_MSA optimizations:
off: disable the optimizations")
set_property(CACHE PNG_MIPS_MSA PROPERTY STRINGS
${PNG_MIPS_MSA_POSSIBLE_VALUES})
list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index)
if(index EQUAL -1)
message(FATAL_ERROR
" PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]")
elseif(NOT ${PNG_MIPS_MSA} STREQUAL "off")
set(libpng_mips_sources
mips/mips_init.c
mips/filter_msa_intrinsics.c)
if(${PNG_MIPS_MSA} STREQUAL "on")
add_definitions(-DPNG_MIPS_MSA_OPT=2)
endif()
else()
add_definitions(-DPNG_MIPS_MSA_OPT=0)
endif()
endif()
endif(PNG_HARDWARE_OPTIMIZATIONS)
# SET LIBNAME
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
# to distinguish between debug and release lib
set(CMAKE_DEBUG_POSTFIX "d")
# Use the prebuilt pnglibconf.h file from the scripts folder
# TODO: fix this by building with awk; without this no cmake build can be
# configured directly (to do so indirectly use your local awk to build a
# pnglibconf.h in the build directory.)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
include(CheckCSourceCompiles)
option(ld-version-script "Enable linker version script" ON)
if(ld-version-script AND NOT APPLE)
# Check if LD supports linker scripts.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 {
global: sym;
local: *;
};
VERS_2 {
global: sym2;
main;
} VERS_1;
")
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'")
check_c_source_compiles("void sym(void) {}
void sym2(void) {}
int main(void) {return 0;}
" HAVE_LD_VERSION_SCRIPT)
if(NOT HAVE_LD_VERSION_SCRIPT)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
check_c_source_compiles("void sym(void) {}
void sym2(void) {}
int main(void) {return 0;}
" HAVE_SOLARIS_LD_VERSION_SCRIPT)
endif()
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
endif()
# Find symbol prefix. Likely obsolete and unnecessary with recent
# toolchains (it's not done in many other projects).
function(symbol_prefix)
set(SYMBOL_PREFIX)
execute_process(COMMAND "${CMAKE_C_COMPILER}" "-E" "-"
INPUT_FILE /dev/null
OUTPUT_VARIABLE OUT
RESULT_VARIABLE STATUS)
if(CPP_FAIL)
message(WARNING "Failed to run the C preprocessor")
endif()
string(REPLACE "\n" ";" OUT "${OUT}")
foreach(line ${OUT})
string(REGEX MATCH "^PREFIX=" found_match "${line}")
if(found_match)
STRING(REGEX REPLACE "^PREFIX=(.*\)" "\\1" prefix "${line}")
string(REGEX MATCH "__USER_LABEL_PREFIX__" found_match "${prefix}")
if(found_match)
STRING(REGEX REPLACE "(.*)__USER_LABEL_PREFIX__(.*)" "\\1\\2" prefix "${prefix}")
endif()
set(SYMBOL_PREFIX "${prefix}")
endif()
endforeach()
message(STATUS "Symbol prefix: ${SYMBOL_PREFIX}")
set(SYMBOL_PREFIX "${SYMBOL_PREFIX}" PARENT_SCOPE)
endfunction()
if(UNIX)
symbol_prefix()
endif()
find_program(AWK NAMES gawk awk)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(NOT AWK OR ANDROID)
# No awk available to generate sources; use pre-built pnglibconf.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
add_custom_target(genfiles) # Dummy
else()
include(CMakeParseArguments)
# Generate .chk from .out with awk
# generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
function(generate_chk)
set(options)
set(oneValueArgs INPUT OUTPUT)
set(multiValueArgs DEPENDS)
cmake_parse_arguments(_GC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT _GC_INPUT)
message(FATAL_ERROR "Invalid arguments. generate_out requires input.")
endif()
if (NOT _GC_OUTPUT)
message(FATAL_ERROR "Invalid arguments. generate_out requires output.")
endif()
add_custom_command(OUTPUT "${_GC_OUTPUT}"
COMMAND "${CMAKE_COMMAND}"
"-DINPUT=${_GC_INPUT}"
"-DOUTPUT=${_GC_OUTPUT}"
-P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake"
DEPENDS "${_GC_INPUT}" ${_GC_DEPENDS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endfunction()
# Generate .out from .c with awk
# generate_out(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
function(generate_out)
set(options)
set(oneValueArgs INPUT OUTPUT)
set(multiValueArgs DEPENDS)
cmake_parse_arguments(_GO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT _GO_INPUT)
message(FATAL_ERROR "Invalid arguments. generate_out requires input.")
endif()
if (NOT _GO_OUTPUT)
message(FATAL_ERROR "Invalid arguments. generate_out requires output.")
endif()
add_custom_command(OUTPUT "${_GO_OUTPUT}"
COMMAND "${CMAKE_COMMAND}"
"-DINPUT=${_GO_INPUT}"
"-DOUTPUT=${_GO_OUTPUT}"
-P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake"
DEPENDS "${_GO_INPUT}" ${_GO_DEPENDS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endfunction()
# Generate specific source file with awk
# generate_source(OUTPUT outputfile [DEPENDS dep1 [dep2...]])
function(generate_source)
set(options)
set(oneValueArgs OUTPUT)
set(multiValueArgs DEPENDS)
cmake_parse_arguments(_GSO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT _GSO_OUTPUT)
message(FATAL_ERROR "Invalid arguments. generate_source requires output.")
endif()
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_GSO_OUTPUT}"
COMMAND "${CMAKE_COMMAND}"
"-DOUTPUT=${_GSO_OUTPUT}"
-P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake"
DEPENDS ${_GSO_DEPENDS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endfunction()
# Copy file
function(generate_copy source destination)
add_custom_command(OUTPUT "${destination}"
COMMAND "${CMAKE_COMMAND}" -E remove "${destination}"
COMMAND "${CMAKE_COMMAND}" -E copy "${source}"
"${destination}"
DEPENDS "${source}")
endfunction()
# Generate scripts/pnglibconf.h
generate_source(OUTPUT "scripts/pnglibconf.c"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk"
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
# Generate pnglibconf.c
generate_source(OUTPUT "pnglibconf.c"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk"
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
if(PNG_PREFIX)
set(PNGLIBCONF_H_EXTRA_DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst")
set(PNGPREFIX_H_EXTRA_DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out")
endif()
generate_out(INPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out")
# Generate pnglibconf.h
generate_source(OUTPUT "pnglibconf.h"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out"
${PNGLIBCONF_H_EXTRA_DEPENDS})
generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")
generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out")
# Generate pngprefix.h
generate_source(OUTPUT "pngprefix.h"
DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS})
generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")
generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt")
generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h"
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h"
"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h")
generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk"
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def")
add_custom_target(symbol-check DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk")
generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
"${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")
generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out"
"${CMAKE_CURRENT_BINARY_DIR}/libpng.vers")
add_custom_target(genvers DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers")
add_custom_target(gensym DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")
add_custom_target("genprebuilt"
COMMAND "${CMAKE_COMMAND}"
"-DOUTPUT=scripts/pnglibconf.h.prebuilt"
-P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
# A single target handles generation of all generated files. If
# they are dependend upon separately by multiple targets, this
# confuses parallel make (it would require a separate top-level
# target for each file to track the dependencies properly).
add_custom_target(genfiles DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/libpng.sym"
"${CMAKE_CURRENT_BINARY_DIR}/libpng.vers"
"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c"
"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h"
"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out"
"${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
"${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out")
endif(NOT AWK OR ANDROID)
# OUR SOURCES
set(libpng_public_hdrs
png.h
pngconf.h
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h"
)
set(libpng_sources
${libpng_public_hdrs}
set(libpng_private_hdrs
pngpriv.h
pngdebug.h
pnginfo.h
pngpriv.h
pngstruct.h
)
if(AWK AND NOT ANDROID)
list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
endif()
set(libpng_sources
${libpng_public_hdrs}
${libpng_private_hdrs}
png.c
pngerror.c
pngget.c
@ -88,6 +476,10 @@ set(libpng_sources
pngwrite.c
pngwtran.c
pngwutil.c
${libpng_arm_sources}
${libpng_intel_sources}
${libpng_mips_sources}
${libpng_powerpc_sources}
)
set(pngtest_sources
pngtest.c
@ -98,7 +490,18 @@ set(pngvalid_sources
set(pngstest_sources
contrib/libtests/pngstest.c
)
# SOME NEEDED DEFINITIONS
set(pngunknown_sources
contrib/libtests/pngunknown.c
)
set(pngimage_sources
contrib/libtests/pngimage.c
)
set(pngfix_sources
contrib/tools/pngfix.c
)
set(png_fix_itxt_sources
contrib/tools/png-fix-itxt.c
)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
@ -114,33 +517,59 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
unset(PNG_LIB_TARGETS)
if(PNG_SHARED)
add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
set(PNG_LIB_TARGETS ${PNG_LIB_NAME})
add_library(png SHARED ${libpng_sources})
set(PNG_LIB_TARGETS png)
set_target_properties(png PROPERTIES OUTPUT_NAME ${PNG_LIB_NAME})
add_dependencies(png genfiles)
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
set_target_properties(png PROPERTIES PREFIX "lib")
set_target_properties(png PROPERTIES IMPORT_PREFIX "lib")
endif()
target_link_libraries(png ${ZLIB_LIBRARY} ${M_LIBRARY})
if(UNIX AND AWK)
if(HAVE_LD_VERSION_SCRIPT)
set_target_properties(png PROPERTIES LINK_FLAGS
"-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT)
set_target_properties(png PROPERTIES LINK_FLAGS
"-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
endif()
endif()
target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
endif()
if(PNG_STATIC)
# does not work without changing name
set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC})
set(PNG_LIB_NAME_STATIC png_static)
add_library(png_static STATIC ${libpng_sources})
add_dependencies(png_static genfiles)
# MSVC doesn't use a different file extension for shared vs. static
# libs. We are able to change OUTPUT_NAME to remove the _static
# for all other platforms.
if(NOT MSVC)
set_target_properties(png_static PROPERTIES
OUTPUT_NAME "${PNG_LIB_NAME}"
CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(png_static PROPERTIES
OUTPUT_NAME "${PNG_LIB_NAME}_static"
CLEAN_DIRECT_OUTPUT 1)
endif()
list(APPEND PNG_LIB_TARGETS png_static)
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
set_target_properties(png_static PROPERTIES PREFIX "lib")
endif()
target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
target_link_libraries(png_static ${ZLIB_LIBRARY} ${M_LIBRARY})
endif()
if(PNG_FRAMEWORK)
set(PNG_LIB_NAME_FRAMEWORK ${PNG_LIB_NAME}_framework)
add_library(${PNG_LIB_NAME_FRAMEWORK} SHARED ${libpng_sources})
list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_FRAMEWORK})
set_target_properties(${PNG_LIB_NAME_FRAMEWORK} PROPERTIES
set(PNG_LIB_NAME_FRAMEWORK png_framework)
add_library(png_framework SHARED ${libpng_sources})
add_dependencies(png_framework genfiles)
list(APPEND PNG_LIB_TARGETS png_framework)
set_target_properties(png_framework PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION ${PNGLIB_VERSION}
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}
@ -149,7 +578,7 @@ if(PNG_FRAMEWORK)
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
PUBLIC_HEADER "${libpng_public_hdrs}"
OUTPUT_NAME png)
target_link_libraries(${PNG_LIB_NAME_FRAMEWORK} ${ZLIB_LIBRARY} ${M_LIBRARY})
target_link_libraries(png_framework ${ZLIB_LIBRARY} ${M_LIBRARY})
endif()
if(NOT PNG_LIB_TARGETS)
@ -160,79 +589,233 @@ if(NOT PNG_LIB_TARGETS)
endif()
if(PNG_SHARED AND WIN32)
set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
set_target_properties(png PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
endif()
function(png_add_test)
set(options)
set(oneValueArgs NAME COMMAND)
set(multiValueArgs OPTIONS FILES)
cmake_parse_arguments(_PAT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT _PAT_NAME)
message(FATAL_ERROR "Invalid arguments. png_add_test requires name.")
endif()
if (NOT _PAT_COMMAND)
message(FATAL_ERROR "Invalid arguments. png_add_test requires command.")
endif()
set(TEST_OPTIONS "${_PAT_OPTIONS}")
set(TEST_FILES "${_PAT_FILES}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scripts/test.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake" @ONLY)
if(CMAKE_MAJOR_VERSION GREATER 2) # have generator expressions
add_test(NAME "${_PAT_NAME}"
COMMAND "${CMAKE_COMMAND}"
"-DLIBPNG=$<TARGET_FILE:png>"
"-DTEST_COMMAND=$<TARGET_FILE:${_PAT_COMMAND}>"
-P "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake")
else() # old 2.x add_test; limited and won't work well on Windows
# Note LIBPNG is a dummy value as there are no generator expressions
add_test("${_PAT_NAME}" "${CMAKE_COMMAND}"
"-DLIBPNG=${CMAKE_CURRENT_BINARY_DIR}/libpng.so"
"-DTEST_COMMAND=./${_PAT_COMMAND}"
-P "${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake")
endif()
endfunction()
if(PNG_TESTS AND PNG_SHARED)
# does not work with msvc due to png_lib_ver issue
# Find test PNG files by globbing, but sort lists to ensure
# consistency between different filesystems.
file(GLOB PNGSUITE_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/*.png")
list(SORT PNGSUITE_PNGS)
file(GLOB TEST_PNGS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/*.png")
list(SORT TEST_PNGS)
set(PNGTEST_PNG "${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png")
add_executable(pngtest ${pngtest_sources})
target_link_libraries(pngtest ${PNG_LIB_NAME})
add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
#
target_link_libraries(pngtest png)
png_add_test(NAME pngtest COMMAND pngtest FILES "${PNGTEST_PNG}")
add_executable(pngvalid ${pngvalid_sources})
target_link_libraries(pngvalid ${PNG_LIB_NAME})
add_test(pngvalid ./pngvalid)
target_link_libraries(pngvalid png)
png_add_test(NAME pngvalid-gamma-16-to-8
COMMAND pngvalid OPTIONS --gamma-16-to-8)
png_add_test(NAME pngvalid-gamma-alpha-mode
COMMAND pngvalid OPTIONS --gamma-alpha-mode)
png_add_test(NAME pngvalid-gamma-background
COMMAND pngvalid OPTIONS --gamma-background)
png_add_test(NAME pngvalid-gamma-expand16-alpha-mode
COMMAND pngvalid OPTIONS --gamma-alpha-mode --expand16)
png_add_test(NAME pngvalid-gamma-expand16-background
COMMAND pngvalid OPTIONS --gamma-background --expand16)
png_add_test(NAME pngvalid-gamma-expand16-transform
COMMAND pngvalid OPTIONS --gamma-transform --expand16)
png_add_test(NAME pngvalid-gamma-sbit
COMMAND pngvalid OPTIONS --gamma-sbit)
png_add_test(NAME pngvalid-gamma-threshold
COMMAND pngvalid OPTIONS --gamma-threshold)
png_add_test(NAME pngvalid-gamma-transform
COMMAND pngvalid OPTIONS --gamma-transform)
png_add_test(NAME pngvalid-progressive-interlace-standard
COMMAND pngvalid OPTIONS --standard --progressive-read --interlace)
png_add_test(NAME pngvalid-progressive-size
COMMAND pngvalid OPTIONS --size --progressive-read)
png_add_test(NAME pngvalid-progressive-standard
COMMAND pngvalid OPTIONS --standard --progressive-read)
png_add_test(NAME pngvalid-standard
COMMAND pngvalid OPTIONS --standard)
png_add_test(NAME pngvalid-transform
COMMAND pngvalid OPTIONS --transform)
add_executable(pngstest ${pngstest_sources})
target_link_libraries(pngstest ${PNG_LIB_NAME})
add_test(pngstest ./pngstest
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g01.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g02.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g04.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn2c08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn2c16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p01.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p02.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p04.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn4a08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn4a16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn6a08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn6a16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g01.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g02.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g04.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn2c16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn3p08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbgn2c16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbgn3p08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbrn2c08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbwn0g16.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbwn3p08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbyn3p08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n0g08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n2c08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n3p08.png
${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp1n3p08.png
)
target_link_libraries(pngstest png)
foreach(gamma_type 1.8 linear none sRGB)
foreach(alpha_type none alpha)
set(PNGSTEST_FILES)
foreach(test_png ${TEST_PNGS})
string(REGEX MATCH ".*-linear[-.].*" TEST_PNG_LINEAR "${test_png}")
string(REGEX MATCH ".*-sRGB[-.].*" TEST_PNG_SRGB "${test_png}")
string(REGEX MATCH ".*-1.8[-.].*" TEST_PNG_G18 "${test_png}")
string(REGEX MATCH ".*-alpha-.*" TEST_PNG_ALPHA "${test_png}")
set(TEST_PNG_VALID TRUE)
if(TEST_PNG_ALPHA)
if (NOT "${alpha_type}" STREQUAL "alpha")
set(TEST_PNG_VALID FALSE)
endif()
else()
if ("${alpha_type}" STREQUAL "alpha")
set(TEST_PNG_VALID FALSE)
endif()
endif()
if(TEST_PNG_LINEAR)
if(NOT "${gamma_type}" STREQUAL "linear")
set(TEST_PNG_VALID FALSE)
endif()
elseif(TEST_PNG_SRGB)
if(NOT "${gamma_type}" STREQUAL "sRGB")
set(TEST_PNG_VALID FALSE)
endif()
elseif(TEST_PNG_G18)
if(NOT "${gamma_type}" STREQUAL "1.8")
set(TEST_PNG_VALID FALSE)
endif()
else()
if(NOT "${gamma_type}" STREQUAL "none")
set(TEST_PNG_VALID FALSE)
endif()
endif()
if(TEST_PNG_VALID)
list(APPEND PNGSTEST_FILES "${test_png}")
endif()
endforeach()
# Should already be sorted, but sort anyway to be certain.
list(SORT PNGSTEST_FILES)
png_add_test(NAME pngstest-${gamma_type}-${alpha_type}
COMMAND pngstest
OPTIONS --tmpfile "${gamma_type}-${alpha_type}-" --log
FILES ${PNGSTEST_FILES})
endforeach()
endforeach()
add_executable(pngunknown ${pngunknown_sources})
target_link_libraries(pngunknown png)
png_add_test(NAME pngunknown-discard COMMAND pngunknown OPTIONS --strict default=discard FILES "${PNGTEST_PNG}")
png_add_test(NAME pngunknown-IDAT COMMAND pngunknown OPTIONS --strict default=discard IDAT=save FILES "${PNGTEST_PNG}")
png_add_test(NAME pngunknown-if-safe COMMAND pngunknown OPTIONS --strict default=if-safe FILES "${PNGTEST_PNG}")
png_add_test(NAME pngunknown-sAPI COMMAND pngunknown OPTIONS --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save FILES "${PNGTEST_PNG}")
png_add_test(NAME pngunknown-save COMMAND pngunknown OPTIONS --strict default=save FILES "${PNGTEST_PNG}")
png_add_test(NAME pngunknown-sTER COMMAND pngunknown OPTIONS --strict sTER=if-safe FILES "${PNGTEST_PNG}")
png_add_test(NAME pngunknown-vpAg COMMAND pngunknown OPTIONS --strict vpAg=if-safe FILES "${PNGTEST_PNG}")
add_executable(pngimage ${pngimage_sources})
target_link_libraries(pngimage png)
png_add_test(NAME pngimage-quick COMMAND pngimage OPTIONS --list-combos --log FILES ${PNGSUITE_PNGS})
png_add_test(NAME pngimage-full COMMAND pngimage OPTIONS --exhaustive --list-combos --log FILES ${PNGSUITE_PNGS})
endif()
# Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set
IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
if(PNG_SHARED)
add_executable(pngfix ${pngfix_sources})
target_link_libraries(pngfix png)
set(PNG_BIN_TARGETS pngfix)
add_executable(png-fix-itxt ${png_fix_itxt_sources})
target_link_libraries(png-fix-itxt ${ZLIB_LIBRARY} ${M_LIBRARY})
list(APPEND PNG_BIN_TARGETS png-fix-itxt)
endif()
# Set a variable with CMake code which:
# Creates a symlink from src to dest (if possible) or alternatively
# copies if different.
macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
DEPENDS ${PNG_LIB_TARGETS}
)
ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
else(WIN32 AND NOT CYGWIN AND NOT MSYS)
get_filename_component(LINK_TARGET "${SRC_FILE}" NAME)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif(WIN32 AND NOT CYGWIN AND NOT MSYS)
endmacro()
include(CMakeParseArguments)
function(CREATE_SYMLINK DEST_FILE)
cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})
if(NOT S_TARGET AND NOT S_FILE)
message(FATAL_ERROR "Specify either a TARGET or a FILE for CREATE_SYMLINK to link to.")
endif(NOT S_TARGET AND NOT S_FILE)
if(S_TARGET AND S_FILE)
message(FATAL_ERROR "CREATE_SYMLINK called with both source file ${S_FILE} and build target ${S_TARGET} arguments - can only handle 1 type per call.")
endif(S_TARGET AND S_FILE)
if(S_FILE)
# If we don't need to symlink something that's coming from a build target,
# we can go ahead and symlink/copy at configure time.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN AND NOT MSYS)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
else(CMAKE_HOST_WIN32 AND NOT CYGWIN AND NOT MSYS)
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
endif(CMAKE_HOST_WIN32 AND NOT CYGWIN AND NOT MSYS)
endif(S_FILE)
if(S_TARGET)
# We need to use generator expressions, which can be a bit tricky, so for
# simplicity make the symlink a POST_BUILD step and use the TARGET
# signature of add_custom_command.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN AND NOT MSYS)
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}
)
else(CMAKE_HOST_WIN32 AND NOT CYGWIN AND NOT MSYS)
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E create_symlink $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}
)
endif(CMAKE_HOST_WIN32 AND NOT CYGWIN AND NOT MSYS)
endif(S_TARGET)
endfunction()
# Create source generation scripts.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genchk.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genout.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/gensrc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake @ONLY)
# libpng is a library so default to 'lib'
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
@ -251,31 +834,21 @@ if(NOT WIN32 OR CYGWIN OR MINGW)
set(LIBS "-lz -lm")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc)
CREATE_SYMLINK(libpng.pc FILE ${PNGLIB_NAME}.pc)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config)
CREATE_SYMLINK(libpng-config FILE ${PNGLIB_NAME}-config)
endif(NOT WIN32 OR CYGWIN OR MINGW)
# SET UP LINKS
if(PNG_SHARED)
set_target_properties(${PNG_LIB_NAME} PROPERTIES
# VERSION 16.${PNGLIB_RELEASE}.1.6.17
set_target_properties(png PROPERTIES
# VERSION 16.${PNGLIB_RELEASE}.1.6.34
VERSION 16.${PNGLIB_RELEASE}.0
SOVERSION 16
CLEAN_DIRECT_OUTPUT 1)
endif()
if(PNG_STATIC)
# MSVC doesn't use a different file extension for shared vs. static
# libs. We are able to change OUTPUT_NAME to remove the _static
# for all other platforms.
if(NOT MSVC)
set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
OUTPUT_NAME ${PNG_LIB_NAME}
CLEAN_DIRECT_OUTPUT 1)
endif()
endif()
# If CMake > 2.4.x, we set a variable used below to export
# targets to an export file.
@ -298,26 +871,20 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
if(PNG_SHARED)
# Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
if(CYGWIN OR MINGW)
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
CREATE_SYMLINK(libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET png)
install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(CYGWIN OR MINGW)
if(NOT WIN32)
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
CREATE_SYMLINK(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png)
install(FILES $<TARGET_LINKER_FILE_DIR:png>/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(NOT WIN32)
endif(PNG_SHARED)
if(PNG_STATIC)
if(NOT WIN32 OR CYGWIN OR MINGW)
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE})
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
CREATE_SYMLINK( libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static)
install(FILES $<TARGET_LINKER_FILE_DIR:png_static>/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(NOT WIN32 OR CYGWIN OR MINGW)
endif()
endif()
@ -334,6 +901,11 @@ if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
endif(NOT WIN32 OR CYGWIN OR MINGW)
endif()
if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL )
install(TARGETS ${PNG_BIN_TARGETS}
RUNTIME DESTINATION bin)
endif()
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
# Install man pages
if(NOT PNG_MAN_DIR)
@ -342,7 +914,7 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
# Install pkg-config files
if(NOT WIN32 OR CYGWIN OR MINGW)
if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
@ -351,7 +923,7 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
DESTINATION bin)
endif(NOT WIN32 OR CYGWIN OR MINGW)
endif(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
endif()
# On versions of CMake that support it, create an export file CMake
@ -371,4 +943,3 @@ endif()
# to create msvc import lib for mingw compiled shared lib
# pexports libpng.dll > libpng.def
# lib /def:libpng.def /machine:x86

View File

@ -1,24 +1,26 @@
Installing libpng
Installing libpng
Contents
I. Simple installation
II. Rebuilding the configure scripts
III. Using scripts/makefile*
IV. Using cmake
V. Directory structure
VI. Building with project files
VII. Building with makefiles
VIII. Configuring libpng for 16-bit platforms
IX. Configuring for DOS
X. Configuring for Medium Model
XI. Prepending a prefix to exported symbols
XII. Configuring for compiler xxx:
XIII. Removing unwanted object code
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
XV. Setjmp/longjmp issues
XVI. Other sources of information about libpng
I. Simple installation
II. Rebuilding the configure scripts
III. Using scripts/makefile*
IV. Using cmake
V. Directory structure
VI. Building with project files
VII. Building with makefiles
VIII. Configuring libpng for 16-bit platforms
IX. Configuring for DOS
X. Configuring for Medium Model
XI. Prepending a prefix to exported symbols
XII. Configuring for compiler xxx:
XIII. Removing unwanted object code
XIV. Enabling or disabling hardware optimizations
XV. Changes to the build and configuration of libpng in libpng-1.5.x
XVI. Setjmp/longjmp issues
XVII. Common linking failures
XVIII. Other sources of information about libpng
I. Simple installation
@ -47,7 +49,9 @@ If configure does not work on your system, or if you have a need to
change configure.ac or Makefile.am, and you have a reasonably
up-to-date set of tools, running ./autogen.sh in a git clone before
running ./configure may fix the problem. To be really sure that you
aren't using any of the included pre-built scripts, you can do this:
aren't using any of the included pre-built scripts, especially if you
are building from a tar distribution instead of a git distribution,
do this:
./configure --enable-maintainer-mode
make maintainer-clean
@ -75,8 +79,8 @@ Or you can use one of the "projects" in the "projects" directory.
Before installing libpng, you must first install zlib, if it
is not already on your system. zlib can usually be found
wherever you got libpng; otherwise go to http://zlib.net. You can place
zlib in in the same directory as libpng or in another directory.
wherever you got libpng; otherwise go to https://zlib.net/. You can
place zlib in the same directory as libpng or in another directory.
If your system already has a preinstalled zlib you will still need
to have access to the zlib.h and zconf.h include files that
@ -87,22 +91,24 @@ standard library search path, put ZLIBLIB, ZLIBINC, CPPFLAGS, LDFLAGS,
and LD_LIBRARY_PATH in your environment before running "make test"
or "make distcheck":
ZLIBLIB=/path/to/lib export ZLIBLIB
ZLIBINC=/path/to/include export ZLIBINC
CPPFLAGS="-I$ZLIBINC" export CPPFLAGS
LDFLAGS="-L$ZLIBLIB" export LDFLAGS
LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
ZLIBLIB=/path/to/lib export ZLIBLIB
ZLIBINC=/path/to/include export ZLIBINC
CPPFLAGS="-I$ZLIBINC" export CPPFLAGS
LDFLAGS="-L$ZLIBLIB" export LDFLAGS
LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
If you are using one of the makefile scripts, put ZLIBLIB and ZLIBINC
in your environment and type "make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test".
in your environment and type
make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test
IV. Using cmake
If you want to use "cmake" (see www.cmake.org), type
cmake . -DCMAKE_INSTALL_PREFIX=/path
make
make install
cmake . -DCMAKE_INSTALL_PREFIX=/path
make
make install
As when using the simple configure method described above, "/path" points to
the installation directory where you want to put the libpng "lib", "include",
@ -116,8 +122,8 @@ or "zlib128") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
.. (the parent directory)
libpng (this directory)
.. (the parent directory)
libpng (this directory)
INSTALL (this file)
README
*.h, *.c => libpng source files
@ -160,10 +166,15 @@ VII. Building with makefiles
Copy the file (or files) that you need from the
scripts directory into this directory, for example
MSDOS example: copy scripts\makefile.msc makefile
copy scripts\pnglibconf.h.prebuilt pnglibconf.h
UNIX example: cp scripts/makefile.std makefile
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
MSDOS example:
copy scripts\makefile.msc makefile
copy scripts\pnglibconf.h.prebuilt pnglibconf.h
UNIX example:
cp scripts/makefile.std makefile
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
Read the makefile to see if you need to change any source or
target directories to match your preferences.
@ -239,7 +250,7 @@ libpng are compiled. All the defines end in _SUPPORTED. If you are
never going to use a capability, you can change the #define to #undef
before recompiling libpng and save yourself code and data space, or
you can turn off individual capabilities with defines that begin with
PNG_NO_.
"PNG_NO_".
In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
@ -271,7 +282,57 @@ library to fail if they call functions not available in your library.
The size of the library itself should not be an issue, because only
those sections that are actually used will be loaded into memory.
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
XIV. Enabling or disabling hardware optimizations
Certain hardware capabilites, such as the Intel SSE instructions,
are normally detected at run time. Enable them with configure options
such as one of
--enable-arm-neon=yes
--enable-mips-msa=yes
--enable-intel-sse=yes
--enable-powerpc-vsx=yes
or enable them all at once with
--enable-hardware-optimizations=yes
or, if you are not using "configure", you can use one
or more of
CPPFLAGS += "-DPNG_ARM_NEON"
CPPFLAGS += "-DPNG_MIPS_MSA"
CPPFLAGS += "-DPNG_INTEL_SSE"
CPPFLAGS += "-DPNG_POWERPC_VSX"
See for example scripts/makefile.linux-opt
If you wish to avoid using them,
you can disable them via the configure option
--disable-hardware-optimizations
to disable them all, or
--enable-intel-sse=no
to disable a particular one,
or via compiler-command options such as
CPPFLAGS += "-DPNG_ARM_NEON_OPT=0, -DPNG_MIPS_MSA_OPT=0,
-DPNG_INTEL_SSE_OPT=0, -DPNG_POWERPC_VSX_OPT=0"
If you are using cmake, hardware optimizations are "on"
by default. To disable them, use
cmake . -DPNG_ARM_NEON=no -DPNG_INTEL_SSE=no \
-DPNG_MIPS_MSA=no -DPNG_POWERPC_VSX=no
or disable them all at once with
cmake . -DPNG_HARDWARE_OPTIMIZATIONS=no
XV. Changes to the build and configuration of libpng in libpng-1.5.x
Details of internal changes to the library code can be found in the CHANGES
file and in the GIT repository logs. These will be of no concern to the vast
@ -307,7 +368,7 @@ only png_longjmp_ptr, which must match the C longjmp function.) The new
approach is documented in pngconf.h
Despite these changes, libpng 1.5.0 only supports the native C function
calling standard on those platforms tested so far (__cdecl on Microsoft
calling standard on those platforms tested so far ("__cdecl" on Microsoft
Windows). This is because the support requirements for alternative
calling conventions seem to no longer exist. Developers who find it
necessary to set PNG_API_RULE to 1 should advise the mailing list
@ -362,7 +423,7 @@ $PREFIX/include directory). Do not edit pnglibconf.h after you have built
libpng, because than the settings would not accurately reflect the settings
that were used to build libpng.
XV. Setjmp/longjmp issues
XVI. Setjmp/longjmp issues
Libpng uses setjmp()/longjmp() for error handling. Unfortunately setjmp()
is known to be not thread-safe on some platforms and we don't know of
@ -371,7 +432,7 @@ your application is going to be using multiple threads, you should
configure libpng with PNG_NO_SETJMP in your pngusr.dfa file, with
-DPNG_NO_SETJMP on your compile line, or with
#undef PNG_SETJMP_SUPPORTED
#undef PNG_SETJMP_SUPPORTED
in your pnglibconf.h or pngusr.h.
@ -380,28 +441,25 @@ This requires setjmp/longjmp, so you must either build the library
with PNG_SETJMP_SUPPORTED defined, or with PNG_SIMPLIFIED_READ_SUPPORTED
and PNG_SIMPLIFIED_WRITE_SUPPORTED undefined.
XVI. Other sources of information about libpng:
XVII. Common linking failures
If your application fails to find libpng or zlib entries while linking:
Be sure "-lz" appears after "-lpng" on your linking command.
Be sure you have built libpng, zlib, and your application for the
same platform (e.g., 32-bit or 64-bit).
If you are using the vstudio project, observe the WARNING in
project/vstudio/README.txt.
XVIII. Other sources of information about libpng:
Further information can be found in the README and libpng-manual.txt
files, in the individual makefiles, in png.h, and the manual pages
libpng.3 and png.5.
Using the ./configure script -- 16 December 2002.
=================================================
The ./configure script should work compatibly with what scripts/makefile.*
did, however there are some options you might need to add to configure
explicitly, which previously was done semi-automatically (if you didn't edit
scripts/makefile.* yourself, that is)
CFLAGS="-Wall -O -funroll-loops \
-malign-loops=2 -malign-functions=2" ./configure --prefix=/usr/include \
--with-pkgconfigdir=/usr/lib/pkgconfig --includedir=/usr/include
You can alternatively specify --includedir=/usr/include, /usr/local/include,
/usr/include/libpng16, or whatever.
If you find that the configure script is out-of-date or is not supporting
your platform properly, try running autogen.sh to regenerate "configure",
"Makefile.in", and the other configuration files. Then try configure again.
Copyright (c) 1998-2002,2006-2016 Glenn Randers-Pehrson
This document is released under the libpng license.
For conditions of distribution and use, see the disclaimer
and license in png.h.

View File

@ -10,21 +10,21 @@ this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.6.17, March 26, 2015, are
Copyright (c) 2004, 2006-2015 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
Cosmin Truta
libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.0.6
with the following individuals added to the list of Contributing Authors
libpng versions 1.0.7, July 1, 2000 through 1.6.34, September 29, 2017 are
Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are
derived from libpng-1.0.6, and are distributed according to the same
disclaimer and license as libpng-1.0.6 with the following individuals
added to the list of Contributing Authors:
Simon-Pierre Cadieux
Eric S. Raymond
Mans Rullgard
Cosmin Truta
Gilles Vollant
James Yu
Mandar Sahastrabuddhe
Google Inc.
Vadim Barkov
and with the following additions to the disclaimer:
@ -35,19 +35,25 @@ and with the following additions to the disclaimer:
risk of satisfactory quality, performance, accuracy, and effort is with
the user.
Some files in the "contrib" directory and some configure-generated
files that are distributed with libpng have other copyright owners and
are released under other open source licenses.
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-0.96,
with the following individuals added to the list of Contributing Authors:
Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
libpng-0.96, and are distributed according to the same disclaimer and
license as libpng-0.96, with the following individuals added to the list
of Contributing Authors:
Tom Lane
Glenn Randers-Pehrson
Willem van Schaik
libpng versions 0.89, June 1996, through 0.96, May 1997, are
Copyright (c) 1996, 1997 Andreas Dilger
Distributed according to the same disclaimer and license as libpng-0.88,
with the following individuals added to the list of Contributing Authors:
Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
and are distributed according to the same disclaimer and license as
libpng-0.88, with the following individuals added to the list of
Contributing Authors:
John Bowler
Kevin Bracey
@ -56,8 +62,11 @@ with the following individuals added to the list of Contributing Authors:
Greg Roelofs
Tom Tanner
Some files in the "scripts" directory have other copyright owners
but are released under this license.
libpng versions 0.5, May 1995, through 0.88, January 1996, are
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:
@ -80,13 +89,13 @@ Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:
1. The origin of this source code must not be misrepresented.
1. The origin of this source code must not be misrepresented.
2. Altered versions must be plainly marked as such and must not
be misrepresented as being the original source.
2. Altered versions must be plainly marked as such and must not
be misrepresented as being the original source.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
The Contributing Authors and Group 42, Inc. specifically permit, without
fee, and encourage the use of this source code as a component to
@ -94,18 +103,31 @@ supporting the PNG file format in commercial products. If you use this
source code in a product, acknowledgment is not required but would be
appreciated.
END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
A "png_get_copyright" function is available, for convenient use in "about"
boxes and the like:
TRADEMARK:
printf("%s",png_get_copyright(NULL));
The name "libpng" has not been registered by the Copyright owner
as a trademark in any jurisdiction. However, because libpng has
been distributed and maintained world-wide, continually since 1995,
the Copyright owner claims "common-law trademark protection" in any
jurisdiction where common-law trademark is recognized.
Also, the PNG logo (in PNG format, of course) is supplied in the
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
OSI CERTIFICATION:
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
certification mark of the Open Source Initiative.
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
a certification mark of the Open Source Initiative. OSI has not addressed
the additional disclaimers inserted at version 1.0.7.
EXPORT CONTROL:
The Copyright owner believes that the Export Control Classification
Number (ECCN) for libpng is EAR99, which means not subject to export
controls or International Traffic in Arms Regulations (ITAR) because
it is open source, publicly available software, that does not contain
any encryption software. See the EAR, paragraphs 734.3(b)(3) and
734.7(b).
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
March 26, 2015
September 29, 2017

View File

@ -1,13 +1,21 @@
# Makefile.am:
# Source file for Makefile.in (and hence Makefile)
# Makefile.am, the source file for Makefile.in (and hence Makefile), is
#
# Copyright (c) 2004-2016 Glenn Randers-Pehrson
# Last changed in libpng 1.6.25 [September 1, 2016]
#
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h
PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
ACLOCAL_AMFLAGS = -I scripts
# test programs - run on make check, make distcheck
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage pngcp
if HAVE_CLOCK_GETTIME
check_PROGRAMS += timepng
endif
# Utilities - installed
bin_PROGRAMS= pngfix png-fix-itxt
@ -37,37 +45,38 @@ pngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngimage_SOURCES = contrib/libtests/pngimage.c
pngimage_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
timepng_SOURCES = contrib/libtests/timepng.c
timepng_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngfix_SOURCES = contrib/tools/pngfix.c
pngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
png_fix_itxt_SOURCES = contrib/tools/png-fix-itxt.c
pngcp_SOURCES = contrib/tools/pngcp.c
pngcp_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
# Generally these are single line shell scripts to run a test with a particular
# set of parameters:
TESTS =\
tests/pngtest\
tests/pngtest-badpngs\
tests/pngvalid-gamma-16-to-8 tests/pngvalid-gamma-alpha-mode\
tests/pngvalid-gamma-background tests/pngvalid-gamma-expand16-alpha-mode\
tests/pngvalid-gamma-expand16-background\
tests/pngvalid-gamma-expand16-transform tests/pngvalid-gamma-sbit\
tests/pngvalid-gamma-threshold tests/pngvalid-gamma-transform\
tests/pngvalid-progressive-interlace-size\
tests/pngvalid-progressive-size\
tests/pngvalid-progressive-interlace-standard\
tests/pngvalid-progressive-interlace-transform\
tests/pngvalid-transform\
tests/pngvalid-progressive-standard tests/pngvalid-standard\
tests/pngstest-0g01 tests/pngstest-0g02 tests/pngstest-0g04\
tests/pngstest-0g08 tests/pngstest-0g16 tests/pngstest-2c08\
tests/pngstest-2c16 tests/pngstest-3p01 tests/pngstest-3p02\
tests/pngstest-3p04 tests/pngstest-3p08 tests/pngstest-4a08\
tests/pngstest-4a16 tests/pngstest-6a08 tests/pngstest-6a16\
tests/pngstest-error tests/pngunknown-IDAT\
tests/pngstest-1.8 tests/pngstest-1.8-alpha tests/pngstest-linear\
tests/pngstest-linear-alpha tests/pngstest-none tests/pngstest-none-alpha\
tests/pngstest-sRGB tests/pngstest-sRGB-alpha tests/pngunknown-IDAT\
tests/pngunknown-discard tests/pngunknown-if-safe tests/pngunknown-sAPI\
tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg\
tests/pngimage-quick tests/pngimage-full
# These tests are expected, and required, to fail:
XFAIL_TESTS = tests/pngstest-error
# man pages
dist_man_MANS= libpng.3 libpngpf.3 png.5
@ -89,6 +98,21 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\
arm/filter_neon.S arm/filter_neon_intrinsics.c
endif
if PNG_MIPS_MSA
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/mips_init.c\
mips/filter_msa_intrinsics.c
endif
if PNG_INTEL_SSE
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += intel/intel_init.c\
intel/filter_sse2_intrinsics.c
endif
if PNG_POWERPC_VSX
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += powerpc/powerpc_init.c\
powerpc/filter_vsx_intrinsics.c
endif
nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \
@ -225,6 +249,7 @@ contrib/libtests/timepng.o: pnglibconf.h
contrib/tools/makesRGB.o: pnglibconf.h
contrib/tools/pngfix.o: pnglibconf.h
contrib/tools/pngcp.o: pnglibconf.h
# We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually
# be built with PNG_USE_READ_MACROS; this prevents the read macros from

View File

@ -14,9 +14,14 @@
@SET_MAKE@
# Makefile.am:
# Source file for Makefile.in (and hence Makefile)
# Makefile.am, the source file for Makefile.in (and hence Makefile), is
#
# Copyright (c) 2004-2016 Glenn Randers-Pehrson
# Last changed in libpng 1.6.25 [September 1, 2016]
#
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h
@ -96,18 +101,29 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
check_PROGRAMS = pngtest$(EXEEXT) pngunknown$(EXEEXT) \
pngstest$(EXEEXT) pngvalid$(EXEEXT) pngimage$(EXEEXT)
pngstest$(EXEEXT) pngvalid$(EXEEXT) pngimage$(EXEEXT) \
pngcp$(EXEEXT) $(am__EXEEXT_1)
@HAVE_CLOCK_GETTIME_TRUE@am__append_1 = timepng
bin_PROGRAMS = pngfix$(EXEEXT) png-fix-itxt$(EXEEXT)
@PNG_ARM_NEON_TRUE@am__append_1 = arm/arm_init.c\
@PNG_ARM_NEON_TRUE@am__append_2 = arm/arm_init.c\
@PNG_ARM_NEON_TRUE@ arm/filter_neon.S arm/filter_neon_intrinsics.c
@PNG_MIPS_MSA_TRUE@am__append_3 = mips/mips_init.c\
@PNG_MIPS_MSA_TRUE@ mips/filter_msa_intrinsics.c
@PNG_INTEL_SSE_TRUE@am__append_4 = intel/intel_init.c\
@PNG_INTEL_SSE_TRUE@ intel/filter_sse2_intrinsics.c
@PNG_POWERPC_VSX_TRUE@am__append_5 = powerpc/powerpc_init.c\
@PNG_POWERPC_VSX_TRUE@ powerpc/filter_vsx_intrinsics.c
# Versioned symbols and restricted exports
@HAVE_LD_VERSION_SCRIPT_TRUE@@HAVE_SOLARIS_LD_TRUE@am__append_2 = -Wl,-M -Wl,libpng.vers
@HAVE_LD_VERSION_SCRIPT_TRUE@@HAVE_SOLARIS_LD_FALSE@am__append_3 = -Wl,--version-script=libpng.vers
@HAVE_LD_VERSION_SCRIPT_TRUE@@HAVE_SOLARIS_LD_TRUE@am__append_6 = -Wl,-M -Wl,libpng.vers
@HAVE_LD_VERSION_SCRIPT_TRUE@@HAVE_SOLARIS_LD_FALSE@am__append_7 = -Wl,--version-script=libpng.vers
# Only restricted exports when possible
@HAVE_LD_VERSION_SCRIPT_FALSE@am__append_4 = -export-symbols libpng.sym
@DO_PNG_PREFIX_TRUE@am__append_5 = -DPNG_PREFIX='@PNG_PREFIX@'
@HAVE_LD_VERSION_SCRIPT_FALSE@am__append_8 = -export-symbols libpng.sym
@DO_PNG_PREFIX_TRUE@am__append_9 = -DPNG_PREFIX='@PNG_PREFIX@'
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/scripts/libtool.m4 \
@ -164,14 +180,24 @@ am__libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES_DIST = png.c \
pngrtran.c pngrutil.c pngset.c pngtrans.c pngwio.c pngwrite.c \
pngwtran.c pngwutil.c png.h pngconf.h pngdebug.h pnginfo.h \
pngpriv.h pngstruct.h pngusr.dfa arm/arm_init.c \
arm/filter_neon.S arm/filter_neon_intrinsics.c
arm/filter_neon.S arm/filter_neon_intrinsics.c \
mips/mips_init.c mips/filter_msa_intrinsics.c \
intel/intel_init.c intel/filter_sse2_intrinsics.c \
powerpc/powerpc_init.c powerpc/filter_vsx_intrinsics.c
am__dirstamp = $(am__leading_dot)dirstamp
@PNG_ARM_NEON_TRUE@am__objects_1 = arm/arm_init.lo arm/filter_neon.lo \
@PNG_ARM_NEON_TRUE@ arm/filter_neon_intrinsics.lo
@PNG_MIPS_MSA_TRUE@am__objects_2 = mips/mips_init.lo \
@PNG_MIPS_MSA_TRUE@ mips/filter_msa_intrinsics.lo
@PNG_INTEL_SSE_TRUE@am__objects_3 = intel/intel_init.lo \
@PNG_INTEL_SSE_TRUE@ intel/filter_sse2_intrinsics.lo
@PNG_POWERPC_VSX_TRUE@am__objects_4 = powerpc/powerpc_init.lo \
@PNG_POWERPC_VSX_TRUE@ powerpc/filter_vsx_intrinsics.lo
am_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS = png.lo pngerror.lo \
pngget.lo pngmem.lo pngpread.lo pngread.lo pngrio.lo \
pngrtran.lo pngrutil.lo pngset.lo pngtrans.lo pngwio.lo \
pngwrite.lo pngwtran.lo pngwutil.lo $(am__objects_1)
pngwrite.lo pngwtran.lo pngwutil.lo $(am__objects_1) \
$(am__objects_2) $(am__objects_3) $(am__objects_4)
nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS =
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS = \
$(am_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS) \
@ -185,10 +211,14 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LINK = $(LIBTOOL) $(AM_V_lt) \
$(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS) $(LDFLAGS) -o \
$@
@HAVE_CLOCK_GETTIME_TRUE@am__EXEEXT_1 = timepng$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
am_png_fix_itxt_OBJECTS = contrib/tools/png-fix-itxt.$(OBJEXT)
png_fix_itxt_OBJECTS = $(am_png_fix_itxt_OBJECTS)
png_fix_itxt_LDADD = $(LDADD)
am_pngcp_OBJECTS = contrib/tools/pngcp.$(OBJEXT)
pngcp_OBJECTS = $(am_pngcp_OBJECTS)
pngcp_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
am_pngfix_OBJECTS = contrib/tools/pngfix.$(OBJEXT)
pngfix_OBJECTS = $(am_pngfix_OBJECTS)
pngfix_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
@ -207,6 +237,9 @@ pngunknown_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
am_pngvalid_OBJECTS = contrib/libtests/pngvalid.$(OBJEXT)
pngvalid_OBJECTS = $(am_pngvalid_OBJECTS)
pngvalid_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
am_timepng_OBJECTS = contrib/libtests/timepng.$(OBJEXT)
timepng_OBJECTS = $(am_timepng_OBJECTS)
timepng_DEPENDENCIES = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
SCRIPTS = $(bin_SCRIPTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@ -254,14 +287,14 @@ am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES) \
$(nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES) \
$(png_fix_itxt_SOURCES) $(pngfix_SOURCES) $(pngimage_SOURCES) \
$(pngstest_SOURCES) $(pngtest_SOURCES) $(pngunknown_SOURCES) \
$(pngvalid_SOURCES)
$(png_fix_itxt_SOURCES) $(pngcp_SOURCES) $(pngfix_SOURCES) \
$(pngimage_SOURCES) $(pngstest_SOURCES) $(pngtest_SOURCES) \
$(pngunknown_SOURCES) $(pngvalid_SOURCES) $(timepng_SOURCES)
DIST_SOURCES = \
$(am__libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES_DIST) \
$(png_fix_itxt_SOURCES) $(pngfix_SOURCES) $(pngimage_SOURCES) \
$(pngstest_SOURCES) $(pngtest_SOURCES) $(pngunknown_SOURCES) \
$(pngvalid_SOURCES)
$(png_fix_itxt_SOURCES) $(pngcp_SOURCES) $(pngfix_SOURCES) \
$(pngimage_SOURCES) $(pngstest_SOURCES) $(pngtest_SOURCES) \
$(pngunknown_SOURCES) $(pngvalid_SOURCES) $(timepng_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@ -664,37 +697,36 @@ pngunknown_SOURCES = contrib/libtests/pngunknown.c
pngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngimage_SOURCES = contrib/libtests/pngimage.c
pngimage_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
timepng_SOURCES = contrib/libtests/timepng.c
timepng_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
pngfix_SOURCES = contrib/tools/pngfix.c
pngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
png_fix_itxt_SOURCES = contrib/tools/png-fix-itxt.c
pngcp_SOURCES = contrib/tools/pngcp.c
pngcp_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
# Generally these are single line shell scripts to run a test with a particular
# set of parameters:
TESTS = \
tests/pngtest\
tests/pngtest-badpngs\
tests/pngvalid-gamma-16-to-8 tests/pngvalid-gamma-alpha-mode\
tests/pngvalid-gamma-background tests/pngvalid-gamma-expand16-alpha-mode\
tests/pngvalid-gamma-expand16-background\
tests/pngvalid-gamma-expand16-transform tests/pngvalid-gamma-sbit\
tests/pngvalid-gamma-threshold tests/pngvalid-gamma-transform\
tests/pngvalid-progressive-interlace-size\
tests/pngvalid-progressive-size\
tests/pngvalid-progressive-interlace-standard\
tests/pngvalid-progressive-interlace-transform\
tests/pngvalid-transform\
tests/pngvalid-progressive-standard tests/pngvalid-standard\
tests/pngstest-0g01 tests/pngstest-0g02 tests/pngstest-0g04\
tests/pngstest-0g08 tests/pngstest-0g16 tests/pngstest-2c08\
tests/pngstest-2c16 tests/pngstest-3p01 tests/pngstest-3p02\
tests/pngstest-3p04 tests/pngstest-3p08 tests/pngstest-4a08\
tests/pngstest-4a16 tests/pngstest-6a08 tests/pngstest-6a16\
tests/pngstest-error tests/pngunknown-IDAT\
tests/pngstest-1.8 tests/pngstest-1.8-alpha tests/pngstest-linear\
tests/pngstest-linear-alpha tests/pngstest-none tests/pngstest-none-alpha\
tests/pngstest-sRGB tests/pngstest-sRGB-alpha tests/pngunknown-IDAT\
tests/pngunknown-discard tests/pngunknown-if-safe tests/pngunknown-sAPI\
tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg\
tests/pngimage-quick tests/pngimage-full
# These tests are expected, and required, to fail:
XFAIL_TESTS = tests/pngstest-error
# man pages
dist_man_MANS = libpng.3 libpngpf.3 png.5
EXTRA_SCRIPTS = libpng-config libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@-config
@ -707,12 +739,13 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = png.c pngerror.c \
pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c \
pngrutil.c pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c \
pngwutil.c png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h \
pngstruct.h pngusr.dfa $(am__append_1)
pngstruct.h pngusr.dfa $(am__append_2) $(am__append_3) \
$(am__append_4) $(am__append_5)
nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined \
-export-dynamic -version-number \
@PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0 \
$(am__append_2) $(am__append_3) $(am__append_4)
$(am__append_6) $(am__append_7) $(am__append_8)
@HAVE_LD_VERSION_SCRIPT_FALSE@libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES = libpng.sym
@HAVE_LD_VERSION_SCRIPT_TRUE@libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES = libpng.vers
pkginclude_HEADERS = png.h pngconf.h
@ -748,7 +781,7 @@ SUFFIXES = .chk .out
SYMBOL_CFLAGS = -DPNGLIB_LIBNAME='PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0' \
-DPNGLIB_VERSION='@PNGLIB_VERSION@' \
-DSYMBOL_PREFIX='$(SYMBOL_PREFIX)' -DPNG_NO_USE_READ_MACROS \
-DPNG_BUILDING_SYMBOL_TABLE $(am__append_5)
-DPNG_BUILDING_SYMBOL_TABLE $(am__append_9)
# EXT_LIST is a list of the possibly library directory extensions, this exists
# because we can't find a good way of discovering the file extensions that are
@ -857,6 +890,35 @@ arm/arm_init.lo: arm/$(am__dirstamp) arm/$(DEPDIR)/$(am__dirstamp)
arm/filter_neon.lo: arm/$(am__dirstamp) arm/$(DEPDIR)/$(am__dirstamp)
arm/filter_neon_intrinsics.lo: arm/$(am__dirstamp) \
arm/$(DEPDIR)/$(am__dirstamp)
mips/$(am__dirstamp):
@$(MKDIR_P) mips
@: > mips/$(am__dirstamp)
mips/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) mips/$(DEPDIR)
@: > mips/$(DEPDIR)/$(am__dirstamp)
mips/mips_init.lo: mips/$(am__dirstamp) mips/$(DEPDIR)/$(am__dirstamp)
mips/filter_msa_intrinsics.lo: mips/$(am__dirstamp) \
mips/$(DEPDIR)/$(am__dirstamp)
intel/$(am__dirstamp):
@$(MKDIR_P) intel
@: > intel/$(am__dirstamp)
intel/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) intel/$(DEPDIR)
@: > intel/$(DEPDIR)/$(am__dirstamp)
intel/intel_init.lo: intel/$(am__dirstamp) \
intel/$(DEPDIR)/$(am__dirstamp)
intel/filter_sse2_intrinsics.lo: intel/$(am__dirstamp) \
intel/$(DEPDIR)/$(am__dirstamp)
powerpc/$(am__dirstamp):
@$(MKDIR_P) powerpc
@: > powerpc/$(am__dirstamp)
powerpc/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) powerpc/$(DEPDIR)
@: > powerpc/$(DEPDIR)/$(am__dirstamp)
powerpc/powerpc_init.lo: powerpc/$(am__dirstamp) \
powerpc/$(DEPDIR)/$(am__dirstamp)
powerpc/filter_vsx_intrinsics.lo: powerpc/$(am__dirstamp) \
powerpc/$(DEPDIR)/$(am__dirstamp)
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la: $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS) $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES) $(EXTRA_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES)
$(AM_V_CCLD)$(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LINK) -rpath $(libdir) $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS) $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LIBADD) $(LIBS)
@ -930,6 +992,12 @@ contrib/tools/png-fix-itxt.$(OBJEXT): contrib/tools/$(am__dirstamp) \
png-fix-itxt$(EXEEXT): $(png_fix_itxt_OBJECTS) $(png_fix_itxt_DEPENDENCIES) $(EXTRA_png_fix_itxt_DEPENDENCIES)
@rm -f png-fix-itxt$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(png_fix_itxt_OBJECTS) $(png_fix_itxt_LDADD) $(LIBS)
contrib/tools/pngcp.$(OBJEXT): contrib/tools/$(am__dirstamp) \
contrib/tools/$(DEPDIR)/$(am__dirstamp)
pngcp$(EXEEXT): $(pngcp_OBJECTS) $(pngcp_DEPENDENCIES) $(EXTRA_pngcp_DEPENDENCIES)
@rm -f pngcp$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(pngcp_OBJECTS) $(pngcp_LDADD) $(LIBS)
contrib/tools/pngfix.$(OBJEXT): contrib/tools/$(am__dirstamp) \
contrib/tools/$(DEPDIR)/$(am__dirstamp)
@ -971,6 +1039,12 @@ contrib/libtests/pngvalid.$(OBJEXT): contrib/libtests/$(am__dirstamp) \
pngvalid$(EXEEXT): $(pngvalid_OBJECTS) $(pngvalid_DEPENDENCIES) $(EXTRA_pngvalid_DEPENDENCIES)
@rm -f pngvalid$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(pngvalid_OBJECTS) $(pngvalid_LDADD) $(LIBS)
contrib/libtests/timepng.$(OBJEXT): contrib/libtests/$(am__dirstamp) \
contrib/libtests/$(DEPDIR)/$(am__dirstamp)
timepng$(EXEEXT): $(timepng_OBJECTS) $(timepng_DEPENDENCIES) $(EXTRA_timepng_DEPENDENCIES)
@rm -f timepng$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(timepng_OBJECTS) $(timepng_LDADD) $(LIBS)
install-binSCRIPTS: $(bin_SCRIPTS)
@$(NORMAL_INSTALL)
@list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \
@ -1013,6 +1087,12 @@ mostlyclean-compile:
-rm -f arm/*.lo
-rm -f contrib/libtests/*.$(OBJEXT)
-rm -f contrib/tools/*.$(OBJEXT)
-rm -f intel/*.$(OBJEXT)
-rm -f intel/*.lo
-rm -f mips/*.$(OBJEXT)
-rm -f mips/*.lo
-rm -f powerpc/*.$(OBJEXT)
-rm -f powerpc/*.lo
distclean-compile:
-rm -f *.tab.c
@ -1040,8 +1120,16 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@contrib/libtests/$(DEPDIR)/pngstest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@contrib/libtests/$(DEPDIR)/pngunknown.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@contrib/libtests/$(DEPDIR)/pngvalid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@contrib/libtests/$(DEPDIR)/timepng.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@contrib/tools/$(DEPDIR)/png-fix-itxt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@contrib/tools/$(DEPDIR)/pngcp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@contrib/tools/$(DEPDIR)/pngfix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@intel/$(DEPDIR)/filter_sse2_intrinsics.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@intel/$(DEPDIR)/intel_init.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@mips/$(DEPDIR)/filter_msa_intrinsics.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@mips/$(DEPDIR)/mips_init.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@powerpc/$(DEPDIR)/filter_vsx_intrinsics.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@powerpc/$(DEPDIR)/powerpc_init.Plo@am__quote@
.S.o:
@am__fastdepCCAS_TRUE@ $(AM_V_CPPAS)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@ -1097,6 +1185,9 @@ mostlyclean-libtool:
clean-libtool:
-rm -rf .libs _libs
-rm -rf arm/.libs arm/_libs
-rm -rf intel/.libs intel/_libs
-rm -rf mips/.libs mips/_libs
-rm -rf powerpc/.libs powerpc/_libs
distclean-libtool:
-rm -f libtool config.lt
@ -1457,6 +1548,13 @@ tests/pngtest.log: tests/pngtest
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngtest-badpngs.log: tests/pngtest-badpngs
@p='tests/pngtest-badpngs'; \
b='tests/pngtest-badpngs'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngvalid-gamma-16-to-8.log: tests/pngvalid-gamma-16-to-8
@p='tests/pngvalid-gamma-16-to-8'; \
b='tests/pngvalid-gamma-16-to-8'; \
@ -1520,9 +1618,9 @@ tests/pngvalid-gamma-transform.log: tests/pngvalid-gamma-transform
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngvalid-progressive-interlace-size.log: tests/pngvalid-progressive-interlace-size
@p='tests/pngvalid-progressive-interlace-size'; \
b='tests/pngvalid-progressive-interlace-size'; \
tests/pngvalid-progressive-size.log: tests/pngvalid-progressive-size
@p='tests/pngvalid-progressive-size'; \
b='tests/pngvalid-progressive-size'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
@ -1534,9 +1632,9 @@ tests/pngvalid-progressive-interlace-standard.log: tests/pngvalid-progressive-in
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngvalid-progressive-interlace-transform.log: tests/pngvalid-progressive-interlace-transform
@p='tests/pngvalid-progressive-interlace-transform'; \
b='tests/pngvalid-progressive-interlace-transform'; \
tests/pngvalid-transform.log: tests/pngvalid-transform
@p='tests/pngvalid-transform'; \
b='tests/pngvalid-transform'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
@ -1555,114 +1653,58 @@ tests/pngvalid-standard.log: tests/pngvalid-standard
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-0g01.log: tests/pngstest-0g01
@p='tests/pngstest-0g01'; \
b='tests/pngstest-0g01'; \
tests/pngstest-1.8.log: tests/pngstest-1.8
@p='tests/pngstest-1.8'; \
b='tests/pngstest-1.8'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-0g02.log: tests/pngstest-0g02
@p='tests/pngstest-0g02'; \
b='tests/pngstest-0g02'; \
tests/pngstest-1.8-alpha.log: tests/pngstest-1.8-alpha
@p='tests/pngstest-1.8-alpha'; \
b='tests/pngstest-1.8-alpha'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-0g04.log: tests/pngstest-0g04
@p='tests/pngstest-0g04'; \
b='tests/pngstest-0g04'; \
tests/pngstest-linear.log: tests/pngstest-linear
@p='tests/pngstest-linear'; \
b='tests/pngstest-linear'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-0g08.log: tests/pngstest-0g08
@p='tests/pngstest-0g08'; \
b='tests/pngstest-0g08'; \
tests/pngstest-linear-alpha.log: tests/pngstest-linear-alpha
@p='tests/pngstest-linear-alpha'; \
b='tests/pngstest-linear-alpha'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-0g16.log: tests/pngstest-0g16
@p='tests/pngstest-0g16'; \
b='tests/pngstest-0g16'; \
tests/pngstest-none.log: tests/pngstest-none
@p='tests/pngstest-none'; \
b='tests/pngstest-none'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-2c08.log: tests/pngstest-2c08
@p='tests/pngstest-2c08'; \
b='tests/pngstest-2c08'; \
tests/pngstest-none-alpha.log: tests/pngstest-none-alpha
@p='tests/pngstest-none-alpha'; \
b='tests/pngstest-none-alpha'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-2c16.log: tests/pngstest-2c16
@p='tests/pngstest-2c16'; \
b='tests/pngstest-2c16'; \
tests/pngstest-sRGB.log: tests/pngstest-sRGB
@p='tests/pngstest-sRGB'; \
b='tests/pngstest-sRGB'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-3p01.log: tests/pngstest-3p01
@p='tests/pngstest-3p01'; \
b='tests/pngstest-3p01'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-3p02.log: tests/pngstest-3p02
@p='tests/pngstest-3p02'; \
b='tests/pngstest-3p02'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-3p04.log: tests/pngstest-3p04
@p='tests/pngstest-3p04'; \
b='tests/pngstest-3p04'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-3p08.log: tests/pngstest-3p08
@p='tests/pngstest-3p08'; \
b='tests/pngstest-3p08'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-4a08.log: tests/pngstest-4a08
@p='tests/pngstest-4a08'; \
b='tests/pngstest-4a08'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-4a16.log: tests/pngstest-4a16
@p='tests/pngstest-4a16'; \
b='tests/pngstest-4a16'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-6a08.log: tests/pngstest-6a08
@p='tests/pngstest-6a08'; \
b='tests/pngstest-6a08'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-6a16.log: tests/pngstest-6a16
@p='tests/pngstest-6a16'; \
b='tests/pngstest-6a16'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
tests/pngstest-error.log: tests/pngstest-error
@p='tests/pngstest-error'; \
b='tests/pngstest-error'; \
tests/pngstest-sRGB-alpha.log: tests/pngstest-sRGB-alpha
@p='tests/pngstest-sRGB-alpha'; \
b='tests/pngstest-sRGB-alpha'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
@ -1960,6 +2002,12 @@ distclean-generic:
-rm -f contrib/libtests/$(am__dirstamp)
-rm -f contrib/tools/$(DEPDIR)/$(am__dirstamp)
-rm -f contrib/tools/$(am__dirstamp)
-rm -f intel/$(DEPDIR)/$(am__dirstamp)
-rm -f intel/$(am__dirstamp)
-rm -f mips/$(DEPDIR)/$(am__dirstamp)
-rm -f mips/$(am__dirstamp)
-rm -f powerpc/$(DEPDIR)/$(am__dirstamp)
-rm -f powerpc/$(am__dirstamp)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@ -1976,7 +2024,7 @@ clean-am: clean-binPROGRAMS clean-checkPROGRAMS clean-generic \
distclean: distclean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf ./$(DEPDIR) arm/$(DEPDIR) contrib/libtests/$(DEPDIR) contrib/tools/$(DEPDIR)
-rm -rf ./$(DEPDIR) arm/$(DEPDIR) contrib/libtests/$(DEPDIR) contrib/tools/$(DEPDIR) intel/$(DEPDIR) mips/$(DEPDIR) powerpc/$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-hdr distclean-libtool distclean-tags
@ -2028,7 +2076,7 @@ installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache
-rm -rf ./$(DEPDIR) arm/$(DEPDIR) contrib/libtests/$(DEPDIR) contrib/tools/$(DEPDIR)
-rm -rf ./$(DEPDIR) arm/$(DEPDIR) contrib/libtests/$(DEPDIR) contrib/tools/$(DEPDIR) intel/$(DEPDIR) mips/$(DEPDIR) powerpc/$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
@ -2152,6 +2200,7 @@ contrib/libtests/timepng.o: pnglibconf.h
contrib/tools/makesRGB.o: pnglibconf.h
contrib/tools/pngfix.o: pnglibconf.h
contrib/tools/pngcp.o: pnglibconf.h
.c.out:
rm -f $@ $*.tf[12]

View File

@ -1,4 +1,4 @@
README for libpng version 1.6.17 - March 26, 2015 (shared library 16.0)
README for libpng version 1.6.34 - September 29, 2017 (shared library 16.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@ -23,7 +23,7 @@ earlier versions if you are using a shared library. The type of the
png_uint_32, which will affect shared-library applications that use
this function.
To avoid problems with changes to the internals of png info_struct,
To avoid problems with changes to the internals of the png info_struct,
new APIs have been made available in 0.95 to avoid direct application
access to info_ptr. These functions are the png_set_<chunk> and
png_get_<chunk> functions. These functions should be used when
@ -88,11 +88,11 @@ zlib should be available at the same place that libpng is, or at zlib.net.
You may also want a copy of the PNG specification. It is available
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
these at http://www.libpng.org/pub/png/documents/
these at http://www.libpng.org/pub/png/pngdocs.html .
This code is currently being archived at libpng.sf.net in the
[DOWNLOAD] area, and at ftp://ftp.simplesystems.org. If you can't find it
in any of those places, e-mail me, and I'll help you find it.
This code is currently being archived at libpng.sourceforge.io in the
[DOWNLOAD] area, and at http://libpng.download/src . If you
can't find it in any of those places, e-mail me, and I'll help you find it.
I am not a lawyer, but I believe that the Export Control Classification
Number (ECCN) for libpng is EAR99, which means not subject to export
@ -134,7 +134,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
to others, if necessary.
Please do not send suggestions on how to change PNG. We have
been discussing PNG for nineteen years now, and it is official and
been discussing PNG for twenty years now, and it is official and
finished. If you have suggestions for libpng, however, I'll
gladly listen. Even if your suggestion is not used immediately,
it may be used later.
@ -179,18 +179,25 @@ Files in this distribution:
pngwtran.c => Write data transformations
pngwutil.c => Write utility functions
arm => Contains optimized code for the ARM platform
powerpc => Contains optimized code for the PowerPC platform
contrib => Contributions
arm-neon => Optimized code for ARM-NEON platform
powerpc-vsx => Optimized code for POWERPC-VSX platform
examples => Example programs
gregbook => source code for PNG reading and writing, from
Greg Roelofs' "PNG: The Definitive Guide",
O'Reilly, 1999
libtests => Test programs
mips-msa => Optimized code for MIPS-MSA platform
pngminim => Minimal decoder, encoder, and progressive decoder
programs demonstrating use of pngusr.dfa
pngminus => Simple pnm2png and png2pnm programs
pngsuite => Test images
testpngs
tools => Various tools
visupng => Contains a MSVC workspace for VisualPng
intel => Optimized code for INTEL-SSE2 platform
mips => Optimized code for MIPS platform
projects => Contains project files and workspaces for
building a DLL
owatcom => Contains a WATCOM project for building libpng

View File

@ -5,13 +5,14 @@ Final bug fixes.
Better C++ wrapper/full C++ implementation?
Fix problem with C++ and EXTERN "C".
cHRM transformation.
Remove setjmp/longjmp usage in favor of returning error codes.
Remove setjmp/longjmp usage in favor of returning error codes. As a start on
this, minimize the use of png_error(), replacing them with
png_warning(); return(0); or similar.
Palette creation.
Add "grayscale->palette" transformation and "palette->grayscale" detection.
Improved dithering.
Multi-lingual error and warning message support.
Complete sRGB transformation (presently it simply uses gamma=0.45455).
Make profile checking optional via a png_set_something() call.
Man pages for function calls.
Better documentation.
Better filter selection
@ -23,7 +24,7 @@ Use greater precision when changing to linear gamma for compositing against
background and doing rgb-to-gray transformation.
Investigate pre-incremented loop counters and other loop constructions.
Add interpolated method of handling interlacing.
Switch to the simpler zlib (zlib/libpng) license if legally possible.
Extend pngvalid.c to validate more of the libpng transformations.
Refactor preprocessor conditionals to compile entire statements
*/

View File

@ -1,9 +1,9 @@
/* arm_init.c - NEON optimised filter functions
*
* Copyright (c) 2014 Glenn Randers-Pehrson
* Copyright (c) 2014,2016 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.16 [December 22, 2014]
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -66,6 +66,7 @@ png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
* wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,
* as documented in png.h
*/
png_debug(1, "in png_init_filter_functions_neon");
#ifdef PNG_ARM_NEON_API_SUPPORTED
switch ((pp->options >> PNG_ARM_NEON) & 3)
{

View File

@ -1,9 +1,9 @@
/* filter_neon.S - NEON optimised filter functions
*
* Copyright (c) 2014 Glenn Randers-Pehrson
* Copyright (c) 2014,2017 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.16 [December 22, 2014]
* Last changed in libpng 1.6.31 [July 27, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -16,7 +16,7 @@
#define PNG_VERSION_INFO_ONLY
#include "../pngpriv.h"
#if defined(__linux__) && defined(__ELF__)
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */
#endif

View File

@ -1,11 +1,11 @@
/* filter_neon_intrinsics.c - NEON optimised filter functions
*
* Copyright (c) 2014 Glenn Randers-Pehrson
* Copyright (c) 2014,2016 Glenn Randers-Pehrson
* Written by James Yu <james.yu at linaro.org>, October 2013.
* Based on filter_neon.S, written by Mans Rullgard, 2011.
*
* Last changed in libpng 1.6.16 [December 22, 2014]
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -47,6 +47,8 @@ png_read_filter_row_up_neon(png_row_infop row_info, png_bytep row,
png_bytep rp_stop = row + row_info->rowbytes;
png_const_bytep pp = prev_row;
png_debug(1, "in png_read_filter_row_up_neon");
for (; rp < rp_stop; rp += 16, pp += 16)
{
uint8x16_t qrp, qpp;
@ -72,6 +74,8 @@ png_read_filter_row_sub3_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_sub3_neon");
for (; rp < rp_stop;)
{
uint8x8_t vtmp1, vtmp2;
@ -113,6 +117,8 @@ png_read_filter_row_sub4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_sub4_neon");
for (; rp < rp_stop; rp += 16)
{
uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp));
@ -148,6 +154,8 @@ png_read_filter_row_avg3_neon(png_row_infop row_info, png_bytep row,
vrpt = png_ptr(uint8x8x2_t,&vtmp);
vrp = *vrpt;
png_debug(1, "in png_read_filter_row_avg3_neon");
for (; rp < rp_stop; pp += 12)
{
uint8x8_t vtmp1, vtmp2, vtmp3;
@ -207,6 +215,8 @@ png_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_avg4_neon");
for (; rp < rp_stop; rp += 16, pp += 16)
{
uint32x2x4_t vtmp;
@ -280,6 +290,8 @@ png_read_filter_row_paeth3_neon(png_row_infop row_info, png_bytep row,
vrpt = png_ptr(uint8x8x2_t,&vtmp);
vrp = *vrpt;
png_debug(1, "in png_read_filter_row_paeth3_neon");
for (; rp < rp_stop; pp += 12)
{
uint8x8x2_t *vppt;
@ -339,6 +351,8 @@ png_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t vdest;
vdest.val[3] = vdup_n_u8(0);
png_debug(1, "in png_read_filter_row_paeth4_neon");
for (; rp < rp_stop; rp += 16, pp += 16)
{
uint32x2x4_t vtmp;

View File

@ -73,12 +73,13 @@ done
# present bad things are happening.
#
# The autotools generated files:
libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in\
config.sub configure depcomp install-sh ltmain.sh missing test-driver"
libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in
config.sub configure depcomp install-sh ltmain.sh missing\
test-driver"
#
# Files generated by versions of configue >2.68 or automake >1.13 (i.e. later
# versions than those required by configure.ac):
libpng_autotools_extra="compile"
libpng_autotools_extra="compile config.h.in~"
#
# These are separate because 'maintainer-clean' does not remove them.
libpng_libtool_files="scripts/libtool.m4 scripts/ltoptions.m4\

View File

@ -78,6 +78,27 @@
/* Enable ARM Neon optimizations */
#undef PNG_ARM_NEON_OPT
/* Enable Intel SSE optimizations */
#undef PNG_INTEL_SSE_OPT
/* Turn on MIPS MSA optimizations at run-time */
#undef PNG_MIPS_MSA_API_SUPPORTED
/* Check for MIPS MSA support at run-time */
#undef PNG_MIPS_MSA_CHECK_SUPPORTED
/* Enable MIPS MSA optimizations */
#undef PNG_MIPS_MSA_OPT
/* Turn on POWERPC VSX optimizations at run-time */
#undef PNG_POWERPC_VSX_API_SUPPORTED
/* Check for POWERPC VSX support at run-time */
#undef PNG_POWERPC_VSX_CHECK_SUPPORTED
/* Enable POWERPC VSX optimizations */
#undef PNG_POWERPC_VSX_OPT
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for libpng 1.6.17.
# Generated by GNU Autoconf 2.69 for libpng 1.6.34.
#
# Report bugs to <png-mng-implement@lists.sourceforge.net>.
#
@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='libpng'
PACKAGE_TARNAME='libpng'
PACKAGE_VERSION='1.6.17'
PACKAGE_STRING='libpng 1.6.17'
PACKAGE_VERSION='1.6.34'
PACKAGE_STRING='libpng 1.6.34'
PACKAGE_BUGREPORT='png-mng-implement@lists.sourceforge.net'
PACKAGE_URL=''
@ -635,6 +635,12 @@ ac_includes_default="\
ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
PNG_POWERPC_VSX_FALSE
PNG_POWERPC_VSX_TRUE
PNG_INTEL_SSE_FALSE
PNG_INTEL_SSE_TRUE
PNG_MIPS_MSA_FALSE
PNG_MIPS_MSA_TRUE
PNG_ARM_NEON_FALSE
PNG_ARM_NEON_TRUE
DO_INSTALL_LIBPNG_CONFIG_FALSE
@ -657,6 +663,8 @@ HAVE_LD_VERSION_SCRIPT_FALSE
HAVE_LD_VERSION_SCRIPT_TRUE
HAVE_SOLARIS_LD_FALSE
HAVE_SOLARIS_LD_TRUE
HAVE_CLOCK_GETTIME_FALSE
HAVE_CLOCK_GETTIME_TRUE
LIBOBJS
POW_LIB
PNG_COPTS
@ -805,7 +813,11 @@ with_libpng_prefix
enable_unversioned_links
enable_unversioned_libpng_pc
enable_unversioned_libpng_config
enable_hardware_optimizations
enable_arm_neon
enable_mips_msa
enable_intel_sse
enable_powerpc_vsx
'
ac_precious_vars='build_alias
host_alias
@ -1360,7 +1372,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures libpng 1.6.17 to adapt to many kinds of systems.
\`configure' configures libpng 1.6.34 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1430,7 +1442,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of libpng 1.6.17:";;
short | recursive ) echo "Configuration of libpng 1.6.34:";;
esac
cat <<\_ACEOF
@ -1482,6 +1494,8 @@ Optional Features:
link to the versioned version. This is done by
default - use --disable-unversioned-libpng-config to
change this.
--enable-hardware-optimizations
Enable hardware optimizations: =no/off, yes/on:
--enable-arm-neon Enable ARM NEON optimizations: =no/off, check, api,
yes/on: no/off: disable the optimizations; check:
use internal checking code (deprecated and poorly
@ -1489,6 +1503,23 @@ Optional Features:
call to png_set_option; yes/on: turn on
unconditionally. If not specified: determined by the
compiler.
--enable-mips-msa Enable MIPS MSA optimizations: =no/off, check, api,
yes/on: no/off: disable the optimizations; check:
use internal checking code (deprecated and poorly
supported); api: disable by default, enable by a
call to png_set_option; yes/on: turn on
unconditionally. If not specified: determined by the
compiler.
--enable-intel-sse Enable Intel SSE optimizations: =no/off, yes/on:
no/off: disable the optimizations; yes/on: enable
the optimizations. If not specified: determined by
the compiler.
--enable-powerpc-vsx Enable POWERPC VSX optimizations: =no/off, check,
api, yes/on: no/off: disable the optimizations;
check: use internal checking code api: disable by
default, enable by a call to png_set_option yes/on:
turn on unconditionally. If not specified:
determined by the compiler.
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -1591,7 +1622,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
libpng configure 1.6.17
libpng configure 1.6.34
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@ -1923,7 +1954,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by libpng $as_me 1.6.17, which was
It was created by libpng $as_me 1.6.34, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@ -2794,7 +2825,7 @@ fi
# Define the identity of the package.
PACKAGE='libpng'
VERSION='1.6.17'
VERSION='1.6.34'
cat >>confdefs.h <<_ACEOF
@ -2888,7 +2919,7 @@ END
fi
# The following line causes --disable-maintainer-mode to be the default to
# configure, this is necessary because libpng distributions cannot rely on the
# configure. This is necessary because libpng distributions cannot rely on the
# time stamps of the autotools generated files being correct
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
@ -2915,10 +2946,10 @@ fi
PNGLIB_VERSION=1.6.17
PNGLIB_VERSION=1.6.34
PNGLIB_MAJOR=1
PNGLIB_MINOR=6
PNGLIB_RELEASE=17
PNGLIB_RELEASE=34
@ -12597,6 +12628,41 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
# For GCC 5 the default mode for C is -std=gnu11 instead of -std=gnu89
# In pngpriv.h we request just the POSIX 1003.1 and C89 APIs by defining _POSIX_SOURCE to 1
# This is incompatible with the new default mode, so we test for that and force the
# "-std=c89" compiler option:
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we need to force back C standard to C89" >&5
$as_echo_n "checking if we need to force back C standard to C89... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#define _POSIX_SOURCE 1
#include <stdio.h>
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
else
if test "x$GCC" != "xyes"; then
as_fn_error $? "Forcing back to C89 is required but the flags are only known for GCC" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
CFLAGS="$CFLAGS -std=c89"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
# Checks for header files.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; }
@ -13073,6 +13139,26 @@ fi
done
# Some later POSIX 1003.1 functions are required for test programs, failure here
# is soft (the corresponding test program is not built).
ac_fn_c_check_func "$LINENO" "clock_gettime" "ac_cv_func_clock_gettime"
if test "x$ac_cv_func_clock_gettime" = xyes; then :
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: not building timepng" >&5
$as_echo "$as_me: WARNING: not building timepng" >&2;}
fi
if test "$ac_cv_func_clock_gettime" = "yes"; then
HAVE_CLOCK_GETTIME_TRUE=
HAVE_CLOCK_GETTIME_FALSE='#'
else
HAVE_CLOCK_GETTIME_TRUE='#'
HAVE_CLOCK_GETTIME_FALSE=
fi
# Check whether --with-zlib-prefix was given.
if test "${with_zlib_prefix+set}" = set; then :
withval=$with_zlib_prefix; ZPREFIX=${withval}
@ -13420,6 +13506,64 @@ fi
# HOST SPECIFIC OPTIONS
# =====================
#
# DEFAULT
# =======
#
# Check whether --enable-hardware-optimizations was given.
if test "${enable_hardware_optimizations+set}" = set; then :
enableval=$enable_hardware_optimizations; case "$enableval" in
no|off)
# disable hardware optimization on all systems:
enable_arm_neon=no
$as_echo "#define PNG_ARM_NEON_OPT 0" >>confdefs.h
enable_mips_msa=no
$as_echo "#define PNG_MIPS_MSA_OPT 0" >>confdefs.h
enable_powerpc_vsx=no
$as_echo "#define PNG_POWERPC_VSX_OPT 0" >>confdefs.h
enable_intel_sse=no
$as_echo "#define PNG_INTEL_SSE_OPT 0" >>confdefs.h
;;
*)
# allow enabling hardware optimization on any system:
case "$host_cpu" in
arm*|aarch64*)
enable_arm_neon=yes
$as_echo "#define PNG_ARM_NEON_OPT 0" >>confdefs.h
;;
mipsel*|mips64el*)
enable_mips_msa=yes
$as_echo "#define PNG_MIPS_MSA_OPT 0" >>confdefs.h
;;
i?86|x86_64)
enable_intel_sse=yes
$as_echo "#define PNG_INTEL_SSE_OPT 1" >>confdefs.h
;;
powerpc*|ppc64*)
enable_powerpc_vsx=yes
$as_echo "#define PNG_POWERPC_VSX_OPT 2" >>confdefs.h
;;
esac
;;
esac
fi
# ARM
# ===
#
@ -13476,6 +13620,162 @@ else
fi
# MIPS
# ===
#
# MIPS MSA (SIMD) support.
# Check whether --enable-mips-msa was given.
if test "${enable_mips_msa+set}" = set; then :
enableval=$enable_mips_msa; case "$enableval" in
no|off)
# disable the default enabling on __mips_msa systems:
$as_echo "#define PNG_MIPS_MSA_OPT 0" >>confdefs.h
# Prevent inclusion of the assembler files below:
enable_mips_msa=no;;
check)
$as_echo "#define PNG_MIPS_MSA_CHECK_SUPPORTED /**/" >>confdefs.h
;;
api)
$as_echo "#define PNG_MIPS_MSA_API_SUPPORTED /**/" >>confdefs.h
;;
yes|on)
$as_echo "#define PNG_MIPS_MSA_OPT 2" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --enable-mips-msa: please specify 'check' or 'api', if
you want the optimizations unconditionally pass '-mmsa -mfp64'
to the compiler." >&5
$as_echo "$as_me: WARNING: --enable-mips-msa: please specify 'check' or 'api', if
you want the optimizations unconditionally pass '-mmsa -mfp64'
to the compiler." >&2;};;
*)
as_fn_error $? "--enable-mips-msa=${enable_mips_msa}: invalid value" "$LINENO" 5
esac
fi
# Add MIPS specific files to all builds where the host_cpu is mips ('mips*') or
# where MIPS optimizations were explicitly requested (this allows a fallback if a
# future host CPU does not match 'mips*')
if test "$enable_mips_msa" != 'no' &&
case "$host_cpu" in
mipsel*|mips64el*) :;;
esac; then
PNG_MIPS_MSA_TRUE=
PNG_MIPS_MSA_FALSE='#'
else
PNG_MIPS_MSA_TRUE='#'
PNG_MIPS_MSA_FALSE=
fi
# INTEL
# =====
#
# INTEL SSE (SIMD) support.
# Check whether --enable-intel-sse was given.
if test "${enable_intel_sse+set}" = set; then :
enableval=$enable_intel_sse; case "$enableval" in
no|off)
# disable the default enabling:
$as_echo "#define PNG_INTEL_SSE_OPT 0" >>confdefs.h
# Prevent inclusion of the assembler files below:
enable_intel_sse=no;;
yes|on)
$as_echo "#define PNG_INTEL_SSE_OPT 1" >>confdefs.h
;;
*)
as_fn_error $? "--enable-intel-sse=${enable_intel_sse}: invalid value" "$LINENO" 5
esac
fi
# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')
# or where Intel optimizations were explicitly requested (this allows a
# fallback if a future host CPU does not match 'x86*')
if test "$enable_intel_sse" != 'no' &&
case "$host_cpu" in
i?86|x86_64) :;;
*) test "$enable_intel_sse" != '';;
esac; then
PNG_INTEL_SSE_TRUE=
PNG_INTEL_SSE_FALSE='#'
else
PNG_INTEL_SSE_TRUE='#'
PNG_INTEL_SSE_FALSE=
fi
# PowerPC
# ===
#
# PowerPC VSX (SIMD) support.
# Check whether --enable-powerpc-vsx was given.
if test "${enable_powerpc_vsx+set}" = set; then :
enableval=$enable_powerpc_vsx; case "$enableval" in
no|off)
# disable the default enabling on __ppc64__ systems:
$as_echo "#define PNG_POWERPC_VSX_OPT 0" >>confdefs.h
# Prevent inclusion of the platform specific files below:
enable_powerpc_vsx=no;;
check)
$as_echo "#define PNG_POWERPC_VSX_CHECK_SUPPORTED /**/" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --enable-powerpc-vsx Please check contrib/powerpc/README file
for the list of supported OSes." >&5
$as_echo "$as_me: WARNING: --enable-powerpc-vsx Please check contrib/powerpc/README file
for the list of supported OSes." >&2;};;
api)
$as_echo "#define PNG_POWERPC_VSX_API_SUPPORTED /**/" >>confdefs.h
;;
yes|on)
$as_echo "#define PNG_POWERPC_VSX_OPT 2" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --enable-powerpc-vsx: please specify 'check' or 'api', if
you want the optimizations unconditionally pass '-maltivec -mvsx'
or '-mcpu=power8'to the compiler." >&5
$as_echo "$as_me: WARNING: --enable-powerpc-vsx: please specify 'check' or 'api', if
you want the optimizations unconditionally pass '-maltivec -mvsx'
or '-mcpu=power8'to the compiler." >&2;};;
*)
as_fn_error $? "--enable-powerpc-vsx=${enable_powerpc_vsx}: invalid value" "$LINENO" 5
esac
fi
# Add PowerPC specific files to all builds where the host_cpu is powerpc('powerpc*') or
# where POWERPC optimizations were explicitly requested (this allows a fallback if a
# future host CPU does not match 'powerpc*')
if test "$enable_powerpc_vsx" != 'no' &&
case "$host_cpu" in
powerpc*|ppc64*) :;;
esac; then
PNG_POWERPC_VSX_TRUE=
PNG_POWERPC_VSX_FALSE='#'
else
PNG_POWERPC_VSX_TRUE='#'
PNG_POWERPC_VSX_FALSE=
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: Extra options for compiler: $PNG_COPTS" >&5
$as_echo "$as_me: Extra options for compiler: $PNG_COPTS" >&6;}
@ -13626,6 +13926,10 @@ if test -z "${am__fastdepCCAS_TRUE}" && test -z "${am__fastdepCCAS_FALSE}"; then
as_fn_error $? "conditional \"am__fastdepCCAS\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_CLOCK_GETTIME_TRUE}" && test -z "${HAVE_CLOCK_GETTIME_FALSE}"; then
as_fn_error $? "conditional \"HAVE_CLOCK_GETTIME\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_SOLARIS_LD_TRUE}" && test -z "${HAVE_SOLARIS_LD_FALSE}"; then
as_fn_error $? "conditional \"HAVE_SOLARIS_LD\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
@ -13654,6 +13958,18 @@ if test -z "${PNG_ARM_NEON_TRUE}" && test -z "${PNG_ARM_NEON_FALSE}"; then
as_fn_error $? "conditional \"PNG_ARM_NEON\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${PNG_MIPS_MSA_TRUE}" && test -z "${PNG_MIPS_MSA_FALSE}"; then
as_fn_error $? "conditional \"PNG_MIPS_MSA\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${PNG_INTEL_SSE_TRUE}" && test -z "${PNG_INTEL_SSE_FALSE}"; then
as_fn_error $? "conditional \"PNG_INTEL_SSE\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${PNG_POWERPC_VSX_TRUE}" && test -z "${PNG_POWERPC_VSX_FALSE}"; then
as_fn_error $? "conditional \"PNG_POWERPC_VSX\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
@ -14051,7 +14367,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by libpng $as_me 1.6.17, which was
This file was extended by libpng $as_me 1.6.34, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -14117,7 +14433,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
libpng config.status 1.6.17
libpng config.status 1.6.34
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

View File

@ -1,5 +1,12 @@
# configure.ac
# Copyright (c) 2004-2016 Glenn Randers-Pehrson
# Last changed in libpng 1.6.25 [September 1, 2016]
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h
dnl Process this file with autoconf to produce a configure script.
dnl
dnl Minor upgrades (compatible ABI): increment the package version
@ -18,7 +25,7 @@ AC_PREREQ([2.68])
dnl Version number stuff here:
AC_INIT([libpng],[1.6.17],[png-mng-implement@lists.sourceforge.net])
AC_INIT([libpng],[1.6.34],[png-mng-implement@lists.sourceforge.net])
AC_CONFIG_MACRO_DIR([scripts])
# libpng does not follow GNU file name conventions (hence 'foreign')
@ -29,7 +36,7 @@ AC_CONFIG_MACRO_DIR([scripts])
# 1.13 is required for parallel tests
AM_INIT_AUTOMAKE([1.13 foreign dist-xz color-tests silent-rules subdir-objects])
# The following line causes --disable-maintainer-mode to be the default to
# configure, this is necessary because libpng distributions cannot rely on the
# configure. This is necessary because libpng distributions cannot rely on the
# time stamps of the autotools generated files being correct
AM_MAINTAINER_MODE
@ -39,10 +46,10 @@ dnl automake, so the following is not necessary (and is not defined anyway):
dnl AM_PREREQ([1.11.2])
dnl stop configure from automagically running automake
PNGLIB_VERSION=1.6.17
PNGLIB_VERSION=1.6.34
PNGLIB_MAJOR=1
PNGLIB_MINOR=6
PNGLIB_RELEASE=17
PNGLIB_RELEASE=34
dnl End of version number stuff
@ -60,7 +67,7 @@ AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
dnl libtool/libtoolize; version 2.4.2 is the tested version, this or any
dnl libtool/libtoolize; version 2.4.2 is the tested version. This or any
dnl compatible later version may be used
LT_INIT([win32-dll])
LT_PREREQ([2.4.2])
@ -107,6 +114,25 @@ AC_ARG_ENABLE(werror,
CFLAGS="$sav_CFLAGS"
fi],)
# For GCC 5 the default mode for C is -std=gnu11 instead of -std=gnu89
# In pngpriv.h we request just the POSIX 1003.1 and C89 APIs by defining _POSIX_SOURCE to 1
# This is incompatible with the new default mode, so we test for that and force the
# "-std=c89" compiler option:
AC_MSG_CHECKING([if we need to force back C standard to C89])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([
[#define _POSIX_SOURCE 1]
[#include <stdio.h>]
])],
AC_MSG_RESULT(no),[
if test "x$GCC" != "xyes"; then
AC_MSG_ERROR(
[Forcing back to C89 is required but the flags are only known for GCC])
fi
AC_MSG_RESULT(yes)
CFLAGS="$CFLAGS -std=c89"
])
# Checks for header files.
AC_HEADER_STDC
@ -120,6 +146,12 @@ AC_C_RESTRICT
AC_FUNC_STRTOD
AC_CHECK_FUNCS([memset], , AC_MSG_ERROR(memset not found in libc))
AC_CHECK_FUNCS([pow], , AC_CHECK_LIB(m, pow, , AC_MSG_ERROR(cannot find pow)) )
# Some later POSIX 1003.1 functions are required for test programs, failure here
# is soft (the corresponding test program is not built).
AC_CHECK_FUNC([clock_gettime],,[AC_MSG_WARN([not building timepng])])
AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "$ac_cv_func_clock_gettime" = "yes"])
AC_ARG_WITH(zlib-prefix,
AS_HELP_STRING([[[--with-zlib-prefix]]],
[prefix that may have been used in installed zlib]),
@ -268,6 +300,55 @@ AM_CONDITIONAL([DO_INSTALL_LIBPNG_CONFIG],
# HOST SPECIFIC OPTIONS
# =====================
#
# DEFAULT
# =======
#
AC_ARG_ENABLE([hardware-optimizations],
AS_HELP_STRING([[[--enable-hardware-optimizations]]],
[Enable hardware optimizations: =no/off, yes/on:]),
[case "$enableval" in
no|off)
# disable hardware optimization on all systems:
enable_arm_neon=no
AC_DEFINE([PNG_ARM_NEON_OPT], [0],
[Disable ARM_NEON optimizations])
enable_mips_msa=no
AC_DEFINE([PNG_MIPS_MSA_OPT], [0],
[Disable MIPS_MSA optimizations])
enable_powerpc_vsx=no
AC_DEFINE([PNG_POWERPC_VSX_OPT], [0],
[Disable POWERPC VSX optimizations])
enable_intel_sse=no
AC_DEFINE([PNG_INTEL_SSE_OPT], [0],
[Disable INTEL_SSE optimizations])
;;
*)
# allow enabling hardware optimization on any system:
case "$host_cpu" in
arm*|aarch64*)
enable_arm_neon=yes
AC_DEFINE([PNG_ARM_NEON_OPT], [0],
[Enable ARM_NEON optimizations])
;;
mipsel*|mips64el*)
enable_mips_msa=yes
AC_DEFINE([PNG_MIPS_MSA_OPT], [0],
[Enable MIPS_MSA optimizations])
;;
i?86|x86_64)
enable_intel_sse=yes
AC_DEFINE([PNG_INTEL_SSE_OPT], [1],
[Enable Intel SSE optimizations])
;;
powerpc*|ppc64*)
enable_powerpc_vsx=yes
AC_DEFINE([PNG_POWERPC_VSX_OPT], [2],
[Enable POWERPC VSX optimizations])
;;
esac
;;
esac])
# ARM
# ===
#
@ -314,6 +395,134 @@ AM_CONDITIONAL([PNG_ARM_NEON],
*) test "$enable_arm_neon" != '';;
esac])
# MIPS
# ===
#
# MIPS MSA (SIMD) support.
AC_ARG_ENABLE([mips-msa],
AS_HELP_STRING([[[--enable-mips-msa]]],
[Enable MIPS MSA optimizations: =no/off, check, api, yes/on:]
[no/off: disable the optimizations; check: use internal checking code]
[(deprecated and poorly supported); api: disable by default, enable by]
[a call to png_set_option; yes/on: turn on unconditionally.]
[If not specified: determined by the compiler.]),
[case "$enableval" in
no|off)
# disable the default enabling on __mips_msa systems:
AC_DEFINE([PNG_MIPS_MSA_OPT], [0],
[Disable MIPS MSA optimizations])
# Prevent inclusion of the assembler files below:
enable_mips_msa=no;;
check)
AC_DEFINE([PNG_MIPS_MSA_CHECK_SUPPORTED], [],
[Check for MIPS MSA support at run-time]);;
api)
AC_DEFINE([PNG_MIPS_MSA_API_SUPPORTED], [],
[Turn on MIPS MSA optimizations at run-time]);;
yes|on)
AC_DEFINE([PNG_MIPS_MSA_OPT], [2],
[Enable MIPS MSA optimizations])
AC_MSG_WARN([--enable-mips-msa: please specify 'check' or 'api', if]
[you want the optimizations unconditionally pass '-mmsa -mfp64']
[to the compiler.]);;
*)
AC_MSG_ERROR([--enable-mips-msa=${enable_mips_msa}: invalid value])
esac])
# Add MIPS specific files to all builds where the host_cpu is mips ('mips*') or
# where MIPS optimizations were explicitly requested (this allows a fallback if a
# future host CPU does not match 'mips*')
AM_CONDITIONAL([PNG_MIPS_MSA],
[test "$enable_mips_msa" != 'no' &&
case "$host_cpu" in
mipsel*|mips64el*) :;;
esac])
# INTEL
# =====
#
# INTEL SSE (SIMD) support.
AC_ARG_ENABLE([intel-sse],
AS_HELP_STRING([[[--enable-intel-sse]]],
[Enable Intel SSE optimizations: =no/off, yes/on:]
[no/off: disable the optimizations;]
[yes/on: enable the optimizations.]
[If not specified: determined by the compiler.]),
[case "$enableval" in
no|off)
# disable the default enabling:
AC_DEFINE([PNG_INTEL_SSE_OPT], [0],
[Disable Intel SSE optimizations])
# Prevent inclusion of the assembler files below:
enable_intel_sse=no;;
yes|on)
AC_DEFINE([PNG_INTEL_SSE_OPT], [1],
[Enable Intel SSE optimizations]);;
*)
AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])
esac])
# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')
# or where Intel optimizations were explicitly requested (this allows a
# fallback if a future host CPU does not match 'x86*')
AM_CONDITIONAL([PNG_INTEL_SSE],
[test "$enable_intel_sse" != 'no' &&
case "$host_cpu" in
i?86|x86_64) :;;
*) test "$enable_intel_sse" != '';;
esac])
# PowerPC
# ===
#
# PowerPC VSX (SIMD) support.
AC_ARG_ENABLE([powerpc-vsx],
AS_HELP_STRING([[[--enable-powerpc-vsx]]],
[Enable POWERPC VSX optimizations: =no/off, check, api, yes/on:]
[no/off: disable the optimizations; check: use internal checking code]
[api: disable by default, enable by a call to png_set_option]
[yes/on: turn on unconditionally.]
[If not specified: determined by the compiler.]),
[case "$enableval" in
no|off)
# disable the default enabling on __ppc64__ systems:
AC_DEFINE([PNG_POWERPC_VSX_OPT], [0],
[Disable POWERPC VSX optimizations])
# Prevent inclusion of the platform specific files below:
enable_powerpc_vsx=no;;
check)
AC_DEFINE([PNG_POWERPC_VSX_CHECK_SUPPORTED], [],
[Check for POWERPC VSX support at run-time])
AC_MSG_WARN([--enable-powerpc-vsx Please check contrib/powerpc/README file]
[for the list of supported OSes.]);;
api)
AC_DEFINE([PNG_POWERPC_VSX_API_SUPPORTED], [],
[Turn on POWERPC VSX optimizations at run-time]);;
yes|on)
AC_DEFINE([PNG_POWERPC_VSX_OPT], [2],
[Enable POWERPC VSX optimizations])
AC_MSG_WARN([--enable-powerpc-vsx: please specify 'check' or 'api', if]
[you want the optimizations unconditionally pass '-maltivec -mvsx']
[or '-mcpu=power8'to the compiler.]);;
*)
AC_MSG_ERROR([--enable-powerpc-vsx=${enable_powerpc_vsx}: invalid value])
esac])
# Add PowerPC specific files to all builds where the host_cpu is powerpc('powerpc*') or
# where POWERPC optimizations were explicitly requested (this allows a fallback if a
# future host CPU does not match 'powerpc*')
AM_CONDITIONAL([PNG_POWERPC_VSX],
[test "$enable_powerpc_vsx" != 'no' &&
case "$host_cpu" in
powerpc*|ppc64*) :;;
esac])
AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]])
# Config files, substituting as above

View File

@ -1,4 +1,5 @@
This "contrib" directory contains contributions which are not necessarily under
the libpng license, although all are open source. They are not part of
libpng proper and are not used for building the library.
libpng proper and are not used for building the library, although some are used
for testing the library via "make check".

View File

@ -1,7 +1,7 @@
OPERATING SYSTEM SPECIFIC ARM NEON DETECTION
--------------------------------------------
Detection of the ability to exexcute ARM NEON on an ARM processor requires
Detection of the ability to execute ARM NEON on an ARM processor requires
operating system support. (The information is not available in user mode.)
HOW TO USE THIS

View File

@ -17,7 +17,7 @@
*
* Documentation:
* http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html
* http://code.google.com/p/android/issues/detail?id=49065
* https://code.google.com/p/android/issues/detail?id=49065
*
* NOTE: this requires that libpng is built against the Android NDK and linked
* with an implementation of the Android ARM 'cpu-features' library. The code

View File

@ -7,7 +7,7 @@
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
*
* SEE contrib/arm-neon/README before reporting bugs
*
* STATUS: COMPILED, TESTED

View File

@ -1,8 +1,8 @@
/* contrib/arm-neon/linux.c
*
* Copyright (c) 2014 Glenn Randers-Pehrson
* Written by John Bowler, 2014.
* Last changed in libpng 1.6.16 [December 22, 2014]
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2014, 2017 Glenn Randers-Pehrson
* Written by John Bowler, 2014, 2017.
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -62,7 +62,7 @@ png_have_neon(png_structp png_ptr)
counter=0;
state = Feature;
/* FALL THROUGH */
/* FALLTHROUGH */
case Feature:
/* Match 'FEATURE', ASCII case insensitive. */
@ -72,10 +72,10 @@ png_have_neon(png_structp png_ptr)
state = Colon;
break;
}
/* did not match 'feature' */
state = SkipLine;
/* FALL THROUGH */
/* FALLTHROUGH */
case SkipLine:
skipLine:
@ -110,7 +110,7 @@ png_have_neon(png_structp png_ptr)
state = Neon;
counter = 0;
/* FALL THROUGH */
/* FALLTHROUGH */
case Neon:
/* Look for 'neon' tag */
@ -122,7 +122,7 @@ png_have_neon(png_structp png_ptr)
}
state = SkipTag;
/* FALL THROUGH */
/* FALLTHROUGH */
case SkipTag:
/* Skip non-space characters */

View File

@ -0,0 +1,57 @@
# pngcp.dfa
# Build time configuration of libpng
#
# Author: John Bowler
# Copyright: (c) John Bowler, 2016
# Usage rights:
# To the extent possible under law, the author has waived all copyright and
# related or neighboring rights to this work. This work is published from:
# United States.
#
# Build libpng with support for pngcp. This means just png_read_png,
# png_write_png and small number of configuration settings.
#
everything = off
# This option is specific to this configuration; it adds a #define to the
# generated pnglibconf.h which turns on the (not portable) timing option for
# pngcp. Note that any option is automatically preceded by PNG_; there is no
# way round this and this is deliberate.
option PNGCP_TIMING
# Because of the everything off above the option must also be turned on. This
# may not be done in one step because it is safer and avoids mis-spelled options
# in user .dfa files to error out if an unrecognized option is turned on.
option PNGCP_TIMING on
# Options to turn on png_read_png and png_write_png:
option INFO_IMAGE on
option SEQUENTIAL_READ on
option EASY_ACCESS on
option WRITE on
option WRITE_16BIT on
option WRITE_FILTER on
# pngcp needs this to preserve unknown chunks, switching all these on means that
# pngcp can work without explicit known chunk reading suppport
option UNKNOWN_CHUNKS on
option SET_UNKNOWN_CHUNKS on
option HANDLE_AS_UNKNOWN on
option SAVE_UNKNOWN_CHUNKS on
option WRITE_UNKNOWN_CHUNKS on
# pngcp needs this to handle palette files with invalid indices:
option CHECK_FOR_INVALID_INDEX on
option GET_PALETTE_MAX on
# Pre-libpng 1.7 pngcp has to stash text chunks manually, post 1.7 without this
# text chunks should be handled as unknown ok.
option TEXT on
# this is used to turn off limits:
option USER_LIMITS on
option SET_USER_LIMITS on
# these are are just required for specific customizations
option WRITE_CUSTOMIZE_ZTXT_COMPRESSION on
option WRITE_CUSTOMIZE_COMPRESSION on

View File

@ -21,4 +21,4 @@ ORIGINAL AUTHORS
of the people below claim any rights with regard to the contents of this
directory.
John Bowler <jbowler@acm.org>
John Bowler <jbowler at acm.org>

View File

@ -26,6 +26,10 @@
#include <png.h>
#if defined(PNG_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) && \
defined (PNG_iCCP_SUPPORTED)
static int verbose = 1;
static png_byte no_profile[] = "no profile";
@ -178,3 +182,4 @@ main(int argc, char **argv)
/* Exit code is true if any extract succeeds */
return extracted == 0;
}
#endif /* READ && STDIO && iCCP */

View File

@ -27,6 +27,8 @@
*/
#include "../../png.h"
#if defined(PNG_READ_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)
/* Return component 'c' of pixel 'x' from the given row. */
static unsigned int
component(png_const_bytep row, png_uint_32 x, unsigned int c,
@ -85,7 +87,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
*/
case PNG_COLOR_TYPE_PALETTE:
{
PNG_CONST unsigned int index = component(row, x, 0, bit_depth, 1);
PNG_CONST int index = component(row, x, 0, bit_depth, 1);
png_colorp palette = NULL;
int num_palette = 0;
@ -366,3 +368,4 @@ int main(int argc, const char **argv)
return result;
}
#endif /* READ && SEQUENTIAL_READ */

View File

@ -1,10 +1,12 @@
/*- pngtopng
*
* COPYRIGHT: Written by John Cunningham Bowler, 2011.
* COPYRIGHT: Written by John Cunningham Bowler, 2011, 2017.
* To the extent possible under law, the author has waived all copyright and
* related or neighboring rights to this work. This work is published from:
* United States.
*
* Last changed in libpng 1.6.29 [March 16, 2017]
*
* Read a PNG and write it out in a fixed format, using the 'simplified API'
* that was introduced in libpng-1.6.0.
*
@ -20,6 +22,8 @@
* ensure the code picks up the local libpng implementation:
*/
#include "../../png.h"
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && \
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
int main(int argc, const char **argv)
{
@ -57,26 +61,27 @@ int main(int argc, const char **argv)
else
fprintf(stderr, "pngtopng: write %s: %s\n", argv[2],
image.message);
free(buffer);
}
else
{
fprintf(stderr, "pngtopng: read %s: %s\n", argv[1],
image.message);
/* This is the only place where a 'free' is required; libpng does
* the cleanup on error and success, but in this case we couldn't
* complete the read because of running out of memory.
*/
png_image_free(&image);
}
free(buffer);
}
else
{
fprintf(stderr, "pngtopng: out of memory: %lu bytes\n",
(unsigned long)PNG_IMAGE_SIZE(image));
/* This is the only place where a 'free' is required; libpng does
* the cleanup on error and success, but in this case we couldn't
* complete the read because of running out of memory and so libpng
* has not got to the point where it can do cleanup.
*/
png_image_free(&image);
}
}
else
@ -90,3 +95,4 @@ int main(int argc, const char **argv)
return result;
}
#endif /* READ && WRITE */

View File

@ -0,0 +1,648 @@
/*- simpleover
*
* COPYRIGHT: Written by John Cunningham Bowler, 2015.
* To the extent possible under law, the author has waived all copyright and
* related or neighboring rights to this work. This work is published from:
* United States.
*
* Read several PNG files, which should have an alpha channel or transparency
* information, and composite them together to produce one or more 16-bit linear
* RGBA intermediates. This involves doing the correct 'over' composition to
* combine the alpha channels and corresponding data.
*
* Finally read an output (background) PNG using the 24-bit RGB format (the
* PNG will be composited on green (#00ff00) by default if it has an alpha
* channel), and apply the intermediate image generated above to specified
* locations in the image.
*
* The command line has the general format:
*
* simpleover <background.png> [output.png]
* {--sprite=width,height,name {[--at=x,y] {sprite.png}}}
* {--add=name {x,y}}
*
* The --sprite and --add options may occur multiple times. They are executed
* in order. --add may refer to any sprite already read.
*
* This code is intended to show how to composite multiple images together
* correctly. Apart from the libpng Simplified API the only work done in here
* is to combine multiple input PNG images into a single sprite; this involves
* a Porter-Duff 'over' operation and the input PNG images may, as a result,
* be regarded as being layered one on top of the other with the first (leftmost
* on the command line) being at the bottom and the last on the top.
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
/* Normally use <png.h> here to get the installed libpng, but this is done to
* ensure the code picks up the local libpng implementation, so long as this
* file is linked against a sufficiently recent libpng (1.6+) it is ok to
* change this to <png.h>:
*/
#include "../../png.h"
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
#define sprite_name_chars 15
struct sprite {
FILE *file;
png_uint_16p buffer;
unsigned int width;
unsigned int height;
char name[sprite_name_chars+1];
};
#if 0 /* div by 65535 test program */
#include <math.h>
#include <stdio.h>
int main(void) {
double err = 0;
unsigned int xerr = 0;
unsigned int r = 32769;
{
unsigned int x = 0;
do {
unsigned int t = x + (x >> 16) /*+ (x >> 31)*/ + r;
double v = x, errtest;
if (t < x) {
fprintf(stderr, "overflow: %u+%u -> %u\n", x, r, t);
return 1;
}
v /= 65535;
errtest = v;
t >>= 16;
errtest -= t;
if (errtest > err) {
err = errtest;
xerr = x;
if (errtest >= .5) {
fprintf(stderr, "error: %u/65535 = %f, not %u, error %f\n",
x, v, t, errtest);
return 0;
}
}
} while (++x <= 65535U*65535U);
}
printf("error %f @ %u\n", err, xerr);
return 0;
}
#endif /* div by 65535 test program */
static void
sprite_op(const struct sprite *sprite, int x_offset, int y_offset,
png_imagep image, const png_uint_16 *buffer)
{
/* This is where the Porter-Duff 'Over' operator is evaluated; change this
* code to change the operator (this could be parameterized). Any other
* image processing operation could be used here.
*/
/* Check for an x or y offset that pushes any part of the image beyond the
* right or bottom of the sprite:
*/
if ((y_offset < 0 || (unsigned)/*SAFE*/y_offset < sprite->height) &&
(x_offset < 0 || (unsigned)/*SAFE*/x_offset < sprite->width))
{
unsigned int y = 0;
if (y_offset < 0)
y = -y_offset; /* Skip to first visible row */
do
{
unsigned int x = 0;
if (x_offset < 0)
x = -x_offset;
do
{
/* In and out are RGBA values, so: */
const png_uint_16 *in_pixel = buffer + (y * image->width + x)*4;
png_uint_32 in_alpha = in_pixel[3];
/* This is the optimized Porter-Duff 'Over' operation, when the
* input alpha is 0 the output is not changed.
*/
if (in_alpha > 0)
{
png_uint_16 *out_pixel = sprite->buffer +
((y+y_offset) * sprite->width + (x+x_offset))*4;
/* This is the weight to apply to the output: */
in_alpha = 65535-in_alpha;
if (in_alpha > 0)
{
/* The input must be composed onto the output. This means
* multiplying the current output pixel value by the inverse
* of the input alpha (1-alpha). A division is required but
* it is by the constant 65535. Approximate this as:
*
* (x + (x >> 16) + 32769) >> 16;
*
* This is exact (and does not overflow) for all values of
* x in the range 0..65535*65535. (Note that the calculation
* produces the closest integer; the maximum error is <0.5).
*/
png_uint_32 tmp;
# define compose(c)\
tmp = out_pixel[c] * in_alpha;\
tmp = (tmp + (tmp >> 16) + 32769) >> 16;\
out_pixel[c] = tmp + in_pixel[c]
/* The following is very vectorizable... */
compose(0);
compose(1);
compose(2);
compose(3);
}
else
out_pixel[0] = in_pixel[0],
out_pixel[1] = in_pixel[1],
out_pixel[2] = in_pixel[2],
out_pixel[3] = in_pixel[3];
}
}
while (++x < image->width);
}
while (++y < image->height);
}
}
static int
create_sprite(struct sprite *sprite, int *argc, const char ***argv)
{
/* Read the arguments and create this sprite. The sprite buffer has already
* been allocated. This reads the input PNGs one by one in linear format,
* composes them onto the sprite buffer (the code in the function above)
* then saves the result, converting it on the fly to PNG RGBA 8-bit format.
*/
while (*argc > 0)
{
char tombstone;
int x = 0, y = 0;
if ((*argv)[0][0] == '-' && (*argv)[0][1] == '-')
{
/* The only supported option is --at. */
if (sscanf((*argv)[0], "--at=%d,%d%c", &x, &y, &tombstone) != 2)
break; /* success; caller will parse this option */
++*argv, --*argc;
}
else
{
/* The argument has to be a file name */
png_image image;
image.version = PNG_IMAGE_VERSION;
image.opaque = NULL;
if (png_image_begin_read_from_file(&image, (*argv)[0]))
{
png_uint_16p buffer;
image.format = PNG_FORMAT_LINEAR_RGB_ALPHA;
buffer = malloc(PNG_IMAGE_SIZE(image));
if (buffer != NULL)
{
if (png_image_finish_read(&image, NULL/*background*/, buffer,
0/*row_stride*/,
NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP*/))
{
/* This is the place where the Porter-Duff 'Over' operator
* needs to be done by this code. In fact, any image
* processing required can be done here; the data is in
* the correct format (linear, 16-bit) and source and
* destination are in memory.
*/
sprite_op(sprite, x, y, &image, buffer);
free(buffer);
++*argv, --*argc;
/* And continue to the next argument */
continue;
}
else
{
free(buffer);
fprintf(stderr, "simpleover: read %s: %s\n", (*argv)[0],
image.message);
}
}
else
{
fprintf(stderr, "simpleover: out of memory: %lu bytes\n",
(unsigned long)PNG_IMAGE_SIZE(image));
/* png_image_free must be called if we abort the Simplified API
* read because of a problem detected in this code. If problems
* are detected in the Simplified API it cleans up itself.
*/
png_image_free(&image);
}
}
else
{
/* Failed to read the first argument: */
fprintf(stderr, "simpleover: %s: %s\n", (*argv)[0], image.message);
}
return 0; /* failure */
}
}
/* All the sprite operations have completed successfully. Save the RGBA
* buffer as a PNG using the simplified write API.
*/
sprite->file = tmpfile();
if (sprite->file != NULL)
{
png_image save;
memset(&save, 0, sizeof save);
save.version = PNG_IMAGE_VERSION;
save.opaque = NULL;
save.width = sprite->width;
save.height = sprite->height;
save.format = PNG_FORMAT_LINEAR_RGB_ALPHA;
save.flags = PNG_IMAGE_FLAG_FAST;
save.colormap_entries = 0;
if (png_image_write_to_stdio(&save, sprite->file, 1/*convert_to_8_bit*/,
sprite->buffer, 0/*row_stride*/, NULL/*colormap*/))
{
/* Success; the buffer is no longer needed: */
free(sprite->buffer);
sprite->buffer = NULL;
return 1; /* ok */
}
else
fprintf(stderr, "simpleover: write sprite %s: %s\n", sprite->name,
save.message);
}
else
fprintf(stderr, "simpleover: sprite %s: could not allocate tmpfile: %s\n",
sprite->name, strerror(errno));
return 0; /* fail */
}
static int
add_sprite(png_imagep output, png_bytep out_buf, struct sprite *sprite,
int *argc, const char ***argv)
{
/* Given a --add argument naming this sprite, perform the operations listed
* in the following arguments. The arguments are expected to have the form
* (x,y), which is just an offset at which to add the sprite to the
* output.
*/
while (*argc > 0)
{
char tombstone;
int x, y;
if ((*argv)[0][0] == '-' && (*argv)[0][1] == '-')
return 1; /* success */
if (sscanf((*argv)[0], "%d,%d%c", &x, &y, &tombstone) == 2)
{
/* Now add the new image into the sprite data, but only if it
* will fit.
*/
if (x < 0 || y < 0 ||
(unsigned)/*SAFE*/x >= output->width ||
(unsigned)/*SAFE*/y >= output->height ||
sprite->width > output->width-x ||
sprite->height > output->height-y)
{
fprintf(stderr, "simpleover: sprite %s @ (%d,%d) outside image\n",
sprite->name, x, y);
/* Could just skip this, but for the moment it is an error */
return 0; /* error */
}
else
{
/* Since we know the sprite fits we can just read it into the
* output using the simplified API.
*/
png_image in;
in.version = PNG_IMAGE_VERSION;
rewind(sprite->file);
if (png_image_begin_read_from_stdio(&in, sprite->file))
{
in.format = PNG_FORMAT_RGB; /* force compose */
if (png_image_finish_read(&in, NULL/*background*/,
out_buf + (y*output->width + x)*3/*RGB*/,
output->width*3/*row_stride*/,
NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP*/))
{
++*argv, --*argc;
continue;
}
}
/* The read failed: */
fprintf(stderr, "simpleover: add sprite %s: %s\n", sprite->name,
in.message);
return 0; /* error */
}
}
else
{
fprintf(stderr, "simpleover: --add='%s': invalid position %s\n",
sprite->name, (*argv)[0]);
return 0; /* error */
}
}
return 1; /* ok */
}
static int
simpleover_process(png_imagep output, png_bytep out_buf, int argc,
const char **argv)
{
int result = 1; /* success */
# define csprites 10/*limit*/
# define str(a) #a
int nsprites = 0;
struct sprite sprites[csprites];
while (argc > 0)
{
result = 0; /* fail */
if (strncmp(argv[0], "--sprite=", 9) == 0)
{
char tombstone;
if (nsprites < csprites)
{
int n;
sprites[nsprites].width = sprites[nsprites].height = 0;
sprites[nsprites].name[0] = 0;
n = sscanf(argv[0], "--sprite=%u,%u,%" str(sprite_name_chars) "s%c",
&sprites[nsprites].width, &sprites[nsprites].height,
sprites[nsprites].name, &tombstone);
if ((n == 2 || n == 3) &&
sprites[nsprites].width > 0 && sprites[nsprites].height > 0)
{
size_t buf_size, tmp;
/* Default a name if not given. */
if (sprites[nsprites].name[0] == 0)
sprintf(sprites[nsprites].name, "sprite-%d", nsprites+1);
/* Allocate a buffer for the sprite and calculate the buffer
* size:
*/
buf_size = sizeof (png_uint_16 [4]);
buf_size *= sprites[nsprites].width;
buf_size *= sprites[nsprites].height;
/* This can overflow a (size_t); check for this: */
tmp = buf_size;
tmp /= sprites[nsprites].width;
tmp /= sprites[nsprites].height;
if (tmp == sizeof (png_uint_16 [4]))
{
sprites[nsprites].buffer = malloc(buf_size);
/* This buffer must be initialized to transparent: */
memset(sprites[nsprites].buffer, 0, buf_size);
if (sprites[nsprites].buffer != NULL)
{
sprites[nsprites].file = NULL;
++argv, --argc;
if (create_sprite(sprites+nsprites++, &argc, &argv))
{
result = 1; /* still ok */
continue;
}
break; /* error */
}
}
/* Overflow, or OOM */
fprintf(stderr, "simpleover: %s: sprite too large\n", argv[0]);
break;
}
else
{
fprintf(stderr, "simpleover: %s: invalid sprite (%u,%u)\n",
argv[0], sprites[nsprites].width, sprites[nsprites].height);
break;
}
}
else
{
fprintf(stderr, "simpleover: %s: too many sprites\n", argv[0]);
break;
}
}
else if (strncmp(argv[0], "--add=", 6) == 0)
{
const char *name = argv[0]+6;
int isprite = nsprites;
++argv, --argc;
while (--isprite >= 0)
{
if (strcmp(sprites[isprite].name, name) == 0)
{
if (!add_sprite(output, out_buf, sprites+isprite, &argc, &argv))
goto out; /* error in add_sprite */
break;
}
}
if (isprite < 0) /* sprite not found */
{
fprintf(stderr, "simpleover: --add='%s': sprite not found\n", name);
break;
}
}
else
{
fprintf(stderr, "simpleover: %s: unrecognized operation\n", argv[0]);
break;
}
result = 1; /* ok */
}
/* Clean up the cache of sprites: */
out:
while (--nsprites >= 0)
{
if (sprites[nsprites].buffer != NULL)
free(sprites[nsprites].buffer);
if (sprites[nsprites].file != NULL)
(void)fclose(sprites[nsprites].file);
}
return result;
}
int main(int argc, const char **argv)
{
int result = 1; /* default to fail */
if (argc >= 2)
{
int argi = 2;
const char *output = NULL;
png_image image;
if (argc > 2 && argv[2][0] != '-'/*an operation*/)
{
output = argv[2];
argi = 3;
}
image.version = PNG_IMAGE_VERSION;
image.opaque = NULL;
if (png_image_begin_read_from_file(&image, argv[1]))
{
png_bytep buffer;
image.format = PNG_FORMAT_RGB; /* 24-bit RGB */
buffer = malloc(PNG_IMAGE_SIZE(image));
if (buffer != NULL)
{
png_color background = {0, 0xff, 0}; /* fully saturated green */
if (png_image_finish_read(&image, &background, buffer,
0/*row_stride*/, NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP */))
{
/* At this point png_image_finish_read has cleaned up the
* allocated data in png_image, and only the buffer needs to be
* freed.
*
* Perform the remaining operations:
*/
if (simpleover_process(&image, buffer, argc-argi, argv+argi))
{
/* Write the output: */
if ((output != NULL &&
png_image_write_to_file(&image, output,
0/*convert_to_8bit*/, buffer, 0/*row_stride*/,
NULL/*colormap*/)) ||
(output == NULL &&
png_image_write_to_stdio(&image, stdout,
0/*convert_to_8bit*/, buffer, 0/*row_stride*/,
NULL/*colormap*/)))
result = 0;
else
fprintf(stderr, "simpleover: write %s: %s\n",
output == NULL ? "stdout" : output, image.message);
}
/* else simpleover_process writes an error message */
}
else
fprintf(stderr, "simpleover: read %s: %s\n", argv[1],
image.message);
free(buffer);
}
else
{
fprintf(stderr, "simpleover: out of memory: %lu bytes\n",
(unsigned long)PNG_IMAGE_SIZE(image));
/* This is the only place where a 'free' is required; libpng does
* the cleanup on error and success, but in this case we couldn't
* complete the read because of running out of memory.
*/
png_image_free(&image);
}
}
else
{
/* Failed to read the first argument: */
fprintf(stderr, "simpleover: %s: %s\n", argv[1], image.message);
}
}
else
{
/* Usage message */
fprintf(stderr,
"simpleover: usage: simpleover background.png [output.png]\n"
" Output 'background.png' as a 24-bit RGB PNG file in 'output.png'\n"
" or, if not given, stdout. 'background.png' will be composited\n"
" on fully saturated green.\n"
"\n"
" Optionally, before output, process additional PNG files:\n"
"\n"
" --sprite=width,height,name {[--at=x,y] {sprite.png}}\n"
" Produce a transparent sprite of size (width,height) and with\n"
" name 'name'.\n"
" For each sprite.png composite it using a Porter-Duff 'Over'\n"
" operation at offset (x,y) in the sprite (defaulting to (0,0)).\n"
" Input PNGs will be truncated to the area of the sprite.\n"
"\n"
" --add='name' {x,y}\n"
" Optionally, before output, composite a sprite, 'name', which\n"
" must have been previously produced using --sprite, at each\n"
" offset (x,y) in the output image. Each sprite must fit\n"
" completely within the output image.\n"
"\n"
" PNG files are processed in the order they occur on the command\n"
" line and thus the first PNG processed appears as the bottommost\n"
" in the output image.\n");
}
return result;
}
#endif /* SIMPLIFIED_READ */

View File

@ -15,7 +15,7 @@ of PBMPLUS/NetPBM) and converts them to PNG.
The source code for all three demo programs currently compiles under
Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser,
zinser@decus.de, for making the necessary changes for OpenVMS and for
zinser at decus.de, for making the necessary changes for OpenVMS and for
providing an appropriate build script.) Build instructions can be found
below.
@ -55,7 +55,7 @@ mation and links to the latest version of the source code, and Chapters
13-15 of the book for detailed discussion of the three programs.
Greg Roelofs
http://pobox.com/~newt/greg_contact.html
https://pobox.com/~newt/greg_contact.html
16 March 2008
@ -63,7 +63,7 @@ BUILD INSTRUCTIONS
- Prerequisites (in order of compilation):
- zlib http://zlib.net/
- zlib https://zlib.net/
- libpng http://www.libpng.org/pub/png/libpng.html
- pngbook http://www.libpng.org/pub/png/book/sources.html

View File

@ -4,7 +4,7 @@
---------------------------------------------------------------------------
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2007,2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -264,6 +264,12 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
*pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
*pChannels = (int)png_get_channels(png_ptr, info_ptr);
/* Guard against integer overflow */
if (height > ((size_t)(-1))/rowbytes) {
fprintf(stderr, "readpng: image_data buffer would be too large\n",
return NULL;
}
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;

View File

@ -4,7 +4,7 @@
---------------------------------------------------------------------------
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2015 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -51,6 +51,12 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
---------------------------------------------------------------------------
Changelog:
2015-11-12 - Check return value of png_get_bKGD() (Glenn R-P)
2017-04-22 - Guard against integer overflow (Glenn R-P)
---------------------------------------------------------------------------*/
@ -261,36 +267,38 @@ static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
/* since we know we've read all of the PNG file's "header" (i.e., up
* to IDAT), we can check for a background color here */
if (mainprog_ptr->need_bgcolor &&
png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
if (mainprog_ptr->need_bgcolor)
{
png_color_16p pBackground;
/* it is not obvious from the libpng documentation, but this function
* takes a pointer to a pointer, and it always returns valid red,
* green and blue values, regardless of color_type: */
png_get_bKGD(png_ptr, info_ptr, &pBackground);
if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
{
/* however, it always returns the raw bKGD data, regardless of any
* bit-depth transformations, so check depth and adjust if necessary */
if (bit_depth == 16) {
mainprog_ptr->bg_red = pBackground->red >> 8;
mainprog_ptr->bg_green = pBackground->green >> 8;
mainprog_ptr->bg_blue = pBackground->blue >> 8;
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
if (bit_depth == 1)
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
else if (bit_depth == 2)
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
else /* bit_depth == 4 */
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
} else {
mainprog_ptr->bg_red = (uch)pBackground->red;
mainprog_ptr->bg_green = (uch)pBackground->green;
mainprog_ptr->bg_blue = (uch)pBackground->blue;
/* however, it always returns the raw bKGD data, regardless of any
* bit-depth transformations, so check depth and adjust if necessary
*/
if (bit_depth == 16) {
mainprog_ptr->bg_red = pBackground->red >> 8;
mainprog_ptr->bg_green = pBackground->green >> 8;
mainprog_ptr->bg_blue = pBackground->blue >> 8;
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
if (bit_depth == 1)
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
else if (bit_depth == 2)
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
else /* bit_depth == 4 */
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
} else {
mainprog_ptr->bg_red = (uch)pBackground->red;
mainprog_ptr->bg_green = (uch)pBackground->green;
mainprog_ptr->bg_blue = (uch)pBackground->blue;
}
}
}

View File

@ -9,7 +9,7 @@
---------------------------------------------------------------------------
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2007,2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -154,12 +154,17 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
*pRowbytes = rowbytes = channels*width;
*pChannels = channels;
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
/* Guard against integer overflow */
if (height > ((size_t)(-1))/rowbytes) {
fprintf(stderr, PROGNAME ": image_data buffer would be too large\n",
return NULL;
}
Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
return NULL;
}
/* now we can go ahead and just read the whole image */

View File

@ -24,10 +24,11 @@
- 1.10: enabled "message window"/console (thanks to David Geldreich)
- 2.00: dual-licensed (added GNU GPL)
- 2.01: fixed improper display of usage screen on PNG error(s)
- 2.02: check for integer overflow (Glenn R-P)
---------------------------------------------------------------------------
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2008, 2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -182,7 +183,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
#ifndef __CYGWIN__
/* First reenable console output, which normally goes to the bit bucket
* for windowed apps. Closing the console window will terminate the
* app. Thanks to David.Geldreich@realviz.com for supplying the magical
* app. Thanks to David.Geldreich at realviz.com for supplying the magical
* incantation. */
AllocConsole();
@ -496,6 +497,12 @@ static int rpng_win_create_window(HINSTANCE hInst, int showmode)
wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2;
/* Guard against integer overflow */
if (image_height > ((size_t)(-1))/wimage_rowbytes) {
fprintf(stderr, PROGNAME ": image_data buffer would be too large\n");
return 4; /* fail */
}
if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
wimage_rowbytes*image_height)))
{

View File

@ -28,10 +28,11 @@
- 2.01: fixed improper display of usage screen on PNG error(s)
- 2.02: Added "void(argc);" statement to quiet pedantic compiler warnings
about unused variable (GR-P)
- 2.03: check for integer overflow (Glenn R-P)
---------------------------------------------------------------------------
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2008, 2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors

View File

@ -33,12 +33,11 @@
- 2.02: fixed improper display of usage screen on PNG error(s); fixed
unexpected-EOF and file-read-error cases
- 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options
- 2.04:
(GR-P)
- 2.04: check for integer overflow (Glenn R-P)
---------------------------------------------------------------------------
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2008, 2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -301,7 +300,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
#ifndef __CYGWIN__
/* Next reenable console output, which normally goes to the bit bucket
* for windowed apps. Closing the console window will terminate the
* app. Thanks to David.Geldreich@realviz.com for supplying the magical
* app. Thanks to David.Geldreich at realviz.com for supplying the magical
* incantation. */
AllocConsole();
@ -650,6 +649,13 @@ static void rpng2_win_init()
Trace((stderr, " width = %ld\n", rpng2_info.width))
Trace((stderr, " height = %ld\n", rpng2_info.height))
/* Guard against integer overflow */
if (rpng2_info.height > ((size_t)(-1))/rowbytes) {
fprintf(stderr, PROGNAME ": image_data buffer would be too large\n",
readpng2_cleanup(&rpng2_info);
return;
}
rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
if (!rpng2_info.image_data) {
readpng2_cleanup(&rpng2_info);

View File

@ -43,12 +43,12 @@
- 2.03: deleted runtime MMX-enabling/disabling and obsolete -mmx* options
- 2.04: Added "void(foo);" statements to quiet pedantic compiler warnings
about unused variables (GR-P)
TO DO:
use nanosleep() instead of usleep(), which is obsolete/deprecated.
- 2.05: Use nanosleep() instead of usleep(), which is deprecated (GR-P).
- 2.06: check for integer overflow (Glenn R-P)
---------------------------------------------------------------------------
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2010, 2014-2015, 2017 Greg Roelofs. All rights
reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -119,6 +119,7 @@
# undef usleep
# define usleep(usec) { \
struct timespec ts; \
ts.tv_sec = 0; \
ts.tv_nsec = (usec) * 1000; \
nanosleep(&ts, NULL); }
# endif
@ -497,12 +498,12 @@ int main(int argc, char **argv)
"\t\t transparent images; overrides -bgcolor\n",
num_bgpat-1);
#ifdef FEATURE_LOOP
fprintf(stderr,
fprintf(stderr,
" -loop\tloops through background images after initial display\n"
"\t\t is complete (depends on -bgpat)\n"
" sec \tseconds to display each background image (default = 2)\n");
#endif
fprintf(stderr,
fprintf(stderr,
" dur \tduration in microseconds to wait after displaying each\n"
"\t\t row (for demo purposes)\n"
" -timing\tenables delay for every block read, to simulate modem\n"
@ -781,6 +782,13 @@ static void rpng2_x_init(void)
Trace((stderr, " width = %ld\n", rpng2_info.width))
Trace((stderr, " height = %ld\n", rpng2_info.height))
/* Guard against integer overflow */
if (rpng2_info.height > ((size_t)(-1))/rpng2_info.rowbytes) {
fprintf(stderr, PROGNAME ": image_data buffer would be too large\n");
readpng2_cleanup(&rpng2_info);
return;
}
rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
if (!rpng2_info.image_data) {
readpng2_cleanup(&rpng2_info);

View File

@ -29,6 +29,7 @@
- 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix
(see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff)
- 2.00: dual-licensed (added GNU GPL)
- 2.01: check for integer overflow (Glenn R-P)
[REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line
dose not work! In order to do something useful I needed to redirect
@ -38,7 +39,7 @@
---------------------------------------------------------------------------
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2007, 2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
@ -702,7 +703,18 @@ int main(int argc, char **argv)
if (wpng_info.interlaced) {
long i;
ulg bytes;
ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */
ulg image_bytes;
/* Guard against integer overflow */
if (wpng_info_height > ((size_t)(-1)/rowbytes ||
wpng_info_height > ((ulg)(-1)/rowbytes) {
fprintf(stderr, PROGNAME ": image_data buffer too large\n");
writepng_cleanup(&wpng_info);
wpng_cleanup();
exit(5);
}
image_bytes = rowbytes * wpng_info.height;
wpng_info.image_data = (uch *)malloc(image_bytes);
wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));

View File

@ -4,7 +4,7 @@
---------------------------------------------------------------------------
Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
Copyright (c) 1998-2007, 2017 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors

View File

@ -1,4 +1,12 @@
/* Fake a PNG - just write it out directly. */
/* Fake a PNG - just write it out directly.
*
* COPYRIGHT: Written by John Cunningham Bowler, 2014.
* To the extent possible under law, the author has waived all copyright and
* related or neighboring rights to this work. This work is published from:
* United States.
*
*/
#include <stdio.h>
#include <zlib.h> /* for crc32 */

View File

@ -1,8 +1,9 @@
/* makepng.c
*
* Copyright (c) 2013 John Cunningham Bowler
*
* Last changed in libpng 1.6.1 [March 28, 2013]
/* makepng.c */
#define _ISOC99_SOURCE
/* Copyright: */
#define COPYRIGHT "\251 2013,2015 John Cunningham Bowler"
/*
* Last changed in libpng 1.6.20 [November 24, 2015]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -10,8 +11,8 @@
*
* Make a test PNG image. The arguments are as follows:
*
* makepng [--sRGB|--linear|--1.8] [--color=<color>] color-type bit-depth \
* [file-name]
* makepng [--sRGB|--linear|--1.8] [--tRNS] [--nofilters] \
* color-type bit-depth [file-name]
*
* The color-type may be numeric (and must match the numbers used by the PNG
* specification) or one of the format names listed below. The bit-depth is the
@ -39,8 +40,8 @@
* 4 channels: linear combinations of, from the top-left corner clockwise,
* transparent, red, green, blue.
*
* For color-mapped images a four channel color-map is used and the PNG file has
* a tRNS chunk, as follows:
* For color-mapped images a four channel color-map is used and if --tRNS is
* given the PNG file has a tRNS chunk, as follows:
*
* 1-bit: entry 0 is transparent-red, entry 1 is opaque-white
* 2-bit: entry 0: transparent-green
@ -53,6 +54,9 @@
* The palette always has 2^bit-depth entries and the tRNS chunk one fewer. The
* image is the 1-channel diamond, but using palette index, not luminosity.
*
* For formats other than color-mapped ones if --tRNS is specified a tRNS chunk
* is generated with all channels equal to the low bits of 0x0101.
*
* Image size is determined by the final pixel depth in bits, i.e. channels x
* bit-depth, as follows:
*
@ -60,20 +64,64 @@
* 16 bits: 256x256
* More than 16 bits: 1024x1024
*
* Row filtering is turned off (the 'none' filter is used on every row) and the
* images are not interlaced.
* Row filtering is the libpng default but may be turned off (the 'none' filter
* is used on every row) with the --nofilters option.
*
* The images are not interlaced.
*
* If file-name is given then the PNG is written to that file, else it is
* written to stdout. Notice that stdout is not supported on systems where, by
* default, it assumes text output; this program makes no attempt to change the
* text mode of stdout!
*
* makepng --color=<color> ...
*
* If --color is given then the whole image has that color, color-mapped images
* will have exactly one palette entry and all image files with be 16x16 in
* size. The color value is 1 to 4 decimal numbers as appropriate for the color
* type.
*
* If file-name is given then the PNG is written to that file, else it is
* written to stdout. Notice that stdout is not supported on systems where, by
* default, it assumes text output; this program makes no attempt to change the
* text mode of stdout!
* makepng --small ...
*
* If --small is given the images are no larger than required to include every
* possible pixel value for the format.
*
* For formats with pixels 8 bits or fewer in size the images consist of a
* single row with 2^pixel-depth pixels, one of every possible value.
*
* For formats with 16-bit pixels a 256x256 image is generated containing every
* possible pixel value.
*
* For larger pixel sizes a 256x256 image is generated where the first row
* consists of each pixel that has identical byte values throughout the pixel
* followed by rows where the byte values differ within the pixel.
*
* In all cases the pixel values are arranged in such a way that the SUB and UP
* filters give byte sequences for maximal zlib compression. By default (if
* --nofilters is not given) the SUB filter is used on the first row and the UP
* filter on all following rows.
*
* The --small option is meant to provide good test-case coverage, however the
* images are not easy to examine visually. Without the --small option the
* images contain identical color values; the pixel values are adjusted
* according to the gamma encoding with no gamma encoding being interpreted as
* sRGB.
*
* LICENSING
* =========
*
* This code is copyright of the authors, see the COPYRIGHT define above. The
* code is licensed as above, using the libpng license. The code generates
* images which are solely the product of the code; the options choose which of
* the many possibilities to generate. The images that result (but not the code
* which generates them) are licensed as defined here:
*
* IMPORTANT: the COPYRIGHT #define must contain ISO-Latin-1 characters, the
* IMAGE_LICENSING #define must contain UTF-8 characters. The 'copyright'
* symbol 0xA9U (\251) in ISO-Latin-1 encoding and 0xC20xA9 (\302\251) in UTF-8.
*/
#define _ISOC99_SOURCE /* for strtoull */
#define IMAGE_LICENSING "Dedicated to the public domain per Creative Commons "\
"license \"CC0 1.0\"; https://creativecommons.org/publicdomain/zero/1.0/"
#include <stddef.h> /* for offsetof */
#include <stdlib.h>
@ -82,6 +130,8 @@
#include <ctype.h>
#include <math.h>
#include <errno.h>
#include <assert.h>
#include <stdint.h>
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
# include <config.h>
@ -96,6 +146,25 @@
# include "../../png.h"
#endif
#include <zlib.h>
/* Work round for GCC complaints about casting a (double) function result to
* an unsigned:
*/
static unsigned int
flooru(double d)
{
d = floor(d);
return (unsigned int)d;
}
static png_byte
floorb(double d)
{
d = floor(d);
return (png_byte)d;
}
/* This structure is used for inserting extra chunks (the --insert argument, not
* documented above.)
*/
@ -107,7 +176,7 @@ typedef struct chunk_insert
png_charp parameters[1];
} chunk_insert;
static int
static unsigned int
channels_of_type(int color_type)
{
if (color_type & PNG_COLOR_MASK_PALETTE)
@ -128,14 +197,15 @@ channels_of_type(int color_type)
}
}
static int
static unsigned int
pixel_depth_of_type(int color_type, int bit_depth)
{
return channels_of_type(color_type) * bit_depth;
}
static unsigned int
image_size_of_type(int color_type, int bit_depth, unsigned int *colors)
image_size_of_type(int color_type, int bit_depth, unsigned int *colors,
int small)
{
if (*colors)
return 16;
@ -144,7 +214,16 @@ image_size_of_type(int color_type, int bit_depth, unsigned int *colors)
{
int pixel_depth = pixel_depth_of_type(color_type, bit_depth);
if (pixel_depth < 8)
if (small)
{
if (pixel_depth <= 8) /* there will be one row */
return 1 << pixel_depth;
else
return 256;
}
else if (pixel_depth < 8)
return 64;
else if (pixel_depth > 16)
@ -217,7 +296,8 @@ generate_palette(png_colorp palette, png_bytep trans, int bit_depth,
else
{
unsigned int size = 1U << (bit_depth/2); /* 2, 4 or 16 */
unsigned int x, y, ip;
unsigned int x, y;
volatile unsigned int ip = 0;
for (x=0; x<size; ++x) for (y=0; y<size; ++y)
{
@ -281,7 +361,7 @@ set_value(png_bytep row, size_t rowbytes, png_uint_32 x, unsigned int bit_depth,
exit(1);
case 16:
value = (unsigned int)floor(65535*pow(value/65535.,conv)+.5);
value = flooru(65535*pow(value/65535.,conv)+.5);
*row++ = (png_byte)(value >> 8);
*row = (png_byte)value;
return;
@ -306,15 +386,148 @@ set_value(png_bytep row, size_t rowbytes, png_uint_32 x, unsigned int bit_depth,
}
}
static void
static int /* filter mask for row */
generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
int bit_depth, png_const_bytep gamma_table, double conv,
unsigned int *colors)
unsigned int *colors, int small)
{
png_uint_32 size_max = image_size_of_type(color_type, bit_depth, colors)-1;
int filters = 0; /* file *MASK*, 0 means the default, not NONE */
png_uint_32 size_max =
image_size_of_type(color_type, bit_depth, colors, small)-1;
png_uint_32 depth_max = (1U << bit_depth)-1; /* up to 65536 */
if (colors[0] == 0) switch (channels_of_type(color_type))
if (colors[0] == 0) if (small)
{
unsigned int pixel_depth = pixel_depth_of_type(color_type, bit_depth);
/* For pixel depths less than 16 generate a single row containing all the
* possible pixel values. For 16 generate all 65536 byte pair
* combinations in a 256x256 pixel array.
*/
switch (pixel_depth)
{
case 1:
assert(y == 0 && rowbytes == 1 && size_max == 1);
row[0] = 0x6CU; /* binary: 01101100, only top 2 bits used */
filters = PNG_FILTER_NONE;
break;
case 2:
assert(y == 0 && rowbytes == 1 && size_max == 3);
row[0] = 0x1BU; /* binary 00011011, all bits used */
filters = PNG_FILTER_NONE;
break;
case 4:
assert(y == 0 && rowbytes == 8 && size_max == 15);
row[0] = 0x01U;
row[1] = 0x23U; /* SUB gives 0x22U for all following bytes */
row[2] = 0x45U;
row[3] = 0x67U;
row[4] = 0x89U;
row[5] = 0xABU;
row[6] = 0xCDU;
row[7] = 0xEFU;
filters = PNG_FILTER_SUB;
break;
case 8:
/* The row will have all the pixel values in order starting with
* '1', the SUB filter will change every byte into '1' (including
* the last, which generates pixel value '0'). Since the SUB filter
* has value 1 this should result in maximum compression.
*/
assert(y == 0 && rowbytes == 256 && size_max == 255);
for (;;)
{
row[size_max] = 0xFFU & (size_max+1);
if (size_max == 0)
break;
--size_max;
}
filters = PNG_FILTER_SUB;
break;
case 16:
/* Rows are generated such that each row has a constant difference
* between the first and second byte of each pixel and so that the
* difference increases by 1 at each row. The rows start with the
* first byte value of 0 and the value increases to 255 across the
* row.
*
* The difference starts at 1, so the first row is:
*
* 0 1 1 2 2 3 3 4 ... 254 255 255 0
*
* This means that running the SUB filter on the first row produces:
*
* [SUB==1] 0 1 0 1 0 1...
*
* Then the difference is 2 on the next row, giving:
*
* 0 2 1 3 2 4 3 5 ... 254 0 255 1
*
* When the UP filter is run on this libpng produces:
*
* [UP ==2] 0 1 0 1 0 1...
*
* And so on for all the remain rows to the final two * rows:
*
* row 254: 0 255 1 0 2 1 3 2 4 3 ... 254 253 255 254
* row 255: 0 0 1 1 2 2 3 3 4 4 ... 254 254 255 255
*/
assert(rowbytes == 512 && size_max == 255);
for (;;)
{
row[2*size_max ] = 0xFFU & size_max;
row[2*size_max+1] = 0xFFU & (size_max+y+1);
if (size_max == 0)
break;
--size_max;
}
/* The first row must include PNG_FILTER_UP so that libpng knows we
* need to keep it for the following row:
*/
filters = (y == 0 ? PNG_FILTER_SUB+PNG_FILTER_UP : PNG_FILTER_UP);
break;
case 24:
case 32:
case 48:
case 64:
/* The rows are filled by an alogorithm similar to the above, in the
* first row pixel bytes are all equal, increasing from 0 by 1 for
* each pixel. In the second row the bytes within a pixel are
* incremented 1,3,5,7,... from the previous row byte. Using an odd
* number ensures all the possible byte values are used.
*/
assert(size_max == 255 && rowbytes == 256*(pixel_depth>>3));
pixel_depth >>= 3; /* now in bytes */
while (rowbytes > 0)
{
const size_t pixel_index = --rowbytes/pixel_depth;
if (y == 0)
row[rowbytes] = 0xFFU & pixel_index;
else
{
const size_t byte_offset =
rowbytes - pixel_index * pixel_depth;
row[rowbytes] =
0xFFU & (pixel_index + (byte_offset * 2*y) + 1);
}
}
filters = (y == 0 ? PNG_FILTER_SUB+PNG_FILTER_UP : PNG_FILTER_UP);
break;
default:
assert(0/*NOT REACHED*/);
}
}
else switch (channels_of_type(color_type))
{
/* 1 channel: a square image with a diamond, the least luminous colors are on
* the edge of the image, the most luminous in the center.
@ -526,6 +739,8 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
colors[0], channels_of_type(color_type));
exit(1);
}
return filters;
}
@ -554,7 +769,7 @@ makepng_error(png_structp png_ptr, png_const_charp message)
static int /* 0 on success, else an error code */
write_png(const char **name, FILE *fp, int color_type, int bit_depth,
volatile png_fixed_point gamma, chunk_insert * volatile insert,
unsigned int filters, unsigned int *colors)
unsigned int filters, unsigned int *colors, int small, int tRNS)
{
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
name, makepng_error, makepng_warning);
@ -581,6 +796,15 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
/* Allow benign errors so that we can write PNGs with errors */
png_set_benign_errors(png_ptr, 1/*allowed*/);
/* Max out the text compression level in an attempt to make the license
* small. If --small then do the same for the IDAT.
*/
if (small)
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
png_set_text_compression_level(png_ptr, Z_BEST_COMPRESSION);
png_init_io(png_ptr, fp);
info_ptr = png_create_info_struct(png_ptr);
@ -588,11 +812,37 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
png_error(png_ptr, "OOM allocating info structure");
{
unsigned int size = image_size_of_type(color_type, bit_depth, colors);
const unsigned int size =
image_size_of_type(color_type, bit_depth, colors, small);
unsigned int ysize;
png_fixed_point real_gamma = 45455; /* For sRGB */
png_byte gamma_table[256];
double conv;
/* Normally images are square, but with 'small' we want to simply generate
* all the pixel values, or all that we reasonably can:
*/
if (small)
{
const unsigned int pixel_depth =
pixel_depth_of_type(color_type, bit_depth);
if (pixel_depth <= 8U)
{
assert(size == (1U<<pixel_depth));
ysize = 1U;
}
else
{
assert(size == 256U);
ysize = 256U;
}
}
else
ysize = size;
/* This function uses the libpng values used on read to carry extra
* information about the gamma:
*/
@ -625,13 +875,13 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
gamma_table[0] = 0;
for (i=1; i<255; ++i)
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + .5);
gamma_table[i] = floorb(pow(i/255.,conv) * 255 + .5);
gamma_table[255] = 255;
}
}
png_set_IHDR(png_ptr, info_ptr, size, size, bit_depth, color_type,
png_set_IHDR(png_ptr, info_ptr, size, ysize, bit_depth, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
if (color_type & PNG_COLOR_MASK_PALETTE)
@ -643,14 +893,26 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
npalette = generate_palette(palette, trans, bit_depth, gamma_table,
colors);
png_set_PLTE(png_ptr, info_ptr, palette, npalette);
png_set_tRNS(png_ptr, info_ptr, trans, npalette-1,
NULL/*transparent color*/);
if (tRNS)
png_set_tRNS(png_ptr, info_ptr, trans, npalette-1,
NULL/*transparent color*/);
/* Reset gamma_table to prevent the image rows being changed */
for (npalette=0; npalette<256; ++npalette)
gamma_table[npalette] = (png_byte)npalette;
}
else if (tRNS)
{
png_color_16 col;
col.red = col.green = col.blue = col.gray =
0x0101U & ((1U<<bit_depth)-1U);
col.index = 0U;
png_set_tRNS(png_ptr, info_ptr, NULL/*trans*/, 1U, &col);
}
if (gamma == PNG_DEFAULT_sRGB)
png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_ABSOLUTE);
@ -682,7 +944,11 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters);
{
int passes = png_set_interlace_handling(png_ptr);
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
int passes = png_set_interlace_handling(png_ptr);
# else /* !WRITE_INTERLACING */
int passes = 1;
# endif /* !WRITE_INTERLACING */
int pass;
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
@ -695,10 +961,15 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
{
unsigned int y;
for (y=0; y<size; ++y)
for (y=0; y<ysize; ++y)
{
generate_row(row, rowbytes, y, color_type, bit_depth,
gamma_table, conv, colors);
unsigned int row_filters =
generate_row(row, rowbytes, y, color_type, bit_depth,
gamma_table, conv, colors, small);
if (row_filters != 0 && filters == PNG_ALL_FILTERS)
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, row_filters);
png_write_row(png_ptr, row);
}
}
@ -827,7 +1098,7 @@ static png_size_t
load_fake(png_charp param, png_bytepp profile)
{
char *endptr = NULL;
unsigned long long int size = strtoull(param, &endptr, 0/*base*/);
uint64_t size = strtoull(param, &endptr, 0/*base*/);
/* The 'fake' format is <number>*[string] */
if (endptr != NULL && *endptr == '*')
@ -1062,7 +1333,8 @@ insert_iTXt(png_structp png_ptr, png_infop info_ptr, int nparams,
}
static void
insert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams, png_charpp params)
insert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams,
png_charpp params)
{
int i;
png_uint_16 freq[256];
@ -1089,6 +1361,56 @@ insert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams, png_charpp par
png_set_hIST(png_ptr, info_ptr, freq);
}
static png_byte
bval(png_const_structrp png_ptr, png_charp param, unsigned int maxval)
{
char *endptr = NULL;
unsigned long int l = strtoul(param, &endptr, 0/*base*/);
if (param[0] && *endptr == 0 && l <= maxval)
return (png_byte)l;
else
png_error(png_ptr, "sBIT: invalid sBIT value");
}
static void
insert_sBIT(png_structp png_ptr, png_infop info_ptr, int nparams,
png_charpp params)
{
const int ct = png_get_color_type(png_ptr, info_ptr);
const int c = (ct & PNG_COLOR_MASK_COLOR ? 3 : 1) +
(ct & PNG_COLOR_MASK_ALPHA ? 1 : 0);
const unsigned int maxval =
ct & PNG_COLOR_MASK_PALETTE ? 8U : png_get_bit_depth(png_ptr, info_ptr);
png_color_8 sBIT;
if (nparams != c)
png_error(png_ptr, "sBIT: incorrect parameter count");
if (ct & PNG_COLOR_MASK_COLOR)
{
sBIT.red = bval(png_ptr, params[0], maxval);
sBIT.green = bval(png_ptr, params[1], maxval);
sBIT.blue = bval(png_ptr, params[2], maxval);
sBIT.gray = 42;
}
else
{
sBIT.red = sBIT.green = sBIT.blue = 42;
sBIT.gray = bval(png_ptr, params[0], maxval);
}
if (ct & PNG_COLOR_MASK_ALPHA)
sBIT.alpha = bval(png_ptr, params[nparams-1], maxval);
else
sBIT.alpha = 42;
png_set_sBIT(png_ptr, info_ptr, &sBIT);
}
#if 0
static void
insert_sPLT(png_structp png_ptr, png_infop info_ptr, int nparams, png_charpp params)
@ -1216,6 +1538,11 @@ find_insert(png_const_charp what, png_charp param)
return make_insert(what, insert_hIST, nparams, parameter_list);
break;
case CHUNK(115,66,73,84): /* sBIT */
if (nparams <= 4)
return make_insert(what, insert_sBIT, nparams, parameter_list);
break;
#if 0
case CHUNK(115,80,76,84): /* sPLT */
return make_insert(what, insert_sPLT, nparams, parameter_list);
@ -1231,6 +1558,80 @@ find_insert(png_const_charp what, png_charp param)
return NULL;
}
/* This is necessary because libpng expects writeable strings for things like
* text chunks (maybe this should be fixed...)
*/
static png_charp
strstash(png_const_charp foo)
{
/* The program indicates a memory allocation error by crashing, this is by
* design.
*/
if (foo != NULL)
{
png_charp bar = malloc(strlen(foo)+1);
return strcpy(bar, foo);
}
return NULL;
}
static png_charp
strstash_list(const png_const_charp *text)
{
size_t foo = 0;
png_charp result, bar;
const png_const_charp *line = text;
while (*line != NULL)
foo += strlen(*line++);
result = bar = malloc(foo+1);
line = text;
while (*line != NULL)
{
foo = strlen(*line);
memcpy(bar, *line++, foo);
bar += foo;
}
*bar = 0;
return result;
}
/* These are used to insert Copyright and Licence fields, they allow the text to
* have \n unlike the --insert option.
*/
static chunk_insert *
add_tEXt(const char *key, const png_const_charp *text)
{
static char what[5] = { 116, 69, 88, 116, 0 };
png_charp parameter_list[3];
parameter_list[0] = strstash(key);
parameter_list[1] = strstash_list(text);
parameter_list[2] = NULL;
return make_insert(what, insert_tEXt, 2, parameter_list);
}
static chunk_insert *
add_iTXt(const char *key, const char *language, const char *language_key,
const png_const_charp *text)
{
static char what[5] = { 105, 84, 88, 116, 0 };
png_charp parameter_list[5];
parameter_list[0] = strstash(key);
parameter_list[1] = strstash(language);
parameter_list[2] = strstash(language_key);
parameter_list[3] = strstash_list(text);
parameter_list[4] = NULL;
return make_insert(what, insert_iTXt, 4, parameter_list);
}
/* This is a not-very-good parser for a sequence of numbers (including 0). It
* doesn't accept some apparently valid things, but it accepts all the sensible
* combinations.
@ -1280,6 +1681,8 @@ main(int argc, char **argv)
const char *file_name = NULL;
int color_type = 8; /* invalid */
int bit_depth = 32; /* invalid */
int small = 0; /* make full size images */
int tRNS = 0; /* don't output a tRNS chunk */
unsigned int colors[5];
unsigned int filters = PNG_ALL_FILTERS;
png_fixed_point gamma = 0; /* not set */
@ -1292,6 +1695,18 @@ main(int argc, char **argv)
{
char *arg = *++argv;
if (strcmp(arg, "--small") == 0)
{
small = 1;
continue;
}
if (strcmp(arg, "--tRNS") == 0)
{
tRNS = 1;
continue;
}
if (strcmp(arg, "--sRGB") == 0)
{
gamma = PNG_DEFAULT_sRGB;
@ -1432,9 +1847,10 @@ main(int argc, char **argv)
if (color_type == 8 || bit_depth == 32)
{
fprintf(stderr, "usage: makepng [--sRGB|--linear|--1.8] "
fprintf(stderr, "usage: makepng [--small] [--sRGB|--linear|--1.8] "
"[--color=...] color-type bit-depth [file-name]\n"
" Make a test PNG file, by default writes to stdout.\n");
" Make a test PNG file, by default writes to stdout.\n"
" Other options are available, UTSL.\n");
exit(1);
}
@ -1453,10 +1869,19 @@ main(int argc, char **argv)
}
}
/* small and colors are incomparible (will probably crash if both are used at
* the same time!)
*/
if (small && colors[0] != 0)
{
fprintf(stderr, "makepng: --color --small: only one at a time!\n");
exit(1);
}
/* Restrict the filters for more speed to those we know are used for the
* generated images.
*/
if (filters == PNG_ALL_FILTERS)
if (filters == PNG_ALL_FILTERS && !small/*small provides defaults*/)
{
if ((color_type & PNG_COLOR_MASK_PALETTE) != 0 || bit_depth < 8)
filters = PNG_FILTER_NONE;
@ -1474,9 +1899,39 @@ main(int argc, char **argv)
filters &= ~PNG_FILTER_NONE;
}
/* Insert standard copyright and licence text. */
{
static png_const_charp copyright[] =
{
COPYRIGHT, /* ISO-Latin-1 */
NULL
};
static png_const_charp licensing[] =
{
IMAGE_LICENSING, /* UTF-8 */
NULL
};
chunk_insert *new_insert;
new_insert = add_tEXt("Copyright", copyright);
if (new_insert != NULL)
{
*insert_ptr = new_insert;
insert_ptr = &new_insert->next;
}
new_insert = add_iTXt("Licensing", "en", NULL, licensing);
if (new_insert != NULL)
{
*insert_ptr = new_insert;
insert_ptr = &new_insert->next;
}
}
{
int ret = write_png(&file_name, fp, color_type, bit_depth, gamma,
head_insert, filters, colors);
head_insert, filters, colors, small, tRNS);
if (ret != 0 && file_name != NULL)
remove(file_name);

View File

@ -1,8 +1,8 @@
/* pngimage.c
*
* Copyright (c) 2014 John Cunningham Bowler
* Copyright (c) 2015,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.10 [March 6, 2014]
* Last changed in libpng 1.6.24 [August 4, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -36,7 +36,28 @@
# include <setjmp.h> /* because png.h did *not* include this */
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
#if PNG_LIBPNG_VER < 10700
/* READ_PNG and WRITE_PNG were not defined, so: */
# ifdef PNG_INFO_IMAGE_SUPPORTED
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
# define PNG_READ_PNG_SUPPORTED
# endif /* SEQUENTIAL_READ */
# ifdef PNG_WRITE_SUPPORTED
# define PNG_WRITE_PNG_SUPPORTED
# endif /* WRITE */
# endif /* INFO_IMAGE */
#endif /* pre 1.7.0 */
#ifdef PNG_READ_PNG_SUPPORTED
/* If a transform is valid on both read and write this implies that if the
* transform is applied to read it must also be applied on write to produce
* meaningful data. This is because these transforms when performed on read
@ -236,10 +257,12 @@ static struct transform_info
*/
#endif
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
T(SCALE_16, NONE, X, X, 16, R)
T(SCALE_16, NONE, X, X, 16, R),
/* scales 16-bit components to 8-bits. */
#endif
{ NULL /*name*/, 0, 0, 0, 0, 0, 0, 0/*!tested*/ }
#undef T
};
@ -294,7 +317,7 @@ transform_name(int t)
t &= -t; /* first set bit */
for (i=0; i<TTABLE_SIZE; ++i)
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{
if ((transform_info[i].transform & t) != 0)
return transform_info[i].name;
@ -315,7 +338,7 @@ validate_T(void)
{
unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i)
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{
if (transform_info[i].when & TRANSFORM_R)
read_transforms |= transform_info[i].transform;
@ -383,7 +406,7 @@ buffer_destroy(struct buffer *buffer)
buffer_destroy_list(list);
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
buffer_start_write(struct buffer *buffer)
{
@ -505,6 +528,7 @@ typedef enum
#define SKIP_BUGS 0x100 /* Skip over known bugs */
#define LOG_SKIPPED 0x200 /* Log skipped bugs */
#define FIND_BAD_COMBOS 0x400 /* Attempt to deduce bad combos */
#define LIST_COMBOS 0x800 /* List combos by name */
/* Result masks apply to the result bits in the 'results' field below; these
* bits are simple 1U<<error_level. A pass requires either nothing worse than
@ -552,7 +576,7 @@ struct display
png_structp read_pp;
png_infop read_ip;
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
/* Used to write a new image (the original info_ptr is used) */
png_structp write_pp;
struct buffer written_file; /* where the file gets written */
@ -579,7 +603,7 @@ display_init(struct display *dp)
dp->read_ip = NULL;
buffer_init(&dp->original_file);
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
dp->write_pp = NULL;
buffer_init(&dp->written_file);
# endif
@ -592,7 +616,7 @@ display_clean_read(struct display *dp)
png_destroy_read_struct(&dp->read_pp, &dp->read_ip, NULL);
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
display_clean_write(struct display *dp)
{
@ -604,7 +628,7 @@ display_clean_write(struct display *dp)
static void
display_clean(struct display *dp)
{
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
display_clean_write(dp);
# endif
display_clean_read(dp);
@ -622,7 +646,7 @@ static void
display_destroy(struct display *dp)
{
/* Release any memory held in the display. */
# ifdef PNG_WRITE_SUPPORTED
# ifdef PNG_WRITE_PNG_SUPPORTED
buffer_destroy(&dp->written_file);
# endif
@ -690,7 +714,35 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
int tr = dp->transforms;
if (is_combo(tr))
fprintf(stderr, "(0x%x)", tr);
{
if (dp->options & LIST_COMBOS)
{
int trx = tr;
fprintf(stderr, "(");
if (trx)
{
int start = 0;
while (trx)
{
int trz = trx & -trx;
if (start) fprintf(stderr, "+");
fprintf(stderr, "%s", transform_name(trz));
start = 1;
trx &= ~trz;
}
}
else
fprintf(stderr, "-");
fprintf(stderr, ")");
}
else
fprintf(stderr, "(0x%x)", tr);
}
else
fprintf(stderr, "(%s)", transform_name(tr));
@ -910,13 +962,13 @@ update_display(struct display *dp)
int bd = dp->bit_depth;
unsigned int i;
for (i=0; i<TTABLE_SIZE; ++i)
for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)
{
int transform = transform_info[i].transform;
if ((transform_info[i].valid_chunks == 0 ||
(transform_info[i].valid_chunks & chunks) != 0) &&
(transform_info[i].color_mask_required & ct) ==
(transform_info[i].color_mask_required & ct) ==
transform_info[i].color_mask_required &&
(transform_info[i].color_mask_absent & ct) == 0 &&
(transform_info[i].bit_depths & bd) != 0 &&
@ -935,9 +987,6 @@ update_display(struct display *dp)
dp->active_transforms = active;
dp->ignored_transforms = inactive; /* excluding write-only transforms */
if (active == 0)
display_log(dp, INTERNAL_ERROR, "bad transform table");
}
}
@ -977,7 +1026,7 @@ compare_read(struct display *dp, int applied_transforms)
{
unsigned long chunks =
png_get_valid(dp->read_pp, dp->read_ip, 0xffffffff);
if (chunks != dp->chunks)
display_log(dp, APP_FAIL, "PNG chunks changed from 0x%lx to 0x%lx",
(unsigned long)dp->chunks, chunks);
@ -1044,6 +1093,7 @@ compare_read(struct display *dp, int applied_transforms)
}
else
# ifdef PNG_sBIT_SUPPORTED
{
unsigned long y;
int bpp; /* bits-per-pixel then bytes-per-pixel */
@ -1120,8 +1170,8 @@ compare_read(struct display *dp, int applied_transforms)
{
int b;
case 16: /* Two bytes per component, bit-endian */
for (b = (bpp >> 4); b > 0; )
case 16: /* Two bytes per component, big-endian */
for (b = (bpp >> 4); b > 0; --b)
{
unsigned int sig = (unsigned int)(0xffff0000 >> sig_bits[b]);
@ -1205,12 +1255,16 @@ compare_read(struct display *dp, int applied_transforms)
}
} /* for y */
}
# else /* !sBIT */
display_log(dp, INTERNAL_ERROR,
"active shift transform but no sBIT support");
# endif /* !sBIT */
}
return 1; /* compare succeeded */
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
static void
buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
png_size_t size)
@ -1309,7 +1363,7 @@ write_png(struct display *dp, png_infop ip, int transforms)
*/
display_clean_write(dp);
}
#endif /* WRITE_SUPPORTED */
#endif /* WRITE_PNG */
static int
skip_transform(struct display *dp, int tr)
@ -1371,7 +1425,7 @@ test_one_file(struct display *dp, const char *filename)
return; /* no point testing more */
}
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
/* Second test: write the original PNG data out to a new file (to test the
* write side) then read the result back in and make sure that it hasn't
* changed.
@ -1412,7 +1466,7 @@ test_one_file(struct display *dp, const char *filename)
* out and read it back in again (without the reversible transforms)
* we should get back to the place where we started.
*/
#ifdef PNG_WRITE_SUPPORTED
#ifdef PNG_WRITE_PNG_SUPPORTED
if ((current & write_transforms) == current)
{
/* All transforms reversible: write the PNG with the transformations
@ -1588,6 +1642,12 @@ main(const int argc, const char * const * const argv)
else if (strcmp(name, "--nofind-bad-combos") == 0)
d.options &= ~FIND_BAD_COMBOS;
else if (strcmp(name, "--list-combos") == 0)
d.options |= LIST_COMBOS;
else if (strcmp(name, "--nolist-combos") == 0)
d.options &= ~LIST_COMBOS;
else if (name[0] == '-' && name[1] == '-')
{
fprintf(stderr, "pngimage: %s: unknown option\n", name);
@ -1642,11 +1702,11 @@ main(const int argc, const char * const * const argv)
return errors != 0;
}
}
#else /* !PNG_INFO_IMAGE_SUPPORTED || !PNG_READ_SUPPORTED */
#else /* !READ_PNG */
int
main(void)
{
fprintf(stderr, "pngimage: no support for png_read/write_image\n");
return 77;
return SKIP;
}
#endif

View File

@ -0,0 +1,165 @@
/* contrib/libtests/pngstest-errors.h
*
* BUILT USING: libpng version 1.6.19beta03 - September 25, 2015
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* THIS IS A MACHINE GENERATED FILE: do not edit it directly!
* Instead run:
*
* pngstest --accumulate
*
* on as many PNG files as possible; at least PNGSuite and
* contrib/libtests/testpngs.
*/
static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] =
{
{ /* input: sRGB-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 372, 0 }, { 0, 0, 372, 0 }, { 0, 0, 372, 0 }, { 0, 0, 372, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: sRGB-gray+alpha */
{ 0, 19, 0, 0 }, { 0, 0, 0, 0 }, { 0, 20, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: sRGB-rgb */
{ 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 893, 0 }, { 0, 0, 893, 0 }, { 0, 0, 811, 0 }, { 0, 0, 811, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: sRGB-rgb+alpha */
{ 0, 16, 17, 0 }, { 0, 17, 17, 0 }, { 0, 19, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 850, 875, 0 }, { 0, 850, 875, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-gray */
{ 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-gray+alpha */
{ 0, 74, 9, 0 }, { 0, 20, 9, 0 }, { 0, 74, 9, 0 }, { 0, 20, 9, 0 },
{ 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-rgb */
{ 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 4, 0 }, { 0, 0, 4, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-rgb+alpha */
{ 0, 126, 143, 0 }, { 0, 11, 7, 0 }, { 0, 74, 9, 0 }, { 0, 17, 9, 0 },
{ 0, 4, 4, 0 }, { 0, 5, 4, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-rgb */
{ 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 673, 0 }, { 0, 0, 673, 0 }, { 0, 0, 674, 0 }, { 0, 0, 674, 0 },
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 460, 0 }, { 0, 0, 460, 0 }, { 0, 0, 263, 0 }, { 0, 0, 263, 0 }
}, { /* input: color-mapped-sRGB-rgb+alpha */
{ 0, 6, 8, 0 }, { 0, 7, 8, 0 }, { 0, 75, 9, 0 }, { 0, 9, 9, 0 },
{ 0, 585, 427, 0 }, { 0, 585, 427, 0 }, { 0, 717, 514, 0 }, { 0, 717, 514, 0 },
{ 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 13323, 460, 0 }, { 0, 427, 460, 0 }, { 0, 16480, 263, 0 }, { 0, 243, 263, 0 }
}, { /* input: color-mapped-linear-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 282, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 253, 282, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 265, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 243, 265, 0 }
}
};
static png_uint_16 gpc_error_via_linear[16][4/*out*/][4] =
{
{ /* input: sRGB-gray */
{ 0, 0, 7, 0 }, { 0, 0, 7, 0 }, { 0, 0, 7, 0 }, { 0, 0, 7, 0 }
}, { /* input: sRGB-gray+alpha */
{ 0, 15, 15, 0 }, { 0, 186, 15, 0 }, { 0, 15, 15, 0 }, { 0, 186, 15, 0 }
}, { /* input: sRGB-rgb */
{ 0, 0, 20, 0 }, { 0, 0, 20, 0 }, { 0, 0, 15, 0 }, { 0, 0, 15, 0 }
}, { /* input: sRGB-rgb+alpha */
{ 0, 16, 17, 0 }, { 0, 187, 17, 0 }, { 0, 15, 15, 0 }, { 0, 186, 15, 0 }
}, { /* input: linear-gray */
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
}, { /* input: linear-gray+alpha */
{ 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
}, { /* input: linear-rgb */
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
}, { /* input: linear-rgb+alpha */
{ 0, 1, 1, 0 }, { 0, 9, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
}, { /* input: color-mapped-sRGB-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-rgb */
{ 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 14, 0 }, { 0, 0, 14, 0 }
}, { /* input: color-mapped-sRGB-rgb+alpha */
{ 0, 4, 8, 0 }, { 0, 9, 8, 0 }, { 0, 9, 5, 0 }, { 0, 32, 5, 0 }
}, { /* input: color-mapped-linear-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}
};
static png_uint_16 gpc_error_to_colormap[8/*i*/][8/*o*/][4] =
{
{ /* input: sRGB-gray */
{ 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }
}, { /* input: sRGB-gray+alpha */
{ 0, 19, 9, 0 }, { 0, 255, 9, 25 }, { 0, 88, 9, 0 }, { 0, 255, 9, 25 },
{ 0, 1012, 928, 0 }, { 0, 16026, 928, 6425 }, { 0, 1012, 928, 0 }, { 0, 16026, 928, 6425 }
}, { /* input: sRGB-rgb */
{ 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 25, 0 }, { 0, 0, 25, 0 },
{ 0, 0, 962, 0 }, { 0, 0, 962, 0 }, { 0, 0, 13677, 0 }, { 0, 0, 13677, 0 }
}, { /* input: sRGB-rgb+alpha */
{ 0, 63, 77, 0 }, { 0, 255, 19, 25 }, { 0, 225, 25, 0 }, { 0, 255, 25, 67 },
{ 0, 17534, 18491, 0 }, { 0, 15736, 2824, 6425 }, { 0, 14019, 13677, 0 }, { 0, 50115, 13677, 17219 }
}, { /* input: linear-gray */
{ 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 },
{ 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }
}, { /* input: linear-gray+alpha */
{ 0, 74, 74, 0 }, { 0, 255, 74, 25 }, { 0, 99, 74, 0 }, { 0, 255, 74, 25 },
{ 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6553 }, { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6553 }
}, { /* input: linear-rgb */
{ 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 98, 0 }, { 0, 0, 98, 0 },
{ 0, 0, 18664, 0 }, { 0, 0, 18664, 0 }, { 0, 0, 24998, 0 }, { 0, 0, 24998, 0 }
}, { /* input: linear-rgb+alpha */
{ 0, 181, 196, 0 }, { 0, 255, 61, 25 }, { 206, 187, 98, 0 }, { 0, 255, 98, 67 },
{ 0, 18141, 18137, 0 }, { 0, 17494, 17504, 6553 }, { 0, 24979, 24992, 0 }, { 0, 49172, 24992, 17347 }
}
};
/* END MACHINE GENERATED */

View File

@ -1,9 +1,8 @@
/*-
* pngstest.c
*
* Copyright (c) 2013-2014 John Cunningham Bowler
*
* Last changed in libpng 1.6.16 [December 22, 2014]
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2013-2017 John Cunningham Bowler
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -35,6 +34,15 @@
# include "../../png.h"
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED /* Else nothing can be done */
#include "../tools/sRGB.h"
@ -99,10 +107,18 @@ make_random_bytes(png_uint_32* seed, void* pv, size_t size)
seed[1] = u1;
}
static png_uint_32 color_seed[2];
static void
reseed(void)
{
color_seed[0] = 0x12345678U;
color_seed[1] = 0x9abcdefU;
}
static void
random_color(png_colorp color)
{
static png_uint_32 color_seed[2] = { 0x12345678, 0x9abcdef };
make_random_bytes(color_seed, color, sizeof *color);
}
@ -307,7 +323,7 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
}
#endif /* unused */
#define READ_FILE 1 /* else memory */
#define USE_FILE 1 /* else memory */
#define USE_STDIO 2 /* else use file name */
#define STRICT 4 /* fail on warnings too */
#define VERBOSE 8
@ -316,16 +332,19 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
#define ACCUMULATE 64
#define FAST_WRITE 128
#define sRGB_16BIT 256
#define NO_RESEED 512 /* do not reseed on each new file */
#define GBG_ERROR 1024 /* do not ignore the gamma+background_rgb_to_gray
* libpng warning. */
static void
print_opts(png_uint_32 opts)
{
if (opts & READ_FILE)
if (opts & USE_FILE)
printf(" --file");
if (opts & USE_STDIO)
printf(" --stdio");
if (opts & STRICT)
printf(" --strict");
if (!(opts & STRICT))
printf(" --nostrict");
if (opts & VERBOSE)
printf(" --verbose");
if (opts & KEEP_TMPFILES)
@ -338,6 +357,12 @@ print_opts(png_uint_32 opts)
printf(" --slow");
if (opts & sRGB_16BIT)
printf(" --sRGB-16bit");
if (opts & NO_RESEED)
printf(" --noreseed");
#if PNG_LIBPNG_VER < 10700 /* else on by default */
if (opts & GBG_ERROR)
printf(" --fault-gbg-warning");
#endif
}
#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
@ -615,7 +640,7 @@ freeimage(Image *image)
if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)
{
remove(image->tmpfile_name);
(void)remove(image->tmpfile_name);
image->tmpfile_name[0] = 0;
}
}
@ -741,8 +766,15 @@ checkopaque(Image *image)
return logerror(image, image->file_name, ": opaque not NULL", "");
}
else if (image->image.warning_or_error != 0 && (image->opts & STRICT) != 0)
return logerror(image, image->file_name, " --strict", "");
/* Separate out the gamma+background_rgb_to_gray warning because it may
* produce opaque component errors:
*/
else if (image->image.warning_or_error != 0 &&
(strcmp(image->image.message,
"libpng does not support gamma+background+rgb_to_gray") == 0 ?
(image->opts & GBG_ERROR) != 0 : (image->opts & STRICT) != 0))
return logerror(image, image->file_name, (image->opts & GBG_ERROR) != 0 ?
" --fault-gbg-warning" : " --strict", "");
else
return 1;
@ -1984,156 +2016,7 @@ static void (* const gpc_fn_colormapped[8/*in*/][8/*out*/])
* gpc_error_to_colormap.
*/
#if PNG_FORMAT_FLAG_COLORMAP == 8 /* extra check also required */
/* START MACHINE GENERATED */
static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] =
{
{ /* input: sRGB-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 372, 0 }, { 0, 0, 372, 0 }, { 0, 0, 372, 0 }, { 0, 0, 372, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: sRGB-gray+alpha */
{ 0, 18, 0, 0 }, { 0, 0, 0, 0 }, { 0, 20, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: sRGB-rgb */
{ 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 893, 0 }, { 0, 0, 893, 0 }, { 0, 0, 811, 0 }, { 0, 0, 811, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: sRGB-rgb+alpha */
{ 0, 4, 13, 0 }, { 0, 14, 13, 0 }, { 0, 19, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 832, 764, 0 }, { 0, 832, 764, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-gray */
{ 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-gray+alpha */
{ 0, 74, 9, 0 }, { 0, 20, 9, 0 }, { 0, 74, 9, 0 }, { 0, 20, 9, 0 },
{ 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-rgb */
{ 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 4, 0 }, { 0, 0, 4, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: linear-rgb+alpha */
{ 0, 126, 143, 0 }, { 0, 9, 7, 0 }, { 0, 74, 9, 0 }, { 0, 16, 9, 0 },
{ 0, 4, 4, 0 }, { 0, 5, 4, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-rgb */
{ 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 8, 0 }, { 0, 0, 8, 0 },
{ 0, 0, 673, 0 }, { 0, 0, 673, 0 }, { 0, 0, 674, 0 }, { 0, 0, 674, 0 },
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 460, 0 }, { 0, 0, 460, 0 }, { 0, 0, 263, 0 }, { 0, 0, 263, 0 }
}, { /* input: color-mapped-sRGB-rgb+alpha */
{ 0, 6, 8, 0 }, { 0, 7, 8, 0 }, { 0, 75, 8, 0 }, { 0, 9, 8, 0 },
{ 0, 585, 427, 0 }, { 0, 585, 427, 0 }, { 0, 717, 409, 0 }, { 0, 717, 409, 0 },
{ 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 13323, 460, 0 }, { 0, 334, 460, 0 }, { 0, 16480, 263, 0 }, { 0, 243, 263, 0 }
}, { /* input: color-mapped-linear-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 282, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 253, 282, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 265, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 243, 265, 0 }
}
};
static png_uint_16 gpc_error_via_linear[16][4/*out*/][4] =
{
{ /* input: sRGB-gray */
{ 0, 0, 7, 0 }, { 0, 0, 7, 0 }, { 0, 0, 7, 0 }, { 0, 0, 7, 0 }
}, { /* input: sRGB-gray+alpha */
{ 0, 15, 15, 0 }, { 0, 186, 15, 0 }, { 0, 15, 15, 0 }, { 0, 186, 15, 0 }
}, { /* input: sRGB-rgb */
{ 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 15, 0 }, { 0, 0, 15, 0 }
}, { /* input: sRGB-rgb+alpha */
{ 0, 12, 14, 0 }, { 0, 180, 14, 0 }, { 0, 14, 15, 0 }, { 0, 186, 15, 0 }
}, { /* input: linear-gray */
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
}, { /* input: linear-gray+alpha */
{ 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
}, { /* input: linear-rgb */
{ 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
}, { /* input: linear-rgb+alpha */
{ 0, 1, 1, 0 }, { 0, 8, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }
}, { /* input: color-mapped-sRGB-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-sRGB-rgb */
{ 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 14, 0 }, { 0, 0, 14, 0 }
}, { /* input: color-mapped-sRGB-rgb+alpha */
{ 0, 4, 8, 0 }, { 0, 9, 8, 0 }, { 0, 8, 3, 0 }, { 0, 32, 3, 0 }
}, { /* input: color-mapped-linear-gray */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-gray+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}, { /* input: color-mapped-linear-rgb+alpha */
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }
}
};
static png_uint_16 gpc_error_to_colormap[8/*i*/][8/*o*/][4] =
{
{ /* input: sRGB-gray */
{ 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },
{ 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }
}, { /* input: sRGB-gray+alpha */
{ 0, 19, 2, 0 }, { 0, 255, 2, 25 }, { 0, 88, 2, 0 }, { 0, 255, 2, 25 },
{ 0, 1012, 745, 0 }, { 0, 16026, 745, 6425 }, { 0, 1012, 745, 0 }, { 0, 16026, 745, 6425 }
}, { /* input: sRGB-rgb */
{ 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 25, 0 }, { 0, 0, 25, 0 },
{ 0, 0, 937, 0 }, { 0, 0, 937, 0 }, { 0, 0, 13677, 0 }, { 0, 0, 13677, 0 }
}, { /* input: sRGB-rgb+alpha */
{ 0, 63, 77, 0 }, { 0, 255, 19, 25 }, { 0, 220, 25, 0 }, { 0, 255, 25, 67 },
{ 0, 17534, 18491, 0 }, { 0, 15614, 2824, 6425 }, { 0, 14019, 13677, 0 }, { 0, 48573, 13677, 17219 }
}, { /* input: linear-gray */
{ 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 },
{ 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }
}, { /* input: linear-gray+alpha */
{ 0, 74, 74, 0 }, { 0, 255, 74, 25 }, { 0, 97, 74, 0 }, { 0, 255, 74, 25 },
{ 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6552 }, { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6552 }
}, { /* input: linear-rgb */
{ 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 98, 0 }, { 0, 0, 98, 0 },
{ 0, 0, 18664, 0 }, { 0, 0, 18664, 0 }, { 0, 0, 24998, 0 }, { 0, 0, 24998, 0 }
}, { /* input: linear-rgb+alpha */
{ 0, 181, 196, 0 }, { 0, 255, 61, 25 }, { 206, 187, 98, 0 }, { 0, 255, 98, 67 },
{ 0, 18141, 18137, 0 }, { 0, 17494, 17504, 6553 }, { 0, 24979, 24992, 0 }, { 0, 46509, 24992, 17347 }
}
};
/* END MACHINE GENERATED */
# include "pngstest-errors.h" /* machine generated */
#endif /* COLORMAP flag check */
#endif /* flag checks */
@ -2154,7 +2037,7 @@ typedef struct
int in_opaque; /* Value of input alpha that is opaque */
int is_palette; /* Sample values come from the palette */
int accumulate; /* Accumlate component errors (don't log) */
int output_8bit; /* Output is 8 bit (else 16 bit) */
int output_8bit; /* Output is 8-bit (else 16-bit) */
void (*in_gp)(Pixel*, png_const_voidp);
void (*out_gp)(Pixel*, png_const_voidp);
@ -2727,9 +2610,9 @@ compare_two_images(Image *a, Image *b, int via_linear,
const unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);
int alpha_added, alpha_removed;
int bchannels;
int btoa[4];
png_uint_32 y;
Transform tr;
int btoa[4]={0,0,0,0};
/* This should never happen: */
if (width != b->image.width || height != b->image.height)
@ -2828,7 +2711,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
else if (y >= b->image.colormap_entries)
{
if ((a->opts & ACCUMULATE) == 0)
if ((b->opts & ACCUMULATE) == 0)
{
char pindex[9];
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
@ -2862,22 +2745,27 @@ compare_two_images(Image *a, Image *b, int via_linear,
*/
else if ((a->opts & ACCUMULATE) == 0)
{
# ifdef __GNUC__
# define BYTE_CHARS 20 /* 2^32: GCC sprintf warning */
# else
# define BYTE_CHARS 3 /* 2^8: real maximum value */
# endif
/* Check the original image first,
* TODO: deal with input images with bad pixel values?
*/
if (amax >= a->image.colormap_entries)
{
char pindex[9];
sprintf(pindex, "%d[%lu]", amax,
(unsigned long)a->image.colormap_entries);
char pindex[3+2*BYTE_CHARS];
sprintf(pindex, "%d[%u]", amax,
(png_byte)/*SAFE*/a->image.colormap_entries);
return logerror(a, a->file_name, ": bad pixel index: ", pindex);
}
else if (bmax >= b->image.colormap_entries)
{
char pindex[9];
sprintf(pindex, "%d[%lu]", bmax,
(unsigned long)b->image.colormap_entries);
char pindex[3+2*BYTE_CHARS];
sprintf(pindex, "%d[%u]", bmax,
(png_byte)/*SAFE*/b->image.colormap_entries);
return logerror(b, b->file_name, ": bad pixel index: ", pindex);
}
}
@ -2997,10 +2885,13 @@ compare_two_images(Image *a, Image *b, int via_linear,
{
case 4:
if (pua[btoa[3]] != pub[3]) break;
/* FALLTHROUGH */
case 3:
if (pua[btoa[2]] != pub[2]) break;
/* FALLTHROUGH */
case 2:
if (pua[btoa[1]] != pub[1]) break;
/* FALLTHROUGH */
case 1:
if (pua[btoa[0]] != pub[0]) break;
if (alpha_added != 4 && pub[alpha_added] != 65535) break;
@ -3016,10 +2907,13 @@ compare_two_images(Image *a, Image *b, int via_linear,
{
case 4:
if (psa[btoa[3]] != psb[3]) break;
/* FALLTHROUGH */
case 3:
if (psa[btoa[2]] != psb[2]) break;
/* FALLTHROUGH */
case 2:
if (psa[btoa[1]] != psb[1]) break;
/* FALLTHROUGH */
case 1:
if (psa[btoa[0]] != psb[0]) break;
if (alpha_added != 4 && psb[alpha_added] != 255) break;
@ -3157,14 +3051,14 @@ read_file(Image *image, png_uint_32 format, png_const_colorp background)
static int
read_one_file(Image *image)
{
if (!(image->opts & READ_FILE) || (image->opts & USE_STDIO))
if (!(image->opts & USE_FILE) || (image->opts & USE_STDIO))
{
/* memory or stdio. */
FILE *f = fopen(image->file_name, "rb");
if (f != NULL)
{
if (image->opts & READ_FILE)
if (image->opts & USE_FILE)
image->input_file = f;
else /* memory */
@ -3175,7 +3069,9 @@ read_one_file(Image *image)
if (cb > 0)
{
#ifndef __COVERITY__
if ((unsigned long int)cb <= (size_t)~(size_t)0)
#endif
{
png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
@ -3243,7 +3139,41 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
if (image->opts & USE_STDIO)
{
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
#ifndef __COVERITY__
FILE *f = tmpfile();
#else
/* Experimental. Coverity says tmpfile() is insecure because it
* generates predictable names.
*
* It is possible to satisfy Coverity by using mkstemp(); however,
* any platform supporting mkstemp() undoubtedly has a secure tmpfile()
* implementation as well, and doesn't need the fix. Note that
* the fix won't work on platforms that don't support mkstemp().
*
* https://www.securecoding.cert.org/confluence/display/c/
* FIO21-C.+Do+not+create+temporary+files+in+shared+directories
* says that most historic implementations of tmpfile() provide
* only a limited number of possible temporary file names
* (usually 26) before file names are recycled. That article also
* provides a secure solution that unfortunately depends upon mkstemp().
*/
char tmpfile[] = "pngstest-XXXXXX";
int filedes;
FILE *f;
umask(0177);
filedes = mkstemp(tmpfile);
if (filedes < 0)
f = NULL;
else
{
f = fdopen(filedes,"w+");
/* Hide the filename immediately and ensure that the file does
* not exist after the program ends
*/
(void) unlink(tmpfile);
}
#endif
if (f != NULL)
{
@ -3272,10 +3202,14 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
else
return logerror(image, "tmpfile", ": open: ", strerror(errno));
#else /* SIMPLIFIED_WRITE_STDIO */
return logerror(image, "tmpfile", ": open: unsupported", "");
#endif /* SIMPLIFIED_WRITE_STDIO */
}
else
else if (image->opts & USE_FILE)
{
#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED
static int counter = 0;
char name[32];
@ -3295,6 +3229,51 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
else
return logerror(image, name, ": write failed", "");
#else /* SIMPLIFIED_WRITE_STDIO */
return logerror(image, "stdio", ": open: unsupported", "");
#endif /* SIMPLIFIED_WRITE_STDIO */
}
else /* use memory */
{
png_alloc_size_t size;
if (png_image_write_get_memory_size(image->image, size, convert_to_8bit,
image->buffer+16, (png_int_32)image->stride, image->colormap))
{
/* This is non-fatal but ignoring it was causing serious problems in
* the macro to be ignored:
*/
if (size > PNG_IMAGE_PNG_SIZE_MAX(image->image))
return logerror(image, "memory", ": PNG_IMAGE_SIZE_MAX wrong", "");
initimage(output, image->opts, "memory", image->stride_extra);
output->input_memory = malloc(size);
if (output->input_memory != NULL)
{
output->input_memory_size = size;
if (png_image_write_to_memory(&image->image, output->input_memory,
&output->input_memory_size, convert_to_8bit, image->buffer+16,
(png_int_32)image->stride, image->colormap))
{
/* This is also non-fatal but it safes safer to error out anyway:
*/
if (size != output->input_memory_size)
return logerror(image, "memory", ": memory size wrong", "");
}
else
return logerror(image, "memory", ": write failed", "");
}
else
return logerror(image, "memory", ": out of memory", "");
}
else
return logerror(image, "memory", ": get size:", "");
}
/* 'output' has an initialized temporary image, read this back in and compare
@ -3470,6 +3449,8 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
int result;
Image image;
if (!(opts & NO_RESEED))
reseed(); /* ensure that the random numbers don't depend on file order */
newimage(&image);
initimage(&image, opts, file_name, stride_extra);
result = read_one_file(&image);
@ -3507,7 +3488,7 @@ test_one_file(const char *file_name, format_list *formats, png_uint_32 opts,
int
main(int argc, char **argv)
{
png_uint_32 opts = FAST_WRITE;
png_uint_32 opts = FAST_WRITE | STRICT;
format_list formats;
const char *touch = NULL;
int log_pass = 0;
@ -3516,11 +3497,17 @@ main(int argc, char **argv)
int retval = 0;
int c;
#if PNG_LIBPNG_VER >= 10700
/* This error should not exist in 1.7 or later: */
opts |= GBG_ERROR;
#endif
init_sRGB_to_d();
#if 0
init_error_via_linear();
#endif
format_init(&formats);
reseed(); /* initialize random number seeds */
for (c=1; c<argc; ++c)
{
@ -3535,17 +3522,17 @@ main(int argc, char **argv)
}
else if (strcmp(arg, "--file") == 0)
# ifdef PNG_STDIO_SUPPORTED
opts |= READ_FILE;
opts |= USE_FILE;
# else
return 77; /* skipped: no support */
return SKIP; /* skipped: no support */
# endif
else if (strcmp(arg, "--memory") == 0)
opts &= ~READ_FILE;
opts &= ~USE_FILE;
else if (strcmp(arg, "--stdio") == 0)
# ifdef PNG_STDIO_SUPPORTED
opts |= USE_STDIO;
# else
return 77; /* skipped: no support */
return SKIP; /* skipped: no support */
# endif
else if (strcmp(arg, "--name") == 0)
opts &= ~USE_STDIO;
@ -3571,10 +3558,16 @@ main(int argc, char **argv)
opts &= ~KEEP_GOING;
else if (strcmp(arg, "--strict") == 0)
opts |= STRICT;
else if (strcmp(arg, "--nostrict") == 0)
opts &= ~STRICT;
else if (strcmp(arg, "--sRGB-16bit") == 0)
opts |= sRGB_16BIT;
else if (strcmp(arg, "--linear-16bit") == 0)
opts &= ~sRGB_16BIT;
else if (strcmp(arg, "--noreseed") == 0)
opts |= NO_RESEED;
else if (strcmp(arg, "--fault-gbg-warning") == 0)
opts |= GBG_ERROR;
else if (strcmp(arg, "--tmpfile") == 0)
{
if (c+1 < argc)
@ -3588,7 +3581,7 @@ main(int argc, char **argv)
}
/* Safe: checked above */
strcpy(tmpf, argv[c]);
strncpy(tmpf, argv[c], sizeof (tmpf)-1);
}
else
@ -3687,6 +3680,23 @@ main(int argc, char **argv)
{
unsigned int in;
printf("/* contrib/libtests/pngstest-errors.h\n");
printf(" *\n");
printf(" * BUILT USING:" PNG_HEADER_VERSION_STRING);
printf(" *\n");
printf(" * This code is released under the libpng license.\n");
printf(" * For conditions of distribution and use, see the disclaimer\n");
printf(" * and license in png.h\n");
printf(" *\n");
printf(" * THIS IS A MACHINE GENERATED FILE: do not edit it directly!\n");
printf(" * Instead run:\n");
printf(" *\n");
printf(" * pngstest --accumulate\n");
printf(" *\n");
printf(" * on as many PNG files as possible; at least PNGSuite and\n");
printf(" * contrib/libtests/testpngs.\n");
printf(" */\n");
printf("static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] =\n");
printf("{\n");
for (in=0; in<16; ++in)
@ -3776,6 +3786,7 @@ main(int argc, char **argv)
putchar('\n');
}
printf("};\n");
printf("/* END MACHINE GENERATED */\n");
}
if (retval == 0 && touch != NULL)
@ -3813,6 +3824,6 @@ int main(void)
{
fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
/* So the test is skipped: */
return 77;
return SKIP;
}
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */

View File

@ -1,8 +1,8 @@
/* pngunknown.c - test the read side unknown chunk handling
*
* Last changed in libpng 1.6.10 [March 6, 2014]
* Copyright (c) 2014 Glenn Randers-Pehrson
* Last changed in libpng 1.6.32 [August 24, 2017]
* Copyright (c) 2015,2017 Glenn Randers-Pehrson
* Written by John Cunningham Bowler
*
* This code is released under the libpng license.
@ -30,10 +30,21 @@
# include "../../png.h"
#endif
/* 1.6.1 added support for the configure test harness, which uses 77 to indicate
* a skipped test, in earlier versions we need to succeed on a skipped test, so:
*/
#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
# define SKIP 77
#else
# define SKIP 0
#endif
/* Since this program tests the ability to change the unknown chunk handling
* these must be defined:
*/
#if defined(PNG_SET_UNKNOWN_CHUNKS_SUPPORTED) &&\
defined(PNG_STDIO_SUPPORTED) &&\
defined(PNG_READ_SUPPORTED)
/* One of these must be defined to allow us to find out what happened. It is
@ -103,6 +114,7 @@ typedef png_byte *png_const_bytep;
#define png_PLTE PNG_U32( 80, 76, 84, 69)
#define png_bKGD PNG_U32( 98, 75, 71, 68)
#define png_cHRM PNG_U32( 99, 72, 82, 77)
#define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
#define png_gAMA PNG_U32(103, 65, 77, 65)
#define png_gIFg PNG_U32(103, 73, 70, 103)
@ -199,6 +211,13 @@ static struct
1,
# endif
1, START, 0 },
{ "eXIf", PNG_INFO_eXIf, png_eXIf,
# ifdef PNG_READ_eXIf_SUPPORTED
0,
# else
1,
# endif
1, END, 0 },
{ "gAMA", PNG_INFO_gAMA, png_gAMA,
# ifdef PNG_READ_gAMA_SUPPORTED
0,
@ -363,7 +382,7 @@ ancillary(const char *name)
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
}
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
static int
ancillaryb(const png_byte *name)
{
@ -467,7 +486,7 @@ get_valid(display *d, png_infop info_ptr)
png_textp text;
png_uint_32 ntext = png_get_text(d->png_ptr, info_ptr, &text, NULL);
while (ntext-- > 0) switch (text[ntext].compression)
while (ntext > 0) switch (text[--ntext].compression)
{
case -1:
flags |= PNG_INFO_tEXt;
@ -554,7 +573,7 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
/* However if there is no support to store unknown chunks don't ask libpng to
* do it; there will be an png_error.
*/
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
return discard;
# else
return 1; /*handled; discard*/
@ -562,7 +581,7 @@ read_callback(png_structp pp, png_unknown_chunkp pc)
}
#endif /* READ_USER_CHUNKS_SUPPORTED */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
static png_uint_32
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
{
@ -603,7 +622,7 @@ get_unknown(display *d, png_infop info_ptr, int after_IDAT)
++(d->error_count);
break;
}
/* FALL THROUGH (safe) */
/* FALLTHROUGH */ /* (safe) */
case PNG_HANDLE_CHUNK_ALWAYS:
break;
}
@ -615,7 +634,7 @@ get_unknown(display *d, png_infop info_ptr, int after_IDAT)
return flags;
}
#else
#else /* SAVE_UNKNOWN_CHUNKS */
static png_uint_32
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
/* Otherwise this will return the cached values set by any user callback */
@ -634,8 +653,8 @@ get_unknown(display *d, png_infop info_ptr, int after_IDAT)
* a check to ensure the logic is correct.
*/
# error No store support and no user chunk support, this will not work
# endif
#endif
# endif /* READ_USER_CHUNKS */
#endif /* SAVE_UNKNOWN_CHUNKS */
static int
check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
@ -722,11 +741,17 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
* in this case, so we just check the arguments! This could
* be improved in the future by using the read callback.
*/
png_byte name[5];
# if PNG_LIBPNG_VER >= 10700 &&\
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
{
png_byte name[5];
memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option;
memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option;
}
continue;
}
@ -735,7 +760,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 7: /* default */
if (memcmp(argv[i], "default", 7) == 0)
{
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
# if PNG_LIBPNG_VER >= 10700 &&\
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
d->keep = option;
continue;
}
@ -745,7 +775,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 3: /* all */
if (memcmp(argv[i], "all", 3) == 0)
{
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
# if PNG_LIBPNG_VER >= 10700 &&\
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
d->keep = option;
for (chunk = 0; chunk < NINFO; ++chunk)
@ -985,6 +1020,20 @@ perform_one_test(FILE *fp, int argc, const char **argv,
def = check(fp, argc, argv, flags[1], d, set_callback);
/* If IDAT is being handled as unknown the image read is skipped and all the
* IDATs after the first end up in the end info struct, so in this case add
* IDAT to the list of unknowns. (Do this after 'check' above sets the
* chunk_info 'keep' fields.)
*
* Note that the flag setting has to be in the 'known' field to avoid
* triggering the consistency check below and the flag must only be set if
* there are multiple IDATs, so if the check above did find an unknown IDAT
* after IDAT.
*/
if (chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT &&
(flags[1][3] & PNG_INFO_IDAT) != 0)
flags[0][2] |= PNG_INFO_IDAT;
/* Chunks should either be known or unknown, never both and this should apply
* whether the chunk is before or after the IDAT (actually, the app can
* probably change this by swapping the handling after the image, but this
@ -1049,7 +1098,7 @@ static const char *standard_tests[] =
"sTER", "sTER=if-safe", 0,
"IDAT", "default=discard", "IDAT=save", 0,
"sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",
"sBIT=save", "sRGB=save", 0,
"sBIT=save", "sRGB=save", "eXIf=save", 0,
0/*end*/
};
@ -1229,7 +1278,7 @@ main(void)
fprintf(stderr,
" test ignored: no support to find out about unknown chunks\n");
/* So the test is skipped: */
return 77;
return SKIP;
}
#endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */
@ -1240,6 +1289,6 @@ main(void)
fprintf(stderr,
" test ignored: no support to modify unknown chunk handling\n");
/* So the test is skipped: */
return 77;
return SKIP;
}
#endif /* SET_UNKNOWN_CHUNKS && READ */
#endif /* SET_UNKNOWN_CHUNKS && READ*/

File diff suppressed because it is too large Load Diff

View File

@ -62,6 +62,7 @@ read_png(FILE *fp)
{
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
/* Failure to initialize these is harmless */
row = malloc(rowbytes);
display = malloc(rowbytes);
@ -70,7 +71,12 @@ read_png(FILE *fp)
{
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
int passes = png_set_interlace_handling(png_ptr);
# ifdef PNG_READ_INTERLACING_SUPPORTED
int passes = png_set_interlace_handling(png_ptr);
# else /* !READ_INTERLACING */
int passes = png_get_interlace_type(png_ptr, info_ptr) ==
PNG_INTERLACE_ADAM7 ? PNG_INTERLACE_ADAM7_PASSES : 1;
# endif /* !READ_INTERLACING */
int pass;
png_start_read_image(png_ptr);
@ -79,6 +85,11 @@ read_png(FILE *fp)
{
png_uint_32 y = height;
# ifndef PNG_READ_INTERLACING_SUPPORTED
if (passes == PNG_INTERLACE_ADAM7_PASSES)
y = PNG_PASS_ROWS(y, pass);
# endif /* READ_INTERLACING */
/* NOTE: this trashes the row each time; interlace handling won't
* work, but this avoids memory thrashing for speed testing.
*/

View File

@ -634,7 +634,7 @@ int validation_muldiv(int count, int argc, char **argv)
{
png_fixed_point result;
/* NOTE: your mileage may vary, a type is required below that can
* hold 64 bits or more, if floating point is used a 64 bit or
* hold 64 bits or more, if floating point is used a 64-bit or
* better mantissa is required.
*/
long long int fp, fpround;
@ -721,7 +721,7 @@ int validation_muldiv(int count, int argc, char **argv)
}
while (--count > 0);
printf("%d tests including %d overflows, %d passed, %d failed (%d 64 bit "
printf("%d tests including %d overflows, %d passed, %d failed (%d 64-bit "
"errors)\n", tested, overflow, passed, error, error64);
return 0;
}
@ -799,13 +799,13 @@ int validation_gamma(int argc, char **argv)
if (i == 0 && png_log8bit(i) != 0xffffffff ||
i != 0 && png_log8bit(i) != floor(correct+.5))
{
fprintf(stderr, "8 bit log error: %d: got %u, expected %f\n",
fprintf(stderr, "8-bit log error: %d: got %u, expected %f\n",
i, png_log8bit(i), correct);
}
}
if (!silent)
printf("maximum 8 bit log error = %f\n", maxerr);
printf("maximum 8-bit log error = %f\n", maxerr);
maxerr = 0;
for (i=0; i<65536; ++i)
@ -821,14 +821,14 @@ int validation_gamma(int argc, char **argv)
{
if (error > .68) /* By experiment error is less than .68 */
{
fprintf(stderr, "16 bit log error: %d: got %u, expected %f"
fprintf(stderr, "16-bit log error: %d: got %u, expected %f"
" error: %f\n", i, png_log16bit(i), correct, error);
}
}
}
if (!silent)
printf("maximum 16 bit log error = %f\n", maxerr);
printf("maximum 16-bit log error = %f\n", maxerr);
/* Now exponentiations. */
maxerr = 0;
@ -841,13 +841,13 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > 1883) /* By experiment. */
{
fprintf(stderr, "32 bit exp error: %d: got %u, expected %f"
fprintf(stderr, "32-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp(i), correct, error);
}
}
if (!silent)
printf("maximum 32 bit exp error = %f\n", maxerr);
printf("maximum 32-bit exp error = %f\n", maxerr);
maxerr = 0;
for (i=0; i<=0xfffff; ++i)
@ -859,13 +859,13 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > .50002) /* By experiment */
{
fprintf(stderr, "8 bit exp error: %d: got %u, expected %f"
fprintf(stderr, "8-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp8bit(i), correct, error);
}
}
if (!silent)
printf("maximum 8 bit exp error = %f\n", maxerr);
printf("maximum 8-bit exp error = %f\n", maxerr);
maxerr = 0;
for (i=0; i<=0xfffff; ++i)
@ -877,13 +877,13 @@ int validation_gamma(int argc, char **argv)
maxerr = fabs(error);
if (fabs(error) > .524) /* By experiment */
{
fprintf(stderr, "16 bit exp error: %d: got %u, expected %f"
fprintf(stderr, "16-bit exp error: %d: got %u, expected %f"
" error: %f\n", i, png_exp16bit(i), correct, error);
}
}
if (!silent)
printf("maximum 16 bit exp error = %f\n", maxerr);
printf("maximum 16-bit exp error = %f\n", maxerr);
} /* !onlygamma */
/* Test the overall gamma correction. */
@ -913,7 +913,7 @@ int validation_gamma(int argc, char **argv)
}
if (!silent)
printf("gamma %f: maximum 8 bit error %f\n", g, maxerr);
printf("gamma %f: maximum 8-bit error %f\n", g, maxerr);
maxerr = 0;
for (j=0; j<65536; ++j)
@ -932,7 +932,7 @@ int validation_gamma(int argc, char **argv)
}
if (!silent)
printf("gamma %f: maximum 16 bit error %f\n", g, maxerr);
printf("gamma %f: maximum 16-bit error %f\n", g, maxerr);
}
return 0;

View File

@ -1,8 +1,8 @@
/* timepng.c
*
* Copyright (c) 2013 John Cunningham Bowler
* Copyright (c) 2013,2016 John Cunningham Bowler
*
* Last changed in libpng 1.6.1 [March 28, 2013]
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
@ -10,15 +10,17 @@
*
* Load an arbitrary number of PNG files (from the command line, or, if there
* are no arguments on the command line, from stdin) then run a time test by
* reading each file by row. The test does nothing with the read result and
* does no transforms. The only output is a time as a floating point number of
* seconds with 9 decimal digits.
* reading each file by row or by image (possibly with transforms in the latter
* case). The only output is a time as a floating point number of seconds with
* 9 decimal digits.
*/
#define _POSIX_C_SOURCE 199309L /* for clock_gettime */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
@ -35,36 +37,73 @@
# include "../../png.h"
#endif
static int read_png(FILE *fp)
/* The following is to support direct compilation of this file as C++ */
#ifdef __cplusplus
# define voidcast(type, value) static_cast<type>(value)
#else
# define voidcast(type, value) (value)
#endif /* __cplusplus */
/* 'CLOCK_PROCESS_CPUTIME_ID' is one of the clock timers for clock_gettime. It
* need not be supported even when clock_gettime is available. It returns the
* 'CPU' time the process has consumed. 'CPU' time is assumed to include time
* when the CPU is actually blocked by a pending cache fill but not time
* waiting for page faults. The attempt is to get a measure of the actual time
* the implementation takes to read a PNG ignoring the potentially very large IO
* overhead.
*/
#if defined (CLOCK_PROCESS_CPUTIME_ID) && defined(PNG_STDIO_SUPPORTED) &&\
defined(PNG_EASY_ACCESS_SUPPORTED) &&\
(PNG_LIBPNG_VER >= 10700 ? defined(PNG_READ_PNG_SUPPORTED) :\
defined (PNG_SEQUENTIAL_READ_SUPPORTED) &&\
defined(PNG_INFO_IMAGE_SUPPORTED))
typedef struct
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
png_infop info_ptr = NULL;
png_bytep row = NULL, display = NULL;
FILE *input;
FILE *output;
} io_data;
if (png_ptr == NULL)
return 0;
static PNG_CALLBACK(void, read_and_copy,
(png_structp png_ptr, png_bytep buffer, png_size_t cb))
{
io_data *io = (io_data*)png_get_io_ptr(png_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
if (fread(buffer, cb, 1, io->input) != 1)
png_error(png_ptr, strerror(errno));
if (fwrite(buffer, cb, 1, io->output) != 1)
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
if (row != NULL) free(row);
if (display != NULL) free(display);
return 0;
perror("temporary file");
fprintf(stderr, "temporary file PNG write failed\n");
exit(1);
}
}
png_init_io(png_ptr, fp);
static void read_by_row(png_structp png_ptr, png_infop info_ptr,
FILE *write_ptr, FILE *read_ptr)
{
/* These don't get freed on error, this is fine; the program immediately
* exits.
*/
png_bytep row = NULL, display = NULL;
io_data io_copy;
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
png_error(png_ptr, "OOM allocating info structure");
if (write_ptr != NULL)
{
/* Set up for a copy to the temporary file: */
io_copy.input = read_ptr;
io_copy.output = write_ptr;
png_set_read_fn(png_ptr, &io_copy, read_and_copy);
}
png_read_info(png_ptr, info_ptr);
{
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
row = malloc(rowbytes);
display = malloc(rowbytes);
row = voidcast(png_bytep,malloc(rowbytes));
display = voidcast(png_bytep,malloc(rowbytes));
if (row == NULL || display == NULL)
png_error(png_ptr, "OOM allocating row buffers");
@ -81,7 +120,8 @@ static int read_png(FILE *fp)
png_uint_32 y = height;
/* NOTE: this trashes the row each time; interlace handling won't
* work, but this avoids memory thrashing for speed testing.
* work, but this avoids memory thrashing for speed testing and is
* somewhat representative of an application that works row-by-row.
*/
while (y-- > 0)
png_read_row(png_ptr, row, display);
@ -91,9 +131,51 @@ static int read_png(FILE *fp)
/* Make sure to read to the end of the file: */
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
/* Free this up: */
free(row);
free(display);
}
static PNG_CALLBACK(void, no_warnings, (png_structp png_ptr,
png_const_charp warning))
{
(void)png_ptr;
(void)warning;
}
static int read_png(FILE *fp, png_int_32 transforms, FILE *write_file)
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,
no_warnings);
png_infop info_ptr = NULL;
if (png_ptr == NULL)
return 0;
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 0;
}
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
png_set_benign_errors(png_ptr, 1/*allowed*/);
# endif
png_init_io(png_ptr, fp);
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
png_error(png_ptr, "OOM allocating info structure");
if (transforms < 0)
read_by_row(png_ptr, info_ptr, write_file, fp);
else
png_read_png(png_ptr, info_ptr, transforms, NULL/*params*/);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return 1;
}
@ -108,7 +190,7 @@ static int mytime(struct timespec *t)
return 0;
}
static int perform_one_test(FILE *fp, int nfiles)
static int perform_one_test(FILE *fp, int nfiles, png_int_32 transforms)
{
int i;
struct timespec before, after;
@ -120,7 +202,7 @@ static int perform_one_test(FILE *fp, int nfiles)
{
for (i=0; i<nfiles; ++i)
{
if (read_png(fp))
if (read_png(fp, transforms, NULL/*write*/))
{
if (ferror(fp))
{
@ -184,120 +266,343 @@ static int add_one_file(FILE *fp, char *name)
if (ip != NULL)
{
int ch;
for (;;)
/* Read the file using libpng; this detects errors and also deals with
* files which contain data beyond the end of the file.
*/
int ok = 0;
fpos_t pos;
if (fgetpos(fp, &pos))
{
ch = getc(ip);
if (ch == EOF) break;
putc(ch, fp);
/* Fatal error reading the start: */
perror("temporary file");
fprintf(stderr, "temporary file fgetpos error\n");
exit(1);
}
if (ferror(ip))
if (read_png(ip, -1/*by row*/, fp/*output*/))
{
perror(name);
fprintf(stderr, "%s: read error\n", name);
return 0;
if (ferror(ip))
{
perror(name);
fprintf(stderr, "%s: read error\n", name);
}
else
ok = 1; /* read ok */
}
else
fprintf(stderr, "%s: file not added\n", name);
(void)fclose(ip);
/* An error in the output is fatal; exit immediately: */
if (ferror(fp))
{
perror("temporary file");
fprintf(stderr, "temporary file write error\n");
return 0;
exit(1);
}
if (ok)
return 1;
/* Did not read the file successfully, simply rewind the temporary
* file. This must happen after the ferror check above to avoid clearing
* the error.
*/
if (fsetpos(fp, &pos))
{
perror("temporary file");
fprintf(stderr, "temporary file fsetpos error\n");
exit(1);
}
}
else
{
/* file open error: */
perror(name);
fprintf(stderr, "%s: open failed\n", name);
return 0;
}
return 1;
return 0; /* file not added */
}
static void
usage(FILE *fp)
{
if (fp != NULL) fclose(fp);
fprintf(stderr,
"Usage:\n"
" timepng --assemble <assembly> {files}\n"
" Read the files into <assembly>, output the count. Options are ignored.\n"
" timepng --dissemble <assembly> <count> [options]\n"
" Time <count> files from <assembly>, additional files may not be given.\n"
" Otherwise:\n"
" Read the files into a temporary file and time the decode\n"
"Transforms:\n"
" --by-image: read by image with png_read_png\n"
" --<transform>: implies by-image, use PNG_TRANSFORM_<transform>\n"
" Otherwise: read by row using png_read_row (to a single row buffer)\n"
/* ISO C90 string length max 509 */);fprintf(stderr,
"{files}:\n"
" PNG files to copy into the assembly and time. Invalid files are skipped\n"
" with appropriate error messages. If no files are given the list of files\n"
" is read from stdin with each file name terminated by a newline\n"
"Output:\n"
" For --assemble the output is the name of the assembly file followed by the\n"
" count of the files it contains; the arguments for --dissemble. Otherwise\n"
" the output is the total decode time in seconds.\n");
exit(99);
}
int main(int argc, char **argv)
{
int ok = 0;
FILE *fp = tmpfile();
int err = 0;
int nfiles = 0;
int transforms = -1; /* by row */
const char *assembly = NULL;
FILE *fp;
if (fp != NULL)
if (argc > 2 && strcmp(argv[1], "--assemble") == 0)
{
int err = 0;
int nfiles = 0;
if (argc > 1)
/* Just build the test file, argv[2] is the file name. */
assembly = argv[2];
fp = fopen(assembly, "wb");
if (fp == NULL)
{
int i;
perror(assembly);
fprintf(stderr, "timepng --assemble %s: could not open for write\n",
assembly);
usage(NULL);
}
for (i=1; i<argc; ++i)
argv += 2;
argc -= 2;
}
else if (argc > 3 && strcmp(argv[1], "--dissemble") == 0)
{
fp = fopen(argv[2], "rb");
if (fp == NULL)
{
perror(argv[2]);
fprintf(stderr, "timepng --dissemble %s: could not open for read\n",
argv[2]);
usage(NULL);
}
nfiles = atoi(argv[3]);
if (nfiles <= 0)
{
fprintf(stderr,
"timepng --dissemble <file> <count>: %s is not a count\n",
argv[3]);
exit(99);
}
#ifdef __COVERITY__
else
{
nfiles &= PNG_UINT_31_MAX;
}
#endif
argv += 3;
argc -= 3;
}
else /* Else use a temporary file */
{
#ifndef __COVERITY__
fp = tmpfile();
#else
/* Experimental. Coverity says tmpfile() is insecure because it
* generates predictable names.
*
* It is possible to satisfy Coverity by using mkstemp(); however,
* any platform supporting mkstemp() undoubtedly has a secure tmpfile()
* implementation as well, and doesn't need the fix. Note that
* the fix won't work on platforms that don't support mkstemp().
*
* https://www.securecoding.cert.org/confluence/display/c/
* FIO21-C.+Do+not+create+temporary+files+in+shared+directories
* says that most historic implementations of tmpfile() provide
* only a limited number of possible temporary file names
* (usually 26) before file names are recycled. That article also
* provides a secure solution that unfortunately depends upon mkstemp().
*/
char tmpfile[] = "timepng-XXXXXX";
int filedes;
umask(0177);
filedes = mkstemp(tmpfile);
if (filedes < 0)
fp = NULL;
else
{
fp = fdopen(filedes,"w+");
/* Hide the filename immediately and ensure that the file does
* not exist after the program ends
*/
(void) unlink(tmpfile);
}
#endif
if (fp == NULL)
{
perror("tmpfile");
fprintf(stderr, "timepng: could not open the temporary file\n");
exit(1); /* not a user error */
}
}
/* Handle the transforms: */
while (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-')
{
const char *opt = *++argv + 2;
--argc;
/* Transforms turn on the by-image processing and maybe set some
* transforms:
*/
if (transforms == -1)
transforms = PNG_TRANSFORM_IDENTITY;
if (strcmp(opt, "by-image") == 0)
{
/* handled above */
}
# define OPT(name) else if (strcmp(opt, #name) == 0)\
transforms |= PNG_TRANSFORM_ ## name
OPT(STRIP_16);
OPT(STRIP_ALPHA);
OPT(PACKING);
OPT(PACKSWAP);
OPT(EXPAND);
OPT(INVERT_MONO);
OPT(SHIFT);
OPT(BGR);
OPT(SWAP_ALPHA);
OPT(SWAP_ENDIAN);
OPT(INVERT_ALPHA);
OPT(STRIP_FILLER);
OPT(STRIP_FILLER_BEFORE);
OPT(STRIP_FILLER_AFTER);
OPT(GRAY_TO_RGB);
OPT(EXPAND_16);
OPT(SCALE_16);
else
{
fprintf(stderr, "timepng %s: unrecognized transform\n", opt);
usage(fp);
}
}
/* Handle the files: */
if (argc > 1 && nfiles > 0)
usage(fp); /* Additional files not valid with --dissemble */
else if (argc > 1)
{
int i;
for (i=1; i<argc; ++i)
{
if (nfiles == INT_MAX)
{
if (add_one_file(fp, argv[i]))
fprintf(stderr, "%s: skipped, too many files\n", argv[i]);
break;
}
else if (add_one_file(fp, argv[i]))
++nfiles;
}
}
else if (nfiles == 0) /* Read from stdin withoout --dissemble */
{
char filename[FILENAME_MAX+1];
while (fgets(filename, FILENAME_MAX+1, stdin))
{
size_t len = strlen(filename);
if (filename[len-1] == '\n')
{
filename[len-1] = 0;
if (nfiles == INT_MAX)
{
fprintf(stderr, "%s: skipped, too many files\n", filename);
break;
}
else if (add_one_file(fp, filename))
++nfiles;
}
else
{
fprintf(stderr, "timepng: file name too long: ...%s\n",
filename+len-32);
err = 1;
break;
}
}
if (ferror(stdin))
{
fprintf(stderr, "timepng: stdin: read error\n");
err = 1;
}
}
/* Perform the test, or produce the --assemble output: */
if (!err)
{
if (nfiles > 0)
{
if (assembly != NULL)
{
if (fflush(fp) && !ferror(fp) && fclose(fp))
{
perror(assembly);
fprintf(stderr, "%s: close failed\n", assembly);
}
else
{
err = 1;
break;
printf("%s %d\n", assembly, nfiles);
fflush(stdout);
ok = !ferror(stdout);
}
}
else
{
ok = perform_one_test(fp, nfiles, transforms);
(void)fclose(fp);
}
}
else
{
char filename[FILENAME_MAX+1];
while (fgets(filename, FILENAME_MAX+1, stdin))
{
size_t len = strlen(filename);
if (filename[len-1] == '\n')
{
filename[len-1] = 0;
if (add_one_file(fp, filename))
++nfiles;
else
{
err = 1;
break;
}
}
else
{
fprintf(stderr, "timepng: truncated file name ...%s\n",
filename+len-32);
err = 1;
break;
}
}
if (ferror(stdin))
{
fprintf(stderr, "timepng: stdin: read error\n");
err = 1;
}
}
if (!err)
{
if (nfiles > 0)
ok = perform_one_test(fp, nfiles);
else
fprintf(stderr, "usage: timepng {files} or ls files | timepng\n");
}
(void)fclose(fp);
usage(fp);
}
else
fprintf(stderr, "timepng: could not open temporary file\n");
(void)fclose(fp);
/* Exit code 0 on success. */
return ok == 0;
}
#else /* !sufficient support */
int main(void) { return 77; }
#endif /* !sufficient support */

View File

@ -0,0 +1,83 @@
OPERATING SYSTEM SPECIFIC MIPS MSA DETECTION
--------------------------------------------
Detection of the ability to execute MIPS MSA on an MIPS processor requires
operating system support. (The information is not available in user mode.)
HOW TO USE THIS
---------------
This directory contains C code fragments that can be included in mips/mips_init.c
by setting the macro PNG_MIPS_MSA_FILE to the file name in "" or <> at build
time. This setting is not recorded in pnglibconf.h and can be changed simply by
rebuilding mips/msa_init.o with the required macro definition.
For any of this code to be used the MIPS MSA code must be enabled and run time
checks must be supported. I.e.:
#if PNG_MIPS_MSA_OPT > 0
#ifdef PNG_MIPS_MSA_CHECK_SUPPORTED
This is done in a 'configure' build by passing configure the argument:
--enable-mips-msa=check
Apart from the basic Linux implementation in contrib/mips-msa/linux.c this code
is unsupported. That means that it is not even compiled on a regular basis and
may be broken in any given minor release.
FILE FORMAT
-----------
Each file documents its testing status as of the last time it was tested (which
may have been a long time ago):
STATUS: one of:
SUPPORTED: This indicates that the file is included in the regularly
performed test builds and bugs are fixed when discovered.
COMPILED: This indicates that the code did compile at least once. See the
more detailed description for the extent to which the result was
successful.
TESTED: This means the code was fully compiled into the libpng test programs
and these were run at least once.
BUG REPORTS: an email address to which to send reports of problems
The file is a fragment of C code. It should not define any 'extern' symbols;
everything should be static. It must define the function:
static int png_have_msa(png_structp png_ptr);
That function must return 1 if MIPS MSA instructions are supported, 0 if not.
It must not execute png_error unless it detects a bug. A png_error will prevent
the reading of the PNG and in the future, writing too.
BUG REPORTS
-----------
If you mail a bug report for any file that is not SUPPORTED there may only be
limited response. Consider fixing it and sending a patch to fix the problem -
this is more likely to result in action.
CONTRIBUTIONS
-------------
You may send contributions of new implementations to
png-mng-implement@sourceforge.net. Please write code in strict C90 C where
possible. Obviously OS dependencies are to be expected. If you submit code you
must have the authors permission and it must have a license that is acceptable
to the current maintainer; in particular that license must permit modification
and redistribution.
Please try to make the contribution a single file and give the file a clear and
unambiguous name that identifies the target OS. If multiple files really are
required put them all in a sub-directory.
You must also be prepared to handle bug reports from users of the code, either
by joining the png-mng-implement mailing list or by providing an email for the
"BUG REPORTS" entry or both. Please make sure that the header of the file
contains the STATUS and BUG REPORTS fields as above.
Please list the OS requirements as precisely as possible. Ideally you should
also list the environment in which the code has been tested and certainly list
any environments where you suspect it might not work.

View File

@ -0,0 +1,64 @@
/* contrib/mips-msa/linux.c
*
* Copyright (c) 2016 Glenn Randers-Pehrson
* Written by Mandar Sahastrabuddhe, 2016.
* Last changed in libpng 1.6.25beta03 [August 29, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* SEE contrib/mips-msa/README before reporting bugs
*
* STATUS: SUPPORTED
* BUG REPORTS: png-mng-implement@sourceforge.net
*
* png_have_msa implemented for Linux by reading the widely available
* pseudo-file /proc/cpuinfo.
*
* This code is strict ANSI-C and is probably moderately portable; it does
* however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static int
png_have_msa(png_structp png_ptr)
{
FILE *f = fopen("/proc/cpuinfo", "rb");
char *string = "msa";
char word[10];
if (f != NULL)
{
while(!feof(f))
{
int ch = fgetc(f);
static int i = 0;
while(!(ch <= 32))
{
word[i++] = ch;
ch = fgetc(f);
}
int val = strcmp(string, word);
if (val == 0)
return 1;
i = 0;
memset(word, 0, 10);
}
fclose(f);
}
#ifdef PNG_WARNINGS_SUPPORTED
else
png_warning(png_ptr, "/proc/cpuinfo open failed");
#endif
return 0;
}

View File

@ -0,0 +1,24 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER glennrp@gmail.com
RUN apt-get update && apt-get install -y make autoconf automake libtool zlib1g-dev
RUN git clone --depth 1 https://github.com/glennrp/libpng.git
RUN (cd libpng; git log | head -1)
WORKDIR libpng
COPY build.sh $SRC/

View File

@ -0,0 +1,37 @@
Last changed in libpng 1.6.33 [September 28, 2017]
Copyright (c) 2017 Glenn Randers-Pehrson
This code is released under the libpng license.
For conditions of distribution and use, see the disclaimer
and license in png.h
Files in this directory are used by the oss-fuzz project
(https://github.com/google/oss-fuzz/tree/master/projects/libpng).
for "fuzzing" libpng.
They were licensed by Google Inc, using the BSD-like Chromium license,
which may be found at https://cs.chromium.org/chromium/src/LICENSE, or, if
noted in the source, under the Apache-2.0 license, which may
be found at http://www.apache.org/licenses/LICENSE-2.0 .
If they have been modified, the derivatives are copyright Glenn Randers-Pehrson
and are released under the same licenses as the originals. Several of
the original files (libpng_read_fuzzer.options, png.dict, project.yaml)
had no licensing information; we assumed that these were under the Chromium
license. Any new files are released under the libpng license (see png.h).
The files are
Original
Filename or derived Copyright License
========================= ========== ================ ==========
Dockerfile* derived 2017, Glenn R-P Apache 2.0
build.sh* derived 2017, Glenn R-P Apache 2.0
libpng_read_fuzzer.cc derived 2017, Glenn R-P Chromium
libpng_read_fuzzer.options original 2015, Chrome Devs Chromium
png.dict original 2015, Chrome Devs Chromium
README.txt (this file) original 2017, Glenn R-P libpng
* Dockerfile and build.sh are copies of the files used by oss-fuzz.
png.dict and libpng_read_fuzzer.* are the actual files used by oss-fuzz,
which retrieves them from the libpng repository at Github.
To do: exercise the progressive reader and the png encoder.

View File

@ -0,0 +1,50 @@
#!/bin/bash -eu
# Copyright 2017 Glenn Randers-Pehrson
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Last changed in libpng 1.6.33 [September 28, 2017]
#
# Revisions by Glenn Randers-Pehson, 2017:
# 1. Build only the library, not the tools (changed "make -j$(nproc) all" to
# "make -j$(nproc) libpng16.la").
# 2. Disabled WARNING and WRITE options in pnglibconf.dfa.
################################################################################
# Disable logging via library build configuration control.
cat scripts/pnglibconf.dfa | \
sed -e "s/option STDIO/option STDIO disabled/" \
-e "s/option WARNING /option WARNING disabled/" \
-e "s/option WRITE enables WRITE_INT_FUNCTIONS/option WRITE disabled/" \
> scripts/pnglibconf.dfa.temp
mv scripts/pnglibconf.dfa.temp scripts/pnglibconf.dfa
# build the library.
autoreconf -f -i
./configure
make -j$(nproc) clean
make -j$(nproc) libpng16.la
# build libpng_read_fuzzer.
$CXX $CXXFLAGS -std=c++11 -I. \
$SRC/libpng/contrib/oss-fuzz/libpng_read_fuzzer.cc \
-o $OUT/libpng_read_fuzzer \
-lFuzzingEngine .libs/libpng16.a -lz
# add seed corpus.
find $SRC/libpng -name "*.png" | grep -v crashers | \
xargs zip $OUT/libpng_read_fuzzer_seed_corpus.zip
cp $SRC/libpng/contrib/oss-fuzz/*.dict \
$SRC/libpng/contrib/oss-fuzz/*.options $OUT/

View File

@ -0,0 +1,180 @@
// libpng_read_fuzzer.cc
// Copyright 2017 Glenn Randers-Pehrson
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that may
// be found in the LICENSE file https://cs.chromium.org/chromium/src/LICENSE
// Last changed in libpng 1.6.32 [August 24, 2017]
// The modifications in 2017 by Glenn Randers-Pehrson include
// 1. addition of a PNG_CLEANUP macro,
// 2. setting the option to ignore ADLER32 checksums,
// 3. adding "#include <string.h>" which is needed on some platforms
// to provide memcpy().
// 4. adding read_end_info() and creating an end_info structure.
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <vector>
#define PNG_INTERNAL
#include "png.h"
#define PNG_CLEANUP \
if(png_handler.png_ptr) \
{ \
if (png_handler.row_ptr) \
png_free(png_handler.png_ptr, png_handler.row_ptr); \
if (png_handler.end_info_ptr) \
png_destroy_read_struct(&png_handler.png_ptr, &png_handler.info_ptr,\
&png_handler.end_info_ptr); \
else if (png_handler.info_ptr) \
png_destroy_read_struct(&png_handler.png_ptr, &png_handler.info_ptr,\
nullptr); \
else \
png_destroy_read_struct(&png_handler.png_ptr, nullptr, nullptr); \
png_handler.png_ptr = nullptr; \
png_handler.row_ptr = nullptr; \
png_handler.info_ptr = nullptr; \
png_handler.end_info_ptr = nullptr; \
}
struct BufState {
const uint8_t* data;
size_t bytes_left;
};
struct PngObjectHandler {
png_infop info_ptr = nullptr;
png_structp png_ptr = nullptr;
png_infop end_info_ptr = nullptr;
png_voidp row_ptr = nullptr;
BufState* buf_state = nullptr;
~PngObjectHandler() {
if (row_ptr)
png_free(png_ptr, row_ptr);
if (end_info_ptr)
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr);
else if (info_ptr)
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
else
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
delete buf_state;
}
};
void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
BufState* buf_state = static_cast<BufState*>(png_get_io_ptr(png_ptr));
if (length > buf_state->bytes_left) {
png_error(png_ptr, "read error");
}
memcpy(data, buf_state->data, length);
buf_state->bytes_left -= length;
buf_state->data += length;
}
static const int kPngHeaderSize = 8;
// Entry point for LibFuzzer.
// Roughly follows the libpng book example:
// http://www.libpng.org/pub/png/book/chapter13.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < kPngHeaderSize) {
return 0;
}
std::vector<unsigned char> v(data, data + size);
if (png_sig_cmp(v.data(), 0, kPngHeaderSize)) {
// not a PNG.
return 0;
}
PngObjectHandler png_handler;
png_handler.png_ptr = nullptr;
png_handler.row_ptr = nullptr;
png_handler.info_ptr = nullptr;
png_handler.end_info_ptr = nullptr;
png_handler.png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (!png_handler.png_ptr) {
return 0;
}
png_handler.info_ptr = png_create_info_struct(png_handler.png_ptr);
if (!png_handler.info_ptr) {
PNG_CLEANUP
return 0;
}
png_handler.end_info_ptr = png_create_info_struct(png_handler.png_ptr);
if (!png_handler.end_info_ptr) {
PNG_CLEANUP
return 0;
}
png_set_crc_action(png_handler.png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
#ifdef PNG_IGNORE_ADLER32
png_set_option(png_handler.png_ptr, PNG_IGNORE_ADLER32, PNG_OPTION_ON);
#endif
// Setting up reading from buffer.
png_handler.buf_state = new BufState();
png_handler.buf_state->data = data + kPngHeaderSize;
png_handler.buf_state->bytes_left = size - kPngHeaderSize;
png_set_read_fn(png_handler.png_ptr, png_handler.buf_state, user_read_data);
png_set_sig_bytes(png_handler.png_ptr, kPngHeaderSize);
if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
PNG_CLEANUP
return 0;
}
// Reading.
png_read_info(png_handler.png_ptr, png_handler.info_ptr);
png_handler.row_ptr = png_malloc(
png_handler.png_ptr, png_get_rowbytes(png_handler.png_ptr,
png_handler.info_ptr));
// reset error handler to put png_deleter into scope.
if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
PNG_CLEANUP
return 0;
}
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, compression_type;
int filter_type;
if (!png_get_IHDR(png_handler.png_ptr, png_handler.info_ptr, &width,
&height, &bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type)) {
PNG_CLEANUP
return 0;
}
// This is going to be too slow.
if (width && height > 100000000 / width) {
PNG_CLEANUP
return 0;
}
int passes = png_set_interlace_handling(png_handler.png_ptr);
png_start_read_image(png_handler.png_ptr);
for (int pass = 0; pass < passes; ++pass) {
for (png_uint_32 y = 0; y < height; ++y) {
png_read_row(png_handler.png_ptr,
static_cast<png_bytep>(png_handler.row_ptr), nullptr);
}
}
png_read_end(png_handler.png_ptr, png_handler.end_info_ptr);
PNG_CLEANUP
return 0;
}

View File

@ -0,0 +1,2 @@
[libfuzzer]
dict = png.dict

View File

@ -0,0 +1,190 @@
// libpng_read_fuzzer.cc
// Copyright 2017 Glenn Randers-Pehrson
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that may
// be found in the LICENSE file https://cs.chromium.org/chromium/src/LICENSE
// Last changed in libpng 1.6.33beta03 [September 27, 2017]
// The modifications in 2017 by Glenn Randers-Pehrson include
// 1. addition of a PNG_CLEANUP macro,
// 2. setting the option to ignore ADLER32 checksums,
// 3. adding "#include <string.h>" which is needed on some platforms
// to provide memcpy().
// 4. adding read_end_info() and creating an end_info structure.
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <vector>
#define PNG_INTERNAL
#include "png.h"
struct BufState {
const uint8_t* data;
size_t bytes_left;
};
struct PngObjectHandler {
png_infop info_ptr = nullptr;
png_structp png_ptr = nullptr;
png_infop end_info_ptr = nullptr;
png_voidp row_ptr = nullptr;
BufState* buf_state = nullptr;
~PngObjectHandler() {
if (row_ptr)
png_free(png_ptr, row_ptr);
if (end_info_ptr)
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr);
else if (info_ptr)
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
else
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
delete buf_state;
}
};
void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
BufState* buf_state = static_cast<BufState*>(png_get_io_ptr(png_ptr));
if (length > buf_state->bytes_left) {
png_error(png_ptr, "read error");
}
memcpy(data, buf_state->data, length);
buf_state->bytes_left -= length;
buf_state->data += length;
}
static const int kPngHeaderSize = 8;
// Entry point for LibFuzzer.
// Roughly follows the libpng book example:
// http://www.libpng.org/pub/png/book/chapter13.html
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < kPngHeaderSize) {
return 0;
}
std::vector<unsigned char> v(data, data + size);
if (png_sig_cmp(v.data(), 0, kPngHeaderSize)) {
// not a PNG.
return 0;
}
PngObjectHandler png_handler;
png_handler.png_ptr = nullptr;
png_handler.row_ptr = nullptr;
png_handler.info_ptr = nullptr;
png_handler.end_info_ptr = nullptr;
png_handler.png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (!png_handler.png_ptr) {
return 0;
}
#define PNG_CLEANUP \
if(png_handler.png_ptr) \
{ \
if (png_handler.row_ptr) \
png_free(png_handler.png_ptr, png_handler.row_ptr); \
if (png_handler.end_info_ptr) \
png_destroy_read_struct(&png_handler.png_ptr, &png_handler.info_ptr,\
&png_handler.end_info_ptr); \
else if (png_handler.info_ptr) \
png_destroy_read_struct(&png_handler.png_ptr, &png_handler.info_ptr,\
nullptr); \
else \
png_destroy_read_struct(&png_handler.png_ptr, nullptr, nullptr); \
png_handler.png_ptr = nullptr; \
png_handler.row_ptr = nullptr; \
png_handler.info_ptr = nullptr; \
png_handler.end_info_ptr = nullptr; \
}
png_handler.info_ptr = png_create_info_struct(png_handler.png_ptr);
if (!png_handler.info_ptr) {
PNG_CLEANUP
return 0;
}
png_handler.end_info_ptr = png_create_info_struct(png_handler.png_ptr);
if (!png_handler.end_info_ptr) {
PNG_CLEANUP
return 0;
}
/* Treat benign errors as warnings */
png_set_benign_errors(png_handler.png_ptr, 1);
png_set_crc_action(png_handler.png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
#ifdef PNG_IGNORE_ADLER32
png_set_option(png_handler.png_ptr, PNG_IGNORE_ADLER32, PNG_OPTION_ON);
#endif
// Setting up reading from buffer.
png_handler.buf_state = new BufState();
png_handler.buf_state->data = data + kPngHeaderSize;
png_handler.buf_state->bytes_left = size - kPngHeaderSize;
png_set_read_fn(png_handler.png_ptr, png_handler.buf_state, user_read_data);
png_set_sig_bytes(png_handler.png_ptr, kPngHeaderSize);
if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
PNG_CLEANUP
return 0;
}
// Reading.
png_read_info(png_handler.png_ptr, png_handler.info_ptr);
png_read_update_info(png_handler.png_ptr, png_handler.info_ptr);
png_handler.row_ptr = png_malloc(
png_handler.png_ptr, png_get_rowbytes(png_handler.png_ptr,
png_handler.info_ptr));
// reset error handler to put png_deleter into scope.
if (setjmp(png_jmpbuf(png_handler.png_ptr))) {
PNG_CLEANUP
return 0;
}
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, compression_type;
int filter_type;
if (!png_get_IHDR(png_handler.png_ptr, png_handler.info_ptr, &width,
&height, &bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type)) {
PNG_CLEANUP
return 0;
}
// This is going to be too slow.
if (width && height > 100000000 / width) {
PNG_CLEANUP
return 0;
}
int passes = png_set_interlace_handling(png_handler.png_ptr);
png_start_read_image(png_handler.png_ptr);
/* To do: prevent the optimizer from removing this code entirely */
for (int pass = 0; pass < passes; ++pass) {
for (png_uint_32 y = 0; y < height; ++y) {
png_read_row(png_handler.png_ptr,
static_cast<png_bytep>(png_handler.row_ptr), nullptr);
}
}
png_read_end(png_handler.png_ptr, png_handler.end_info_ptr);
PNG_CLEANUP
/* TO do: exercise the progressive reader here */
return 0;
}

View File

@ -0,0 +1,39 @@
#
# AFL dictionary for PNG images
# -----------------------------
#
# Just the basic, standard-originating sections; does not include vendor
# extensions.
#
# Created by Michal Zalewski <lcamtuf@google.com>
#
header_png="\x89PNG\x0d\x0a\x1a\x0a"
section_IDAT="IDAT"
section_IEND="IEND"
section_IHDR="IHDR"
section_PLTE="PLTE"
section_bKGD="bKGD"
section_cHRM="cHRM"
section_eXIf="eXIf"
section_fRAc="fRAc"
section_gAMA="gAMA"
section_gIFg="gIFg"
section_gIFt="gIFt"
section_gIFx="gIFx"
section_hIST="hIST"
section_iCCP="iCCP"
section_iTXt="iTXt"
section_oFFs="oFFs"
section_pCAL="pCAL"
section_pHYs="pHYs"
section_sBIT="sBIT"
section_sCAL="sCAL"
section_sPLT="sPLT"
section_sRGB="sRGB"
section_sTER="sTER"
section_tEXt="tEXt"
section_tIME="tIME"
section_tRNS="tRNS"
section_zTXt="zTXt"

View File

@ -146,7 +146,7 @@ The Turbo bug
The end
-------
Willem van Schaik
mailto:willem@schaik.com
mailto:willem at schaik.com
http://www.schaik.com/png/
-------
Oct 1999

View File

@ -1,8 +1,12 @@
/*
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
* copyright (C) 1999,2017 by Willem van Schaik <willem at schaik.com>
*
* version 1.0 - 1999.10.15 - First version.
* 1.1 - 2017.04.22 - Add buffer-size check (Glenn Randers-Pehrson)
* 1.2 - 2017.08.24 - Fix potential overflow in buffer-size check
* (Glenn Randers-Pehrson)
* 1.3 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
@ -41,6 +45,7 @@
#define PNG_DEBUG 0
#endif
#include "png.h"
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
@ -48,6 +53,14 @@
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
#endif
#ifndef PNGMINUS_UNUSED
/* Unused formal parameter warnings are silenced using the following macro
* which is expected to have no bad effects on performance (optimizing
* compilers will probably remove it entirely).
*/
# define PNGMINUS_UNUSED(param) (void)param
#endif
/* function prototypes */
int main (int argc, char *argv[]);
@ -266,7 +279,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
png_set_expand (png_ptr);
#ifdef NJET
/* downgrade 16-bit images to 8 bit */
/* downgrade 16-bit images to 8-bit */
if (bit_depth == 16)
png_set_strip_16 (png_ptr);
/* transform grayscale images into full-color */
@ -320,14 +333,21 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
if ((row_bytes == 0 || (size_t)height > ((size_t)(-1))/(size_t)row_bytes))
{
/* too big */
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
}
if ((png_pixels = (png_byte *)
malloc (row_bytes * height * sizeof (png_byte))) == NULL) {
malloc ((size_t)row_bytes * (size_t)height * sizeof (png_byte))) == NULL)
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return FALSE;
}
if ((row_pointers = (png_byte **)
malloc (height * sizeof (png_bytep))) == NULL)
malloc ((size_t)height * sizeof (png_bytep))) == NULL)
{
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
free (png_pixels);
@ -408,7 +428,8 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
if (raw)
fputc ((int) *pix_ptr++ , alpha_file);
else
if (bit_depth == 16){
if (bit_depth == 16)
{
dep_16 = (long) *pix_ptr++;
fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
}
@ -432,6 +453,7 @@ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,
if (png_pixels != (unsigned char*) NULL)
free (png_pixels);
PNGMINUS_UNUSED(raw); /* to quiet a Coverity defect */
return TRUE;
} /* end of source */

View File

@ -1,8 +1,13 @@
/*
* pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
* copyright (C) 1999,2015,2017 by Willem van Schaik <willem at schaik.com>
*
* version 1.0 - 1999.10.15 - First version.
* version 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
* version 1.2 - 2017.04.22 - Add buffer-size check
* 1.3 - 2017.08.24 - Fix potential overflow in buffer-size check
* (Glenn Randers-Pehrson)
* 1.4 - 2017.08.28 - Add PNGMINUS_UNUSED (Christian Hesse)
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted,
@ -46,6 +51,15 @@
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
#endif
#ifndef PNGMINUS_UNUSED
/* Unused formal parameter warnings are silenced using the following macro
* which is expected to have no bad effects on performance (optimizing
* compilers will probably remove it entirely).
*/
# define PNGMINUS_UNUSED(param) (void)param
#endif
/* function prototypes */
int main (int argc, char *argv[]);
@ -200,17 +214,17 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
char width_token[16];
char height_token[16];
char maxval_token[16];
volatile int color_type;
volatile int color_type=1;
unsigned long ul_width=0, ul_alpha_width=0;
unsigned long ul_height=0, ul_alpha_height=0;
unsigned long ul_maxval=0;
volatile png_uint_32 width, height;
volatile png_uint_32 alpha_width, alpha_height;
volatile png_uint_32 width=0, height=0;
volatile png_uint_32 alpha_width=0, alpha_height=0;
png_uint_32 maxval;
volatile int bit_depth = 0;
int channels;
int channels=0;
int alpha_depth = 0;
int alpha_present;
int alpha_present=0;
int row, col;
BOOL raw, alpha_raw = FALSE;
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
@ -356,8 +370,10 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
channels = 3;
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
channels = 4;
#if 0
else
channels = 0; /* should not happen */
channels = 0; /* cannot happen */
#endif
alpha_present = (channels - 1) % 2;
@ -367,11 +383,16 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
row_bytes = (width * channels * bit_depth + 7) / 8;
else
#endif
/* row_bytes is the width x number of channels x (bit-depth / 8) */
/* row_bytes is the width x number of channels x (bit-depth / 8) */
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
if ((row_bytes == 0 || (size_t)height > ((size_t)(-1))/(size_t)row_bytes))
{
/* too big */
return FALSE;
}
if ((png_pixels = (png_byte *)
malloc (row_bytes * height * sizeof (png_byte))) == NULL)
malloc ((size_t)row_bytes * (size_t)height * sizeof (png_byte))) == NULL)
return FALSE;
/* read data from PNM file */
@ -380,7 +401,8 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
for (row = 0; row < (int) height; row++)
{
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
if (packed_bitmap) {
if (packed_bitmap)
{
for (i = 0; i < (int) row_bytes; i++)
/* png supports this format natively so no conversion is needed */
*pix_ptr++ = get_data (pnm_file, 8);
@ -429,12 +451,16 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
NULL);
if (!png_ptr)
{
free (png_pixels);
png_pixels = NULL;
return FALSE;
}
info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
free (png_pixels);
png_pixels = NULL;
return FALSE;
}
@ -449,7 +475,9 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
/* setjmp() must be called in every function that calls a PNG-reading libpng function */
if (setjmp (png_jmpbuf(png_ptr)))
{
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
png_destroy_write_struct (&png_ptr, &info_ptr);
free (png_pixels);
png_pixels = NULL;
return FALSE;
}
@ -470,7 +498,9 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
if ((row_pointers = (png_byte **)
malloc (height * sizeof (png_bytep))) == NULL)
{
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
png_destroy_write_struct (&png_ptr, &info_ptr);
free (png_pixels);
png_pixels = NULL;
return FALSE;
}
}
@ -486,13 +516,15 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
png_write_end (png_ptr, info_ptr);
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
png_destroy_write_struct (&png_ptr, &info_ptr);
if (row_pointers != (unsigned char**) NULL)
free (row_pointers);
if (png_pixels != (unsigned char*) NULL)
free (png_pixels);
PNGMINUS_UNUSED(raw); /* Quiet a Coverity defect */
return TRUE;
} /* end of pnm2png */
@ -509,7 +541,8 @@ void get_token(FILE *pnm_file, char *token)
do
{
ret = fgetc(pnm_file);
if (ret == '#') {
if (ret == '#')
{
/* the rest of this line is a comment */
do
{

View File

@ -1,8 +1,8 @@
pngsuite
--------
(c) Willem van Schaik, 1999, 2011, 2012
Two images are by Glenn Randers-Pehrson, 2012
Copyright (c) Willem van Schaik, 1999, 2011, 2012
Two images (ftbbn0g01.png and ftbbn0g02.png) are by Glenn Randers-Pehrson, 2012
Permission to use, copy, modify, and distribute these images for any
purpose and without fee is hereby granted.
@ -101,5 +101,5 @@ Testing basn6a16.png: PASS (1072 zero samples)
libpng passes test
Willem van Schaik
<willem@schaik.com>
<willem at schaik.com>
October 1999

View File

@ -0,0 +1,81 @@
OPERATING SYSTEM SPECIFIC POWERPC DETECTION
--------------------------------------------
Detection of the ability to execute POWERPC on processor requires
operating system support. (The information is not available in user mode.)
Currently only this feature is supported only for linux platform.
HOW TO USE THIS
---------------
This directory contains C code fragments that can be included in powerpc/powerpc_init.c
by setting the macro PNG_POWERPC_VSX_FILE to the file name in "" or <> at build
time. This setting is not recorded in pnglibconf.h and can be changed simply by
rebuilding arm/arm_init.o with the required macro definition.
For any of this code to be used the POWERPC code must be enabled and run time
checks must be supported. I.e.:
#if PNG_POWERPC_VSX_OPT > 0
#ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED
This is done in a 'configure' build by passing configure the argument:
--enable-powerpc-vsx=check
FILE FORMAT
-----------
Each file documents its testing status as of the last time it was tested (which
may have been a long time ago):
STATUS: one of:
SUPPORTED: This indicates that the file is included in the regularly
performed test builds and bugs are fixed when discovered.
COMPILED: This indicates that the code did compile at least once. See the
more detailed description for the extent to which the result was
successful.
TESTED: This means the code was fully compiled into the libpng test programs
and these were run at least once.
BUG REPORTS: an email address to which to send reports of problems
The file is a fragment of C code. It should not define any 'extern' symbols;
everything should be static. It must define the function:
static int png_have_vsx(png_structp png_ptr);
That function must return 1 if ARM NEON instructions are supported, 0 if not.
It must not execute png_error unless it detects a bug. A png_error will prevent
the reading of the PNG and in the future, writing too.
BUG REPORTS
-----------
If you mail a bug report for any file that is not SUPPORTED there may only be
limited response. Consider fixing it and sending a patch to fix the problem -
this is more likely to result in action.
CONTRIBUTIONS
-------------
You may send contributions of new implementations to
png-mng-implement@sourceforge.net. Please write code in strict C90 C where
possible. Obviously OS dependencies are to be expected. If you submit code you
must have the authors permission and it must have a license that is acceptable
to the current maintainer; in particular that license must permit modification
and redistribution.
Please try to make the contribution a single file and give the file a clear and
unambiguous name that identifies the target OS. If multiple files really are
required put them all in a sub-directory.
You must also be prepared to handle bug reports from users of the code, either
by joining the png-mng-implement mailing list or by providing an email for the
"BUG REPORTS" entry or both. Please make sure that the header of the file
contains the STATUS and BUG REPORTS fields as above.
Please list the OS requirements as precisely as possible. Ideally you should
also list the environment in which the code has been tested and certainly list
any environments where you suspect it might not work.

View File

@ -0,0 +1,57 @@
/* contrib/powerpc-vsx/linux.c
*
* Copyright (c) 2017 Glenn Randers-Pehrson
* Written by Vadim Barkov, 2017.
* Last changed in libpng 1.6.29 [March 16, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* STATUS: TESTED
* BUG REPORTS: png-mng-implement@sourceforge.net
*
* png_have_vsx implemented for Linux by reading the widely available
* pseudo-file /proc/cpuinfo.
*
* This code is strict ANSI-C and is probably moderately portable; it does
* however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "png.h"
#ifndef MAXLINE
# define MAXLINE 1024
#endif
static int
png_have_vsx(png_structp png_ptr)
{
FILE *f;
const char *string = "altivec supported";
char input[MAXLINE];
char *token = NULL;
PNG_UNUSED(png_ptr)
f = fopen("/proc/cpuinfo", "r");
if (f != NULL)
{
memset(input,0,MAXLINE);
while(fgets(input,MAXLINE,f) != NULL)
{
token = strstr(input,string);
if(token != NULL)
return 1;
}
}
#ifdef PNG_WARNINGS_SUPPORTED
else
png_warning(png_ptr, "/proc/cpuinfo open failed");
#endif
return 0;
}

View File

@ -0,0 +1,36 @@
/* contrib/powerpc-vsx/linux_aux.c
*
* Copyright (c) 2017 Glenn Randers-Pehrson
* Written by Vadim Barkov, 2017.
* Last changed in libpng 1.6.29 [March 16, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* STATUS: TESTED
* BUG REPORTS: png-mng-implement@sourceforge.net
*
* png_have_vsx implemented for Linux by using the auxiliary vector mechanism.
*
* This code is strict ANSI-C and is probably moderately portable; it does
* however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
*/
#include "sys/auxv.h"
#include "png.h"
static int
png_have_vsx(png_structp png_ptr)
{
const unsigned long auxv = getauxval( AT_HWCAP );
PNG_UNUSED(png_ptr)
if(auxv & (PPC_FEATURE_HAS_ALTIVEC|PPC_FEATURE_HAS_VSX ))
return 1;
else
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Some files were not shown because too many files have changed in this diff Show More