diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-12-23 16:27:24 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-12-23 16:27:24 +0000 |
commit | d1cfc0855275b55794810162e7ce04a1e16d5188 (patch) | |
tree | 2e2626ee0e4738e8d6b6624c2d7fafe506b3dbfb /Build/source/libs/gd/libgd-src/src | |
parent | 932a0f6f62cb2f33be1bade4059504d9c2749f9c (diff) |
libgd 2.2.3
git-svn-id: svn://tug.org/texlive/trunk@42778 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/gd/libgd-src/src')
53 files changed, 3253 insertions, 3827 deletions
diff --git a/Build/source/libs/gd/libgd-src/src/CMakeLists.txt b/Build/source/libs/gd/libgd-src/src/CMakeLists.txt index e27467dba0d..aec06e8cbad 100644 --- a/Build/source/libs/gd/libgd-src/src/CMakeLists.txt +++ b/Build/source/libs/gd/libgd-src/src/CMakeLists.txt @@ -1,44 +1,45 @@ SET (LIBGD_SRC_FILES + bmp.h gd.c - gdfx.c - gdfx.h + gd.h + gd_bmp.c gd_color.c gd_color.h gd_color_map.c gd_color_map.h gd_crop.c - gd_transform.c - gd_security.c - gdpp.cxx - gdpp.h - gd_bmp.c - bmp.h + gd_filename.c gd_filter.c gd_gd.c gd_gd2.c + gd_gif_in.c + gd_gif_out.c + gd_interpolation.c gd_io.c gd_io.h - gd_io_stream.cxx - gd_io_stream.h gd_io_dp.c - gd_interpolation.c - gd_gif_in.c - gd_gif_out.c gd_io_file.c gd_io_ss.c + gd_io_stream.cxx + gd_io_stream.h gd_jpeg.c gd_matrix.c gd_nnquant.c gd_nnquant.h gd_png.c gd_rotate.c - gd_tiff.c + gd_security.c + gd_ss.c gd_tga.c gd_tga.h - gd_ss.c + gd_tiff.c gd_topal.c + gd_transform.c + gd_version.c gd_wbmp.c + gd_webp.c + gd_xbm.c gdcache.c gdcache.h gdfontg.c @@ -52,22 +53,32 @@ SET (LIBGD_SRC_FILES gdfontt.c gdfontt.h gdft.c + gdfx.c + gdfx.h gdhelpers.c gdhelpers.h gdkanji.c + gdpp.cxx + gdpp.h gdtables.c gdxpm.c jisx0208.h wbmp.c - gd.h wbmp.h - gd_webp.c - webpimg.c - gd_xbm.c - gd_version.c ) -add_library(${GD_LIB} ${LIBGD_SRC_FILES}) +if(MSVC AND MSVC_VERSION LESS 1900) + set(LIBGD_SRC_FILES ${LIBGD_SRC_FILES} + snprintf.c + ) +endif(MSVC AND MSVC_VERSION LESS 1900) + +include(GNUInstallDirs) + +if (BUILD_SHARED_LIBS) + add_library(${GD_LIB} ${LIBGD_SRC_FILES}) +endif() + add_library(${GD_LIB_STATIC} STATIC ${LIBGD_SRC_FILES}) if (WIN32 AND NOT MINGW AND NOT MSYS) @@ -86,18 +97,61 @@ endif (MINGW OR MSYS) INCLUDE_DIRECTORIES(BEFORE "${PROJECT_BINARY_DIR}" "${CMAKE_BINARY_DIR}" "${GD_SOURCE_DIR}/src") -target_link_libraries(${GD_LIB} ${ZLIB_LIBRARIES} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${ICONV_LIBRARIES} ${LIQ_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY} ${VPX_LIBRARIES}) -target_link_libraries(${GD_LIB_STATIC} ${ZLIB_LIBRARIES} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${ICONV_LIBRARIES} ${LIQ_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY} ${VPX_LIBRARIES} ) +if (BUILD_SHARED_LIBS) + target_link_libraries(${GD_LIB} ${ZLIB_LIBRARIES} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${ICONV_LIBRARIES} ${LIQ_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY} ${WEBP_LIBRARIES}) +endif() + +target_link_libraries(${GD_LIB_STATIC} ${ZLIB_LIBRARIES} ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} ${ICONV_LIBRARIES} ${LIQ_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARIES} ${XPM_LIBRARIES} ${FONTCONFIG_LIBRARY} ${WEBP_LIBRARIES} ) + +set(GD_PROGRAMS gdcmpgif) + +if (PNG_FOUND) + set(GD_PROGRAMS ${GD_PROGRAMS} gdtopng pngtogd webpng) + if (ZLIB_FOUND) + set(GD_PROGRAMS ${GD_PROGRAMS} gdparttopng gd2topng pngtogd2) + endif() +endif() + +if (FREETYPE_FOUND) + set(GD_PROGRAMS ${GD_PROGRAMS} annotate) +endif() + +if (ZLIB_FOUND) + set(GD_PROGRAMS ${GD_PROGRAMS} gd2copypal gd2togif giftogd2) +endif() -set(GD_PROGRAMS annotate gdparttopng gdtopng gd2copypal gd2topng pngtogd pngtogd2 webpng gd2togif gdcmpgif giftogd2) foreach(program ${GD_PROGRAMS}) add_executable(${program} ${program}.c) - target_link_libraries(${program} ${GD_LIB}) + if (BUILD_SHARED_LIBS) + target_link_libraries(${program} ${GD_LIB}) + else() + target_link_libraries(${program} ${GD_LIB_STATIC}) + endif() endforeach(program) -install(TARGETS ${GD_LIB} ${GD_LIB_STATIC} ${GD_PROGRAMS} +if (BUILD_SHARED_LIBS) + set(GD_INSTALL_TARGETS ${GD_LIB} ${GD_LIB_STATIC} ${GD_PROGRAMS}) +else() + set(GD_INSTALL_TARGETS ${GD_LIB_STATIC} ${GD_PROGRAMS}) +endif() + +install(TARGETS ${GD_INSTALL_TARGETS} RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(PROGRAMS bdftogd DESTINATION bin) -install(FILES gd.h gdfx.h gd_io.h gdcache.h gdfontg.h gdfontl.h gdfontmb.h gdfonts.h gdfontt.h gd_color_map.h gd_errors.h DESTINATION include) +install(FILES + entities.h + gd.h + gd_color_map.h + gd_errors.h + gd_io.h + gdcache.h + gdfontg.h + gdfontl.h + gdfontmb.h + gdfonts.h + gdfontt.h + gdfx.h + gdpp.h + DESTINATION include) diff --git a/Build/source/libs/gd/libgd-src/src/Makefile.am b/Build/source/libs/gd/libgd-src/src/Makefile.am index 7dc4151134f..92772b79642 100644 --- a/Build/source/libs/gd/libgd-src/src/Makefile.am +++ b/Build/source/libs/gd/libgd-src/src/Makefile.am @@ -1,58 +1,107 @@ -## Process this file with automake to produce Makefile.in -*-Makefile-*-
-
-bin_PROGRAMS = gdcmpgif
-check_PROGRAMS = gifanimtest gd_color_map_test
-
-if HAVE_LIBPNG
-bin_PROGRAMS += gdtopng pngtogd webpng
-check_PROGRAMS += circletexttest fontsizetest fontwheeltest gddemo testac
-if HAVE_LIBZ
-bin_PROGRAMS += gdparttopng gd2topng pngtogd2
-check_PROGRAMS += gdtest
-endif
-endif
-
-if HAVE_LIBJPEG
-if !HAVE_LIBPNG
-check_PROGRAMS += fontsizetest fontwheeltest
-endif
-endif
-
-if HAVE_LIBFONTCONFIG
-check_PROGRAMS += fontconfigtest
-endif
-
-if HAVE_LIBFREETYPE
-bin_PROGRAMS += annotate
-check_PROGRAMS += gdtestft testtr
-endif
-
-if HAVE_LIBZ
-bin_PROGRAMS += gd2copypal gd2togif giftogd2
-endif
-
-bin_SCRIPTS = bdftogd
-
-if HAVE_LIBZ
-check_PROGRAMS += gd2time
-endif
-
-EXTRA_DIST = bdftogd demoin.png entities.html entities.tcl CMakeLists.txt config.h.cmake gd_io_stream.cxx gdpp.cxx msinttypes/inttypes.h msinttypes/stdint.h
-
-include_HEADERS = gd.h gdfx.h gd_io.h gdcache.h gdfontg.h gdfontl.h gdfontmb.h gdfonts.h gdfontt.h entities.h gd_color_map.h gd_errors.h gdpp.h
-
-lib_LTLIBRARIES = libgd.la
-
-libgd_la_SOURCES = gd.c gd_color.c gd_color_map.c gd_transform.c gdfx.c gd_security.c gd_gd.c gd_gd2.c gd_io.c gd_io_dp.c gd_gif_in.c \
- gd_gif_out.c gd_io_file.c gd_io_ss.c gd_jpeg.c gd_png.c gd_ss.c gd_topal.c gd_wbmp.c gdcache.c gdfontg.c gdfontl.c \
- gdfontmb.c gdfonts.c gdfontt.c gdft.c gdhelpers.c gdhelpers.h gdkanji.c gdtables.c gdxpm.c jisx0208.h wbmp.c wbmp.h \
- gd_filter.c gd_nnquant.c gd_rotate.c gd_matrix.c gd_interpolation.c gd_crop.c webpimg.c webpimg.h gd_webp.c gd_tiff.c \
- gd_tga.c gd_tga.h gd_bmp.c bmp.h gd_color.h gd_nnquant.h gd_tga.h gd_intern.h gd_io_stream.h gd_xbm.c \
- gd_color_match.c gd_version.c gd_filename.c
-
-libgd_la_LDFLAGS = -version-info $(GDLIB_CURRENT):$(GDLIB_REVISION):$(GDLIB_AGE) -no-undefined
-
-libgd_la_LIBADD = $(LTLIBICONV)
-
-LDADD = libgd.la $(LIBICONV)
-
+## Process this file with automake to produce Makefile.in -*-Makefile-*- + +bin_PROGRAMS = gdcmpgif +check_PROGRAMS = gifanimtest gd_color_map_test + +if HAVE_LIBPNG +bin_PROGRAMS += gdtopng pngtogd webpng +check_PROGRAMS += circletexttest fontsizetest fontwheeltest gddemo testac +if HAVE_LIBZ +bin_PROGRAMS += gdparttopng gd2topng pngtogd2 +check_PROGRAMS += gdtest +endif +endif + +if HAVE_LIBJPEG +if !HAVE_LIBPNG +check_PROGRAMS += fontsizetest fontwheeltest +endif +endif + +if HAVE_LIBFONTCONFIG +check_PROGRAMS += fontconfigtest +endif + +if HAVE_LIBFREETYPE +bin_PROGRAMS += annotate +check_PROGRAMS += gdtestft testtr +endif + +if HAVE_LIBZ +bin_PROGRAMS += gd2copypal gd2togif giftogd2 +endif + +bin_SCRIPTS = bdftogd + +if HAVE_LIBZ +check_PROGRAMS += gd2time +endif + +EXTRA_DIST = bdftogd demoin.png entities.html entities.tcl CMakeLists.txt config.h.cmake gd_io_stream.cxx gdpp.cxx msinttypes/inttypes.h msinttypes/stdint.h + +include_HEADERS = gd.h gdfx.h gd_io.h gdcache.h gdfontg.h gdfontl.h gdfontmb.h gdfonts.h gdfontt.h entities.h gd_color_map.h gd_errors.h gdpp.h + +lib_LTLIBRARIES = libgd.la + +libgd_la_SOURCES = \ + bmp.h \ + gd.c \ + gd_bmp.c \ + gd_color.c \ + gd_color.h \ + gd_color_map.c \ + gd_color_match.c \ + gd_crop.c \ + gd_filename.c \ + gd_filter.c \ + gd_gd.c \ + gd_gd2.c \ + gd_gif_in.c \ + gd_gif_out.c \ + gd_intern.h \ + gd_interpolation.c \ + gd_io.c \ + gd_io_dp.c \ + gd_io_file.c \ + gd_io_ss.c \ + gd_io_stream.h \ + gd_jpeg.c \ + gd_matrix.c \ + gd_nnquant.c \ + gd_nnquant.h \ + gd_png.c \ + gd_rotate.c \ + gd_security.c \ + gd_ss.c \ + gd_tga.c \ + gd_tga.h \ + gd_tiff.c \ + gd_topal.c \ + gd_transform.c \ + gd_version.c \ + gd_wbmp.c \ + gd_webp.c \ + gd_xbm.c \ + gdcache.c \ + gdfontg.c \ + gdfontl.c \ + gdfontmb.c \ + gdfonts.c \ + gdfontt.c \ + gdft.c \ + gdfx.c \ + gdhelpers.c \ + gdhelpers.h \ + gdkanji.c \ + gdtables.c \ + gdxpm.c \ + jisx0208.h \ + wbmp.c \ + wbmp.h + +libgd_la_LDFLAGS = -version-info $(GDLIB_LT_CURRENT):$(GDLIB_LT_REVISION):$(GDLIB_LT_AGE) -no-undefined + +libgd_la_LIBADD = $(LTLIBICONV) + +LDADD = libgd.la $(LIBICONV) + diff --git a/Build/source/libs/gd/libgd-src/src/annotate.c b/Build/source/libs/gd/libgd-src/src/annotate.c index c66e3311306..00aaf496bbd 100644 --- a/Build/source/libs/gd/libgd-src/src/annotate.c +++ b/Build/source/libs/gd/libgd-src/src/annotate.c @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Standard input should consist of\n"); fprintf(stderr, "lines in the following formats:\n"); fprintf(stderr, "color r g b (0-255 each) [a (0-127, 0 is opaque)]\n"); - fprintf(stderr, "font fontname\n"); + fprintf(stderr, "font fontname (max name length 1024)\n"); fprintf(stderr, "size pointsize\n"); fprintf(stderr, "align (left|right|center)\n"); fprintf(stderr, "move x y\n"); @@ -98,9 +98,14 @@ int main(int argc, char *argv[]) char *st = strtok(0, " \t\r\n"); if(!st) { goto badLine; + } else { + const unsigned int font_len = strlen(st); + if (font_len >= 1024) { + fprintf(stderr, "Font maximum length is 1024, %d given\n", font_len); + goto badLine; + } + strncpy(font, st, font_len); } - - strcpy(font, st); } else if(!strcmp(st, "align")) { char *st = strtok(0, " \t\r\n"); diff --git a/Build/source/libs/gd/libgd-src/src/circletexttest.c b/Build/source/libs/gd/libgd-src/src/circletexttest.c index 55e0970c1a3..c1e67ab742f 100644 --- a/Build/source/libs/gd/libgd-src/src/circletexttest.c +++ b/Build/source/libs/gd/libgd-src/src/circletexttest.c @@ -33,6 +33,10 @@ int main(void) #else im = gdImageCreateTrueColor(300, 300); #endif /* HAVE_LIBJPEG */ + if(!im) { + fprintf(stderr, "gdImageCreateTrueColor failed \n"); + return 1; + } if(gdImageSX(im) < gdImageSY(im)) { radius = gdImageSX(im) / 2; } else { diff --git a/Build/source/libs/gd/libgd-src/src/config.h.cmake b/Build/source/libs/gd/libgd-src/src/config.h.cmake index a8e6f00b64d..acc22be281a 100644 --- a/Build/source/libs/gd/libgd-src/src/config.h.cmake +++ b/Build/source/libs/gd/libgd-src/src/config.h.cmake @@ -1,4 +1,10 @@ -/* config.hin. Generated from config.h.cmake by cmake */ +/* Generated from config.hin via autoheader for cmake; see bootstraps.h. */ + +/* Define is you are building for Win32 API */ +#cmakedefine BGDWIN32 + +/* Define to 1 if you have the <dirent.h> header file. */ +#cmakedefine HAVE_DIRENT_H /* Define to 1 if you have the <dlfcn.h> header file. */ #cmakedefine HAVE_DLFCN_H @@ -6,10 +12,10 @@ /* Define to 1 if you have the <errno.h> header file. */ #cmakedefine HAVE_ERRNO_H -/* Define to 1 if you have the <ft2build.h> header file. */ +/* Define if you have the ft2build.h header. */ #cmakedefine HAVE_FT2BUILD_H -/* Define if you have the iconv() function. */ +/* Define if you have the iconv() function and it works. */ #cmakedefine HAVE_ICONV /* Define to 1 if you have the <iconv.h> header file. */ @@ -21,34 +27,34 @@ /* Define to 1 if you have the <inttypes.h> header file. */ #cmakedefine HAVE_INTTYPES_H -/* Define if you have the fontconfig library. */ +/* Define if you have fontconfig */ #cmakedefine HAVE_LIBFONTCONFIG -/* Define if you have the freetype library. */ +/* Define if you have freetype */ #cmakedefine HAVE_LIBFREETYPE -/* Define if you have the jpeg library. */ -#cmakedefine HAVE_LIBJPEG +/* Define if you have liq */ +#cmakedefine HAVE_LIBIMAGEQUANT -/* Define if you have the jpeg library. */ -#cmakedefine HAVE_LIBTIFF +/* Define if you have jpeg */ +#cmakedefine HAVE_LIBJPEG /* Define to 1 if you have the `m' library (-lm). */ #cmakedefine HAVE_LIBM -/* Define if you have the png library. */ +/* Define if you have png */ #cmakedefine HAVE_LIBPNG -/* Define if you have the VPX library. */ -#cmakedefine HAVE_LIBVPX +/* Define if you have tiff */ +#cmakedefine HAVE_LIBTIFF -/* Define to 1 if you have the <libimagequant.h> header file. */ -#cmakedefine HAVE_LIBIMAGEQUANT_H +/* Define if you have webp */ +#cmakedefine HAVE_LIBWEBP -/* Define if you have the Xpm library. */ +/* Define if you have xpm */ #cmakedefine HAVE_LIBXPM -/* Define if you have zlib. */ +/* Define if you have zlib */ #cmakedefine HAVE_LIBZ /* Define to 1 if you have the <limits.h> header file. */ @@ -57,12 +63,15 @@ /* Define to 1 if you have the <memory.h> header file. */ #cmakedefine HAVE_MEMORY_H -/* Define to 1 if you have the <png.h> header file. */ -#cmakedefine HAVE_PNG_H +/* Define if OpenMP is enabled */ +#cmakedefine HAVE_OPENMP /* Define if you have POSIX threads libraries and header files. */ #cmakedefine HAVE_PTHREAD +/* Have PTHREAD_PRIO_INHERIT. */ +#cmakedefine HAVE_PTHREAD_PRIO_INHERIT + /* Define to 1 if you have the <stddef.h> header file. */ #cmakedefine HAVE_STDDEF_H @@ -85,13 +94,19 @@ #cmakedefine HAVE_SYS_TYPES_H /* Define to 1 if you have the <unistd.h> header file. */ -#ifndef HAVE_UNISTD_H #cmakedefine HAVE_UNISTD_H -#endif + +/* Define to 1 or 0, depending whether the compiler supports simple visibility + declarations. */ +#cmakedefine HAVE_VISIBILITY /* Define as const if the declaration of iconv() needs const. */ #cmakedefine ICONV_CONST +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#cmakedefine LT_OBJDIR + /* Name of package */ #cmakedefine PACKAGE @@ -107,6 +122,9 @@ /* Define to the one symbol short name of this package. */ #cmakedefine PACKAGE_TARNAME +/* Define to the home page for this package. */ +#cmakedefine PACKAGE_URL + /* Define to the version of this package. */ #cmakedefine PACKAGE_VERSION @@ -117,11 +135,5 @@ /* Define to 1 if you have the ANSI C header files. */ #cmakedefine STDC_HEADERS -/* Define to 1 if you have the stdint.h header file. */ -#cmakedefine HAVE_STDINT_H - -/* Define to 1 if you have the inttypes.h header file. */ -#cmakedefine HAVE_INTTYPES_H - /* Version number of package */ - +#cmakedefine VERSION diff --git a/Build/source/libs/gd/libgd-src/src/config.hin b/Build/source/libs/gd/libgd-src/src/config.hin index 5393c70ef94..5d84fae8c97 100644 --- a/Build/source/libs/gd/libgd-src/src/config.hin +++ b/Build/source/libs/gd/libgd-src/src/config.hin @@ -1,133 +1,139 @@ -/* src/config.hin. Generated from configure.ac by autoheader. */
-
-/* Define is you are building for Win32 API */
-#undef BGDWIN32
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <errno.h> header file. */
-#undef HAVE_ERRNO_H
-
-/* Define if you have the ft2build.h header. */
-#undef HAVE_FT2BUILD_H
-
-/* Define if you have the iconv() function and it works. */
-#undef HAVE_ICONV
-
-/* Define to 1 if you have the <iconv.h> header file. */
-#undef HAVE_ICONV_H
-
-/* Define if <iconv.h> defines iconv_t. */
-#undef HAVE_ICONV_T_DEF
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define if you have the fontconfig library. */
-#undef HAVE_LIBFONTCONFIG
-
-/* Define if you have the freetype library. */
-#undef HAVE_LIBFREETYPE
-
-/* Define if you have the jpeg library. */
-#undef HAVE_LIBJPEG
-
-/* Define to 1 if you have the `m' library (-lm). */
-#undef HAVE_LIBM
-
-/* Define if you have the png library. */
-#undef HAVE_LIBPNG
-
-/* Define if you have the Tiff library. */
-#undef HAVE_LIBTIFF
-
-/* Define if you have the VPX library. */
-#undef HAVE_LIBVPX
-
-/* Define if you have the Xpm library. */
-#undef HAVE_LIBXPM
-
-/* Define if you have zlib. */
-#undef HAVE_LIBZ
-
-/* Define to 1 if you have the <limits.h> header file. */
-#undef HAVE_LIMITS_H
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define if you have POSIX threads libraries and header files. */
-#undef HAVE_PTHREAD
-
-/* Have PTHREAD_PRIO_INHERIT. */
-#undef HAVE_PTHREAD_PRIO_INHERIT
-
-/* Define to 1 if you have the <stddef.h> header file. */
-#undef HAVE_STDDEF_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Define to 1 or 0, depending whether the compiler supports simple visibility
- declarations. */
-#undef HAVE_VISIBILITY
-
-/* Define as const if the declaration of iconv() needs const. */
-#undef ICONV_CONST
-
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
- */
-#undef LT_OBJDIR
-
-/* Define to 1 if your C compiler doesn't accept -c and -o together. */
-#undef NO_MINUS_C_MINUS_O
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Define to necessary symbol if this constant uses a non-standard name on
- your system. */
-#undef PTHREAD_CREATE_JOINABLE
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Version number of package */
-#undef VERSION
+/* src/config.hin. Generated from configure.ac by autoheader. */ + +/* Define is you are building for Win32 API */ +#undef BGDWIN32 + +/* Define to 1 if you have the <dirent.h> header file. */ +#undef HAVE_DIRENT_H + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the <errno.h> header file. */ +#undef HAVE_ERRNO_H + +/* Define if you have the ft2build.h header. */ +#undef HAVE_FT2BUILD_H + +/* Define if you have the iconv() function and it works. */ +#undef HAVE_ICONV + +/* Define to 1 if you have the <iconv.h> header file. */ +#undef HAVE_ICONV_H + +/* Define if <iconv.h> defines iconv_t. */ +#undef HAVE_ICONV_T_DEF + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define if you have fontconfig */ +#undef HAVE_LIBFONTCONFIG + +/* Define if you have freetype */ +#undef HAVE_LIBFREETYPE + +/* Define if you have liq */ +#undef HAVE_LIBIMAGEQUANT + +/* Define if you have jpeg */ +#undef HAVE_LIBJPEG + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define if you have png */ +#undef HAVE_LIBPNG + +/* Define if you have tiff */ +#undef HAVE_LIBTIFF + +/* Define if you have webp */ +#undef HAVE_LIBWEBP + +/* Define if you have xpm */ +#undef HAVE_LIBXPM + +/* Define if you have zlib */ +#undef HAVE_LIBZ + +/* Define to 1 if you have the <limits.h> header file. */ +#undef HAVE_LIMITS_H + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define if OpenMP is enabled */ +#undef HAVE_OPENMP + +/* Define if you have POSIX threads libraries and header files. */ +#undef HAVE_PTHREAD + +/* Have PTHREAD_PRIO_INHERIT. */ +#undef HAVE_PTHREAD_PRIO_INHERIT + +/* Define to 1 if you have the <stddef.h> header file. */ +#undef HAVE_STDDEF_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 or 0, depending whether the compiler supports simple visibility + declarations. */ +#undef HAVE_VISIBILITY + +/* Define as const if the declaration of iconv() needs const. */ +#undef ICONV_CONST + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +#undef PTHREAD_CREATE_JOINABLE + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION diff --git a/Build/source/libs/gd/libgd-src/src/entities.html b/Build/source/libs/gd/libgd-src/src/entities.html index f6da3c63e81..5c5d7b65a32 100644 --- a/Build/source/libs/gd/libgd-src/src/entities.html +++ b/Build/source/libs/gd/libgd-src/src/entities.html @@ -1,682 +1,682 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html lang="en"><head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Character entity references in HTML 4</title>
-
-<link rel="previous" href="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html">
-<link rel="next" href="http://www.w3.org/TR/REC-html40/appendix/changes.html">
-<link rel="contents" href="http://www.w3.org/TR/REC-html40/cover.html#toc">
-<link rel="stylesheet" type="text/css" href="entities.html_files/W3C-REC.css">
-<link rel="STYLESHEET" href="entities.html_files/default.css" type="text/css"></head>
-
-<body>
-<div class="navbar" align="center"> <a href="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html">
-previous</a> <a href="http://www.w3.org/TR/REC-html40/appendix/changes.html">next</a> <a href="http://www.w3.org/TR/REC-html40/cover.html#minitoc">contents</a> <a href="http://www.w3.org/TR/REC-html40/index/elements.html">
-elements</a> <a href="http://www.w3.org/TR/REC-html40/index/attributes.html">attributes</a> <a href="http://www.w3.org/TR/REC-html40/index/list.html">index</a>
-
-<hr></div>
-
-<h1 align="center"><a name="h-24">24</a> <a name="entities">Character entity
-references in HTML 4</a></h1>
-
-<div class="subtoc">
-<p><strong>Contents</strong></p>
-
-<ol>
-<li><a class="tocxref" href="#h-24.1">Introduction to character entity
-references</a></li>
-
-<li><a class="tocxref" href="#h-24.2">Character entity references for ISO
-8859-1 characters</a>
-
-<ol>
-<li><a class="tocxref" href="#h-24.2.1">The list of characters</a></li>
-</ol>
-</li>
-
-<li><a class="tocxref" href="#h-24.3">Character entity references for symbols,
-mathematical symbols, and Greek letters</a>
-
-<ol>
-<li><a class="tocxref" href="#h-24.3.1">The list of characters</a></li>
-</ol>
-</li>
-
-<li><a class="tocxref" href="#h-24.4">Character entity references for
-markup-significant and internationalization characters</a>
-
-<ol>
-<li><a class="tocxref" href="#h-24.4.1">The list of characters</a></li>
-</ol>
-</li>
-</ol>
-</div>
-
-<h2><a name="h-24.1">24.1</a> Introduction to character entity references</h2>
-
-A <a href="http://www.w3.org/TR/REC-html40/charset.html#entities">character entity reference</a> is an SGML
-construct that references a character of the <a href="http://www.w3.org/TR/REC-html40/charset.html">document
-character set.</a>
-
-<p>This version of HTML supports several sets of character entity
-references:</p>
-
-<ul>
-<li><a href="#iso-88591">ISO 8859-1 (Latin-1) characters</a> In accordance with
-section 14 of <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-RFC1866" class="informref">[RFC1866]</a>, the set of Latin-1 entities has been extended by
-this specification to cover the whole right part of ISO-8859-1 (all code
-positions with the high-order bit set), including the already commonly used
-&nbsp;, &copy; and &reg;. The names of the entities are taken from
-the appendices of SGML (defined in <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO8879" class="normref">[ISO8879]</a>).</li>
-
-<li><a href="#sym">symbols, mathematical symbols, and Greek letters</a>. These
-characters may be represented by glyphs in the Adobe font "Symbol".</li>
-
-<li><a href="#misc">markup-significant and internationalization characters</a>
-(e.g., for bidirectional text).</li>
-</ul>
-
-<p>The following sections present the complete lists of character entity
-references. Although, by convention, <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> the comments
-following each entry are usually written with uppercase letters, we have
-converted them to lowercase in this specification for reasons of
-readability.</p>
-
-<h2><a name="h-24.2">24.2</a> <a name="iso-88591">Character entity references
-for ISO 8859-1 characters</a></h2>
-
-<p>The character entity references in this section produce characters whose
-numeric equivalents should already be supported by conforming HTML 2.0 user
-agents. Thus, the character entity reference &divide; is a more convenient
-form than &#247; for obtaining the division sign (÷).</p>
-
-<p>To support these named entities, user agents need only recognize the entity
-names and convert them to characters that lie within the repertoire of <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO88591" class="normref">
-[ISO88591]</a>.</p>
-
-<p>Character 65533 (FFFD hexadecimal) is the last valid character in UCS-2.
-65534 (FFFE hexadecimal) is unassigned and reserved as the byte-swapped version
-of ZERO WIDTH NON-BREAKING SPACE for byte-order detection purposes. 65535 (FFFF
-hexadecimal) is unassigned.</p>
-
-<h3><a name="h-24.2.1">24.2.1</a> The list of characters</h3>
-
-<div class="dtd-fragment">
-<pre><!-- Portions © International Organization for Standardization 1986
- Permission to copy in any form is granted for use with
- conforming SGML systems and applications as defined in
- ISO 8879, provided this notice is included in all copies.
--->
-<!-- Character entity set. Typical invocation:
- <!ENTITY % HTMLlat1 PUBLIC
- "-//W3C//ENTITIES Latin 1//EN//HTML">
- %HTMLlat1;
--->
-
-<!ENTITY nbsp CDATA "&#160;" -- no-break space = non-breaking space,
- U+00A0 ISOnum -->
-<!ENTITY iexcl CDATA "&#161;" -- inverted exclamation mark, U+00A1 ISOnum -->
-<!ENTITY cent CDATA "&#162;" -- cent sign, U+00A2 ISOnum -->
-<!ENTITY pound CDATA "&#163;" -- pound sign, U+00A3 ISOnum -->
-<!ENTITY curren CDATA "&#164;" -- currency sign, U+00A4 ISOnum -->
-<!ENTITY yen CDATA "&#165;" -- yen sign = yuan sign, U+00A5 ISOnum -->
-<!ENTITY brvbar CDATA "&#166;" -- broken bar = broken vertical bar,
- U+00A6 ISOnum -->
-<!ENTITY sect CDATA "&#167;" -- section sign, U+00A7 ISOnum -->
-<!ENTITY uml CDATA "&#168;" -- diaeresis = spacing diaeresis,
- U+00A8 ISOdia -->
-<!ENTITY copy CDATA "&#169;" -- copyright sign, U+00A9 ISOnum -->
-<!ENTITY ordf CDATA "&#170;" -- feminine ordinal indicator, U+00AA ISOnum -->
-<!ENTITY laquo CDATA "&#171;" -- left-pointing double angle quotation mark
- = left pointing guillemet, U+00AB ISOnum -->
-<!ENTITY not CDATA "&#172;" -- not sign, U+00AC ISOnum -->
-<!ENTITY shy CDATA "&#173;" -- soft hyphen = discretionary hyphen,
- U+00AD ISOnum -->
-<!ENTITY reg CDATA "&#174;" -- registered sign = registered trade mark sign,
- U+00AE ISOnum -->
-<!ENTITY macr CDATA "&#175;" -- macron = spacing macron = overline
- = APL overbar, U+00AF ISOdia -->
-<!ENTITY deg CDATA "&#176;" -- degree sign, U+00B0 ISOnum -->
-<!ENTITY plusmn CDATA "&#177;" -- plus-minus sign = plus-or-minus sign,
- U+00B1 ISOnum -->
-<!ENTITY sup2 CDATA "&#178;" -- superscript two = superscript digit two
- = squared, U+00B2 ISOnum -->
-<!ENTITY sup3 CDATA "&#179;" -- superscript three = superscript digit three
- = cubed, U+00B3 ISOnum -->
-<!ENTITY acute CDATA "&#180;" -- acute accent = spacing acute,
- U+00B4 ISOdia -->
-<!ENTITY micro CDATA "&#181;" -- micro sign, U+00B5 ISOnum -->
-<!ENTITY para CDATA "&#182;" -- pilcrow sign = paragraph sign,
- U+00B6 ISOnum -->
-<!ENTITY middot CDATA "&#183;" -- middle dot = Georgian comma
- = Greek middle dot, U+00B7 ISOnum -->
-<!ENTITY cedil CDATA "&#184;" -- cedilla = spacing cedilla, U+00B8 ISOdia -->
-<!ENTITY sup1 CDATA "&#185;" -- superscript one = superscript digit one,
- U+00B9 ISOnum -->
-<!ENTITY ordm CDATA "&#186;" -- masculine ordinal indicator,
- U+00BA ISOnum -->
-<!ENTITY raquo CDATA "&#187;" -- right-pointing double angle quotation mark
- = right pointing guillemet, U+00BB ISOnum -->
-<!ENTITY frac14 CDATA "&#188;" -- vulgar fraction one quarter
- = fraction one quarter, U+00BC ISOnum -->
-<!ENTITY frac12 CDATA "&#189;" -- vulgar fraction one half
- = fraction one half, U+00BD ISOnum -->
-<!ENTITY frac34 CDATA "&#190;" -- vulgar fraction three quarters
- = fraction three quarters, U+00BE ISOnum -->
-<!ENTITY iquest CDATA "&#191;" -- inverted question mark
- = turned question mark, U+00BF ISOnum -->
-<!ENTITY Agrave CDATA "&#192;" -- latin capital letter A with grave
- = latin capital letter A grave,
- U+00C0 ISOlat1 -->
-<!ENTITY Aacute CDATA "&#193;" -- latin capital letter A with acute,
- U+00C1 ISOlat1 -->
-<!ENTITY Acirc CDATA "&#194;" -- latin capital letter A with circumflex,
- U+00C2 ISOlat1 -->
-<!ENTITY Atilde CDATA "&#195;" -- latin capital letter A with tilde,
- U+00C3 ISOlat1 -->
-<!ENTITY Auml CDATA "&#196;" -- latin capital letter A with diaeresis,
- U+00C4 ISOlat1 -->
-<!ENTITY Aring CDATA "&#197;" -- latin capital letter A with ring above
- = latin capital letter A ring,
- U+00C5 ISOlat1 -->
-<!ENTITY AElig CDATA "&#198;" -- latin capital letter AE
- = latin capital ligature AE,
- U+00C6 ISOlat1 -->
-<!ENTITY Ccedil CDATA "&#199;" -- latin capital letter C with cedilla,
- U+00C7 ISOlat1 -->
-<!ENTITY Egrave CDATA "&#200;" -- latin capital letter E with grave,
- U+00C8 ISOlat1 -->
-<!ENTITY Eacute CDATA "&#201;" -- latin capital letter E with acute,
- U+00C9 ISOlat1 -->
-<!ENTITY Ecirc CDATA "&#202;" -- latin capital letter E with circumflex,
- U+00CA ISOlat1 -->
-<!ENTITY Euml CDATA "&#203;" -- latin capital letter E with diaeresis,
- U+00CB ISOlat1 -->
-<!ENTITY Igrave CDATA "&#204;" -- latin capital letter I with grave,
- U+00CC ISOlat1 -->
-<!ENTITY Iacute CDATA "&#205;" -- latin capital letter I with acute,
- U+00CD ISOlat1 -->
-<!ENTITY Icirc CDATA "&#206;" -- latin capital letter I with circumflex,
- U+00CE ISOlat1 -->
-<!ENTITY Iuml CDATA "&#207;" -- latin capital letter I with diaeresis,
- U+00CF ISOlat1 -->
-<!ENTITY ETH CDATA "&#208;" -- latin capital letter ETH, U+00D0 ISOlat1 -->
-<!ENTITY Ntilde CDATA "&#209;" -- latin capital letter N with tilde,
- U+00D1 ISOlat1 -->
-<!ENTITY Ograve CDATA "&#210;" -- latin capital letter O with grave,
- U+00D2 ISOlat1 -->
-<!ENTITY Oacute CDATA "&#211;" -- latin capital letter O with acute,
- U+00D3 ISOlat1 -->
-<!ENTITY Ocirc CDATA "&#212;" -- latin capital letter O with circumflex,
- U+00D4 ISOlat1 -->
-<!ENTITY Otilde CDATA "&#213;" -- latin capital letter O with tilde,
- U+00D5 ISOlat1 -->
-<!ENTITY Ouml CDATA "&#214;" -- latin capital letter O with diaeresis,
- U+00D6 ISOlat1 -->
-<!ENTITY times CDATA "&#215;" -- multiplication sign, U+00D7 ISOnum -->
-<!ENTITY Oslash CDATA "&#216;" -- latin capital letter O with stroke
- = latin capital letter O slash,
- U+00D8 ISOlat1 -->
-<!ENTITY Ugrave CDATA "&#217;" -- latin capital letter U with grave,
- U+00D9 ISOlat1 -->
-<!ENTITY Uacute CDATA "&#218;" -- latin capital letter U with acute,
- U+00DA ISOlat1 -->
-<!ENTITY Ucirc CDATA "&#219;" -- latin capital letter U with circumflex,
- U+00DB ISOlat1 -->
-<!ENTITY Uuml CDATA "&#220;" -- latin capital letter U with diaeresis,
- U+00DC ISOlat1 -->
-<!ENTITY Yacute CDATA "&#221;" -- latin capital letter Y with acute,
- U+00DD ISOlat1 -->
-<!ENTITY THORN CDATA "&#222;" -- latin capital letter THORN,
- U+00DE ISOlat1 -->
-<!ENTITY szlig CDATA "&#223;" -- latin small letter sharp s = ess-zed,
- U+00DF ISOlat1 -->
-<!ENTITY agrave CDATA "&#224;" -- latin small letter a with grave
- = latin small letter a grave,
- U+00E0 ISOlat1 -->
-<!ENTITY aacute CDATA "&#225;" -- latin small letter a with acute,
- U+00E1 ISOlat1 -->
-<!ENTITY acirc CDATA "&#226;" -- latin small letter a with circumflex,
- U+00E2 ISOlat1 -->
-<!ENTITY atilde CDATA "&#227;" -- latin small letter a with tilde,
- U+00E3 ISOlat1 -->
-<!ENTITY auml CDATA "&#228;" -- latin small letter a with diaeresis,
- U+00E4 ISOlat1 -->
-<!ENTITY aring CDATA "&#229;" -- latin small letter a with ring above
- = latin small letter a ring,
- U+00E5 ISOlat1 -->
-<!ENTITY aelig CDATA "&#230;" -- latin small letter ae
- = latin small ligature ae, U+00E6 ISOlat1 -->
-<!ENTITY ccedil CDATA "&#231;" -- latin small letter c with cedilla,
- U+00E7 ISOlat1 -->
-<!ENTITY egrave CDATA "&#232;" -- latin small letter e with grave,
- U+00E8 ISOlat1 -->
-<!ENTITY eacute CDATA "&#233;" -- latin small letter e with acute,
- U+00E9 ISOlat1 -->
-<!ENTITY ecirc CDATA "&#234;" -- latin small letter e with circumflex,
- U+00EA ISOlat1 -->
-<!ENTITY euml CDATA "&#235;" -- latin small letter e with diaeresis,
- U+00EB ISOlat1 -->
-<!ENTITY igrave CDATA "&#236;" -- latin small letter i with grave,
- U+00EC ISOlat1 -->
-<!ENTITY iacute CDATA "&#237;" -- latin small letter i with acute,
- U+00ED ISOlat1 -->
-<!ENTITY icirc CDATA "&#238;" -- latin small letter i with circumflex,
- U+00EE ISOlat1 -->
-<!ENTITY iuml CDATA "&#239;" -- latin small letter i with diaeresis,
- U+00EF ISOlat1 -->
-<!ENTITY eth CDATA "&#240;" -- latin small letter eth, U+00F0 ISOlat1 -->
-<!ENTITY ntilde CDATA "&#241;" -- latin small letter n with tilde,
- U+00F1 ISOlat1 -->
-<!ENTITY ograve CDATA "&#242;" -- latin small letter o with grave,
- U+00F2 ISOlat1 -->
-<!ENTITY oacute CDATA "&#243;" -- latin small letter o with acute,
- U+00F3 ISOlat1 -->
-<!ENTITY ocirc CDATA "&#244;" -- latin small letter o with circumflex,
- U+00F4 ISOlat1 -->
-<!ENTITY otilde CDATA "&#245;" -- latin small letter o with tilde,
- U+00F5 ISOlat1 -->
-<!ENTITY ouml CDATA "&#246;" -- latin small letter o with diaeresis,
- U+00F6 ISOlat1 -->
-<!ENTITY divide CDATA "&#247;" -- division sign, U+00F7 ISOnum -->
-<!ENTITY oslash CDATA "&#248;" -- latin small letter o with stroke,
- = latin small letter o slash,
- U+00F8 ISOlat1 -->
-<!ENTITY ugrave CDATA "&#249;" -- latin small letter u with grave,
- U+00F9 ISOlat1 -->
-<!ENTITY uacute CDATA "&#250;" -- latin small letter u with acute,
- U+00FA ISOlat1 -->
-<!ENTITY ucirc CDATA "&#251;" -- latin small letter u with circumflex,
- U+00FB ISOlat1 -->
-<!ENTITY uuml CDATA "&#252;" -- latin small letter u with diaeresis,
- U+00FC ISOlat1 -->
-<!ENTITY yacute CDATA "&#253;" -- latin small letter y with acute,
- U+00FD ISOlat1 -->
-<!ENTITY thorn CDATA "&#254;" -- latin small letter thorn,
- U+00FE ISOlat1 -->
-<!ENTITY yuml CDATA "&#255;" -- latin small letter y with diaeresis,
- U+00FF ISOlat1 -->
-</pre>
-</div>
-
-<h2><a name="h-24.3">24.3</a> <a name="sym">Character entity references for
-symbols, mathematical symbols, and Greek letters</a></h2>
-
-<p>The character entity references in this section produce characters that may
-be represented by glyphs in the widely available Adobe Symbol font, including
-Greek characters, various bracketing symbols, and a selection of mathematical
-operators such as gradient, product, and summation symbols.</p>
-
-<p>To support these entities, user agents may support full <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> or use
-other means. Display of glyphs for these characters may be obtained by being
-able to display the relevant <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> characters or
-by other means, such as internally mapping the listed entities, numeric
-character references, and characters to the appropriate position in some font
-that contains the requisite glyphs.</p>
-
-<div class="note">
-<p><em><strong>When to use Greek entities.</strong> This entity set contains
-all the letters used in modern Greek. However, it does not include Greek
-punctuation, precomposed accented characters nor the non-spacing accents
-(tonos, dialytika) required to compose them. There are no archaic letters,
-Coptic-unique letters, or precomposed letters for Polytonic Greek. The entities
-defined here are not intended for the representation of modern Greek text and
-would not be an efficient representation; rather, they are intended for
-occasional Greek letters used in technical and mathematical works.</em></p>
-</div>
-
-<h3><a name="h-24.3.1">24.3.1</a> The list of characters</h3>
-
-<div class="dtd-fragment">
-<pre><!-- Mathematical, Greek and Symbolic characters for HTML -->
-
-<!-- Character entity set. Typical invocation:
- <!ENTITY % HTMLsymbol PUBLIC
- "-//W3C//ENTITIES Symbols//EN//HTML">
- %HTMLsymbol; -->
-
-<!-- Portions © International Organization for Standardization 1986:
- Permission to copy in any form is granted for use with
- conforming SGML systems and applications as defined in
- ISO 8879, provided this notice is included in all copies.
--->
-
-<!-- Relevant ISO entity set is given unless names are newly introduced.
- New names (i.e., not in ISO 8879 list) do not clash with any
- existing ISO 8879 entity names. ISO 10646 character numbers
- are given for each character, in hex. CDATA values are decimal
- conversions of the ISO 10646 values and refer to the document
- character set. Names are ISO 10646 names.
-
--->
-
-<!-- Latin Extended-B -->
-<!ENTITY fnof CDATA "&#402;" -- latin small f with hook = function
- = florin, U+0192 ISOtech -->
-
-<!-- Greek -->
-<!ENTITY Alpha CDATA "&#913;" -- greek capital letter alpha, U+0391 -->
-<!ENTITY Beta CDATA "&#914;" -- greek capital letter beta, U+0392 -->
-<!ENTITY Gamma CDATA "&#915;" -- greek capital letter gamma,
- U+0393 ISOgrk3 -->
-<!ENTITY Delta CDATA "&#916;" -- greek capital letter delta,
- U+0394 ISOgrk3 -->
-<!ENTITY Epsilon CDATA "&#917;" -- greek capital letter epsilon, U+0395 -->
-<!ENTITY Zeta CDATA "&#918;" -- greek capital letter zeta, U+0396 -->
-<!ENTITY Eta CDATA "&#919;" -- greek capital letter eta, U+0397 -->
-<!ENTITY Theta CDATA "&#920;" -- greek capital letter theta,
- U+0398 ISOgrk3 -->
-<!ENTITY Iota CDATA "&#921;" -- greek capital letter iota, U+0399 -->
-<!ENTITY Kappa CDATA "&#922;" -- greek capital letter kappa, U+039A -->
-<!ENTITY Lambda CDATA "&#923;" -- greek capital letter lambda,
- U+039B ISOgrk3 -->
-<!ENTITY Mu CDATA "&#924;" -- greek capital letter mu, U+039C -->
-<!ENTITY Nu CDATA "&#925;" -- greek capital letter nu, U+039D -->
-<!ENTITY Xi CDATA "&#926;" -- greek capital letter xi, U+039E ISOgrk3 -->
-<!ENTITY Omicron CDATA "&#927;" -- greek capital letter omicron, U+039F -->
-<!ENTITY Pi CDATA "&#928;" -- greek capital letter pi, U+03A0 ISOgrk3 -->
-<!ENTITY Rho CDATA "&#929;" -- greek capital letter rho, U+03A1 -->
-<!-- there is no Sigmaf, and no U+03A2 character either -->
-<!ENTITY Sigma CDATA "&#931;" -- greek capital letter sigma,
- U+03A3 ISOgrk3 -->
-<!ENTITY Tau CDATA "&#932;" -- greek capital letter tau, U+03A4 -->
-<!ENTITY Upsilon CDATA "&#933;" -- greek capital letter upsilon,
- U+03A5 ISOgrk3 -->
-<!ENTITY Phi CDATA "&#934;" -- greek capital letter phi,
- U+03A6 ISOgrk3 -->
-<!ENTITY Chi CDATA "&#935;" -- greek capital letter chi, U+03A7 -->
-<!ENTITY Psi CDATA "&#936;" -- greek capital letter psi,
- U+03A8 ISOgrk3 -->
-<!ENTITY Omega CDATA "&#937;" -- greek capital letter omega,
- U+03A9 ISOgrk3 -->
-
-<!ENTITY alpha CDATA "&#945;" -- greek small letter alpha,
- U+03B1 ISOgrk3 -->
-<!ENTITY beta CDATA "&#946;" -- greek small letter beta, U+03B2 ISOgrk3 -->
-<!ENTITY gamma CDATA "&#947;" -- greek small letter gamma,
- U+03B3 ISOgrk3 -->
-<!ENTITY delta CDATA "&#948;" -- greek small letter delta,
- U+03B4 ISOgrk3 -->
-<!ENTITY epsilon CDATA "&#949;" -- greek small letter epsilon,
- U+03B5 ISOgrk3 -->
-<!ENTITY zeta CDATA "&#950;" -- greek small letter zeta, U+03B6 ISOgrk3 -->
-<!ENTITY eta CDATA "&#951;" -- greek small letter eta, U+03B7 ISOgrk3 -->
-<!ENTITY theta CDATA "&#952;" -- greek small letter theta,
- U+03B8 ISOgrk3 -->
-<!ENTITY iota CDATA "&#953;" -- greek small letter iota, U+03B9 ISOgrk3 -->
-<!ENTITY kappa CDATA "&#954;" -- greek small letter kappa,
- U+03BA ISOgrk3 -->
-<!ENTITY lambda CDATA "&#955;" -- greek small letter lambda,
- U+03BB ISOgrk3 -->
-<!ENTITY mu CDATA "&#956;" -- greek small letter mu, U+03BC ISOgrk3 -->
-<!ENTITY nu CDATA "&#957;" -- greek small letter nu, U+03BD ISOgrk3 -->
-<!ENTITY xi CDATA "&#958;" -- greek small letter xi, U+03BE ISOgrk3 -->
-<!ENTITY omicron CDATA "&#959;" -- greek small letter omicron, U+03BF NEW -->
-<!ENTITY pi CDATA "&#960;" -- greek small letter pi, U+03C0 ISOgrk3 -->
-<!ENTITY rho CDATA "&#961;" -- greek small letter rho, U+03C1 ISOgrk3 -->
-<!ENTITY sigmaf CDATA "&#962;" -- greek small letter final sigma,
- U+03C2 ISOgrk3 -->
-<!ENTITY sigma CDATA "&#963;" -- greek small letter sigma,
- U+03C3 ISOgrk3 -->
-<!ENTITY tau CDATA "&#964;" -- greek small letter tau, U+03C4 ISOgrk3 -->
-<!ENTITY upsilon CDATA "&#965;" -- greek small letter upsilon,
- U+03C5 ISOgrk3 -->
-<!ENTITY phi CDATA "&#966;" -- greek small letter phi, U+03C6 ISOgrk3 -->
-<!ENTITY chi CDATA "&#967;" -- greek small letter chi, U+03C7 ISOgrk3 -->
-<!ENTITY psi CDATA "&#968;" -- greek small letter psi, U+03C8 ISOgrk3 -->
-<!ENTITY omega CDATA "&#969;" -- greek small letter omega,
- U+03C9 ISOgrk3 -->
-<!ENTITY thetasym CDATA "&#977;" -- greek small letter theta symbol,
- U+03D1 NEW -->
-<!ENTITY upsih CDATA "&#978;" -- greek upsilon with hook symbol,
- U+03D2 NEW -->
-<!ENTITY piv CDATA "&#982;" -- greek pi symbol, U+03D6 ISOgrk3 -->
-
-<!-- General Punctuation -->
-<!ENTITY bull CDATA "&#8226;" -- bullet = black small circle,
- U+2022 ISOpub -->
-<!-- bullet is NOT the same as bullet operator, U+2219 -->
-<!ENTITY hellip CDATA "&#8230;" -- horizontal ellipsis = three dot leader,
- U+2026 ISOpub -->
-<!ENTITY prime CDATA "&#8242;" -- prime = minutes = feet, U+2032 ISOtech -->
-<!ENTITY Prime CDATA "&#8243;" -- double prime = seconds = inches,
- U+2033 ISOtech -->
-<!ENTITY oline CDATA "&#8254;" -- overline = spacing overscore,
- U+203E NEW -->
-<!ENTITY frasl CDATA "&#8260;" -- fraction slash, U+2044 NEW -->
-
-<!-- Letterlike Symbols -->
-<!ENTITY weierp CDATA "&#8472;" -- script capital P = power set
- = Weierstrass p, U+2118 ISOamso -->
-<!ENTITY image CDATA "&#8465;" -- blackletter capital I = imaginary part,
- U+2111 ISOamso -->
-<!ENTITY real CDATA "&#8476;" -- blackletter capital R = real part symbol,
- U+211C ISOamso -->
-<!ENTITY trade CDATA "&#8482;" -- trade mark sign, U+2122 ISOnum -->
-<!ENTITY alefsym CDATA "&#8501;" -- alef symbol = first transfinite cardinal,
- U+2135 NEW -->
-<!-- alef symbol is NOT the same as hebrew letter alef,
- U+05D0 although the same glyph could be used to depict both characters -->
-
-<!-- Arrows -->
-<!ENTITY larr CDATA "&#8592;" -- leftwards arrow, U+2190 ISOnum -->
-<!ENTITY uarr CDATA "&#8593;" -- upwards arrow, U+2191 ISOnum-->
-<!ENTITY rarr CDATA "&#8594;" -- rightwards arrow, U+2192 ISOnum -->
-<!ENTITY darr CDATA "&#8595;" -- downwards arrow, U+2193 ISOnum -->
-<!ENTITY harr CDATA "&#8596;" -- left right arrow, U+2194 ISOamsa -->
-<!ENTITY crarr CDATA "&#8629;" -- downwards arrow with corner leftwards
- = carriage return, U+21B5 NEW -->
-<!ENTITY lArr CDATA "&#8656;" -- leftwards double arrow, U+21D0 ISOtech -->
-<!-- ISO 10646 does not say that lArr is the same as the 'is implied by' arrow
- but also does not have any other character for that function. So ? lArr can
- be used for 'is implied by' as ISOtech suggests -->
-<!ENTITY uArr CDATA "&#8657;" -- upwards double arrow, U+21D1 ISOamsa -->
-<!ENTITY rArr CDATA "&#8658;" -- rightwards double arrow,
- U+21D2 ISOtech -->
-<!-- ISO 10646 does not say this is the 'implies' character but does not have
- another character with this function so ?
- rArr can be used for 'implies' as ISOtech suggests -->
-<!ENTITY dArr CDATA "&#8659;" -- downwards double arrow, U+21D3 ISOamsa -->
-<!ENTITY hArr CDATA "&#8660;" -- left right double arrow,
- U+21D4 ISOamsa -->
-
-<!-- Mathematical Operators -->
-<!ENTITY forall CDATA "&#8704;" -- for all, U+2200 ISOtech -->
-<!ENTITY part CDATA "&#8706;" -- partial differential, U+2202 ISOtech -->
-<!ENTITY exist CDATA "&#8707;" -- there exists, U+2203 ISOtech -->
-<!ENTITY empty CDATA "&#8709;" -- empty set = null set = diameter,
- U+2205 ISOamso -->
-<!ENTITY nabla CDATA "&#8711;" -- nabla = backward difference,
- U+2207 ISOtech -->
-<!ENTITY isin CDATA "&#8712;" -- element of, U+2208 ISOtech -->
-<!ENTITY notin CDATA "&#8713;" -- not an element of, U+2209 ISOtech -->
-<!ENTITY ni CDATA "&#8715;" -- contains as member, U+220B ISOtech -->
-<!-- should there be a more memorable name than 'ni'? -->
-<!ENTITY prod CDATA "&#8719;" -- n-ary product = product sign,
- U+220F ISOamsb -->
-<!-- prod is NOT the same character as U+03A0 'greek capital letter pi' though
- the same glyph might be used for both -->
-<!ENTITY sum CDATA "&#8721;" -- n-ary sumation, U+2211 ISOamsb -->
-<!-- sum is NOT the same character as U+03A3 'greek capital letter sigma'
- though the same glyph might be used for both -->
-<!ENTITY minus CDATA "&#8722;" -- minus sign, U+2212 ISOtech -->
-<!ENTITY lowast CDATA "&#8727;" -- asterisk operator, U+2217 ISOtech -->
-<!ENTITY radic CDATA "&#8730;" -- square root = radical sign,
- U+221A ISOtech -->
-<!ENTITY prop CDATA "&#8733;" -- proportional to, U+221D ISOtech -->
-<!ENTITY infin CDATA "&#8734;" -- infinity, U+221E ISOtech -->
-<!ENTITY ang CDATA "&#8736;" -- angle, U+2220 ISOamso -->
-<!ENTITY and CDATA "&#8743;" -- logical and = wedge, U+2227 ISOtech -->
-<!ENTITY or CDATA "&#8744;" -- logical or = vee, U+2228 ISOtech -->
-<!ENTITY cap CDATA "&#8745;" -- intersection = cap, U+2229 ISOtech -->
-<!ENTITY cup CDATA "&#8746;" -- union = cup, U+222A ISOtech -->
-<!ENTITY int CDATA "&#8747;" -- integral, U+222B ISOtech -->
-<!ENTITY there4 CDATA "&#8756;" -- therefore, U+2234 ISOtech -->
-<!ENTITY sim CDATA "&#8764;" -- tilde operator = varies with = similar to,
- U+223C ISOtech -->
-<!-- tilde operator is NOT the same character as the tilde, U+007E,
- although the same glyph might be used to represent both -->
-<!ENTITY cong CDATA "&#8773;" -- approximately equal to, U+2245 ISOtech -->
-<!ENTITY asymp CDATA "&#8776;" -- almost equal to = asymptotic to,
- U+2248 ISOamsr -->
-<!ENTITY ne CDATA "&#8800;" -- not equal to, U+2260 ISOtech -->
-<!ENTITY equiv CDATA "&#8801;" -- identical to, U+2261 ISOtech -->
-<!ENTITY le CDATA "&#8804;" -- less-than or equal to, U+2264 ISOtech -->
-<!ENTITY ge CDATA "&#8805;" -- greater-than or equal to,
- U+2265 ISOtech -->
-<!ENTITY sub CDATA "&#8834;" -- subset of, U+2282 ISOtech -->
-<!ENTITY sup CDATA "&#8835;" -- superset of, U+2283 ISOtech -->
-<!-- note that nsup, 'not a superset of, U+2283' is not covered by the Symbol
- font encoding and is not included. Should it be, for symmetry?
- It is in ISOamsn -->
-<!ENTITY nsub CDATA "&#8836;" -- not a subset of, U+2284 ISOamsn -->
-<!ENTITY sube CDATA "&#8838;" -- subset of or equal to, U+2286 ISOtech -->
-<!ENTITY supe CDATA "&#8839;" -- superset of or equal to,
- U+2287 ISOtech -->
-<!ENTITY oplus CDATA "&#8853;" -- circled plus = direct sum,
- U+2295 ISOamsb -->
-<!ENTITY otimes CDATA "&#8855;" -- circled times = vector product,
- U+2297 ISOamsb -->
-<!ENTITY perp CDATA "&#8869;" -- up tack = orthogonal to = perpendicular,
- U+22A5 ISOtech -->
-<!ENTITY sdot CDATA "&#8901;" -- dot operator, U+22C5 ISOamsb -->
-<!-- dot operator is NOT the same character as U+00B7 middle dot -->
-
-<!-- Miscellaneous Technical -->
-<!ENTITY lceil CDATA "&#8968;" -- left ceiling = apl upstile,
- U+2308 ISOamsc -->
-<!ENTITY rceil CDATA "&#8969;" -- right ceiling, U+2309 ISOamsc -->
-<!ENTITY lfloor CDATA "&#8970;" -- left floor = apl downstile,
- U+230A ISOamsc -->
-<!ENTITY rfloor CDATA "&#8971;" -- right floor, U+230B ISOamsc -->
-<!ENTITY lang CDATA "&#9001;" -- left-pointing angle bracket = bra,
- U+2329 ISOtech -->
-<!-- lang is NOT the same character as U+003C 'less than'
- or U+2039 'single left-pointing angle quotation mark' -->
-<!ENTITY rang CDATA "&#9002;" -- right-pointing angle bracket = ket,
- U+232A ISOtech -->
-<!-- rang is NOT the same character as U+003E 'greater than'
- or U+203A 'single right-pointing angle quotation mark' -->
-
-<!-- Geometric Shapes -->
-<!ENTITY loz CDATA "&#9674;" -- lozenge, U+25CA ISOpub -->
-
-<!-- Miscellaneous Symbols -->
-<!ENTITY spades CDATA "&#9824;" -- black spade suit, U+2660 ISOpub -->
-<!-- black here seems to mean filled as opposed to hollow -->
-<!ENTITY clubs CDATA "&#9827;" -- black club suit = shamrock,
- U+2663 ISOpub -->
-<!ENTITY hearts CDATA "&#9829;" -- black heart suit = valentine,
- U+2665 ISOpub -->
-<!ENTITY diams CDATA "&#9830;" -- black diamond suit, U+2666 ISOpub -->
-</pre>
-</div>
-
-<h2><a name="h-24.4">24.4</a> <a name="misc">Character entity references for
-markup-significant and internationalization characters</a></h2>
-
-<p>The character entity references in this section are for escaping
-markup-significant characters (these are the same as those in HTML 2.0 and
-3.2), for denoting spaces and dashes. Other characters in this section apply to
-internationalization issues such as the disambiguation of bidirectional text
-(see the section on <a href="http://www.w3.org/TR/REC-html40/struct/dirlang.html#bidirection">bidirectional
-text</a> for details).</p>
-
-<p>Entities have also been added for the remaining characters occurring in
-CP-1252 which do not occur in the HTMLlat1 or HTMLsymbol entity sets. These all
-occur in the 128 to 159 range within the CP-1252 charset. These entities permit
-the characters to be denoted in a platform-independent manner.</p>
-
-<p>To support these entities, user agents may support full <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> or use
-other means. Display of glyphs for these characters may be obtained by being
-able to display the relevant <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> characters or
-by other means, such as internally mapping the listed entities, numeric
-character references, and characters to the appropriate position in some font
-that contains the requisite glyphs.</p>
-
-<h3><a name="h-24.4.1">24.4.1</a> The list of characters</h3>
-
-<div class="dtd-fragment">
-<pre><!-- Special characters for HTML -->
-
-<!-- Character entity set. Typical invocation:
- <!ENTITY % HTMLspecial PUBLIC
- "-//W3C//ENTITIES Special//EN//HTML">
- %HTMLspecial; -->
-
-<!-- Portions © International Organization for Standardization 1986:
- Permission to copy in any form is granted for use with
- conforming SGML systems and applications as defined in
- ISO 8879, provided this notice is included in all copies.
--->
-
-<!-- Relevant ISO entity set is given unless names are newly introduced.
- New names (i.e., not in ISO 8879 list) do not clash with any
- existing ISO 8879 entity names. ISO 10646 character numbers
- are given for each character, in hex. CDATA values are decimal
- conversions of the ISO 10646 values and refer to the document
- character set. Names are ISO 10646 names.
-
--->
-
-<!-- C0 Controls and Basic Latin -->
-<!ENTITY quot CDATA "&#34;" -- quotation mark = APL quote,
- U+0022 ISOnum -->
-<!ENTITY amp CDATA "&#38;" -- ampersand, U+0026 ISOnum -->
-<!ENTITY lt CDATA "&#60;" -- less-than sign, U+003C ISOnum -->
-<!ENTITY gt CDATA "&#62;" -- greater-than sign, U+003E ISOnum -->
-
-<!-- Latin Extended-A -->
-<!ENTITY OElig CDATA "&#338;" -- latin capital ligature OE,
- U+0152 ISOlat2 -->
-<!ENTITY oelig CDATA "&#339;" -- latin small ligature oe, U+0153 ISOlat2 -->
-<!-- ligature is a misnomer, this is a separate character in some languages -->
-<!ENTITY Scaron CDATA "&#352;" -- latin capital letter S with caron,
- U+0160 ISOlat2 -->
-<!ENTITY scaron CDATA "&#353;" -- latin small letter s with caron,
- U+0161 ISOlat2 -->
-<!ENTITY Yuml CDATA "&#376;" -- latin capital letter Y with diaeresis,
- U+0178 ISOlat2 -->
-
-<!-- Spacing Modifier Letters -->
-<!ENTITY circ CDATA "&#710;" -- modifier letter circumflex accent,
- U+02C6 ISOpub -->
-<!ENTITY tilde CDATA "&#732;" -- small tilde, U+02DC ISOdia -->
-
-<!-- General Punctuation -->
-<!ENTITY ensp CDATA "&#8194;" -- en space, U+2002 ISOpub -->
-<!ENTITY emsp CDATA "&#8195;" -- em space, U+2003 ISOpub -->
-<!ENTITY thinsp CDATA "&#8201;" -- thin space, U+2009 ISOpub -->
-<!ENTITY zwnj CDATA "&#8204;" -- zero width non-joiner,
- U+200C NEW RFC 2070 -->
-<!ENTITY zwj CDATA "&#8205;" -- zero width joiner, U+200D NEW RFC 2070 -->
-<!ENTITY lrm CDATA "&#8206;" -- left-to-right mark, U+200E NEW RFC 2070 -->
-<!ENTITY rlm CDATA "&#8207;" -- right-to-left mark, U+200F NEW RFC 2070 -->
-<!ENTITY ndash CDATA "&#8211;" -- en dash, U+2013 ISOpub -->
-<!ENTITY mdash CDATA "&#8212;" -- em dash, U+2014 ISOpub -->
-<!ENTITY lsquo CDATA "&#8216;" -- left single quotation mark,
- U+2018 ISOnum -->
-<!ENTITY rsquo CDATA "&#8217;" -- right single quotation mark,
- U+2019 ISOnum -->
-<!ENTITY sbquo CDATA "&#8218;" -- single low-9 quotation mark, U+201A NEW -->
-<!ENTITY ldquo CDATA "&#8220;" -- left double quotation mark,
- U+201C ISOnum -->
-<!ENTITY rdquo CDATA "&#8221;" -- right double quotation mark,
- U+201D ISOnum -->
-<!ENTITY bdquo CDATA "&#8222;" -- double low-9 quotation mark, U+201E NEW -->
-<!ENTITY dagger CDATA "&#8224;" -- dagger, U+2020 ISOpub -->
-<!ENTITY Dagger CDATA "&#8225;" -- double dagger, U+2021 ISOpub -->
-<!ENTITY permil CDATA "&#8240;" -- per mille sign, U+2030 ISOtech -->
-<!ENTITY lsaquo CDATA "&#8249;" -- single left-pointing angle quotation mark,
- U+2039 ISO proposed -->
-<!-- lsaquo is proposed but not yet ISO standardized -->
-<!ENTITY rsaquo CDATA "&#8250;" -- single right-pointing angle quotation mark,
- U+203A ISO proposed -->
-<!-- rsaquo is proposed but not yet ISO standardized -->
-<!ENTITY euro CDATA "&#8364;" -- euro sign, U+20AC NEW -->
-</pre>
-</div>
-
-<div class="navbar" align="center">
-<hr><a href="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html">previous</a> <a href="http://www.w3.org/TR/REC-html40/appendix/changes.html">next</a> <a href="http://www.w3.org/TR/REC-html40/cover.html#minitoc">
-contents</a> <a href="http://www.w3.org/TR/REC-html40/index/elements.html">elements</a> <a href="http://www.w3.org/TR/REC-html40/index/attributes.html">attributes</a> <a href="http://www.w3.org/TR/REC-html40/index/list.html">index</a></div>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html lang="en"><head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Character entity references in HTML 4</title> + +<link rel="previous" href="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html"> +<link rel="next" href="http://www.w3.org/TR/REC-html40/appendix/changes.html"> +<link rel="contents" href="http://www.w3.org/TR/REC-html40/cover.html#toc"> +<link rel="stylesheet" type="text/css" href="entities.html_files/W3C-REC.css"> +<link rel="STYLESHEET" href="entities.html_files/default.css" type="text/css"></head> + +<body> +<div class="navbar" align="center"> <a href="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html"> +previous</a> <a href="http://www.w3.org/TR/REC-html40/appendix/changes.html">next</a> <a href="http://www.w3.org/TR/REC-html40/cover.html#minitoc">contents</a> <a href="http://www.w3.org/TR/REC-html40/index/elements.html"> +elements</a> <a href="http://www.w3.org/TR/REC-html40/index/attributes.html">attributes</a> <a href="http://www.w3.org/TR/REC-html40/index/list.html">index</a> + +<hr></div> + +<h1 align="center"><a name="h-24">24</a> <a name="entities">Character entity +references in HTML 4</a></h1> + +<div class="subtoc"> +<p><strong>Contents</strong></p> + +<ol> +<li><a class="tocxref" href="#h-24.1">Introduction to character entity +references</a></li> + +<li><a class="tocxref" href="#h-24.2">Character entity references for ISO +8859-1 characters</a> + +<ol> +<li><a class="tocxref" href="#h-24.2.1">The list of characters</a></li> +</ol> +</li> + +<li><a class="tocxref" href="#h-24.3">Character entity references for symbols, +mathematical symbols, and Greek letters</a> + +<ol> +<li><a class="tocxref" href="#h-24.3.1">The list of characters</a></li> +</ol> +</li> + +<li><a class="tocxref" href="#h-24.4">Character entity references for +markup-significant and internationalization characters</a> + +<ol> +<li><a class="tocxref" href="#h-24.4.1">The list of characters</a></li> +</ol> +</li> +</ol> +</div> + +<h2><a name="h-24.1">24.1</a> Introduction to character entity references</h2> + +A <a href="http://www.w3.org/TR/REC-html40/charset.html#entities">character entity reference</a> is an SGML +construct that references a character of the <a href="http://www.w3.org/TR/REC-html40/charset.html">document +character set.</a> + +<p>This version of HTML supports several sets of character entity +references:</p> + +<ul> +<li><a href="#iso-88591">ISO 8859-1 (Latin-1) characters</a> In accordance with +section 14 of <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-RFC1866" class="informref">[RFC1866]</a>, the set of Latin-1 entities has been extended by +this specification to cover the whole right part of ISO-8859-1 (all code +positions with the high-order bit set), including the already commonly used +&nbsp;, &copy; and &reg;. The names of the entities are taken from +the appendices of SGML (defined in <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO8879" class="normref">[ISO8879]</a>).</li> + +<li><a href="#sym">symbols, mathematical symbols, and Greek letters</a>. These +characters may be represented by glyphs in the Adobe font "Symbol".</li> + +<li><a href="#misc">markup-significant and internationalization characters</a> +(e.g., for bidirectional text).</li> +</ul> + +<p>The following sections present the complete lists of character entity +references. Although, by convention, <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> the comments +following each entry are usually written with uppercase letters, we have +converted them to lowercase in this specification for reasons of +readability.</p> + +<h2><a name="h-24.2">24.2</a> <a name="iso-88591">Character entity references +for ISO 8859-1 characters</a></h2> + +<p>The character entity references in this section produce characters whose +numeric equivalents should already be supported by conforming HTML 2.0 user +agents. Thus, the character entity reference &divide; is a more convenient +form than &#247; for obtaining the division sign (÷).</p> + +<p>To support these named entities, user agents need only recognize the entity +names and convert them to characters that lie within the repertoire of <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO88591" class="normref"> +[ISO88591]</a>.</p> + +<p>Character 65533 (FFFD hexadecimal) is the last valid character in UCS-2. +65534 (FFFE hexadecimal) is unassigned and reserved as the byte-swapped version +of ZERO WIDTH NON-BREAKING SPACE for byte-order detection purposes. 65535 (FFFF +hexadecimal) is unassigned.</p> + +<h3><a name="h-24.2.1">24.2.1</a> The list of characters</h3> + +<div class="dtd-fragment"> +<pre><!-- Portions © International Organization for Standardization 1986 + Permission to copy in any form is granted for use with + conforming SGML systems and applications as defined in + ISO 8879, provided this notice is included in all copies. +--> +<!-- Character entity set. Typical invocation: + <!ENTITY % HTMLlat1 PUBLIC + "-//W3C//ENTITIES Latin 1//EN//HTML"> + %HTMLlat1; +--> + +<!ENTITY nbsp CDATA "&#160;" -- no-break space = non-breaking space, + U+00A0 ISOnum --> +<!ENTITY iexcl CDATA "&#161;" -- inverted exclamation mark, U+00A1 ISOnum --> +<!ENTITY cent CDATA "&#162;" -- cent sign, U+00A2 ISOnum --> +<!ENTITY pound CDATA "&#163;" -- pound sign, U+00A3 ISOnum --> +<!ENTITY curren CDATA "&#164;" -- currency sign, U+00A4 ISOnum --> +<!ENTITY yen CDATA "&#165;" -- yen sign = yuan sign, U+00A5 ISOnum --> +<!ENTITY brvbar CDATA "&#166;" -- broken bar = broken vertical bar, + U+00A6 ISOnum --> +<!ENTITY sect CDATA "&#167;" -- section sign, U+00A7 ISOnum --> +<!ENTITY uml CDATA "&#168;" -- diaeresis = spacing diaeresis, + U+00A8 ISOdia --> +<!ENTITY copy CDATA "&#169;" -- copyright sign, U+00A9 ISOnum --> +<!ENTITY ordf CDATA "&#170;" -- feminine ordinal indicator, U+00AA ISOnum --> +<!ENTITY laquo CDATA "&#171;" -- left-pointing double angle quotation mark + = left pointing guillemet, U+00AB ISOnum --> +<!ENTITY not CDATA "&#172;" -- not sign, U+00AC ISOnum --> +<!ENTITY shy CDATA "&#173;" -- soft hyphen = discretionary hyphen, + U+00AD ISOnum --> +<!ENTITY reg CDATA "&#174;" -- registered sign = registered trade mark sign, + U+00AE ISOnum --> +<!ENTITY macr CDATA "&#175;" -- macron = spacing macron = overline + = APL overbar, U+00AF ISOdia --> +<!ENTITY deg CDATA "&#176;" -- degree sign, U+00B0 ISOnum --> +<!ENTITY plusmn CDATA "&#177;" -- plus-minus sign = plus-or-minus sign, + U+00B1 ISOnum --> +<!ENTITY sup2 CDATA "&#178;" -- superscript two = superscript digit two + = squared, U+00B2 ISOnum --> +<!ENTITY sup3 CDATA "&#179;" -- superscript three = superscript digit three + = cubed, U+00B3 ISOnum --> +<!ENTITY acute CDATA "&#180;" -- acute accent = spacing acute, + U+00B4 ISOdia --> +<!ENTITY micro CDATA "&#181;" -- micro sign, U+00B5 ISOnum --> +<!ENTITY para CDATA "&#182;" -- pilcrow sign = paragraph sign, + U+00B6 ISOnum --> +<!ENTITY middot CDATA "&#183;" -- middle dot = Georgian comma + = Greek middle dot, U+00B7 ISOnum --> +<!ENTITY cedil CDATA "&#184;" -- cedilla = spacing cedilla, U+00B8 ISOdia --> +<!ENTITY sup1 CDATA "&#185;" -- superscript one = superscript digit one, + U+00B9 ISOnum --> +<!ENTITY ordm CDATA "&#186;" -- masculine ordinal indicator, + U+00BA ISOnum --> +<!ENTITY raquo CDATA "&#187;" -- right-pointing double angle quotation mark + = right pointing guillemet, U+00BB ISOnum --> +<!ENTITY frac14 CDATA "&#188;" -- vulgar fraction one quarter + = fraction one quarter, U+00BC ISOnum --> +<!ENTITY frac12 CDATA "&#189;" -- vulgar fraction one half + = fraction one half, U+00BD ISOnum --> +<!ENTITY frac34 CDATA "&#190;" -- vulgar fraction three quarters + = fraction three quarters, U+00BE ISOnum --> +<!ENTITY iquest CDATA "&#191;" -- inverted question mark + = turned question mark, U+00BF ISOnum --> +<!ENTITY Agrave CDATA "&#192;" -- latin capital letter A with grave + = latin capital letter A grave, + U+00C0 ISOlat1 --> +<!ENTITY Aacute CDATA "&#193;" -- latin capital letter A with acute, + U+00C1 ISOlat1 --> +<!ENTITY Acirc CDATA "&#194;" -- latin capital letter A with circumflex, + U+00C2 ISOlat1 --> +<!ENTITY Atilde CDATA "&#195;" -- latin capital letter A with tilde, + U+00C3 ISOlat1 --> +<!ENTITY Auml CDATA "&#196;" -- latin capital letter A with diaeresis, + U+00C4 ISOlat1 --> +<!ENTITY Aring CDATA "&#197;" -- latin capital letter A with ring above + = latin capital letter A ring, + U+00C5 ISOlat1 --> +<!ENTITY AElig CDATA "&#198;" -- latin capital letter AE + = latin capital ligature AE, + U+00C6 ISOlat1 --> +<!ENTITY Ccedil CDATA "&#199;" -- latin capital letter C with cedilla, + U+00C7 ISOlat1 --> +<!ENTITY Egrave CDATA "&#200;" -- latin capital letter E with grave, + U+00C8 ISOlat1 --> +<!ENTITY Eacute CDATA "&#201;" -- latin capital letter E with acute, + U+00C9 ISOlat1 --> +<!ENTITY Ecirc CDATA "&#202;" -- latin capital letter E with circumflex, + U+00CA ISOlat1 --> +<!ENTITY Euml CDATA "&#203;" -- latin capital letter E with diaeresis, + U+00CB ISOlat1 --> +<!ENTITY Igrave CDATA "&#204;" -- latin capital letter I with grave, + U+00CC ISOlat1 --> +<!ENTITY Iacute CDATA "&#205;" -- latin capital letter I with acute, + U+00CD ISOlat1 --> +<!ENTITY Icirc CDATA "&#206;" -- latin capital letter I with circumflex, + U+00CE ISOlat1 --> +<!ENTITY Iuml CDATA "&#207;" -- latin capital letter I with diaeresis, + U+00CF ISOlat1 --> +<!ENTITY ETH CDATA "&#208;" -- latin capital letter ETH, U+00D0 ISOlat1 --> +<!ENTITY Ntilde CDATA "&#209;" -- latin capital letter N with tilde, + U+00D1 ISOlat1 --> +<!ENTITY Ograve CDATA "&#210;" -- latin capital letter O with grave, + U+00D2 ISOlat1 --> +<!ENTITY Oacute CDATA "&#211;" -- latin capital letter O with acute, + U+00D3 ISOlat1 --> +<!ENTITY Ocirc CDATA "&#212;" -- latin capital letter O with circumflex, + U+00D4 ISOlat1 --> +<!ENTITY Otilde CDATA "&#213;" -- latin capital letter O with tilde, + U+00D5 ISOlat1 --> +<!ENTITY Ouml CDATA "&#214;" -- latin capital letter O with diaeresis, + U+00D6 ISOlat1 --> +<!ENTITY times CDATA "&#215;" -- multiplication sign, U+00D7 ISOnum --> +<!ENTITY Oslash CDATA "&#216;" -- latin capital letter O with stroke + = latin capital letter O slash, + U+00D8 ISOlat1 --> +<!ENTITY Ugrave CDATA "&#217;" -- latin capital letter U with grave, + U+00D9 ISOlat1 --> +<!ENTITY Uacute CDATA "&#218;" -- latin capital letter U with acute, + U+00DA ISOlat1 --> +<!ENTITY Ucirc CDATA "&#219;" -- latin capital letter U with circumflex, + U+00DB ISOlat1 --> +<!ENTITY Uuml CDATA "&#220;" -- latin capital letter U with diaeresis, + U+00DC ISOlat1 --> +<!ENTITY Yacute CDATA "&#221;" -- latin capital letter Y with acute, + U+00DD ISOlat1 --> +<!ENTITY THORN CDATA "&#222;" -- latin capital letter THORN, + U+00DE ISOlat1 --> +<!ENTITY szlig CDATA "&#223;" -- latin small letter sharp s = ess-zed, + U+00DF ISOlat1 --> +<!ENTITY agrave CDATA "&#224;" -- latin small letter a with grave + = latin small letter a grave, + U+00E0 ISOlat1 --> +<!ENTITY aacute CDATA "&#225;" -- latin small letter a with acute, + U+00E1 ISOlat1 --> +<!ENTITY acirc CDATA "&#226;" -- latin small letter a with circumflex, + U+00E2 ISOlat1 --> +<!ENTITY atilde CDATA "&#227;" -- latin small letter a with tilde, + U+00E3 ISOlat1 --> +<!ENTITY auml CDATA "&#228;" -- latin small letter a with diaeresis, + U+00E4 ISOlat1 --> +<!ENTITY aring CDATA "&#229;" -- latin small letter a with ring above + = latin small letter a ring, + U+00E5 ISOlat1 --> +<!ENTITY aelig CDATA "&#230;" -- latin small letter ae + = latin small ligature ae, U+00E6 ISOlat1 --> +<!ENTITY ccedil CDATA "&#231;" -- latin small letter c with cedilla, + U+00E7 ISOlat1 --> +<!ENTITY egrave CDATA "&#232;" -- latin small letter e with grave, + U+00E8 ISOlat1 --> +<!ENTITY eacute CDATA "&#233;" -- latin small letter e with acute, + U+00E9 ISOlat1 --> +<!ENTITY ecirc CDATA "&#234;" -- latin small letter e with circumflex, + U+00EA ISOlat1 --> +<!ENTITY euml CDATA "&#235;" -- latin small letter e with diaeresis, + U+00EB ISOlat1 --> +<!ENTITY igrave CDATA "&#236;" -- latin small letter i with grave, + U+00EC ISOlat1 --> +<!ENTITY iacute CDATA "&#237;" -- latin small letter i with acute, + U+00ED ISOlat1 --> +<!ENTITY icirc CDATA "&#238;" -- latin small letter i with circumflex, + U+00EE ISOlat1 --> +<!ENTITY iuml CDATA "&#239;" -- latin small letter i with diaeresis, + U+00EF ISOlat1 --> +<!ENTITY eth CDATA "&#240;" -- latin small letter eth, U+00F0 ISOlat1 --> +<!ENTITY ntilde CDATA "&#241;" -- latin small letter n with tilde, + U+00F1 ISOlat1 --> +<!ENTITY ograve CDATA "&#242;" -- latin small letter o with grave, + U+00F2 ISOlat1 --> +<!ENTITY oacute CDATA "&#243;" -- latin small letter o with acute, + U+00F3 ISOlat1 --> +<!ENTITY ocirc CDATA "&#244;" -- latin small letter o with circumflex, + U+00F4 ISOlat1 --> +<!ENTITY otilde CDATA "&#245;" -- latin small letter o with tilde, + U+00F5 ISOlat1 --> +<!ENTITY ouml CDATA "&#246;" -- latin small letter o with diaeresis, + U+00F6 ISOlat1 --> +<!ENTITY divide CDATA "&#247;" -- division sign, U+00F7 ISOnum --> +<!ENTITY oslash CDATA "&#248;" -- latin small letter o with stroke, + = latin small letter o slash, + U+00F8 ISOlat1 --> +<!ENTITY ugrave CDATA "&#249;" -- latin small letter u with grave, + U+00F9 ISOlat1 --> +<!ENTITY uacute CDATA "&#250;" -- latin small letter u with acute, + U+00FA ISOlat1 --> +<!ENTITY ucirc CDATA "&#251;" -- latin small letter u with circumflex, + U+00FB ISOlat1 --> +<!ENTITY uuml CDATA "&#252;" -- latin small letter u with diaeresis, + U+00FC ISOlat1 --> +<!ENTITY yacute CDATA "&#253;" -- latin small letter y with acute, + U+00FD ISOlat1 --> +<!ENTITY thorn CDATA "&#254;" -- latin small letter thorn, + U+00FE ISOlat1 --> +<!ENTITY yuml CDATA "&#255;" -- latin small letter y with diaeresis, + U+00FF ISOlat1 --> +</pre> +</div> + +<h2><a name="h-24.3">24.3</a> <a name="sym">Character entity references for +symbols, mathematical symbols, and Greek letters</a></h2> + +<p>The character entity references in this section produce characters that may +be represented by glyphs in the widely available Adobe Symbol font, including +Greek characters, various bracketing symbols, and a selection of mathematical +operators such as gradient, product, and summation symbols.</p> + +<p>To support these entities, user agents may support full <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> or use +other means. Display of glyphs for these characters may be obtained by being +able to display the relevant <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> characters or +by other means, such as internally mapping the listed entities, numeric +character references, and characters to the appropriate position in some font +that contains the requisite glyphs.</p> + +<div class="note"> +<p><em><strong>When to use Greek entities.</strong> This entity set contains +all the letters used in modern Greek. However, it does not include Greek +punctuation, precomposed accented characters nor the non-spacing accents +(tonos, dialytika) required to compose them. There are no archaic letters, +Coptic-unique letters, or precomposed letters for Polytonic Greek. The entities +defined here are not intended for the representation of modern Greek text and +would not be an efficient representation; rather, they are intended for +occasional Greek letters used in technical and mathematical works.</em></p> +</div> + +<h3><a name="h-24.3.1">24.3.1</a> The list of characters</h3> + +<div class="dtd-fragment"> +<pre><!-- Mathematical, Greek and Symbolic characters for HTML --> + +<!-- Character entity set. Typical invocation: + <!ENTITY % HTMLsymbol PUBLIC + "-//W3C//ENTITIES Symbols//EN//HTML"> + %HTMLsymbol; --> + +<!-- Portions © International Organization for Standardization 1986: + Permission to copy in any form is granted for use with + conforming SGML systems and applications as defined in + ISO 8879, provided this notice is included in all copies. +--> + +<!-- Relevant ISO entity set is given unless names are newly introduced. + New names (i.e., not in ISO 8879 list) do not clash with any + existing ISO 8879 entity names. ISO 10646 character numbers + are given for each character, in hex. CDATA values are decimal + conversions of the ISO 10646 values and refer to the document + character set. Names are ISO 10646 names. + +--> + +<!-- Latin Extended-B --> +<!ENTITY fnof CDATA "&#402;" -- latin small f with hook = function + = florin, U+0192 ISOtech --> + +<!-- Greek --> +<!ENTITY Alpha CDATA "&#913;" -- greek capital letter alpha, U+0391 --> +<!ENTITY Beta CDATA "&#914;" -- greek capital letter beta, U+0392 --> +<!ENTITY Gamma CDATA "&#915;" -- greek capital letter gamma, + U+0393 ISOgrk3 --> +<!ENTITY Delta CDATA "&#916;" -- greek capital letter delta, + U+0394 ISOgrk3 --> +<!ENTITY Epsilon CDATA "&#917;" -- greek capital letter epsilon, U+0395 --> +<!ENTITY Zeta CDATA "&#918;" -- greek capital letter zeta, U+0396 --> +<!ENTITY Eta CDATA "&#919;" -- greek capital letter eta, U+0397 --> +<!ENTITY Theta CDATA "&#920;" -- greek capital letter theta, + U+0398 ISOgrk3 --> +<!ENTITY Iota CDATA "&#921;" -- greek capital letter iota, U+0399 --> +<!ENTITY Kappa CDATA "&#922;" -- greek capital letter kappa, U+039A --> +<!ENTITY Lambda CDATA "&#923;" -- greek capital letter lambda, + U+039B ISOgrk3 --> +<!ENTITY Mu CDATA "&#924;" -- greek capital letter mu, U+039C --> +<!ENTITY Nu CDATA "&#925;" -- greek capital letter nu, U+039D --> +<!ENTITY Xi CDATA "&#926;" -- greek capital letter xi, U+039E ISOgrk3 --> +<!ENTITY Omicron CDATA "&#927;" -- greek capital letter omicron, U+039F --> +<!ENTITY Pi CDATA "&#928;" -- greek capital letter pi, U+03A0 ISOgrk3 --> +<!ENTITY Rho CDATA "&#929;" -- greek capital letter rho, U+03A1 --> +<!-- there is no Sigmaf, and no U+03A2 character either --> +<!ENTITY Sigma CDATA "&#931;" -- greek capital letter sigma, + U+03A3 ISOgrk3 --> +<!ENTITY Tau CDATA "&#932;" -- greek capital letter tau, U+03A4 --> +<!ENTITY Upsilon CDATA "&#933;" -- greek capital letter upsilon, + U+03A5 ISOgrk3 --> +<!ENTITY Phi CDATA "&#934;" -- greek capital letter phi, + U+03A6 ISOgrk3 --> +<!ENTITY Chi CDATA "&#935;" -- greek capital letter chi, U+03A7 --> +<!ENTITY Psi CDATA "&#936;" -- greek capital letter psi, + U+03A8 ISOgrk3 --> +<!ENTITY Omega CDATA "&#937;" -- greek capital letter omega, + U+03A9 ISOgrk3 --> + +<!ENTITY alpha CDATA "&#945;" -- greek small letter alpha, + U+03B1 ISOgrk3 --> +<!ENTITY beta CDATA "&#946;" -- greek small letter beta, U+03B2 ISOgrk3 --> +<!ENTITY gamma CDATA "&#947;" -- greek small letter gamma, + U+03B3 ISOgrk3 --> +<!ENTITY delta CDATA "&#948;" -- greek small letter delta, + U+03B4 ISOgrk3 --> +<!ENTITY epsilon CDATA "&#949;" -- greek small letter epsilon, + U+03B5 ISOgrk3 --> +<!ENTITY zeta CDATA "&#950;" -- greek small letter zeta, U+03B6 ISOgrk3 --> +<!ENTITY eta CDATA "&#951;" -- greek small letter eta, U+03B7 ISOgrk3 --> +<!ENTITY theta CDATA "&#952;" -- greek small letter theta, + U+03B8 ISOgrk3 --> +<!ENTITY iota CDATA "&#953;" -- greek small letter iota, U+03B9 ISOgrk3 --> +<!ENTITY kappa CDATA "&#954;" -- greek small letter kappa, + U+03BA ISOgrk3 --> +<!ENTITY lambda CDATA "&#955;" -- greek small letter lambda, + U+03BB ISOgrk3 --> +<!ENTITY mu CDATA "&#956;" -- greek small letter mu, U+03BC ISOgrk3 --> +<!ENTITY nu CDATA "&#957;" -- greek small letter nu, U+03BD ISOgrk3 --> +<!ENTITY xi CDATA "&#958;" -- greek small letter xi, U+03BE ISOgrk3 --> +<!ENTITY omicron CDATA "&#959;" -- greek small letter omicron, U+03BF NEW --> +<!ENTITY pi CDATA "&#960;" -- greek small letter pi, U+03C0 ISOgrk3 --> +<!ENTITY rho CDATA "&#961;" -- greek small letter rho, U+03C1 ISOgrk3 --> +<!ENTITY sigmaf CDATA "&#962;" -- greek small letter final sigma, + U+03C2 ISOgrk3 --> +<!ENTITY sigma CDATA "&#963;" -- greek small letter sigma, + U+03C3 ISOgrk3 --> +<!ENTITY tau CDATA "&#964;" -- greek small letter tau, U+03C4 ISOgrk3 --> +<!ENTITY upsilon CDATA "&#965;" -- greek small letter upsilon, + U+03C5 ISOgrk3 --> +<!ENTITY phi CDATA "&#966;" -- greek small letter phi, U+03C6 ISOgrk3 --> +<!ENTITY chi CDATA "&#967;" -- greek small letter chi, U+03C7 ISOgrk3 --> +<!ENTITY psi CDATA "&#968;" -- greek small letter psi, U+03C8 ISOgrk3 --> +<!ENTITY omega CDATA "&#969;" -- greek small letter omega, + U+03C9 ISOgrk3 --> +<!ENTITY thetasym CDATA "&#977;" -- greek small letter theta symbol, + U+03D1 NEW --> +<!ENTITY upsih CDATA "&#978;" -- greek upsilon with hook symbol, + U+03D2 NEW --> +<!ENTITY piv CDATA "&#982;" -- greek pi symbol, U+03D6 ISOgrk3 --> + +<!-- General Punctuation --> +<!ENTITY bull CDATA "&#8226;" -- bullet = black small circle, + U+2022 ISOpub --> +<!-- bullet is NOT the same as bullet operator, U+2219 --> +<!ENTITY hellip CDATA "&#8230;" -- horizontal ellipsis = three dot leader, + U+2026 ISOpub --> +<!ENTITY prime CDATA "&#8242;" -- prime = minutes = feet, U+2032 ISOtech --> +<!ENTITY Prime CDATA "&#8243;" -- double prime = seconds = inches, + U+2033 ISOtech --> +<!ENTITY oline CDATA "&#8254;" -- overline = spacing overscore, + U+203E NEW --> +<!ENTITY frasl CDATA "&#8260;" -- fraction slash, U+2044 NEW --> + +<!-- Letterlike Symbols --> +<!ENTITY weierp CDATA "&#8472;" -- script capital P = power set + = Weierstrass p, U+2118 ISOamso --> +<!ENTITY image CDATA "&#8465;" -- blackletter capital I = imaginary part, + U+2111 ISOamso --> +<!ENTITY real CDATA "&#8476;" -- blackletter capital R = real part symbol, + U+211C ISOamso --> +<!ENTITY trade CDATA "&#8482;" -- trade mark sign, U+2122 ISOnum --> +<!ENTITY alefsym CDATA "&#8501;" -- alef symbol = first transfinite cardinal, + U+2135 NEW --> +<!-- alef symbol is NOT the same as hebrew letter alef, + U+05D0 although the same glyph could be used to depict both characters --> + +<!-- Arrows --> +<!ENTITY larr CDATA "&#8592;" -- leftwards arrow, U+2190 ISOnum --> +<!ENTITY uarr CDATA "&#8593;" -- upwards arrow, U+2191 ISOnum--> +<!ENTITY rarr CDATA "&#8594;" -- rightwards arrow, U+2192 ISOnum --> +<!ENTITY darr CDATA "&#8595;" -- downwards arrow, U+2193 ISOnum --> +<!ENTITY harr CDATA "&#8596;" -- left right arrow, U+2194 ISOamsa --> +<!ENTITY crarr CDATA "&#8629;" -- downwards arrow with corner leftwards + = carriage return, U+21B5 NEW --> +<!ENTITY lArr CDATA "&#8656;" -- leftwards double arrow, U+21D0 ISOtech --> +<!-- ISO 10646 does not say that lArr is the same as the 'is implied by' arrow + but also does not have any other character for that function. So ? lArr can + be used for 'is implied by' as ISOtech suggests --> +<!ENTITY uArr CDATA "&#8657;" -- upwards double arrow, U+21D1 ISOamsa --> +<!ENTITY rArr CDATA "&#8658;" -- rightwards double arrow, + U+21D2 ISOtech --> +<!-- ISO 10646 does not say this is the 'implies' character but does not have + another character with this function so ? + rArr can be used for 'implies' as ISOtech suggests --> +<!ENTITY dArr CDATA "&#8659;" -- downwards double arrow, U+21D3 ISOamsa --> +<!ENTITY hArr CDATA "&#8660;" -- left right double arrow, + U+21D4 ISOamsa --> + +<!-- Mathematical Operators --> +<!ENTITY forall CDATA "&#8704;" -- for all, U+2200 ISOtech --> +<!ENTITY part CDATA "&#8706;" -- partial differential, U+2202 ISOtech --> +<!ENTITY exist CDATA "&#8707;" -- there exists, U+2203 ISOtech --> +<!ENTITY empty CDATA "&#8709;" -- empty set = null set = diameter, + U+2205 ISOamso --> +<!ENTITY nabla CDATA "&#8711;" -- nabla = backward difference, + U+2207 ISOtech --> +<!ENTITY isin CDATA "&#8712;" -- element of, U+2208 ISOtech --> +<!ENTITY notin CDATA "&#8713;" -- not an element of, U+2209 ISOtech --> +<!ENTITY ni CDATA "&#8715;" -- contains as member, U+220B ISOtech --> +<!-- should there be a more memorable name than 'ni'? --> +<!ENTITY prod CDATA "&#8719;" -- n-ary product = product sign, + U+220F ISOamsb --> +<!-- prod is NOT the same character as U+03A0 'greek capital letter pi' though + the same glyph might be used for both --> +<!ENTITY sum CDATA "&#8721;" -- n-ary sumation, U+2211 ISOamsb --> +<!-- sum is NOT the same character as U+03A3 'greek capital letter sigma' + though the same glyph might be used for both --> +<!ENTITY minus CDATA "&#8722;" -- minus sign, U+2212 ISOtech --> +<!ENTITY lowast CDATA "&#8727;" -- asterisk operator, U+2217 ISOtech --> +<!ENTITY radic CDATA "&#8730;" -- square root = radical sign, + U+221A ISOtech --> +<!ENTITY prop CDATA "&#8733;" -- proportional to, U+221D ISOtech --> +<!ENTITY infin CDATA "&#8734;" -- infinity, U+221E ISOtech --> +<!ENTITY ang CDATA "&#8736;" -- angle, U+2220 ISOamso --> +<!ENTITY and CDATA "&#8743;" -- logical and = wedge, U+2227 ISOtech --> +<!ENTITY or CDATA "&#8744;" -- logical or = vee, U+2228 ISOtech --> +<!ENTITY cap CDATA "&#8745;" -- intersection = cap, U+2229 ISOtech --> +<!ENTITY cup CDATA "&#8746;" -- union = cup, U+222A ISOtech --> +<!ENTITY int CDATA "&#8747;" -- integral, U+222B ISOtech --> +<!ENTITY there4 CDATA "&#8756;" -- therefore, U+2234 ISOtech --> +<!ENTITY sim CDATA "&#8764;" -- tilde operator = varies with = similar to, + U+223C ISOtech --> +<!-- tilde operator is NOT the same character as the tilde, U+007E, + although the same glyph might be used to represent both --> +<!ENTITY cong CDATA "&#8773;" -- approximately equal to, U+2245 ISOtech --> +<!ENTITY asymp CDATA "&#8776;" -- almost equal to = asymptotic to, + U+2248 ISOamsr --> +<!ENTITY ne CDATA "&#8800;" -- not equal to, U+2260 ISOtech --> +<!ENTITY equiv CDATA "&#8801;" -- identical to, U+2261 ISOtech --> +<!ENTITY le CDATA "&#8804;" -- less-than or equal to, U+2264 ISOtech --> +<!ENTITY ge CDATA "&#8805;" -- greater-than or equal to, + U+2265 ISOtech --> +<!ENTITY sub CDATA "&#8834;" -- subset of, U+2282 ISOtech --> +<!ENTITY sup CDATA "&#8835;" -- superset of, U+2283 ISOtech --> +<!-- note that nsup, 'not a superset of, U+2283' is not covered by the Symbol + font encoding and is not included. Should it be, for symmetry? + It is in ISOamsn --> +<!ENTITY nsub CDATA "&#8836;" -- not a subset of, U+2284 ISOamsn --> +<!ENTITY sube CDATA "&#8838;" -- subset of or equal to, U+2286 ISOtech --> +<!ENTITY supe CDATA "&#8839;" -- superset of or equal to, + U+2287 ISOtech --> +<!ENTITY oplus CDATA "&#8853;" -- circled plus = direct sum, + U+2295 ISOamsb --> +<!ENTITY otimes CDATA "&#8855;" -- circled times = vector product, + U+2297 ISOamsb --> +<!ENTITY perp CDATA "&#8869;" -- up tack = orthogonal to = perpendicular, + U+22A5 ISOtech --> +<!ENTITY sdot CDATA "&#8901;" -- dot operator, U+22C5 ISOamsb --> +<!-- dot operator is NOT the same character as U+00B7 middle dot --> + +<!-- Miscellaneous Technical --> +<!ENTITY lceil CDATA "&#8968;" -- left ceiling = apl upstile, + U+2308 ISOamsc --> +<!ENTITY rceil CDATA "&#8969;" -- right ceiling, U+2309 ISOamsc --> +<!ENTITY lfloor CDATA "&#8970;" -- left floor = apl downstile, + U+230A ISOamsc --> +<!ENTITY rfloor CDATA "&#8971;" -- right floor, U+230B ISOamsc --> +<!ENTITY lang CDATA "&#9001;" -- left-pointing angle bracket = bra, + U+2329 ISOtech --> +<!-- lang is NOT the same character as U+003C 'less than' + or U+2039 'single left-pointing angle quotation mark' --> +<!ENTITY rang CDATA "&#9002;" -- right-pointing angle bracket = ket, + U+232A ISOtech --> +<!-- rang is NOT the same character as U+003E 'greater than' + or U+203A 'single right-pointing angle quotation mark' --> + +<!-- Geometric Shapes --> +<!ENTITY loz CDATA "&#9674;" -- lozenge, U+25CA ISOpub --> + +<!-- Miscellaneous Symbols --> +<!ENTITY spades CDATA "&#9824;" -- black spade suit, U+2660 ISOpub --> +<!-- black here seems to mean filled as opposed to hollow --> +<!ENTITY clubs CDATA "&#9827;" -- black club suit = shamrock, + U+2663 ISOpub --> +<!ENTITY hearts CDATA "&#9829;" -- black heart suit = valentine, + U+2665 ISOpub --> +<!ENTITY diams CDATA "&#9830;" -- black diamond suit, U+2666 ISOpub --> +</pre> +</div> + +<h2><a name="h-24.4">24.4</a> <a name="misc">Character entity references for +markup-significant and internationalization characters</a></h2> + +<p>The character entity references in this section are for escaping +markup-significant characters (these are the same as those in HTML 2.0 and +3.2), for denoting spaces and dashes. Other characters in this section apply to +internationalization issues such as the disambiguation of bidirectional text +(see the section on <a href="http://www.w3.org/TR/REC-html40/struct/dirlang.html#bidirection">bidirectional +text</a> for details).</p> + +<p>Entities have also been added for the remaining characters occurring in +CP-1252 which do not occur in the HTMLlat1 or HTMLsymbol entity sets. These all +occur in the 128 to 159 range within the CP-1252 charset. These entities permit +the characters to be denoted in a platform-independent manner.</p> + +<p>To support these entities, user agents may support full <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> or use +other means. Display of glyphs for these characters may be obtained by being +able to display the relevant <a rel="biblioentry" href="http://www.w3.org/TR/REC-html40/references.html#ref-ISO10646" class="normref">[ISO10646]</a> characters or +by other means, such as internally mapping the listed entities, numeric +character references, and characters to the appropriate position in some font +that contains the requisite glyphs.</p> + +<h3><a name="h-24.4.1">24.4.1</a> The list of characters</h3> + +<div class="dtd-fragment"> +<pre><!-- Special characters for HTML --> + +<!-- Character entity set. Typical invocation: + <!ENTITY % HTMLspecial PUBLIC + "-//W3C//ENTITIES Special//EN//HTML"> + %HTMLspecial; --> + +<!-- Portions © International Organization for Standardization 1986: + Permission to copy in any form is granted for use with + conforming SGML systems and applications as defined in + ISO 8879, provided this notice is included in all copies. +--> + +<!-- Relevant ISO entity set is given unless names are newly introduced. + New names (i.e., not in ISO 8879 list) do not clash with any + existing ISO 8879 entity names. ISO 10646 character numbers + are given for each character, in hex. CDATA values are decimal + conversions of the ISO 10646 values and refer to the document + character set. Names are ISO 10646 names. + +--> + +<!-- C0 Controls and Basic Latin --> +<!ENTITY quot CDATA "&#34;" -- quotation mark = APL quote, + U+0022 ISOnum --> +<!ENTITY amp CDATA "&#38;" -- ampersand, U+0026 ISOnum --> +<!ENTITY lt CDATA "&#60;" -- less-than sign, U+003C ISOnum --> +<!ENTITY gt CDATA "&#62;" -- greater-than sign, U+003E ISOnum --> + +<!-- Latin Extended-A --> +<!ENTITY OElig CDATA "&#338;" -- latin capital ligature OE, + U+0152 ISOlat2 --> +<!ENTITY oelig CDATA "&#339;" -- latin small ligature oe, U+0153 ISOlat2 --> +<!-- ligature is a misnomer, this is a separate character in some languages --> +<!ENTITY Scaron CDATA "&#352;" -- latin capital letter S with caron, + U+0160 ISOlat2 --> +<!ENTITY scaron CDATA "&#353;" -- latin small letter s with caron, + U+0161 ISOlat2 --> +<!ENTITY Yuml CDATA "&#376;" -- latin capital letter Y with diaeresis, + U+0178 ISOlat2 --> + +<!-- Spacing Modifier Letters --> +<!ENTITY circ CDATA "&#710;" -- modifier letter circumflex accent, + U+02C6 ISOpub --> +<!ENTITY tilde CDATA "&#732;" -- small tilde, U+02DC ISOdia --> + +<!-- General Punctuation --> +<!ENTITY ensp CDATA "&#8194;" -- en space, U+2002 ISOpub --> +<!ENTITY emsp CDATA "&#8195;" -- em space, U+2003 ISOpub --> +<!ENTITY thinsp CDATA "&#8201;" -- thin space, U+2009 ISOpub --> +<!ENTITY zwnj CDATA "&#8204;" -- zero width non-joiner, + U+200C NEW RFC 2070 --> +<!ENTITY zwj CDATA "&#8205;" -- zero width joiner, U+200D NEW RFC 2070 --> +<!ENTITY lrm CDATA "&#8206;" -- left-to-right mark, U+200E NEW RFC 2070 --> +<!ENTITY rlm CDATA "&#8207;" -- right-to-left mark, U+200F NEW RFC 2070 --> +<!ENTITY ndash CDATA "&#8211;" -- en dash, U+2013 ISOpub --> +<!ENTITY mdash CDATA "&#8212;" -- em dash, U+2014 ISOpub --> +<!ENTITY lsquo CDATA "&#8216;" -- left single quotation mark, + U+2018 ISOnum --> +<!ENTITY rsquo CDATA "&#8217;" -- right single quotation mark, + U+2019 ISOnum --> +<!ENTITY sbquo CDATA "&#8218;" -- single low-9 quotation mark, U+201A NEW --> +<!ENTITY ldquo CDATA "&#8220;" -- left double quotation mark, + U+201C ISOnum --> +<!ENTITY rdquo CDATA "&#8221;" -- right double quotation mark, + U+201D ISOnum --> +<!ENTITY bdquo CDATA "&#8222;" -- double low-9 quotation mark, U+201E NEW --> +<!ENTITY dagger CDATA "&#8224;" -- dagger, U+2020 ISOpub --> +<!ENTITY Dagger CDATA "&#8225;" -- double dagger, U+2021 ISOpub --> +<!ENTITY permil CDATA "&#8240;" -- per mille sign, U+2030 ISOtech --> +<!ENTITY lsaquo CDATA "&#8249;" -- single left-pointing angle quotation mark, + U+2039 ISO proposed --> +<!-- lsaquo is proposed but not yet ISO standardized --> +<!ENTITY rsaquo CDATA "&#8250;" -- single right-pointing angle quotation mark, + U+203A ISO proposed --> +<!-- rsaquo is proposed but not yet ISO standardized --> +<!ENTITY euro CDATA "&#8364;" -- euro sign, U+20AC NEW --> +</pre> +</div> + +<div class="navbar" align="center"> +<hr><a href="http://www.w3.org/TR/REC-html40/sgml/framesetdtd.html">previous</a> <a href="http://www.w3.org/TR/REC-html40/appendix/changes.html">next</a> <a href="http://www.w3.org/TR/REC-html40/cover.html#minitoc"> +contents</a> <a href="http://www.w3.org/TR/REC-html40/index/elements.html">elements</a> <a href="http://www.w3.org/TR/REC-html40/index/attributes.html">attributes</a> <a href="http://www.w3.org/TR/REC-html40/index/list.html">index</a></div> </body></html>
\ No newline at end of file diff --git a/Build/source/libs/gd/libgd-src/src/entities.tcl b/Build/source/libs/gd/libgd-src/src/entities.tcl index 29f87dbc977..1f7c9e7e4af 100644 --- a/Build/source/libs/gd/libgd-src/src/entities.tcl +++ b/Build/source/libs/gd/libgd-src/src/entities.tcl @@ -1,50 +1,50 @@ -#!/usr/bin/tclsh
-
-# get names for html-4.0 characters from:
-# http://www.w3.org/TR/REC-html40/sgml/entities.html
-set f [open entities.html r]
-set entity_name_length_max 0
-set nr_of_entities 0
-while {! [eof $f]} {
- set rec [gets $f]
- if {[scan $rec {<!ENTITY %s CDATA "&#%d;"; --} name val] == 2} {
- set entity($name) $val
- set entity_name_length [string length $name]
- if {$entity_name_length > $entity_name_length_max} {
- set entity_name_length_max $entity_name_length
- }
- incr nr_of_entities
- }
-}
-close $f
-
-set f [open entities.h w]
-puts $f "/*"
-puts $f " * Generated file - do not edit directly."
-puts $f " *"
-puts $f " * This file was generated from:"
-puts $f " * http://www.w3.org/TR/REC-html40/sgml/entities.html"
-puts $f " * by means of the script:"
-puts $f " * entities.tcl"
-puts $f " */"
-puts $f ""
-puts $f "#ifdef __cplusplus"
-puts $f "extern \"C\" {"
-puts $f "#endif"
-puts $f ""
-puts $f "static struct entities_s {"
-puts $f " char *name;"
-puts $f " int value;"
-puts $f "} entities\[\] = {"
-foreach name [lsort [array names entity]] {
- puts $f " {\"$name\", $entity($name)},"
-}
-puts $f "};"
-puts $f ""
-puts $f "#define ENTITY_NAME_LENGTH_MAX $entity_name_length_max"
-puts $f "#define NR_OF_ENTITIES $nr_of_entities"
-puts $f ""
-puts $f "#ifdef __cplusplus"
-puts $f "}"
-puts $f "#endif"
-close $f
+#!/usr/bin/tclsh + +# get names for html-4.0 characters from: +# http://www.w3.org/TR/REC-html40/sgml/entities.html +set f [open entities.html r] +set entity_name_length_max 0 +set nr_of_entities 0 +while {! [eof $f]} { + set rec [gets $f] + if {[scan $rec {<!ENTITY %s CDATA "&#%d;"; --} name val] == 2} { + set entity($name) $val + set entity_name_length [string length $name] + if {$entity_name_length > $entity_name_length_max} { + set entity_name_length_max $entity_name_length + } + incr nr_of_entities + } +} +close $f + +set f [open entities.h w] +puts $f "/*" +puts $f " * Generated file - do not edit directly." +puts $f " *" +puts $f " * This file was generated from:" +puts $f " * http://www.w3.org/TR/REC-html40/sgml/entities.html" +puts $f " * by means of the script:" +puts $f " * entities.tcl" +puts $f " */" +puts $f "" +puts $f "#ifdef __cplusplus" +puts $f "extern \"C\" {" +puts $f "#endif" +puts $f "" +puts $f "static struct entities_s {" +puts $f " char *name;" +puts $f " int value;" +puts $f "} entities\[\] = {" +foreach name [lsort [array names entity]] { + puts $f " {\"$name\", $entity($name)}," +} +puts $f "};" +puts $f "" +puts $f "#define ENTITY_NAME_LENGTH_MAX $entity_name_length_max" +puts $f "#define NR_OF_ENTITIES $nr_of_entities" +puts $f "" +puts $f "#ifdef __cplusplus" +puts $f "}" +puts $f "#endif" +close $f diff --git a/Build/source/libs/gd/libgd-src/src/gd.c b/Build/source/libs/gd/libgd-src/src/gd.c index 053873b4d97..f0fc40ede11 100644 --- a/Build/source/libs/gd/libgd-src/src/gd.c +++ b/Build/source/libs/gd/libgd-src/src/gd.c @@ -96,12 +96,19 @@ void gd_stderr_error(int priority, const char *format, va_list args) static gdErrorMethod gd_error_method = gd_stderr_error; +static void _gd_error_ex(int priority, const char *format, va_list args) +{ + if (gd_error_method) { + gd_error_method(priority, format, args); + } +} + void gd_error(const char *format, ...) { va_list args; va_start(args, format); - gd_error_ex(GD_WARNING, format, args); + _gd_error_ex(GD_WARNING, format, args); va_end(args); } void gd_error_ex(int priority, const char *format, ...) @@ -109,17 +116,21 @@ void gd_error_ex(int priority, const char *format, ...) va_list args; va_start(args, format); - if (gd_error_method) { - gd_error_method(priority, format, args); - } + _gd_error_ex(priority, format, args); va_end(args); } +/* + Function: gdSetErrorMethod +*/ BGD_DECLARE(void) gdSetErrorMethod(gdErrorMethod error_method) { gd_error_method = error_method; } +/* + Function: gdClearErrorMethod +*/ BGD_DECLARE(void) gdClearErrorMethod(void) { gd_error_method = gd_stderr_error; @@ -127,6 +138,10 @@ BGD_DECLARE(void) gdClearErrorMethod(void) static void gdImageBrushApply (gdImagePtr im, int x, int y); static void gdImageTileApply (gdImagePtr im, int x, int y); + +/* + Function: gdImageGetTrueColorPixel +*/ BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y); @@ -272,7 +287,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateTrueColor (int sx, int sy) return 0; } - if (overflow2(sizeof(int), sx)) { + if (overflow2(sizeof(int *), sx)) { return NULL; } @@ -380,11 +395,17 @@ BGD_DECLARE(void) gdImageDestroy (gdImagePtr im) gdFree (im); } +/* + Function: gdImageColorClosest +*/ BGD_DECLARE(int) gdImageColorClosest (gdImagePtr im, int r, int g, int b) { return gdImageColorClosestAlpha (im, r, g, b, gdAlphaOpaque); } +/* + Function: gdImageColorClosestAlpha +*/ BGD_DECLARE(int) gdImageColorClosestAlpha (gdImagePtr im, int r, int g, int b, int a) { int i; @@ -552,6 +573,9 @@ HWB_to_RGB (HWBType HWB, RGBType * RGB) } #endif +/* + Function: gdImageColorClosestHWB +*/ BGD_DECLARE(int) gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b) { int i; @@ -577,11 +601,17 @@ BGD_DECLARE(int) gdImageColorClosestHWB (gdImagePtr im, int r, int g, int b) return ct; } +/* + Function: gdImageColorExact +*/ BGD_DECLARE(int) gdImageColorExact (gdImagePtr im, int r, int g, int b) { return gdImageColorExactAlpha (im, r, g, b, gdAlphaOpaque); } +/* + Function: gdImageColorExactAlpha +*/ BGD_DECLARE(int) gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int a) { int i; @@ -600,11 +630,17 @@ BGD_DECLARE(int) gdImageColorExactAlpha (gdImagePtr im, int r, int g, int b, int return -1; } +/* + Function: gdImageColorAllocate +*/ BGD_DECLARE(int) gdImageColorAllocate (gdImagePtr im, int r, int g, int b) { return gdImageColorAllocateAlpha (im, r, g, b, gdAlphaOpaque); } +/* + Function: gdImageColorAllocateAlpha +*/ BGD_DECLARE(int) gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, int a) { int i; @@ -634,21 +670,24 @@ BGD_DECLARE(int) gdImageColorAllocateAlpha (gdImagePtr im, int r, int g, int b, } /* - * gdImageColorResolve is an alternative for the code fragment: - * - * if ((color=gdImageColorExact(im,R,G,B)) < 0) - * if ((color=gdImageColorAllocate(im,R,G,B)) < 0) - * color=gdImageColorClosest(im,R,G,B); - * - * in a single function. Its advantage is that it is guaranteed to - * return a color index in one search over the color table. - */ + Function: gdImageColorResolve + + gdImageColorResolve is an alternative for the code fragment + | if ((color=gdImageColorExact(im,R,G,B)) < 0) + | if ((color=gdImageColorAllocate(im,R,G,B)) < 0) + | color=gdImageColorClosest(im,R,G,B); + in a single function. Its advantage is that it is guaranteed to + return a color index in one search over the color table. +*/ BGD_DECLARE(int) gdImageColorResolve (gdImagePtr im, int r, int g, int b) { return gdImageColorResolveAlpha (im, r, g, b, gdAlphaOpaque); } +/* + Function: gdImageColorResolveAlpha +*/ BGD_DECLARE(int) gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, int a) { int c; @@ -700,6 +739,9 @@ BGD_DECLARE(int) gdImageColorResolveAlpha (gdImagePtr im, int r, int g, int b, i return op; /* Return newly allocated color */ } +/* + Function: gdImageColorDeallocate +*/ BGD_DECLARE(void) gdImageColorDeallocate (gdImagePtr im, int color) { if (im->trueColor || (color >= gdMaxColors) || (color < 0)) { @@ -709,8 +751,15 @@ BGD_DECLARE(void) gdImageColorDeallocate (gdImagePtr im, int color) im->open[color] = 1; } +/* + Function: gdImageColorTransparent +*/ BGD_DECLARE(void) gdImageColorTransparent (gdImagePtr im, int color) { + if (color < 0) { + return; + } + if (!im->trueColor) { if((color < -1) || (color >= gdMaxColors)) { return; @@ -725,6 +774,9 @@ BGD_DECLARE(void) gdImageColorTransparent (gdImagePtr im, int color) im->transparent = color; } +/* + Function: gdImagePaletteCopy +*/ BGD_DECLARE(void) gdImagePaletteCopy (gdImagePtr to, gdImagePtr from) { int i; @@ -777,6 +829,9 @@ BGD_DECLARE(void) gdImagePaletteCopy (gdImagePtr to, gdImagePtr from) } +/* + Function: gdImageColorReplace +*/ BGD_DECLARE(int) gdImageColorReplace (gdImagePtr im, int src, int dst) { register int x, y; @@ -808,6 +863,9 @@ BGD_DECLARE(int) gdImageColorReplace (gdImagePtr im, int src, int dst) return n; } +/* + Function: gdImageColorReplaceThreshold +*/ BGD_DECLARE(int) gdImageColorReplaceThreshold (gdImagePtr im, int src, int dst, float threshold) { register int x, y; @@ -846,6 +904,9 @@ static int colorCmp (const void *x, const void *y) return (a > b) - (a < b); } +/* + Function: gdImageColorReplaceArray +*/ BGD_DECLARE(int) gdImageColorReplaceArray (gdImagePtr im, int len, int *src, int *dst) { register int x, y; @@ -895,6 +956,9 @@ BGD_DECLARE(int) gdImageColorReplaceArray (gdImagePtr im, int len, int *src, int return n; } +/* + Function: gdImageColorReplaceCallback +*/ BGD_DECLARE(int) gdImageColorReplaceCallback (gdImagePtr im, gdCallbackImageColor callback) { int c, d, n = 0; @@ -1020,6 +1084,9 @@ clip_1d (int *x0, int *y0, int *x1, int *y1, int mindim, int maxdim) /* end of line clipping code */ +/* + Function: gdImageSetPixel +*/ BGD_DECLARE(void) gdImageSetPixel (gdImagePtr im, int x, int y, int color) { int p; @@ -1211,6 +1278,9 @@ gdImageTileApply (gdImagePtr im, int x, int y) } } +/* + Function: gdImageGetPixel +*/ BGD_DECLARE(int) gdImageGetPixel (gdImagePtr im, int x, int y) { if (gdImageBoundsSafeMacro (im, x, y)) { @@ -1224,6 +1294,9 @@ BGD_DECLARE(int) gdImageGetPixel (gdImagePtr im, int x, int y) } } +/* + Function: gdImageGetTrueColorPixel +*/ BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y) { int p = gdImageGetPixel (im, x, y); @@ -1236,19 +1309,26 @@ BGD_DECLARE(int) gdImageGetTrueColorPixel (gdImagePtr im, int x, int y) } } +/* + Function: gdImageAABlend + + NO-OP, kept for library compatibility. +*/ BGD_DECLARE(void) gdImageAABlend (gdImagePtr im) { - /* NO-OP, kept for library compatibility. */ (void)im; } static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col); +static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, + int color); + static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col) { if (im->thick > 1) { int thickhalf = im->thick >> 1; - gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col); + _gdImageFilledHRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col); } else { if (x2 < x1) { int t = x2; @@ -1282,7 +1362,11 @@ static void gdImageVLine(gdImagePtr im, int x, int y1, int y2, int col) return; } -/* Bresenham as presented in Foley & Van Dam */ +/* + Function: gdImageLine + + Bresenham as presented in Foley & Van Dam. +*/ BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color) { int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag; @@ -1325,20 +1409,17 @@ BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, in if (dy <= dx) { /* More-or-less horizontal. use wid for vertical stroke */ /* Doug Claar: watch out for NaN in atan2 (2.0.5) */ - if ((dx == 0) && (dy == 0)) { - wid = 1; + + /* 2.0.12: Michael Schwartz: divide rather than multiply; + TBB: but watch out for /0! */ + double ac = cos (atan2 (dy, dx)); + if (ac != 0) { + wid = thick / ac; } else { - /* 2.0.12: Michael Schwartz: divide rather than multiply; - TBB: but watch out for /0! */ - double ac = cos (atan2 (dy, dx)); - if (ac != 0) { - wid = thick / ac; - } else { - wid = 1; - } - if (wid == 0) { - wid = 1; - } + wid = 1; + } + if (wid == 0) { + wid = 1; } d = 2 * dy - dx; incr1 = 2 * dy; @@ -1453,6 +1534,9 @@ BGD_DECLARE(void) gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, in static void dashedSet (gdImagePtr im, int x, int y, int color, int *onP, int *dashStepP, int wid, int vert); +/* + Function: gdImageDashedLine +*/ BGD_DECLARE(void) gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color) { int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag; @@ -1594,11 +1678,17 @@ dashedSet (gdImagePtr im, int x, int y, int color, *onP = on; } +/* + Function: gdImageBoundsSafe +*/ BGD_DECLARE(int) gdImageBoundsSafe (gdImagePtr im, int x, int y) { return gdImageBoundsSafeMacro (im, x, y); } +/* + Function: gdImageChar +*/ BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color) { int cx, cy; @@ -1625,6 +1715,9 @@ BGD_DECLARE(void) gdImageChar (gdImagePtr im, gdFontPtr f, int x, int y, int c, } } +/* + Function: gdImageCharUp +*/ BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c, int color) { int cx, cy; @@ -1651,6 +1744,9 @@ BGD_DECLARE(void) gdImageCharUp (gdImagePtr im, gdFontPtr f, int x, int y, int c } } +/* + Function: gdImageString +*/ BGD_DECLARE(void) gdImageString (gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color) { @@ -1663,6 +1759,9 @@ BGD_DECLARE(void) gdImageString (gdImagePtr im, gdFontPtr f, } } +/* + Function: gdImageStringUp +*/ BGD_DECLARE(void) gdImageStringUp (gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color) { @@ -1677,6 +1776,9 @@ BGD_DECLARE(void) gdImageStringUp (gdImagePtr im, gdFontPtr f, static int strlen16 (unsigned short *s); +/* + Function: gdImageString16 +*/ BGD_DECLARE(void) gdImageString16 (gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color) { @@ -1689,6 +1791,9 @@ BGD_DECLARE(void) gdImageString16 (gdImagePtr im, gdFontPtr f, } } +/* + Function: gdImageStringUp16 +*/ BGD_DECLARE(void) gdImageStringUp16 (gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color) { @@ -1727,21 +1832,25 @@ lsqrt (long n) /* s and e are integers modulo 360 (degrees), with 0 degrees being the rightmost extreme and degrees changing clockwise. cx and cy are the center in pixels; w and h are the horizontal - and vertical diameter in pixels. Nice interface, but slow. - See gd_arc_f_buggy.c for a better version that doesn't - seem to be bug-free yet. */ + and vertical diameter in pixels. */ +/* + Function: gdImageArc +*/ BGD_DECLARE(void) gdImageArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color) { gdImageFilledArc (im, cx, cy, w, h, s, e, color, gdNoFill); } +/* + Function: gdImageFilledArc +*/ BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color, int style) { - gdPoint pts[3]; - int i; + gdPoint pts[363]; + int i, pti; int lx = 0, ly = 0; int fx = 0, fy = 0; @@ -1771,7 +1880,7 @@ BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, } } - for (i = s; (i <= e); i++) { + for (i = s, pti = 1; (i <= e); i++, pti++) { int x, y; x = ((long) gdCosT[i % 360] * (long) w / (2 * 1024)) + cx; y = ((long) gdSinT[i % 360] * (long) h / (2 * 1024)) + cy; @@ -1780,19 +1889,29 @@ BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, if (style & gdNoFill) { gdImageLine (im, lx, ly, x, y, color); } else { - /* This is expensive! */ - pts[0].x = lx; - pts[0].y = ly; - pts[1].x = x; - pts[1].y = y; - pts[2].x = cx; - pts[2].y = cy; - gdImageFilledPolygon (im, pts, 3, color); + if (y == ly) { + pti--; /* don't add this point */ + if (((i > 270 || i < 90) && x > lx) || ((i > 90 && i < 270) && x < lx)) { + /* replace the old x coord, if increasing on the + right side or decreasing on the left side */ + pts[pti].x = x; + } + } else { + pts[pti].x = x; + pts[pti].y = y; + } } } } else { fx = x; fy = y; + + if (!(style & (gdChord | gdNoFill))) { + pts[0].x = cx; + pts[0].y = cy; + pts[pti].x = x; + pts[pti].y = y; + } } lx = x; ly = y; @@ -1819,10 +1938,17 @@ BGD_DECLARE(void) gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, gdImageLine (im, cx, cy, lx, ly, color); gdImageLine (im, cx, cy, fx, fy, color); } + } else { + pts[pti].x = cx; + pts[pti].y = cy; + gdImageFilledPolygon(im, pts, pti+1, color); } } } +/* + Function: gdImageEllipse +*/ BGD_DECLARE(void) gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c) { int x=0,mx1=0,mx2=0,my1=0,my2=0; @@ -1867,6 +1993,9 @@ BGD_DECLARE(void) gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, in } +/* + Function: gdImageFilledEllipse +*/ BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c) { int x=0,mx1=0,mx2=0,my1=0,my2=0; @@ -1909,20 +2038,20 @@ BGD_DECLARE(void) gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, in rx -=dy; r +=rx; } - if(old_y2!=my2) { - for(i=mx1; i<=mx2; i++) { - gdImageSetPixel(im,i,my1,c); - } - } + if(old_y2!=my2) { for(i=mx1; i<=mx2; i++) { gdImageSetPixel(im,i,my2,c); + gdImageSetPixel(im,i,my1,c); } } old_y2 = my2; } } +/* + Function: gdImageFillToBorder +*/ BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) { int lastBorder; @@ -1931,16 +2060,33 @@ BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int i; int restoreAlphaBleding; - if (border < 0) { + if (border < 0 || color < 0) { /* Refuse to fill to a non-solid border */ return; } + if (!im->trueColor) { + if ((color > (im->colorsTotal - 1)) || (border > (im->colorsTotal - 1)) || (color < 0)) { + return; + } + } + leftLimit = (-1); restoreAlphaBleding = im->alphaBlendingFlag; im->alphaBlendingFlag = 0; + if (x >= im->sx) { + x = im->sx - 1; + } else if (x < 0) { + x = 0; + } + if (y >= im->sy) { + y = im->sy - 1; + } else if (y < 0) { + y = 0; + } + for (i = x; (i >= 0); i--) { if (gdImageGetPixel (im, i, y) == border) { break; @@ -2051,6 +2197,10 @@ struct seg { {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;} static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc); + +/* + Function: gdImageFill +*/ BGD_DECLARE(void) gdImageFill(gdImagePtr im, int x, int y, int nc) { int l, x1, x2, dy; @@ -2204,9 +2354,9 @@ static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc) FILL_PUSH(y+1, x, x, -1); while (sp>stack) { FILL_POP(y, x1, x2, dy); - for (x=x1; x>=0 && (!pts[y + x*wx2] && gdImageGetPixel(im,x,y)==oc); x--) { + for (x=x1; x>=0 && (!pts[y + x*wy2] && gdImageGetPixel(im,x,y)==oc); x--) { nc = gdImageTileGet(im,x,y); - pts[y + x*wx2]=1; + pts[y + x*wy2]=1; gdImageSetPixel(im,x, y, nc); } if (x>=x1) { @@ -2220,13 +2370,13 @@ static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc) } x = x1+1; do { - for (; x<wx2 && (!pts[y + x*wx2] && gdImageGetPixel(im,x, y)==oc) ; x++) { - if (pts[y + x*wx2]) { + for (; x<wx2 && (!pts[y + x*wy2] && gdImageGetPixel(im,x, y)==oc) ; x++) { + if (pts[y + x*wy2]) { /* we should never be here */ break; } nc = gdImageTileGet(im,x,y); - pts[y + x*wx2]=1; + pts[y + x*wy2]=1; gdImageSetPixel(im, x, y, nc); } FILL_PUSH(y, l, x-1, dy); @@ -2235,7 +2385,7 @@ static void _gdImageFillTiled(gdImagePtr im, int x, int y, int nc) FILL_PUSH(y, x2+1, x-1, -dy); } skip: - for (x++; x<=x2 && (pts[y + x*wx2] || gdImageGetPixel(im,x, y)!=oc); x++); + for (x++; x<=x2 && (pts[y + x*wy2] || gdImageGetPixel(im,x, y)!=oc); x++); l = x; } while (x<=x2); } @@ -2244,6 +2394,9 @@ skip: gdFree(stack); } +/* + Function: gdImageRectangle +*/ BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color) { int thick = im->thick; @@ -2253,6 +2406,16 @@ BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y return; } + if (x1 == x2 && y1 == y2) { + gdImageSetPixel(im, x1, y1, color); + return; + } + + if (x1 == x2 || y1 == y2) { + gdImageLine(im, x1, y1, x2, y2, color); + return; + } + if (y2 < y1) { int t; t = y1; @@ -2314,7 +2477,52 @@ BGD_DECLARE(void) gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y } } -BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, +static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, + int color) +{ + int x, y; + + if (x1 == x2 && y1 == y2) { + gdImageSetPixel(im, x1, y1, color); + return; + } + + if (x1 > x2) { + x = x1; + x1 = x2; + x2 = x; + } + + if (y1 > y2) { + y = y1; + y1 = y2; + y2 = y; + } + + if (x1 < 0) { + x1 = 0; + } + + if (x2 >= gdImageSX(im)) { + x2 = gdImageSX(im) - 1; + } + + if (y1 < 0) { + y1 = 0; + } + + if (y2 >= gdImageSY(im)) { + y2 = gdImageSY(im) - 1; + } + + for (x = x1; (x <= x2); x++) { + for (y = y1; (y <= y2); y++) { + gdImageSetPixel (im, x, y, color); + } + } +} + +static void _gdImageFilledVRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color) { int x, y; @@ -2359,6 +2567,18 @@ BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, } } +/* + Function: gdImageFilledRectangle +*/ +BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, + int color) +{ + _gdImageFilledVRectangle(im, x1, y1, x2, y2, color); +} + +/* + Function: gdImageClone +*/ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) { gdImagePtr dst; register int i, x; @@ -2384,7 +2604,7 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) { } for (i = 0; i < src->sy; i++) { for (x = 0; x < src->sx; x++) { - dst->pixels[i][x] = dst->pixels[i][x]; + dst->pixels[i][x] = src->pixels[i][x]; } } } else { @@ -2454,6 +2674,9 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) { return dst; } +/* + Function: gdImageCopy +*/ BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h) { @@ -2541,8 +2764,12 @@ BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dst } } -/* This function is a substitute for real alpha channel operations, - so it doesn't pay attention to the alpha channel. */ +/* + Function: gdImageCopyMerge + + This function is a substitute for real alpha channel operations, + so it doesn't pay attention to the alpha channel. +*/ BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) { @@ -2585,8 +2812,12 @@ BGD_DECLARE(void) gdImageCopyMerge (gdImagePtr dst, gdImagePtr src, int dstX, in } } -/* This function is a substitute for real alpha channel operations, - so it doesn't pay attention to the alpha channel. */ +/* + Function: gdImageCopyMergeGray + + This function is a substitute for real alpha channel operations, + so it doesn't pay attention to the alpha channel. +*/ BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) { @@ -2645,6 +2876,9 @@ BGD_DECLARE(void) gdImageCopyMergeGray (gdImagePtr dst, gdImagePtr src, int dstX } } +/* + Function: gdImageCopyResized +*/ BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) @@ -2781,6 +3015,9 @@ BGD_DECLARE(void) gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, coordinates allow accurate rotation of objects of odd-numbered width or height. */ +/* + Function: gdImageCopyRotated +*/ BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst, gdImagePtr src, double dstX, double dstY, @@ -2864,6 +3101,9 @@ BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst, #define floor2(exp) ((long) exp) /*#define floor2(exp) floor(exp)*/ +/* + Function: gdImageCopyResampled +*/ BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, @@ -2871,78 +3111,77 @@ BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, int dstW, int dstH, int srcW, int srcH) { int x, y; - double sy1, sy2, sx1, sx2; if (!dst->trueColor) { - gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, - srcW, srcH); + gdImageCopyResized (dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); return; } for (y = dstY; (y < dstY + dstH); y++) { - sy1 = ((double) y - (double) dstY) * (double) srcH / (double) dstH; - sy2 = ((double) (y + 1) - (double) dstY) * (double) srcH / - (double) dstH; for (x = dstX; (x < dstX + dstW); x++) { - double sx, sy; - double spixels = 0; - double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; - double alpha_sum = 0.0, contrib_sum = 0.0; - - sx1 = ((double) x - (double) dstX) * (double) srcW / dstW; - sx2 = ((double) (x + 1) - (double) dstX) * (double) srcW / dstW; + float sy1, sy2, sx1, sx2; + float sx, sy; + float spixels = 0.0; + float red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; + float alpha_factor, alpha_sum = 0.0, contrib_sum = 0.0; + sy1 = ((float)(y - dstY)) * (float)srcH / (float)dstH; + sy2 = ((float)(y + 1 - dstY)) * (float) srcH / (float) dstH; sy = sy1; do { - double yportion; - if (floor2 (sy) == floor2 (sy1)) { - yportion = 1.0 - (sy - floor2 (sy)); + float yportion; + if (floorf(sy) == floorf(sy1)) { + yportion = 1.0 - (sy - floorf(sy)); if (yportion > sy2 - sy1) { yportion = sy2 - sy1; } - sy = floor2 (sy); - } else if (sy == floor2 (sy2)) { - yportion = sy2 - floor2 (sy2); + sy = floorf(sy); + } else if (sy == floorf(sy2)) { + yportion = sy2 - floorf(sy2); } else { yportion = 1.0; } + sx1 = ((float)(x - dstX)) * (float) srcW / dstW; + sx2 = ((float)(x + 1 - dstX)) * (float) srcW / dstW; sx = sx1; do { - double xportion; - double pcontribution; + float xportion; + float pcontribution; int p; - if (floor2 (sx) == floor2 (sx1)) { - xportion = 1.0 - (sx - floor2 (sx)); + if (floorf(sx) == floorf(sx1)) { + xportion = 1.0 - (sx - floorf(sx)); if (xportion > sx2 - sx1) { xportion = sx2 - sx1; } - sx = floor2 (sx); - } else if (sx == floor2 (sx2)) { - xportion = sx2 - floor2 (sx2); + sx = floorf(sx); + } else if (sx == floorf(sx2)) { + xportion = sx2 - floorf(sx2); } else { xportion = 1.0; } pcontribution = xportion * yportion; - /* 2.08: previously srcX and srcY were ignored. - Andrew Pattison */ - p = gdImageGetTrueColorPixel (src, - (int) sx + srcX, - (int) sy + srcY); - red += gdTrueColorGetRed (p) * pcontribution; - green += gdTrueColorGetGreen (p) * pcontribution; - blue += gdTrueColorGetBlue (p) * pcontribution; + p = gdImageGetTrueColorPixel(src, (int) sx + srcX, (int) sy + srcY); + + alpha_factor = ((gdAlphaMax - gdTrueColorGetAlpha(p))) * pcontribution; + red += gdTrueColorGetRed (p) * alpha_factor; + green += gdTrueColorGetGreen (p) * alpha_factor; + blue += gdTrueColorGetBlue (p) * alpha_factor; alpha += gdTrueColorGetAlpha (p) * pcontribution; + alpha_sum += alpha_factor; + contrib_sum += pcontribution; spixels += xportion * yportion; sx += 1.0; - } while (sx < sx2); - sy += 1.0; - } while (sy < sy2); + } + while (sx < sx2); + sy += 1.0f; + } + while (sy < sy2); + if (spixels != 0.0) { red /= spixels; green /= spixels; blue /= spixels; alpha /= spixels; - alpha += 0.5; } - if ( alpha_sum != 0.0f) { - if( contrib_sum != 0.0f) { + if ( alpha_sum != 0.0) { + if( contrib_sum != 0.0) { alpha_sum /= contrib_sum; } red /= alpha_sum; @@ -2956,21 +3195,20 @@ BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, if (green > 255.0) { green = 255.0; } - if (blue > 255.0) { + if (blue > 255.0f) { blue = 255.0; } if (alpha > gdAlphaMax) { alpha = gdAlphaMax; } - gdImageSetPixel (dst, - x, y, - gdTrueColorAlpha ((int) red, - (int) green, - (int) blue, (int) alpha)); + gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int) red, (int) green, (int) blue, (int) alpha)); } } } +/* + Function: gdImagePolygon +*/ BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c) { if (n <= 0) { @@ -2982,6 +3220,9 @@ BGD_DECLARE(void) gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c) gdImageOpenPolygon (im, p, n, c); } +/* + Function: gdImageOpenPolygon +*/ BGD_DECLARE(void) gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c) { int i; @@ -3009,6 +3250,9 @@ BGD_DECLARE(void) gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c) /* That could help to adjust intersections to produce a nice */ /* interior_extrema. */ +/* + Function: gdImageFilledPolygon +*/ BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c) { int i; @@ -3063,6 +3307,19 @@ BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int maxy = p[i].y; } } + /* necessary special case: horizontal line */ + if (n > 1 && miny == maxy) { + x1 = x2 = p[0].x; + for (i = 1; (i < n); i++) { + if (p[i].x < x1) { + x1 = p[i].x; + } else if (p[i].x > x2) { + x2 = p[i].x; + } + } + gdImageLine(im, x1, miny, x2, miny, c); + return; + } pmaxy = maxy; /* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */ /* 2.0.26: clipping rectangle is even better */ @@ -3139,6 +3396,9 @@ BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color, int t); +/* + Function: gdImageSetStyle +*/ BGD_DECLARE(void) gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels) { if (im->style) { @@ -3156,11 +3416,17 @@ BGD_DECLARE(void) gdImageSetStyle (gdImagePtr im, int *style, int noOfPixels) im->stylePos = 0; } +/* + Function: gdImageSetThickness +*/ BGD_DECLARE(void) gdImageSetThickness (gdImagePtr im, int thickness) { im->thick = thickness; } +/* + Function: gdImageSetBrush +*/ BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush) { int i; @@ -3178,6 +3444,9 @@ BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush) } } +/* + Function: gdImageSetTile +*/ BGD_DECLARE(void) gdImageSetTile (gdImagePtr im, gdImagePtr tile) { int i; @@ -3195,6 +3464,9 @@ BGD_DECLARE(void) gdImageSetTile (gdImagePtr im, gdImagePtr tile) } } +/* + Function: gdImageSetAntiAliased +*/ BGD_DECLARE(void) gdImageSetAntiAliased (gdImagePtr im, int c) { im->AA = 1; @@ -3202,6 +3474,9 @@ BGD_DECLARE(void) gdImageSetAntiAliased (gdImagePtr im, int c) im->AA_dont_blend = -1; } +/* + Function: gdImageSetAntiAliasedDontBlend +*/ BGD_DECLARE(void) gdImageSetAntiAliasedDontBlend (gdImagePtr im, int c, int dont_blend) { im->AA = 1; @@ -3209,11 +3484,17 @@ BGD_DECLARE(void) gdImageSetAntiAliasedDontBlend (gdImagePtr im, int c, int dont im->AA_dont_blend = dont_blend; } +/* + Function: gdImageInterlace +*/ BGD_DECLARE(void) gdImageInterlace (gdImagePtr im, int interlaceArg) { im->interlace = interlaceArg; } +/* + Function: gdImageCompare +*/ BGD_DECLARE(int) gdImageCompare (gdImagePtr im1, gdImagePtr im2) { int x, y; @@ -3296,6 +3577,9 @@ BGD_DECLARE(int) gdImageCompare (gdImagePtr im1, gdImagePtr im2) of gdAlphaBlend(), which merges alpha in the destination color much better. */ +/* + Function: gdAlphaBlend +*/ BGD_DECLARE(int) gdAlphaBlend (int dst, int src) { int src_alpha = gdTrueColorGetAlpha(src); @@ -3342,6 +3626,10 @@ BGD_DECLARE(int) gdAlphaBlend (int dst, int src) } static int gdAlphaOverlayColor (int src, int dst, int max ); + +/* + Function: gdLayerOverlay +*/ BGD_DECLARE(int) gdLayerOverlay (int dst, int src) { int a1, a2; @@ -3367,7 +3655,11 @@ static int gdAlphaOverlayColor (int src, int dst, int max ) } } -/* Apply 'multiply' effect */ +/* + Function: gdLayerMultiply + + Apply 'multiply' effect. +*/ BGD_DECLARE(int) gdLayerMultiply (int dst, int src) { int a1, a2, r1, r2, g1, g2, b1, b2; @@ -3390,16 +3682,25 @@ BGD_DECLARE(int) gdLayerMultiply (int dst, int src) ); } +/* + Function: gdImageAlphaBlending +*/ BGD_DECLARE(void) gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg) { im->alphaBlendingFlag = alphaBlendingArg; } +/* + Function: gdImageSaveAlpha +*/ BGD_DECLARE(void) gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg) { im->saveAlphaFlag = saveAlphaArg; } +/* + Function: gdImageSetClip +*/ BGD_DECLARE(void) gdImageSetClip (gdImagePtr im, int x1, int y1, int x2, int y2) { if (x1 < 0) { @@ -3432,6 +3733,9 @@ BGD_DECLARE(void) gdImageSetClip (gdImagePtr im, int x1, int y1, int x2, int y2) im->cy2 = y2; } +/* + Function: gdImageGetClip +*/ BGD_DECLARE(void) gdImageGetClip (gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P) { *x1P = im->cx1; @@ -3440,6 +3744,9 @@ BGD_DECLARE(void) gdImageGetClip (gdImagePtr im, int *x1P, int *y1P, int *x2P, i *y2P = im->cy2; } +/* + Function: gdImageSetResolution +*/ BGD_DECLARE(void) gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y) { if (res_x > 0) im->res_x = res_x; @@ -3511,9 +3818,11 @@ static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int co return; } else { double ag; - ag = (abs(dy) < abs(dx)) ? cos(atan2(dy, dx)) : sin(atan2(dy, dx)); + /* Cast the long to an int to avoid compiler warnings about truncation. + * This isn't a problem as computed dy/dx values came from ints above. */ + ag = fabs(abs((int)dy) < abs((int)dx) ? cos(atan2(dy, dx)) : sin(atan2(dy, dx))); if (ag != 0) { - wid = abs(thick / ag); + wid = thick / ag; } else { wid = 1; } @@ -3531,7 +3840,7 @@ static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int co return; } - if (abs(dx) > abs(dy)) { + if (abs((int)dx) > abs((int)dy)) { if (dx < 0) { tmp = x1; x1 = x2; @@ -3595,7 +3904,11 @@ static void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int co } -/* convert a palette image to true color */ +/* + Function: gdImagePaletteToTrueColor + + Convert a palette image to true color. +*/ BGD_DECLARE(int) gdImagePaletteToTrueColor(gdImagePtr src) { unsigned int y; diff --git a/Build/source/libs/gd/libgd-src/src/gd.h b/Build/source/libs/gd/libgd-src/src/gd.h index bdc479c9275..cf60be3ad85 100644 --- a/Build/source/libs/gd/libgd-src/src/gd.h +++ b/Build/source/libs/gd/libgd-src/src/gd.h @@ -2,6 +2,7 @@ extern "C" { #endif +#include <stdlib.h> #ifndef GD_H #define GD_H 1 @@ -11,8 +12,8 @@ extern "C" { * whitespace, take the form GD_*_VERSION and contain the magical * trailing comment. */ #define GD_MAJOR_VERSION 2 /*version605b5d1778*/ -#define GD_MINOR_VERSION 1 /*version605b5d1778*/ -#define GD_RELEASE_VERSION 1 /*version605b5d1778*/ +#define GD_MINOR_VERSION 2 /*version605b5d1778*/ +#define GD_RELEASE_VERSION 3 /*version605b5d1778*/ #define GD_EXTRA_VERSION "" /*version605b5d1778*/ /* End parsable section. */ @@ -65,7 +66,7 @@ extern "C" { # define BGD_STDCALL # define BGD_EXPORT_DATA_IMPL #else -# ifdef HAVE_VISIBILITY +# if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY==1 # define BGD_EXPORT_DATA_PROT __attribute__ ((visibility ("default"))) # define BGD_EXPORT_DATA_IMPL __attribute__ ((visibility ("hidden"))) # else @@ -88,9 +89,9 @@ extern "C" { # ifndef strcasecmp # define strcasecmp _stricmp # endif -# ifndef snprintf -# define snprintf _snprintf -# endif +#if _MSC_VER < 1900 + extern int snprintf(char*, size_t, const char*, ...); +#endif #endif #ifdef __cplusplus @@ -207,6 +208,7 @@ enum gdPaletteQuantizationMethod { * GD_SINC - Sinc * GD_TRIANGLE - Triangle * GD_WEIGHTED4 - 4 pixels weighted bilinear interpolation + * GD_LINEAR - bilinear interpolation * * See also: * <gdSetInterpolationMethod> @@ -234,7 +236,8 @@ typedef enum { GD_SINC, GD_TRIANGLE, GD_WEIGHTED4, - GD_METHOD_COUNT = 21 + GD_LINEAR, + GD_METHOD_COUNT = 23 } gdInterpolationMethod; /* define struct with name and func ptr and add it to gdImageStruct gdInterpolationMethod interpolation; */ diff --git a/Build/source/libs/gd/libgd-src/src/gd_bmp.c b/Build/source/libs/gd/libgd-src/src/gd_bmp.c index 5f39b67c3e4..e1194c54d80 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_bmp.c +++ b/Build/source/libs/gd/libgd-src/src/gd_bmp.c @@ -60,6 +60,9 @@ static int gdBMPPutInt(gdIOCtx *out, int w) return 0; } +/* + Function: gdImageBmpPtr +*/ BGD_DECLARE(void *) gdImageBmpPtr(gdImagePtr im, int *size, int compression) { void *rv; @@ -71,6 +74,9 @@ BGD_DECLARE(void *) gdImageBmpPtr(gdImagePtr im, int *size, int compression) return rv; } +/* + Function: gdImageBmp +*/ BGD_DECLARE(void) gdImageBmp(gdImagePtr im, FILE *outFile, int compression) { gdIOCtx *out = gdNewFileCtx(outFile); @@ -79,6 +85,9 @@ BGD_DECLARE(void) gdImageBmp(gdImagePtr im, FILE *outFile, int compression) out->gd_free(out); } +/* + Function: gdImageBmpCtx +*/ BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression) { int bitmap_size = 0, info_size, total_size, padding; @@ -343,8 +352,6 @@ static int compress_row(unsigned char *row, int length) if (compressed_run) { if (rle_type == BMP_RLE_TYPE_RLE) { compressed_length += build_rle_packet(row, rle_type, compressed_run, uncompressed_row); - } else { - compressed_length += build_rle_packet(row, rle_type, compressed_run, uncompressed_row); } } @@ -399,6 +406,9 @@ static int build_rle_packet(unsigned char *row, int packet_type, int length, uns return compressed_size; } +/* + Function: gdImageCreateFromBmp +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromBmp(FILE * inFile) { gdImagePtr im = 0; @@ -409,6 +419,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromBmp(FILE * inFile) return im; } +/* + Function: gdImageCreateFromBmpPtr +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromBmpPtr(int size, void *data) { gdImagePtr im; @@ -419,6 +432,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromBmpPtr(int size, void *data) return im; } +/* + Function: gdImageCreateFromBmpCtx +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromBmpCtx(gdIOCtxPtr infile) { bmp_hdr_t *hdr; @@ -678,11 +694,13 @@ static int bmp_read_direct(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, b BMP_DEBUG(printf("RLE is only valid for 8-bit images\n")); return 1; } + break; case BMP_BI_RLE4: if (info->depth != 4) { BMP_DEBUG(printf("RLE is only valid for 4-bit images\n")); return 1; } + break; case BMP_BI_JPEG: case BMP_BI_PNG: default: diff --git a/Build/source/libs/gd/libgd-src/src/gd_color_map.c b/Build/source/libs/gd/libgd-src/src/gd_color_map.c index ff48399a982..46f3bfa5e81 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_color_map.c +++ b/Build/source/libs/gd/libgd-src/src/gd_color_map.c @@ -767,6 +767,9 @@ BGD_EXPORT_DATA_PROT gdColorMap GD_COLOR_MAP_X11 = { (gdColorMapEntry *)GD_COLOR_MAP_X11_ENTRIES }; +/* + Function: gdColorMapLookup +*/ BGD_DECLARE(int) gdColorMapLookup(const gdColorMap color_map, const char *color_name, int *r, int *g, int *b) { diff --git a/Build/source/libs/gd/libgd-src/src/gd_color_match.c b/Build/source/libs/gd/libgd-src/src/gd_color_match.c index 5f0fd0a86c2..f0842b69ed7 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_color_match.c +++ b/Build/source/libs/gd/libgd-src/src/gd_color_match.c @@ -5,8 +5,10 @@ #include "gd.h" #include "gdhelpers.h" -/* bring the palette colors in im2 to be closer to im1 - * +/* + Function: gdImageColorMatch + + Bring the palette colors in im2 to be closer to im1. */ BGD_DECLARE(int) gdImageColorMatch (gdImagePtr im1, gdImagePtr im2) { diff --git a/Build/source/libs/gd/libgd-src/src/gd_crop.c b/Build/source/libs/gd/libgd-src/src/gd_crop.c index 02966336d18..6cca8198cf0 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_crop.c +++ b/Build/source/libs/gd/libgd-src/src/gd_crop.c @@ -18,6 +18,9 @@ static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color); +/* + Function: gdImageCrop + */ BGD_DECLARE(gdImagePtr) gdImageCrop(gdImagePtr src, const gdRect *crop) { gdImagePtr dst; @@ -29,6 +32,9 @@ BGD_DECLARE(gdImagePtr) gdImageCrop(gdImagePtr src, const gdRect *crop) return dst; } +/* + Function: gdImageCropAuto + */ BGD_DECLARE(gdImagePtr) gdImageCropAuto(gdImagePtr im, const unsigned int mode) { const int width = gdImageSX(im); @@ -117,6 +123,9 @@ BGD_DECLARE(gdImagePtr) gdImageCropAuto(gdImagePtr im, const unsigned int mode) return gdImageCrop(im, &crop); } +/* + Function: gdImageCropThreshold + */ BGD_DECLARE(gdImagePtr) gdImageCropThreshold(gdImagePtr im, const unsigned int color, const float threshold) { const int width = gdImageSX(im); @@ -136,6 +145,10 @@ BGD_DECLARE(gdImagePtr) gdImageCropThreshold(gdImagePtr im, const unsigned int c return NULL; } + if (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im)) { + return NULL; + } + /* TODO: Add gdImageGetRowPtr and works with ptr at the row level * for the true color and palette images * new formats will simply work with ptr diff --git a/Build/source/libs/gd/libgd-src/src/gd_filename.c b/Build/source/libs/gd/libgd-src/src/gd_filename.c index ba636cfe0e7..fd61677d581 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_filename.c +++ b/Build/source/libs/gd/libgd-src/src/gd_filename.c @@ -70,7 +70,7 @@ static struct FileType { {".gd2", gdImageCreateFromGd2, writegd2, NULL}, #endif -#ifdef HAVE_LIBVPX +#ifdef HAVE_LIBWEBP {".webp", gdImageCreateFromWebp, gdImageWebp, NULL}, #endif diff --git a/Build/source/libs/gd/libgd-src/src/gd_filter.c b/Build/source/libs/gd/libgd-src/src/gd_filter.c index a3119f77f80..d3a5918addc 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_filter.c +++ b/Build/source/libs/gd/libgd-src/src/gd_filter.c @@ -15,7 +15,11 @@ #include <time.h> #include <math.h> -#define NDEBUG /* Uncomment to enable assertions. */ +#undef NDEBUG +/* Comment out this line to enable asserts. + * TODO: This logic really belongs in cmake and configure. + */ +#define NDEBUG 1 #include <assert.h> typedef int (BGD_STDCALL *FuncPtr)(gdImagePtr, int, int); @@ -30,6 +34,9 @@ typedef int (BGD_STDCALL *FuncPtr)(gdImagePtr, int, int); # define GD_SCATTER_SEED() (unsigned int)(time(0) * getpid()) #endif +/* + Function: gdImageScatter + */ BGD_DECLARE(int) gdImageScatter(gdImagePtr im, int sub, int plus) { gdScatter s; @@ -41,6 +48,9 @@ BGD_DECLARE(int) gdImageScatter(gdImagePtr im, int sub, int plus) return gdImageScatterEx(im, &s); } +/* + Function: gdImageScatterColor + */ BGD_DECLARE(int) gdImageScatterColor(gdImagePtr im, int sub, int plus, int colors[], unsigned int num_colors) { gdScatter s; @@ -53,6 +63,9 @@ BGD_DECLARE(int) gdImageScatterColor(gdImagePtr im, int sub, int plus, int color return gdImageScatterEx(im, &s); } +/* + Function: gdImageScatterEx + */ BGD_DECLARE(int) gdImageScatterEx(gdImagePtr im, gdScatterPtr scatter) { register int x, y; @@ -112,6 +125,9 @@ BGD_DECLARE(int) gdImageScatterEx(gdImagePtr im, gdScatterPtr scatter) return 1; } +/* + Function: gdImagePixelate + */ BGD_DECLARE(int) gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode) { int x, y; @@ -168,7 +184,11 @@ BGD_DECLARE(int) gdImagePixelate(gdImagePtr im, int block_size, const unsigned i return 1; } -/* invert src image */ +/* + Function: gdImageNegate + + Invert src image. + */ BGD_DECLARE(int) gdImageNegate(gdImagePtr src) { int x, y; @@ -200,7 +220,11 @@ BGD_DECLARE(int) gdImageNegate(gdImagePtr src) return 1; } -/* Convert the image src to a grayscale image */ +/* + Function: gdImageGrayScale + + Convert the image src to a grayscale image. + */ BGD_DECLARE(int) gdImageGrayScale(gdImagePtr src) { int x, y; @@ -233,7 +257,11 @@ BGD_DECLARE(int) gdImageGrayScale(gdImagePtr src) return 1; } -/* Set the brightness level <level> for the image src */ +/* + Function: gdImageBrightness + + Set the brightness level <level> for the image src. + */ BGD_DECLARE(int) gdImageBrightness(gdImagePtr src, int brightness) { int x, y; @@ -279,6 +307,9 @@ BGD_DECLARE(int) gdImageBrightness(gdImagePtr src, int brightness) } +/* + Function: gdImageContrast + */ BGD_DECLARE(int) gdImageContrast(gdImagePtr src, double contrast) { int x, y; @@ -339,6 +370,9 @@ BGD_DECLARE(int) gdImageContrast(gdImagePtr src, double contrast) } +/* + Function: gdImageColor + */ BGD_DECLARE(int) gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha) { int x, y; @@ -381,6 +415,9 @@ BGD_DECLARE(int) gdImageColor(gdImagePtr src, const int red, const int green, co return 1; } +/* + Function: gdImageConvolution + */ BGD_DECLARE(int) gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset) { int x, y, i, j, new_a; @@ -441,6 +478,9 @@ BGD_DECLARE(int) gdImageConvolution(gdImagePtr src, float filter[3][3], float fi return 1; } +/* + Function: gdImageSelectiveBlur + */ BGD_DECLARE(int) gdImageSelectiveBlur( gdImagePtr src) { int x, y, i, j; @@ -559,6 +599,9 @@ BGD_DECLARE(int) gdImageSelectiveBlur( gdImagePtr src) return 1; } +/* + Function: gdImageEdgeDetectQuick + */ BGD_DECLARE(int) gdImageEdgeDetectQuick(gdImagePtr src) { float filter[3][3] = {{-1.0,0.0,-1.0}, @@ -599,6 +642,9 @@ BGD_DECLARE(int) gdImageGaussianBlur(gdImagePtr im) return gdImageConvolution(im, filter, 16, 0); } +/* + Function: gdImageEmboss + */ BGD_DECLARE(int) gdImageEmboss(gdImagePtr im) { /* @@ -613,6 +659,9 @@ BGD_DECLARE(int) gdImageEmboss(gdImagePtr im) return gdImageConvolution(im, filter, 1, 127); } +/* + Function: gdImageMeanRemoval + */ BGD_DECLARE(int) gdImageMeanRemoval(gdImagePtr im) { float filter[3][3] = {{-1.0,-1.0,-1.0}, @@ -622,6 +671,9 @@ BGD_DECLARE(int) gdImageMeanRemoval(gdImagePtr im) return gdImageConvolution(im, filter, 1, 0); } +/* + Function: gdImageSmooth + */ BGD_DECLARE(int) gdImageSmooth(gdImagePtr im, float weight) { float filter[3][3] = {{1.0,1.0,1.0}, diff --git a/Build/source/libs/gd/libgd-src/src/gd_gd.c b/Build/source/libs/gd/libgd-src/src/gd_gd.c index f8d39cb00ce..13defa09e42 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_gd.c +++ b/Build/source/libs/gd/libgd-src/src/gd_gd.c @@ -326,6 +326,9 @@ _gdImageGd (gdImagePtr im, gdIOCtx * out) } } +/* + Function: gdImageGd + */ BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * outFile) { gdIOCtx *out = gdNewFileCtx (outFile); @@ -334,6 +337,9 @@ BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * outFile) out->gd_free (out); } +/* + Function: gdImageGdPtr + */ BGD_DECLARE(void *) gdImageGdPtr (gdImagePtr im, int *size) { void *rv; diff --git a/Build/source/libs/gd/libgd-src/src/gd_gd2.c b/Build/source/libs/gd/libgd-src/src/gd_gd2.c index 3e70bfac673..8df93c12f4e 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_gd2.c +++ b/Build/source/libs/gd/libgd-src/src/gd_gd2.c @@ -14,11 +14,9 @@ #include "config.h" #endif -#include <stdio.h> /* 2.0.29: no more errno.h, makes windows happy */ #include <math.h> #include <string.h> -#include <stdlib.h> #include "gd.h" #include "gd_errors.h" #include "gdhelpers.h" @@ -154,10 +152,18 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy, if (gd2_compressed (*fmt)) { nc = (*ncx) * (*ncy); + GD2_DBG (printf ("Reading %d chunk index entries\n", nc)); + if (overflow2(sizeof(t_chunk_info), nc)) { + goto fail1; + } sidx = sizeof (t_chunk_info) * nc; + if (sidx <= 0) { + goto fail1; + } + cidx = gdCalloc (sidx, 1); - if (!cidx) { + if (cidx == NULL) { goto fail1; } for (i = 0; i < nc; i++) { @@ -167,6 +173,8 @@ _gd2GetHeader (gdIOCtxPtr in, int *sx, int *sy, if (gdGetInt (&cidx[i].size, in) != 1) { goto fail2; }; + if (cidx[i].offset < 0 || cidx[i].size < 0) + goto fail2; }; *chunkIdx = cidx; }; @@ -359,9 +367,8 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ctx (gdIOCtxPtr in) im = _gd2CreateFromFile (in, &sx, &sy, &cs, &vers, &fmt, &ncx, &ncy, &chunkIdx); - if (im == NULL) { - gdFree (chunkIdx); + /* No need to free chunkIdx as _gd2CreateFromFile does it for us. */ return 0; } @@ -1036,6 +1043,9 @@ fail: } +/* + Function: gdImageGd2 +*/ BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt) { gdIOCtx *out = gdNewFileCtx (outFile); @@ -1044,6 +1054,9 @@ BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt) out->gd_free (out); } +/* + Function: gdImageGd2Ptr +*/ BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size) { void *rv; @@ -1056,15 +1069,55 @@ BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size) } #else /* no HAVE_LIBZ */ -BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2 (FILE * inFile) +static void _noLibzError (void) { gd_error("GD2 support is not available - no libz\n"); +} + +BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2 (FILE * inFile) +{ + _noLibzError(); return NULL; } BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ctx (gdIOCtxPtr in) { - gd_error("GD2 support is not available - no libz\n"); + _noLibzError(); + return NULL; +} + +BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h) +{ + _noLibzError(); return NULL; } + +BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Ptr (int size, void *data) +{ + _noLibzError(); + return NULL; +} + +BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h) +{ + _noLibzError(); + return NULL; +} + +BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2PartPtr (int size, void *data, int srcx, int srcy, int w, + int h) +{ + _noLibzError(); + return NULL; +} + +BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt) +{ + _noLibzError(); +} + +BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size) +{ + _noLibzError(); +} #endif /* HAVE_LIBZ */ diff --git a/Build/source/libs/gd/libgd-src/src/gd_gif_out.c b/Build/source/libs/gd/libgd-src/src/gd_gif_out.c index 51ceb753855..3099d4982b7 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_gif_out.c +++ b/Build/source/libs/gd/libgd-src/src/gd_gif_out.c @@ -1442,15 +1442,23 @@ nomatch: * code in turn. When the buffer fills up empty it and start over. */ -static unsigned long masks[] = { +static const unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; +/* Arbitrary value to mark output is done. When we see EOFCode, then we don't + * expect to see any more data. If we do (e.g. corrupt image inputs), cur_bits + * might be negative, so flag it to return early. + */ +#define CUR_BITS_FINISHED -1000 + static void output(code_int code, GifCtx *ctx) { + if (ctx->cur_bits == CUR_BITS_FINISHED) + return; ctx->cur_accum &= masks[ctx->cur_bits]; if(ctx->cur_bits > 0) { @@ -1492,6 +1500,8 @@ static void output(code_int code, GifCtx *ctx) ctx->cur_accum >>= 8; ctx->cur_bits -= 8; } + /* Flag that it's done to prevent re-entry. */ + ctx->cur_bits = CUR_BITS_FINISHED; flush_char(ctx); } diff --git a/Build/source/libs/gd/libgd-src/src/gd_intern.h b/Build/source/libs/gd/libgd-src/src/gd_intern.h index a30062b11f8..86d817e6d4a 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_intern.h +++ b/Build/source/libs/gd/libgd-src/src/gd_intern.h @@ -1,7 +1,7 @@ #ifndef GD_INTERN_H #define GD_INTERN_H -#if HAVE_LIMITS_H +#ifdef HAVE_LIMITS_H #include <limits.h> #endif diff --git a/Build/source/libs/gd/libgd-src/src/gd_interpolation.c b/Build/source/libs/gd/libgd-src/src/gd_interpolation.c index 84cf92a0b89..7e7943d6955 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_interpolation.c +++ b/Build/source/libs/gd/libgd-src/src/gd_interpolation.c @@ -61,9 +61,12 @@ TODO: #include <stdlib.h> #include <string.h> #include <math.h> -#include <assert.h> -#define NDEBUG 1 /* TODO: disable/enable assertions in configure. */ +#undef NDEBUG +/* Comment out this line to enable asserts. + * TODO: This logic really belongs in cmake and configure. + */ +#define NDEBUG 1 #include <assert.h> #include "gd.h" @@ -87,10 +90,6 @@ static gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, static gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor); -static gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, - const int bgColor); -static gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, - const int bgColor); static gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor); @@ -138,28 +137,29 @@ typedef struct } LineContribType; /* Each core filter has its own radius */ -#define DEFAULT_FILTER_BICUBIC 3.0 -#define DEFAULT_FILTER_BOX 0.5 -#define DEFAULT_FILTER_GENERALIZED_CUBIC 0.5 -#define DEFAULT_FILTER_RADIUS 1.0 -#define DEFAULT_LANCZOS8_RADIUS 8.0 -#define DEFAULT_LANCZOS3_RADIUS 3.0 -#define DEFAULT_HERMITE_RADIUS 1.0 -#define DEFAULT_BOX_RADIUS 0.5 -#define DEFAULT_TRIANGLE_RADIUS 1.0 -#define DEFAULT_BELL_RADIUS 1.5 -#define DEFAULT_CUBICSPLINE_RADIUS 2.0 -#define DEFAULT_MITCHELL_RADIUS 2.0 -#define DEFAULT_COSINE_RADIUS 1.0 -#define DEFAULT_CATMULLROM_RADIUS 2.0 -#define DEFAULT_QUADRATIC_RADIUS 1.5 -#define DEFAULT_QUADRATICBSPLINE_RADIUS 1.5 -#define DEFAULT_CUBICCONVOLUTION_RADIUS 3.0 -#define DEFAULT_GAUSSIAN_RADIUS 1.0 -#define DEFAULT_HANNING_RADIUS 1.0 -#define DEFAULT_HAMMING_RADIUS 1.0 -#define DEFAULT_SINC_RADIUS 1.0 -#define DEFAULT_WELSH_RADIUS 1.0 +#define DEFAULT_FILTER_LINEAR 1.0f +#define DEFAULT_FILTER_BICUBIC 3.0f +#define DEFAULT_FILTER_BOX 0.5f +#define DEFAULT_FILTER_GENERALIZED_CUBIC 0.5f +#define DEFAULT_FILTER_RADIUS 1.0f +#define DEFAULT_LANCZOS8_RADIUS 8.0f +#define DEFAULT_LANCZOS3_RADIUS 3.0f +#define DEFAULT_HERMITE_RADIUS 1.0f +#define DEFAULT_BOX_RADIUS 0.5f +#define DEFAULT_TRIANGLE_RADIUS 1.0f +#define DEFAULT_BELL_RADIUS 1.5f +#define DEFAULT_CUBICSPLINE_RADIUS 2.0f +#define DEFAULT_MITCHELL_RADIUS 2.0f +#define DEFAULT_COSINE_RADIUS 1.0f +#define DEFAULT_CATMULLROM_RADIUS 2.0f +#define DEFAULT_QUADRATIC_RADIUS 1.5f +#define DEFAULT_QUADRATICBSPLINE_RADIUS 1.5f +#define DEFAULT_CUBICCONVOLUTION_RADIUS 3.0f +#define DEFAULT_GAUSSIAN_RADIUS 1.0f +#define DEFAULT_HANNING_RADIUS 1.0f +#define DEFAULT_HAMMING_RADIUS 1.0f +#define DEFAULT_SINC_RADIUS 1.0f +#define DEFAULT_WELSH_RADIUS 1.0f static double KernelBessel_J1(const double x) { @@ -306,6 +306,15 @@ static double filter_blackman(const double x) return (0.42f+0.5f*(double)cos(M_PI*x)+0.08f*(double)cos(2.0f*M_PI*x)); } +double filter_linear(const double x) { + double ax = fabs(x); + if (ax < 1.0f) { + return (1.0f - ax); + } + return 0.0f; +} + + /** * Bicubic interpolation kernel (a=-1): \verbatim @@ -610,6 +619,8 @@ static double filter_welsh(const double x) # define inline __inline #endif +/* keep it for future usage for affine copy over an existing image, targetting fix for 2.2.2 */ +#ifdef FUNCTION_NOT_USED_YET /* Copied from upstream's libgd */ static inline int _color_blend (const int dst, const int src) { @@ -650,6 +661,7 @@ static inline int _setEdgePixel(const gdImagePtr src, unsigned int x, unsigned i c = c | (( (int) (gd_fxtof(gd_mulfx(coverage, f_127)) + 50.5f)) << 24); return _color_blend(bgColor, c); } +#endif static inline int getPixelOverflowTC(gdImagePtr im, const int x, const int y, const int bgColor) { @@ -660,43 +672,7 @@ static inline int getPixelOverflowTC(gdImagePtr im, const int x, const int y, co } return c; } else { - register int border = 0; - - if (y < im->cy1) { - border = im->tpixels[0][im->cx1]; - goto processborder; - } - - if (y < im->cy1) { - border = im->tpixels[0][im->cx1]; - goto processborder; - } - - if (y > im->cy2) { - if (x >= im->cx1 && x <= im->cx1) { - border = im->tpixels[im->cy2][x]; - goto processborder; - } else { - return gdTrueColorAlpha(0, 0, 0, 127); - } - } - - /* y is bound safe at this point */ - if (x < im->cx1) { - border = im->tpixels[y][im->cx1]; - goto processborder; - } - - if (x > im->cx2) { - border = im->tpixels[y][im->cx2]; - } - -processborder: - if (border == im->transparent) { - return gdTrueColorAlpha(0, 0, 0, 127); - } else{ - return gdTrueColorAlpha(gdTrueColorGetRed(border), gdTrueColorGetGreen(border), gdTrueColorGetBlue(border), 127); - } + return bgColor; } } @@ -711,42 +687,7 @@ static inline int getPixelOverflowPalette(gdImagePtr im, const int x, const int } return colorIndex2RGBA(c); } else { - register int border = 0; - if (y < im->cy1) { - border = gdImageGetPixel(im, im->cx1, 0); - goto processborder; - } - - if (y < im->cy1) { - border = gdImageGetPixel(im, im->cx1, 0); - goto processborder; - } - - if (y > im->cy2) { - if (x >= im->cx1 && x <= im->cx1) { - border = gdImageGetPixel(im, x, im->cy2); - goto processborder; - } else { - return gdTrueColorAlpha(0, 0, 0, 127); - } - } - - /* y is bound safe at this point */ - if (x < im->cx1) { - border = gdImageGetPixel(im, im->cx1, y); - goto processborder; - } - - if (x > im->cx2) { - border = gdImageGetPixel(im, im->cx2, y); - } - -processborder: - if (border == im->transparent) { - return gdTrueColorAlpha(0, 0, 0, 127); - } else{ - return colorIndex2RGBcustomA(border, 127); - } + return bgColor; } } @@ -813,8 +754,8 @@ static int getPixelInterpolateWeight(gdImagePtr im, const double x, const double */ int getPixelInterpolated(gdImagePtr im, const double x, const double y, const int bgColor) { - const int xi=(int)((x) < 0 ? x - 1: x); - const int yi=(int)((y) < 0 ? y - 1: y); + const int xi=(int)(x); + const int yi=(int)(y); int yii; int i; double kernel, kernel_cache_y; @@ -822,7 +763,7 @@ int getPixelInterpolated(gdImagePtr im, const double x, const double y, const in double new_r = 0.0f, new_g = 0.0f, new_b = 0.0f, new_a = 0.0f; /* These methods use special implementations */ - if (im->interpolation_id == GD_BILINEAR_FIXED || im->interpolation_id == GD_BICUBIC_FIXED || im->interpolation_id == GD_NEAREST_NEIGHBOUR) { + if (im->interpolation_id == GD_NEAREST_NEIGHBOUR) { return -1; } @@ -888,6 +829,7 @@ static inline LineContribType * _gdContributionsAlloc(unsigned int line_length, { unsigned int u = 0; LineContribType *res; + int overflow_error = 0; res = (LineContribType *) gdMalloc(sizeof(LineContribType)); if (!res) { @@ -895,10 +837,31 @@ static inline LineContribType * _gdContributionsAlloc(unsigned int line_length, } res->WindowSize = windows_size; res->LineLength = line_length; + if (overflow2(line_length, sizeof(ContributionType))) { + gdFree(res); + return NULL; + } res->ContribRow = (ContributionType *) gdMalloc(line_length * sizeof(ContributionType)); - + if (res->ContribRow == NULL) { + gdFree(res); + return NULL; + } for (u = 0 ; u < line_length ; u++) { - res->ContribRow[u].Weights = (double *) gdMalloc(windows_size * sizeof(double)); + if (overflow2(windows_size, sizeof(double))) { + overflow_error = 1; + } else { + res->ContribRow[u].Weights = (double *) gdMalloc(windows_size * sizeof(double)); + } + if (overflow_error == 1 || res->ContribRow[u].Weights == NULL) { + unsigned int i; + u--; + for (i=0;i<=u;i++) { + gdFree(res->ContribRow[i].Weights); + } + gdFree(res->ContribRow); + gdFree(res); + return NULL; + } } return res; } @@ -931,7 +894,9 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi windows_size = 2 * (int)ceil(width_d) + 1; res = _gdContributionsAlloc(line_size, windows_size); - + if (res == NULL) { + return NULL; + } for (u = 0; u < line_size; u++) { const double dCenter = (double)u / scale_d; /* get the significant edge points affecting the pixel */ @@ -1036,7 +1001,6 @@ _gdScalePass(const gdImagePtr pSrc, const unsigned int src_len, _gdScaleOneAxis(pSrc, pDst, dst_len, line_ndx, contrib, axis); } _gdContributionsFree (contrib); - return 1; }/* _gdScalePass*/ @@ -1049,6 +1013,7 @@ gdImageScaleTwoPass(const gdImagePtr src, const unsigned int new_width, const unsigned int src_height = src->sy; gdImagePtr tmp_im = NULL; gdImagePtr dst = NULL; + int scale_pass_res; /* First, handle the trivial case. */ if (src_width == new_width && src_height == new_height) { @@ -1070,7 +1035,11 @@ gdImageScaleTwoPass(const gdImagePtr src, const unsigned int new_width, } gdImageSetInterpolationMethod(tmp_im, src->interpolation_id); - _gdScalePass(src, src_width, tmp_im, new_width, src_height, HORIZONTAL); + scale_pass_res = _gdScalePass(src, src_width, tmp_im, new_width, src_height, HORIZONTAL); + if (scale_pass_res != 1) { + gdImageDestroy(tmp_im); + return NULL; + } }/* if .. else*/ /* If vertical sizes match, we're done. */ @@ -1083,11 +1052,19 @@ gdImageScaleTwoPass(const gdImagePtr src, const unsigned int new_width, dst = gdImageCreateTrueColor(new_width, new_height); if (dst != NULL) { gdImageSetInterpolationMethod(dst, src->interpolation_id); - _gdScalePass(tmp_im, src_height, dst, new_height, new_width, VERTICAL); + scale_pass_res = _gdScalePass(tmp_im, src_height, dst, new_height, new_width, VERTICAL); + if (scale_pass_res != 1) { + gdImageDestroy(dst); + if (tmp_im != NULL && src != tmp_im) { + gdImageDestroy(tmp_im); + } + return NULL; + } }/* if */ - if (src != tmp_im) { - gdFree(tmp_im); + + if (tmp_im != NULL && src != tmp_im) { + gdImageDestroy(tmp_im); }/* if */ return dst; @@ -1156,6 +1133,7 @@ gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsi return dst_img; } +#if 0 static inline int getPixelOverflowColorTC(gdImagePtr im, const int x, const int y, const int color) { if (gdImageBoundsSafe(im, x, y)) { @@ -1203,6 +1181,7 @@ processborder: } } } +#endif static gdImagePtr gdImageScaleBilinearPalette(gdImagePtr im, const unsigned int new_width, const unsigned int new_height) { @@ -1224,7 +1203,13 @@ static gdImagePtr gdImageScaleBilinearPalette(gdImagePtr im, const unsigned int if (new_img == NULL) { return NULL; } - new_img->transparent = gdTrueColorAlpha(im->red[transparent], im->green[transparent], im->blue[transparent], im->alpha[transparent]); + + if (transparent < 0) { + /* uninitialized */ + new_img->transparent = -1; + } else { + new_img->transparent = gdTrueColorAlpha(im->red[transparent], im->green[transparent], im->blue[transparent], im->alpha[transparent]); + } for (i=0; i < _height; i++) { long j; @@ -1452,13 +1437,8 @@ gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, src_offset_y[0] = m; } - if (m < 1) { - src_offset_x[1] = n; - src_offset_y[1] = m; - } else { - src_offset_x[1] = n; - src_offset_y[1] = m; - } + src_offset_x[1] = n; + src_offset_y[1] = m; if ((m < 1) || (n >= src_w - 1)) { src_offset_x[2] = n; @@ -1542,10 +1522,7 @@ gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, src_offset_y[12] = m; } - if (m >= src_h - 2) { - src_offset_x[13] = n; - src_offset_y[13] = m; - } else { + if (!(m >= src_h - 2)) { src_offset_x[13] = n; src_offset_y[13] = m; } @@ -1630,14 +1607,23 @@ gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, return dst; } +/* + Function: gdImageScale +*/ BGD_DECLARE(gdImagePtr) gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height) { gdImagePtr im_scaled = NULL; - if (src == NULL || src->interpolation_id < 0 || src->interpolation_id > GD_METHOD_COUNT) { - return 0; + if (src == NULL || (uintmax_t)src->interpolation_id >= GD_METHOD_COUNT) { + return NULL; } + if (new_width == 0 || new_height == 0) { + return NULL; + } + if (new_width == gdImageSX(src) && new_height == gdImageSY(src)) { + return gdImageClone(src); + } switch (src->interpolation_id) { /*Special cases, optimized implementations */ case GD_NEAREST_NEIGHBOUR: @@ -1645,10 +1631,12 @@ BGD_DECLARE(gdImagePtr) gdImageScale(const gdImagePtr src, const unsigned int ne break; case GD_BILINEAR_FIXED: + case GD_LINEAR: im_scaled = gdImageScaleBilinear(src, new_width, new_height); break; case GD_BICUBIC_FIXED: + case GD_BICUBIC: im_scaled = gdImageScaleBicubicFixed(src, new_width, new_height); break; @@ -1664,6 +1652,23 @@ BGD_DECLARE(gdImagePtr) gdImageScale(const gdImagePtr src, const unsigned int ne return im_scaled; } +static int gdRotatedImageSize(gdImagePtr src, const float angle, gdRectPtr bbox) +{ + gdRect src_area; + double m[6]; + + gdAffineRotate(m, angle); + src_area.x = 0; + src_area.y = 0; + src_area.width = gdImageSX(src); + src_area.height = gdImageSY(src); + if (gdTransformAffineBoundingBox(&src_area, m, bbox) != GD_TRUE) { + return GD_FALSE; + } + + return GD_TRUE; +} + static gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor) @@ -1671,8 +1676,6 @@ gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, float _angle = ((float) (-degrees / 180.0f) * (float)M_PI); const int src_w = gdImageSX(src); const int src_h = gdImageSY(src); - const unsigned int new_width = (unsigned int)(abs((int)(src_w * cos(_angle))) + abs((int)(src_h * sin(_angle))) + 0.5f); - const unsigned int new_height = (unsigned int)(abs((int)(src_w * sin(_angle))) + abs((int)(src_h * cos(_angle))) + 0.5f); const gdFixed f_0_5 = gd_ftofx(0.5f); const gdFixed f_H = gd_itofx(src_h/2); const gdFixed f_W = gd_itofx(src_w/2); @@ -1683,6 +1686,8 @@ gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, unsigned int dst_offset_y = 0; unsigned int i; gdImagePtr dst; + gdRect bbox; + int new_height, new_width; /* impact perf a bit, but not that much. Implementation for palette images can be done at a later point. @@ -1691,6 +1696,10 @@ gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, gdImagePaletteToTrueColor(src); } + gdRotatedImageSize(src, degrees, &bbox); + new_width = bbox.width; + new_height = bbox.height; + dst = gdImageCreateTrueColor(new_width, new_height); if (!dst) { return NULL; @@ -1728,9 +1737,6 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor) float _angle = ((float) (-degrees / 180.0f) * (float)M_PI); const int src_w = gdImageSX(src); const int src_h = gdImageSY(src); - const unsigned int new_width = (unsigned int)(abs((int)(src_w * cos(_angle))) + abs((int)(src_h * sin(_angle))) + 0.5f); - const unsigned int new_height = (unsigned int)(abs((int)(src_w * sin(_angle))) + abs((int)(src_h * cos(_angle))) + 0.5f); - const gdFixed f_0_5 = gd_ftofx(0.5f); const gdFixed f_H = gd_itofx(src_h/2); const gdFixed f_W = gd_itofx(src_w/2); const gdFixed f_cos = gd_ftofx(cos(-_angle)); @@ -1740,12 +1746,8 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor) unsigned int dst_offset_y = 0; unsigned int i; gdImagePtr dst; - - const gdFixed f_slop_y = f_sin; - const gdFixed f_slop_x = f_cos; - const gdFixed f_slop = f_slop_x > 0 && f_slop_x > 0 ? - f_slop_x > f_slop_y ? gd_divfx(f_slop_y, f_slop_x) : gd_divfx(f_slop_x, f_slop_y) - : 0; + int new_width, new_height; + gdRect bbox; if (bgColor < 0) { return NULL; @@ -1758,6 +1760,14 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor) gdImagePaletteToTrueColor(src); } + if (src->interpolation == NULL) { + gdImageSetInterpolationMethod(src, GD_DEFAULT); + } + + gdRotatedImageSize(src, degrees, &bbox); + new_width = bbox.width; + new_height = bbox.height; + dst = gdImageCreateTrueColor(new_width, new_height); if (!dst) { return NULL; @@ -1770,20 +1780,15 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor) for (j = 0; j < new_width; j++) { gdFixed f_i = gd_itofx((int)i - (int)new_height / 2); gdFixed f_j = gd_itofx((int)j - (int)new_width / 2); - gdFixed f_m = gd_mulfx(f_j,f_sin) + gd_mulfx(f_i,f_cos) + f_0_5 + f_H; - gdFixed f_n = gd_mulfx(f_j,f_cos) - gd_mulfx(f_i,f_sin) + f_0_5 + f_W; + gdFixed f_m = gd_mulfx(f_j,f_sin) + gd_mulfx(f_i,f_cos) + f_H; + gdFixed f_n = gd_mulfx(f_j,f_cos) - gd_mulfx(f_i,f_sin) + f_W; long m = gd_fxtoi(f_m); long n = gd_fxtoi(f_n); - if ((n <= 0) || (m <= 0) || (m >= src_h) || (n >= src_w)) { + if (m < -1 || n < -1 || m >= src_h || n >= src_w ) { dst->tpixels[dst_offset_y][dst_offset_x++] = bgColor; - } else if ((n <= 1) || (m <= 1) || (m >= src_h - 1) || (n >= src_w - 1)) { - register int c = getPixelInterpolated(src, n, m, bgColor); - c = c | (( gdTrueColorGetAlpha(c) + ((int)(127* gd_fxtof(f_slop)))) << 24); - - dst->tpixels[dst_offset_y][dst_offset_x++] = _color_blend(bgColor, c); } else { - dst->tpixels[dst_offset_y][dst_offset_x++] = getPixelInterpolated(src, n, m, bgColor); + dst->tpixels[dst_offset_y][dst_offset_x++] = getPixelInterpolated(src, gd_fxtod(f_n), gd_fxtod(f_m), bgColor); } } dst_offset_y++; @@ -1791,405 +1796,9 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor) return dst; } -static gdImagePtr -gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor) -{ - float _angle = (float)((- degrees / 180.0f) * M_PI); - const unsigned int src_w = gdImageSX(src); - const unsigned int src_h = gdImageSY(src); - unsigned int new_width = abs((int)(src_w*cos(_angle))) + abs((int)(src_h*sin(_angle) + 0.5f)); - unsigned int new_height = abs((int)(src_w*sin(_angle))) + abs((int)(src_h*cos(_angle) + 0.5f)); - const gdFixed f_0_5 = gd_ftofx(0.5f); - const gdFixed f_H = gd_itofx(src_h/2); - const gdFixed f_W = gd_itofx(src_w/2); - const gdFixed f_cos = gd_ftofx(cos(-_angle)); - const gdFixed f_sin = gd_ftofx(sin(-_angle)); - const gdFixed f_1 = gd_itofx(1); - unsigned int i; - unsigned int dst_offset_x; - unsigned int dst_offset_y = 0; - unsigned int src_offset_x, src_offset_y; - gdImagePtr dst; - - /* impact perf a bit, but not that much. Implementation for palette - images can be done at a later point. - */ - if (src->trueColor == 0) { - gdImagePaletteToTrueColor(src); - } - - dst = gdImageCreateTrueColor(new_width, new_height); - if (dst == NULL) { - return NULL; - } - dst->saveAlphaFlag = 1; - - for (i = 0; i < new_height; i++) { - unsigned int j; - dst_offset_x = 0; - - for (j=0; j < new_width; j++) { - const gdFixed f_i = gd_itofx((int)i - (int)new_height / 2); - const gdFixed f_j = gd_itofx((int)j - (int)new_width / 2); - const gdFixed f_m = gd_mulfx(f_j,f_sin) + gd_mulfx(f_i,f_cos) + f_0_5 + f_H; - const gdFixed f_n = gd_mulfx(f_j,f_cos) - gd_mulfx(f_i,f_sin) + f_0_5 + f_W; - const unsigned int m = gd_fxtoi(f_m); - const unsigned int n = gd_fxtoi(f_n); - - if ((m > 0) && (m < src_h - 1) && (n > 0) && (n < src_w - 1)) { - const gdFixed f_f = f_m - gd_itofx(m); - const gdFixed f_g = f_n - gd_itofx(n); - const gdFixed f_w1 = gd_mulfx(f_1-f_f, f_1-f_g); - const gdFixed f_w2 = gd_mulfx(f_1-f_f, f_g); - const gdFixed f_w3 = gd_mulfx(f_f, f_1-f_g); - const gdFixed f_w4 = gd_mulfx(f_f, f_g); - - if (n < src_w - 1) { - src_offset_x = n + 1; - src_offset_y = m; - } - - if (m < src_h - 1) { - src_offset_x = n; - src_offset_y = m + 1; - } - - if (!((n >= src_w - 1) || (m >= src_h - 1))) { - src_offset_x = n + 1; - src_offset_y = m + 1; - } - { - const int pixel1 = src->tpixels[src_offset_y][src_offset_x]; - register int pixel2, pixel3, pixel4; - - if (src_offset_y + 1 >= src_h) { - pixel2 = bgColor; - pixel3 = bgColor; - pixel4 = bgColor; - } else if (src_offset_x + 1 >= src_w) { - pixel2 = bgColor; - pixel3 = bgColor; - pixel4 = bgColor; - } else { - pixel2 = src->tpixels[src_offset_y][src_offset_x + 1]; - pixel3 = src->tpixels[src_offset_y + 1][src_offset_x]; - pixel4 = src->tpixels[src_offset_y + 1][src_offset_x + 1]; - } - { - const gdFixed f_r1 = gd_itofx(gdTrueColorGetRed(pixel1)); - const gdFixed f_r2 = gd_itofx(gdTrueColorGetRed(pixel2)); - const gdFixed f_r3 = gd_itofx(gdTrueColorGetRed(pixel3)); - const gdFixed f_r4 = gd_itofx(gdTrueColorGetRed(pixel4)); - const gdFixed f_g1 = gd_itofx(gdTrueColorGetGreen(pixel1)); - const gdFixed f_g2 = gd_itofx(gdTrueColorGetGreen(pixel2)); - const gdFixed f_g3 = gd_itofx(gdTrueColorGetGreen(pixel3)); - const gdFixed f_g4 = gd_itofx(gdTrueColorGetGreen(pixel4)); - const gdFixed f_b1 = gd_itofx(gdTrueColorGetBlue(pixel1)); - const gdFixed f_b2 = gd_itofx(gdTrueColorGetBlue(pixel2)); - const gdFixed f_b3 = gd_itofx(gdTrueColorGetBlue(pixel3)); - const gdFixed f_b4 = gd_itofx(gdTrueColorGetBlue(pixel4)); - const gdFixed f_a1 = gd_itofx(gdTrueColorGetAlpha(pixel1)); - const gdFixed f_a2 = gd_itofx(gdTrueColorGetAlpha(pixel2)); - const gdFixed f_a3 = gd_itofx(gdTrueColorGetAlpha(pixel3)); - const gdFixed f_a4 = gd_itofx(gdTrueColorGetAlpha(pixel4)); - const gdFixed f_red = gd_mulfx(f_w1, f_r1) + gd_mulfx(f_w2, f_r2) + gd_mulfx(f_w3, f_r3) + gd_mulfx(f_w4, f_r4); - const gdFixed f_green = gd_mulfx(f_w1, f_g1) + gd_mulfx(f_w2, f_g2) + gd_mulfx(f_w3, f_g3) + gd_mulfx(f_w4, f_g4); - const gdFixed f_blue = gd_mulfx(f_w1, f_b1) + gd_mulfx(f_w2, f_b2) + gd_mulfx(f_w3, f_b3) + gd_mulfx(f_w4, f_b4); - const gdFixed f_alpha = gd_mulfx(f_w1, f_a1) + gd_mulfx(f_w2, f_a2) + gd_mulfx(f_w3, f_a3) + gd_mulfx(f_w4, f_a4); - - const unsigned char red = (unsigned char) CLAMP(gd_fxtoi(f_red), 0, 255); - const unsigned char green = (unsigned char) CLAMP(gd_fxtoi(f_green), 0, 255); - const unsigned char blue = (unsigned char) CLAMP(gd_fxtoi(f_blue), 0, 255); - const unsigned char alpha = (unsigned char) CLAMP(gd_fxtoi(f_alpha), 0, 127); - - dst->tpixels[dst_offset_y][dst_offset_x++] = gdTrueColorAlpha(red, green, blue, alpha); - } - } - } else { - dst->tpixels[dst_offset_y][dst_offset_x++] = bgColor; - } - } - dst_offset_y++; - } - return dst; -} - -static gdImagePtr -gdImageRotateBicubicFixed(gdImagePtr src, const float degrees,const int bgColor) -{ - const float _angle = (float)((- degrees / 180.0f) * M_PI); - const int src_w = gdImageSX(src); - const int src_h = gdImageSY(src); - const unsigned int new_width = abs((int)(src_w*cos(_angle))) + abs((int)(src_h*sin(_angle) + 0.5f)); - const unsigned int new_height = abs((int)(src_w*sin(_angle))) + abs((int)(src_h*cos(_angle) + 0.5f)); - const gdFixed f_0_5 = gd_ftofx(0.5f); - const gdFixed f_H = gd_itofx(src_h/2); - const gdFixed f_W = gd_itofx(src_w/2); - const gdFixed f_cos = gd_ftofx(cos(-_angle)); - const gdFixed f_sin = gd_ftofx(sin(-_angle)); - const gdFixed f_1 = gd_itofx(1); - const gdFixed f_2 = gd_itofx(2); - const gdFixed f_4 = gd_itofx(4); - const gdFixed f_6 = gd_itofx(6); - const gdFixed f_gama = gd_ftofx(1.04f); - - unsigned int dst_offset_x; - unsigned int dst_offset_y = 0; - unsigned int i; - gdImagePtr dst; - - /* impact perf a bit, but not that much. Implementation for palette - images can be done at a later point. - */ - if (src->trueColor == 0) { - gdImagePaletteToTrueColor(src); - } - - dst = gdImageCreateTrueColor(new_width, new_height); - - if (dst == NULL) { - return NULL; - } - dst->saveAlphaFlag = 1; - - for (i=0; i < new_height; i++) { - unsigned int j; - dst_offset_x = 0; - - for (j=0; j < new_width; j++) { - const gdFixed f_i = gd_itofx((int)i - (int)new_height / 2); - const gdFixed f_j = gd_itofx((int)j - (int)new_width / 2); - const gdFixed f_m = gd_mulfx(f_j,f_sin) + gd_mulfx(f_i,f_cos) + f_0_5 + f_H; - const gdFixed f_n = gd_mulfx(f_j,f_cos) - gd_mulfx(f_i,f_sin) + f_0_5 + f_W; - const int m = gd_fxtoi(f_m); - const int n = gd_fxtoi(f_n); - - if ((m > 0) && (m < src_h - 1) && (n > 0) && (n < src_w-1)) { - const gdFixed f_f = f_m - gd_itofx(m); - const gdFixed f_g = f_n - gd_itofx(n); - unsigned int src_offset_x[16], src_offset_y[16]; - unsigned char red, green, blue, alpha; - gdFixed f_red=0, f_green=0, f_blue=0, f_alpha=0; - int k; - - if ((m < 1) || (n < 1)) { - src_offset_x[0] = n; - src_offset_y[0] = m; - } else { - src_offset_x[0] = n - 1; - src_offset_y[0] = m; - } - - if (m < 1) { - src_offset_x[1] = n; - src_offset_y[1] = m; - } else { - src_offset_x[1] = n; - src_offset_y[1] = m ; - } - - if ((m < 1) || (n >= src_w-1)) { - src_offset_x[2] = - 1; - src_offset_y[2] = - 1; - } else { - src_offset_x[2] = n + 1; - src_offset_y[2] = m ; - } - - if ((m < 1) || (n >= src_w-2)) { - src_offset_x[3] = - 1; - src_offset_y[3] = - 1; - } else { - src_offset_x[3] = n + 1 + 1; - src_offset_y[3] = m ; - } - - if (n < 1) { - src_offset_x[4] = - 1; - src_offset_y[4] = - 1; - } else { - src_offset_x[4] = n - 1; - src_offset_y[4] = m; - } - - src_offset_x[5] = n; - src_offset_y[5] = m; - if (n >= src_w-1) { - src_offset_x[6] = - 1; - src_offset_y[6] = - 1; - } else { - src_offset_x[6] = n + 1; - src_offset_y[6] = m; - } - - if (n >= src_w-2) { - src_offset_x[7] = - 1; - src_offset_y[7] = - 1; - } else { - src_offset_x[7] = n + 1 + 1; - src_offset_y[7] = m; - } - - if ((m >= src_h-1) || (n < 1)) { - src_offset_x[8] = - 1; - src_offset_y[8] = - 1; - } else { - src_offset_x[8] = n - 1; - src_offset_y[8] = m; - } - - if (m >= src_h-1) { - src_offset_x[8] = - 1; - src_offset_y[8] = - 1; - } else { - src_offset_x[9] = n; - src_offset_y[9] = m; - } - - if ((m >= src_h-1) || (n >= src_w-1)) { - src_offset_x[10] = - 1; - src_offset_y[10] = - 1; - } else { - src_offset_x[10] = n + 1; - src_offset_y[10] = m; - } - - if ((m >= src_h-1) || (n >= src_w-2)) { - src_offset_x[11] = - 1; - src_offset_y[11] = - 1; - } else { - src_offset_x[11] = n + 1 + 1; - src_offset_y[11] = m; - } - - if ((m >= src_h-2) || (n < 1)) { - src_offset_x[12] = - 1; - src_offset_y[12] = - 1; - } else { - src_offset_x[12] = n - 1; - src_offset_y[12] = m; - } - - if (m >= src_h-2) { - src_offset_x[13] = - 1; - src_offset_y[13] = - 1; - } else { - src_offset_x[13] = n; - src_offset_y[13] = m; - } - - if ((m >= src_h-2) || (n >= src_w - 1)) { - src_offset_x[14] = - 1; - src_offset_y[14] = - 1; - } else { - src_offset_x[14] = n + 1; - src_offset_y[14] = m; - } - - if ((m >= src_h-2) || (n >= src_w-2)) { - src_offset_x[15] = - 1; - src_offset_y[15] = - 1; - } else { - src_offset_x[15] = n + 1 + 1; - src_offset_y[15] = m; - } - - for (k=-1; k<3; k++) { - const gdFixed f = gd_itofx(k)-f_f; - const gdFixed f_fm1 = f - f_1; - const gdFixed f_fp1 = f + f_1; - const gdFixed f_fp2 = f + f_2; - gdFixed f_a = 0, f_b = 0,f_c = 0, f_d = 0; - gdFixed f_RY; - int l; - - if (f_fp2 > 0) { - f_a = gd_mulfx(f_fp2,gd_mulfx(f_fp2,f_fp2)); - } - - if (f_fp1 > 0) { - f_b = gd_mulfx(f_fp1,gd_mulfx(f_fp1,f_fp1)); - } - - if (f > 0) { - f_c = gd_mulfx(f,gd_mulfx(f,f)); - } - - if (f_fm1 > 0) { - f_d = gd_mulfx(f_fm1,gd_mulfx(f_fm1,f_fm1)); - } - f_RY = gd_divfx((f_a-gd_mulfx(f_4,f_b)+gd_mulfx(f_6,f_c)-gd_mulfx(f_4,f_d)),f_6); - - for (l=-1; l< 3; l++) { - const gdFixed f = gd_itofx(l) - f_g; - const gdFixed f_fm1 = f - f_1; - const gdFixed f_fp1 = f + f_1; - const gdFixed f_fp2 = f + f_2; - gdFixed f_a = 0, f_b = 0, f_c = 0, f_d = 0; - gdFixed f_RX, f_R; - const int _k = ((k + 1) * 4) + (l + 1); - register gdFixed f_rs, f_gs, f_bs, f_as; - register int c; - - if (f_fp2 > 0) { - f_a = gd_mulfx(f_fp2,gd_mulfx(f_fp2,f_fp2)); - } - - if (f_fp1 > 0) { - f_b = gd_mulfx(f_fp1,gd_mulfx(f_fp1,f_fp1)); - } - - if (f > 0) { - f_c = gd_mulfx(f,gd_mulfx(f,f)); - } - - if (f_fm1 > 0) { - f_d = gd_mulfx(f_fm1,gd_mulfx(f_fm1,f_fm1)); - } - - f_RX = gd_divfx((f_a - gd_mulfx(f_4, f_b) + gd_mulfx(f_6, f_c) - gd_mulfx(f_4, f_d)), f_6); - f_R = gd_mulfx(f_RY, f_RX); - - if ((src_offset_x[_k] <= 0) || (src_offset_y[_k] <= 0) || (src_offset_y[_k] >= src_h) || (src_offset_x[_k] >= src_w)) { - c = bgColor; - } else if ((src_offset_x[_k] <= 1) || (src_offset_y[_k] <= 1) || (src_offset_y[_k] >= (int)src_h - 1) || (src_offset_x[_k] >= (int)src_w - 1)) { - gdFixed f_127 = gd_itofx(127); - c = src->tpixels[src_offset_y[_k]][src_offset_x[_k]]; - c = c | (( (int) (gd_fxtof(gd_mulfx(f_R, f_127)) + 50.5f)) << 24); - c = _color_blend(bgColor, c); - } else { - c = src->tpixels[src_offset_y[_k]][src_offset_x[_k]]; - } - - f_rs = gd_itofx(gdTrueColorGetRed(c)); - f_gs = gd_itofx(gdTrueColorGetGreen(c)); - f_bs = gd_itofx(gdTrueColorGetBlue(c)); - f_as = gd_itofx(gdTrueColorGetAlpha(c)); - - f_red += gd_mulfx(f_rs, f_R); - f_green += gd_mulfx(f_gs, f_R); - f_blue += gd_mulfx(f_bs, f_R); - f_alpha += gd_mulfx(f_as, f_R); - } - } - - red = (unsigned char) CLAMP(gd_fxtoi(gd_mulfx(f_red, f_gama)), 0, 255); - green = (unsigned char) CLAMP(gd_fxtoi(gd_mulfx(f_green, f_gama)), 0, 255); - blue = (unsigned char) CLAMP(gd_fxtoi(gd_mulfx(f_blue, f_gama)), 0, 255); - alpha = (unsigned char) CLAMP(gd_fxtoi(gd_mulfx(f_alpha, f_gama)), 0, 127); - - dst->tpixels[dst_offset_y][dst_offset_x] = gdTrueColorAlpha(red, green, blue, alpha); - } else { - dst->tpixels[dst_offset_y][dst_offset_x] = bgColor; - } - dst_offset_x++; - } - - dst_offset_y++; - } - return dst; -} - +/* + Function: gdImageRotateInterpolated +*/ BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor) { /* round to two decimals and keep the 100x multiplication to use it in the common square angles @@ -2216,7 +1825,7 @@ BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const fl return dst; } - case -2700: + case -27000: case 9000: return gdImageRotate90(src, 0); @@ -2239,13 +1848,7 @@ BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const fl break; case GD_BILINEAR_FIXED: - return gdImageRotateBilinear(src, angle, bgcolor); - break; - case GD_BICUBIC_FIXED: - return gdImageRotateBicubicFixed(src, angle, bgcolor); - break; - default: return gdImageRotateGeneric(src, angle, bgcolor); } @@ -2339,7 +1942,7 @@ BGD_DECLARE(int) gdTransformAffineGetImage(gdImagePtr *dst, if (res != GD_TRUE) { gdImageDestroy(*dst); - dst = NULL; + *dst = NULL; return GD_FALSE; } else { return GD_TRUE; @@ -2412,8 +2015,8 @@ BGD_DECLARE(int) gdTransformAffineCopy(gdImagePtr dst, gdImageGetClip(dst, &c1x, &c1y, &c2x, &c2y); - end_x = bbox.width + (int) fabs(bbox.x); - end_y = bbox.height + (int) fabs(bbox.y); + end_x = bbox.width + abs(bbox.x); + end_y = bbox.height + abs(bbox.y); /* Get inverse affine to let us work with destination -> source */ gdAffineInvert(inv, affine); @@ -2508,35 +2111,40 @@ BGD_DECLARE(int) gdTransformAffineBoundingBox(gdRectPtr src, const double affine } bbox->x = (int) min.x; bbox->y = (int) min.y; - bbox->width = (int) floor(max.x - min.x) - 1; - bbox->height = (int) floor(max.y - min.y); + bbox->width = (int) ceil((max.x - min.x)) + 1; + bbox->height = (int) ceil(max.y - min.y) + 1; + return GD_TRUE; } +/* + Function: gdImageSetInterpolationMethod +*/ BGD_DECLARE(int) gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id) { - if (im == NULL || id < 0 || id > GD_METHOD_COUNT) { + if (im == NULL || (uintmax_t)id > GD_METHOD_COUNT) { return 0; } switch (id) { - case GD_DEFAULT: - id = GD_BILINEAR_FIXED; - /* Optimized versions */ - case GD_BILINEAR_FIXED: - case GD_BICUBIC_FIXED: case GD_NEAREST_NEIGHBOUR: case GD_WEIGHTED4: im->interpolation = NULL; break; /* generic versions*/ + /* GD_BILINEAR_FIXED and GD_BICUBIC_FIXED are kept for BC reasons */ + case GD_BILINEAR_FIXED: + case GD_LINEAR: + im->interpolation = filter_linear; + break; case GD_BELL: im->interpolation = filter_bell; break; case GD_BESSEL: im->interpolation = filter_bessel; break; + case GD_BICUBIC_FIXED: case GD_BICUBIC: im->interpolation = filter_bicubic; break; @@ -2582,7 +2190,9 @@ BGD_DECLARE(int) gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMet case GD_TRIANGLE: im->interpolation = filter_triangle; break; - + case GD_DEFAULT: + id = GD_LINEAR; + im->interpolation = filter_linear; default: return 0; break; @@ -2592,9 +2202,13 @@ BGD_DECLARE(int) gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMet } -/* Return the interpolation mode set in 'im'. This is here so that - * the value can be read via a language or VM with an FFI but no - * (portable) way to extract the value from the struct. */ +/* + Function: gdImageGetInterpolationMethod + + Return the interpolation mode set in 'im'. This is here so that + the value can be read via a language or VM with an FFI but no + (portable) way to extract the value from the struct. +*/ BGD_DECLARE(gdInterpolationMethod) gdImageGetInterpolationMethod(gdImagePtr im) { return im->interpolation_id; diff --git a/Build/source/libs/gd/libgd-src/src/gd_io_dp.c b/Build/source/libs/gd/libgd-src/src/gd_io_dp.c index 8dbcc62e2aa..135eda3fcb0 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_io_dp.c +++ b/Build/source/libs/gd/libgd-src/src/gd_io_dp.c @@ -64,13 +64,20 @@ static int dynamicGetchar(gdIOCtxPtr ctx); static int dynamicSeek(struct gdIOCtx *, const int); static long dynamicTell(struct gdIOCtx *); -/* return data as a dynamic pointer */ +/* + Function: gdNewDynamicCtx + + Return data as a dynamic pointer. +*/ BGD_DECLARE(gdIOCtx *) gdNewDynamicCtx(int initialSize, void *data) { /* 2.0.23: Phil Moore: 'return' keyword was missing! */ return gdNewDynamicCtxEx(initialSize, data, 1); } +/* + Function: gdNewDynamicCtxEx +*/ BGD_DECLARE(gdIOCtx *) gdNewDynamicCtxEx(int initialSize, void *data, int freeOKFlag) { dpIOCtx *ctx; @@ -103,6 +110,9 @@ BGD_DECLARE(gdIOCtx *) gdNewDynamicCtxEx(int initialSize, void *data, int freeOK return (gdIOCtx *)ctx; } +/* + Function: gdDPExtractData +*/ BGD_DECLARE(void *) gdDPExtractData (struct gdIOCtx *ctx, int *size) { dynamicPtr *dp; diff --git a/Build/source/libs/gd/libgd-src/src/gd_io_file.c b/Build/source/libs/gd/libgd-src/src/gd_io_file.c index d3893e4cea2..40c4f5921b6 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_io_file.c +++ b/Build/source/libs/gd/libgd-src/src/gd_io_file.c @@ -48,7 +48,11 @@ static int fileSeek(struct gdIOCtx *, const int); static long fileTell(struct gdIOCtx *); static void gdFreeFileCtx(gdIOCtx *ctx); -/* return data as a dynamic pointer */ +/* + Function: gdNewFileCtx + + Return data as a dynamic pointer. +*/ BGD_DECLARE(gdIOCtx *) gdNewFileCtx(FILE *f) { fileIOCtx *ctx; diff --git a/Build/source/libs/gd/libgd-src/src/gd_io_ss.c b/Build/source/libs/gd/libgd-src/src/gd_io_ss.c index a0cf3918f91..abff844affa 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_io_ss.c +++ b/Build/source/libs/gd/libgd-src/src/gd_io_ss.c @@ -47,7 +47,11 @@ static int sinkPutbuf(gdIOCtx *ctx, const void *buf, int size); static void sinkPutchar(gdIOCtx *ctx, int a); static void gdFreeSsCtx(gdIOCtx *ctx); -/* return data as a dynamic pointer */ +/* + Function: gdNewSSCtx + + Return data as a dynamic pointer. +*/ BGD_DECLARE(gdIOCtx *) gdNewSSCtx(gdSourcePtr src, gdSinkPtr snk) { ssIOCtxPtr ctx; diff --git a/Build/source/libs/gd/libgd-src/src/gd_io_stream.cxx b/Build/source/libs/gd/libgd-src/src/gd_io_stream.cxx index 04c0011b3e9..28021afc1ae 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_io_stream.cxx +++ b/Build/source/libs/gd/libgd-src/src/gd_io_stream.cxx @@ -1,145 +1,145 @@ -/* *****************************************************************************
-** $Id$
-** Initial file written and documented by:
-** Kevin Shepherd <kshepherd@php.net> December 2007
-** of Scarlet Line http://www.scarletline.com/
-*******************************************************************************/
-/** \file gd_io_stream.cxx
- \brief Implementation of the methods of the gdIOCtx std stream specialization.
-
- Implements the derived specializations of gdIOCtx.
- These methods are not called by users of libgd, they
- are internal implementation.
- Note that half of the below methods are trivial stubs,
- as an input stream has no need of output methods, and vice-versa.
-*/
-#ifdef __cplusplus
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "gd_io_stream.h"
-
-/** Read into buffer from stream
- Return the number of bytes successfully read.
- If an error occurs, or the end-of-file is reached, the return value
- is a short byte count (or zero).
-*/
-int istreamIOCtx::Getbuf (struct gdIOCtx * ctx, void * buf, int size)
- {
- stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
- _str->read((char * )buf, size);
- return _str->gcount();
- }
-/** Write from buffer to stream
- Return the number of bytes successfully written.
- If an error occurs, or the end-of-file is reached, the return value
- is a short byte count (or zero).
-*/
-int istreamIOCtx::Putbuf (struct gdIOCtx * , const void * , int )
- {
- return 0;
- }
-
-/** Reads the next character from stream and returns it as an
- unsigned char cast to an int, or EOF on end of file or error.
-*/
-int istreamIOCtx::Getchar (struct gdIOCtx * ctx)
- {
- stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
- return _str->get();
- }
-/** Write the character to stream
- Character is cast to unsigned char before writing
-*/
-void istreamIOCtx::Putchar (struct gdIOCtx * , int )
- {
- }
-
-/** Seek to position offset from the beginning of the stream
- must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek!
-*/
-int istreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos)
- {
- stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
- _str->seekg(pos);
- return !_str->fail();
- }
-/** Obtains the current value of the stream position.
- Returns -1 on error.
-*/
-long istreamIOCtx::Tell (struct gdIOCtx * ctx)
- {
- stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
- return _str->tellg();
- }
-/** Deallocate the context
-*/
-void istreamIOCtx::FreeCtx (struct gdIOCtx * ctx)
- {
- delete (istreamIOCtx * )ctx;
- }
-
-/** Read into buffer from stream
- Return the number of bytes successfully read.
- If an error occurs, or the end-of-file is reached, the return value
- is a short byte count (or zero).
-*/
-int ostreamIOCtx::Getbuf (struct gdIOCtx * , void * , int )
- {
- return 0;
- }
-/** Write from buffer to stream
- Return the number of bytes successfully written.
- If an error occurs, or the end-of-file is reached, the return value
- is a short byte count (or zero).
-*/
-int ostreamIOCtx::Putbuf (struct gdIOCtx * ctx, const void * buf, int size)
- {
- stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
- _str->write((const char * )buf, size);
- return _str->bad()?0:size;
- }
-
-/** Reads the next character from stream and returns it as an
- unsigned char cast to an int, or EOF on end of file or error.
-*/
-int ostreamIOCtx::Getchar (struct gdIOCtx * )
- {
- return EOF;
- }
-/** Write the character to stream
- Character is cast to unsigned char before writing
-*/
-void ostreamIOCtx::Putchar (struct gdIOCtx * ctx, int c)
- {
- stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
- _str->put((char)c);
- }
-
-/** Seek to position offset from the beginning of the stream
- must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek!
-*/
-int ostreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos)
- {
- stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
- _str->seekp(pos);
- return !_str->fail();
- }
-/** Obtains the current value of the stream position.
- Returns -1 on error.
-*/
-long ostreamIOCtx::Tell (struct gdIOCtx * ctx)
- {
- stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
- return _str->tellp();
- }
-/** Deallocate the context
-*/
-void ostreamIOCtx::FreeCtx (struct gdIOCtx * ctx)
- {
- delete (ostreamIOCtx * )ctx;
- }
-
-#endif /* __cplusplus */
+/* ***************************************************************************** +** $Id$ +** Initial file written and documented by: +** Kevin Shepherd <kshepherd@php.net> December 2007 +** of Scarlet Line http://www.scarletline.com/ +*******************************************************************************/ +/** \file gd_io_stream.cxx + \brief Implementation of the methods of the gdIOCtx std stream specialization. + + Implements the derived specializations of gdIOCtx. + These methods are not called by users of libgd, they + are internal implementation. + Note that half of the below methods are trivial stubs, + as an input stream has no need of output methods, and vice-versa. +*/ +#ifdef __cplusplus + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gd_io_stream.h" + +/** Read into buffer from stream + Return the number of bytes successfully read. + If an error occurs, or the end-of-file is reached, the return value + is a short byte count (or zero). +*/ +int istreamIOCtx::Getbuf (struct gdIOCtx * ctx, void * buf, int size) + { + stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream; + _str->read((char * )buf, size); + return _str->gcount(); + } +/** Write from buffer to stream + Return the number of bytes successfully written. + If an error occurs, or the end-of-file is reached, the return value + is a short byte count (or zero). +*/ +int istreamIOCtx::Putbuf (struct gdIOCtx * , const void * , int ) + { + return 0; + } + +/** Reads the next character from stream and returns it as an + unsigned char cast to an int, or EOF on end of file or error. +*/ +int istreamIOCtx::Getchar (struct gdIOCtx * ctx) + { + stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream; + return _str->get(); + } +/** Write the character to stream + Character is cast to unsigned char before writing +*/ +void istreamIOCtx::Putchar (struct gdIOCtx * , int ) + { + } + +/** Seek to position offset from the beginning of the stream + must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! +*/ +int istreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos) + { + stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream; + _str->seekg(pos); + return !_str->fail(); + } +/** Obtains the current value of the stream position. + Returns -1 on error. +*/ +long istreamIOCtx::Tell (struct gdIOCtx * ctx) + { + stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream; + return _str->tellg(); + } +/** Deallocate the context +*/ +void istreamIOCtx::FreeCtx (struct gdIOCtx * ctx) + { + delete (istreamIOCtx * )ctx; + } + +/** Read into buffer from stream + Return the number of bytes successfully read. + If an error occurs, or the end-of-file is reached, the return value + is a short byte count (or zero). +*/ +int ostreamIOCtx::Getbuf (struct gdIOCtx * , void * , int ) + { + return 0; + } +/** Write from buffer to stream + Return the number of bytes successfully written. + If an error occurs, or the end-of-file is reached, the return value + is a short byte count (or zero). +*/ +int ostreamIOCtx::Putbuf (struct gdIOCtx * ctx, const void * buf, int size) + { + stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream; + _str->write((const char * )buf, size); + return _str->bad()?0:size; + } + +/** Reads the next character from stream and returns it as an + unsigned char cast to an int, or EOF on end of file or error. +*/ +int ostreamIOCtx::Getchar (struct gdIOCtx * ) + { + return EOF; + } +/** Write the character to stream + Character is cast to unsigned char before writing +*/ +void ostreamIOCtx::Putchar (struct gdIOCtx * ctx, int c) + { + stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream; + _str->put((char)c); + } + +/** Seek to position offset from the beginning of the stream + must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! +*/ +int ostreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos) + { + stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream; + _str->seekp(pos); + return !_str->fail(); + } +/** Obtains the current value of the stream position. + Returns -1 on error. +*/ +long ostreamIOCtx::Tell (struct gdIOCtx * ctx) + { + stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream; + return _str->tellp(); + } +/** Deallocate the context +*/ +void ostreamIOCtx::FreeCtx (struct gdIOCtx * ctx) + { + delete (ostreamIOCtx * )ctx; + } + +#endif /* __cplusplus */ diff --git a/Build/source/libs/gd/libgd-src/src/gd_jpeg.c b/Build/source/libs/gd/libgd-src/src/gd_jpeg.c index 925b417fac3..51233952d44 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_jpeg.c +++ b/Build/source/libs/gd/libgd-src/src/gd_jpeg.c @@ -307,6 +307,10 @@ BGD_DECLARE(void) gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality) if(quality >= 0) { jpeg_set_quality(&cinfo, quality, TRUE); + if (quality >= 90) { + cinfo.comp_info[0].h_samp_factor = 1; + cinfo.comp_info[0].v_samp_factor = 1; + } } /* If user requests interlace, translate that to progressive JPEG */ @@ -863,26 +867,12 @@ static int CMYKToRGB(int c, int m, int y, int k, int inverted) * almost a simple global replace from T. Lane's stdio versions. */ -/* Different versions of libjpeg use either 'jboolean' or 'boolean', and - * some platforms define 'boolean', and so forth. Deal with this - * madness by typedeffing 'safeboolean' to 'boolean' if HAVE_BOOLEAN - * is already set, because this is the test that libjpeg uses. - * Otherwise, typedef it to int, because that's what libjpeg does - * if HAVE_BOOLEAN is not defined. -TBB - */ - -#ifdef HAVE_BOOLEAN -typedef boolean safeboolean; -#else -typedef int safeboolean; -#endif /* HAVE_BOOLEAN */ - /* Expanded data source object for gdIOCtx input */ typedef struct { struct jpeg_source_mgr pub; /* public fields */ gdIOCtx *infile; /* source stream */ unsigned char *buffer; /* start of buffer */ - safeboolean start_of_file; /* have we gotten any data yet? */ + boolean start_of_file; /* have we gotten any data yet? */ } my_source_mgr; @@ -942,7 +932,7 @@ void init_source(j_decompress_ptr cinfo) #define END_JPEG_SEQUENCE "\r\n[*]--:END JPEG:--[*]\r\n" -safeboolean fill_input_buffer(j_decompress_ptr cinfo) +boolean fill_input_buffer(j_decompress_ptr cinfo) { my_src_ptr src = (my_src_ptr)cinfo->src; /* 2.0.12: signed size. Thanks to Geert Jansen */ @@ -1132,7 +1122,7 @@ void init_destination(j_compress_ptr cinfo) * write it out when emptying the buffer externally. */ -safeboolean empty_output_buffer(j_compress_ptr cinfo) +boolean empty_output_buffer(j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr)cinfo->dest; diff --git a/Build/source/libs/gd/libgd-src/src/gd_nnquant.c b/Build/source/libs/gd/libgd-src/src/gd_nnquant.c index c4b43d6ea35..d6b2b275766 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_nnquant.c +++ b/Build/source/libs/gd/libgd-src/src/gd_nnquant.c @@ -246,16 +246,16 @@ void inxbuild(nn_quant *nnq) /* Search for ABGR values 0..255 (after net is unbiased) and return colour index ---------------------------------------------------------------------------- */ -int inxsearch(nnq, al,b,g,r) +unsigned int inxsearch(nnq, al,b,g,r) nn_quant *nnq; register int al, b, g, r; { register int i, j, dist, a, bestd; register int *p; - int best; + unsigned int best; bestd = 1000; /* biggest possible dist is 256*3 */ - best = -1; + best = 0; i = nnq->netindex[g]; /* index on g */ j = i-1; /* start at netindex[g] and work outwards */ @@ -330,12 +330,13 @@ register int al,b,g,r; /* bias[i] = gamma*((1/netsize)-freq[i]) */ register int i,dist,a,biasdist,betafreq; - int bestpos,bestbiaspos,bestd,bestbiasd; + unsigned int bestpos,bestbiaspos; + double bestd,bestbiasd; register int *p,*f, *n; bestd = ~(((int) 1)<<31); bestbiasd = bestd; - bestpos = -1; + bestpos = 0; bestbiaspos = bestpos; p = nnq->bias; f = nnq->freq; @@ -463,7 +464,7 @@ int verbose; radius = initradius; rad = radius >> radiusbiasshift; - if (rad <= 1) rad = 0; + for (i=0; i<rad; i++) nnq->radpower[i] = alpha*(((rad*rad - i*i)*radbias)/(rad*rad)); @@ -505,6 +506,9 @@ int verbose; if (verbose) gd_error_ex(GD_NOTICE, "finished 1D learning: final alpha=%f !\n",((float)alpha)/initalpha); } +/* + Function: gdImageNeuQuant +*/ BGD_DECLARE(gdImagePtr) gdImageNeuQuant(gdImagePtr im, const int max_color, int sample_factor) { const int newcolors = max_color; diff --git a/Build/source/libs/gd/libgd-src/src/gd_png.c b/Build/source/libs/gd/libgd-src/src/gd_png.c index 95139e8b8b5..ab93e4347ce 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_png.c +++ b/Build/source/libs/gd/libgd-src/src/gd_png.c @@ -251,7 +251,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) */ /* setjmp() must be called in every non-callback function that calls a - * PNG-reading libpng function */ + * PNG-reading libpng function. We must reset it everytime we get a + * new allocation that we save in a stack variable. + */ #ifdef PNG_SETJMP_SUPPORTED if (setjmp(jbw.jmpbuf)) { gd_error("gd-png error: setjmp returns error condition 1\n"); @@ -275,9 +277,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) } if (im == NULL) { gd_error("gd-png error: cannot allocate gdImage struct\n"); - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); - - return NULL; + goto error; } if (bit_depth == 16) { @@ -287,18 +287,13 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) } /* setjmp() must be called in every non-callback function that calls a - * PNG-reading libpng function + * PNG-reading libpng function. We must reset it everytime we get a + * new allocation that we save in a stack variable. */ #ifdef PNG_SETJMP_SUPPORTED if (setjmp(jbw.jmpbuf)) { gd_error("gd-png error: setjmp returns error condition 2\n"); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - gdFree(image_data); - gdFree(row_pointers); - if (im) { - gdImageDestroy(im); - } - return NULL; + goto error; } #endif @@ -346,9 +341,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) /* create a fake palette and check for single-shade transparency */ if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) { gd_error("gd-png error: cannot allocate gray palette\n"); - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); - gdImageDestroy(im); - return NULL; + goto error; } palette_allocated = TRUE; if (bit_depth < 8) { @@ -406,65 +399,40 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) break; default: gd_error("gd-png color_type is unknown: %d\n", color_type); - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - gdFree(image_data); - gdFree(row_pointers); - if (im) { - gdImageDestroy(im); - } - return NULL; - break; + goto error; } png_read_update_info (png_ptr, info_ptr); /* allocate space for the PNG image data */ rowbytes = png_get_rowbytes (png_ptr, info_ptr); - if (overflow2(rowbytes, height)) { - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); - if (im) { - gdImageDestroy(im); - } - return NULL; - } + if (overflow2(rowbytes, height)) + goto error; image_data = (png_bytep) gdMalloc (rowbytes * height); if (!image_data) { gd_error("gd-png error: cannot allocate image data\n"); - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); - if (im) { - gdImageDestroy(im); - } - if (palette_allocated) { - gdFree (palette); - } - return NULL; - } - if (overflow2(height, sizeof (png_bytep))) { - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); - gdFree (image_data); - if (im) { - gdImageDestroy(im); - } - if (palette_allocated) { - gdFree (palette); - } - return NULL; + goto error; } + if (overflow2(height, sizeof (png_bytep))) + goto error; row_pointers = (png_bytepp) gdMalloc (height * sizeof (png_bytep)); if (!row_pointers) { gd_error("gd-png error: cannot allocate row pointers\n"); - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); - if (im) { - gdImageDestroy(im); - } - gdFree (image_data); - if (palette_allocated) { - gdFree (palette); - } - return NULL; + goto error; } + /* setjmp() must be called in every non-callback function that calls a + * PNG-reading libpng function. We must reset it everytime we get a + * new allocation that we save in a stack variable. + */ +#ifdef PNG_SETJMP_SUPPORTED + if (setjmp(jbw.jmpbuf)) { + gd_error("gd-png error: setjmp returns error condition 3\n"); + goto error; + } +#endif + /* set the individual row_pointers to point at the correct offsets */ for (h = 0; h < height; ++h) { row_pointers[h] = image_data + h * rowbytes; @@ -527,12 +495,14 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) } break; default: - /* Palette image, or something coerced to be one */ - for (h = 0; h < height; ++h) { - for (w = 0; w < width; ++w) { - register png_byte idx = row_pointers[h][w]; - im->pixels[h][w] = idx; - open[idx] = 0; + if (!im->trueColor) { + /* Palette image, or something coerced to be one */ + for (h = 0; h < height; ++h) { + for (w = 0; w < width; ++w) { + register png_byte idx = row_pointers[h][w]; + im->pixels[h][w] = idx; + open[idx] = 0; + } } } } @@ -548,13 +518,24 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromPngCtx (gdIOCtx * infile) } #endif + done: if (palette_allocated) { gdFree (palette); } - gdFree (image_data); - gdFree (row_pointers); + if (image_data) + gdFree(image_data); + if (row_pointers) + gdFree(row_pointers); return im; + + error: + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + if (im) { + gdImageDestroy(im); + im = NULL; + } + goto done; } diff --git a/Build/source/libs/gd/libgd-src/src/gd_rotate.c b/Build/source/libs/gd/libgd-src/src/gd_rotate.c index eb057e1148e..e590b3f2114 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_rotate.c +++ b/Build/source/libs/gd/libgd-src/src/gd_rotate.c @@ -55,16 +55,28 @@ void gdImageSkewX (gdImagePtr dst, gdImagePtr src, int uRow, int iOffset, double b = (int)(gdImageBlue(src,pxlSrc) * dWeight); a = (int)(gdImageAlpha(src,pxlSrc) * dWeight); - pxlLeft = gdImageColorAllocateAlpha(src, r, g, b, a); + if (r>255) { + r = 255; + } - if (pxlLeft == -1) { - pxlLeft = gdImageColorClosestAlpha(src, r, g, b, a); + if (g>255) { + g = 255; } - r = gdImageRed(src,pxlSrc) - (gdImageRed(src,pxlLeft) - gdImageRed(src,pxlOldLeft)); - g = gdImageGreen(src,pxlSrc) - (gdImageGreen(src,pxlLeft) - gdImageGreen(src,pxlOldLeft)); - b = gdImageBlue(src,pxlSrc) - (gdImageBlue(src,pxlLeft) - gdImageBlue(src,pxlOldLeft)); - a = gdImageAlpha(src,pxlSrc) - (gdImageAlpha(src,pxlLeft) - gdImageAlpha(src,pxlOldLeft)); + if (b>255) { + b = 255; + } + + if (a>127) { + a = 127; + } + + pxlLeft = gdTrueColorAlpha(r, g, b, a); + + r = gdImageRed(src,pxlSrc) - (r - gdImageRed(src,pxlOldLeft)); + g = gdImageGreen(src,pxlSrc) - (g - gdImageGreen(src,pxlOldLeft)); + b = gdImageBlue(src,pxlSrc) - (b - gdImageBlue(src,pxlOldLeft)); + a = gdImageAlpha(src,pxlSrc) - (a - gdImageAlpha(src,pxlOldLeft)); if (r>255) { r = 255; @@ -145,19 +157,31 @@ void gdImageSkewY (gdImagePtr dst, gdImagePtr src, int uCol, int iOffset, double b = (int)((double)gdImageBlue(src,pxlSrc) * dWeight); a = (int)((double)gdImageAlpha(src,pxlSrc) * dWeight); - pxlLeft = gdImageColorAllocateAlpha(src, r, g, b, a); + if (r>255) { + r = 255; + } + + if (g>255) { + g = 255; + } + + if (b>255) { + b = 255; + } - if (pxlLeft == -1) { - pxlLeft = gdImageColorClosestAlpha(src, r, g, b, a); + if (a>127) { + a = 127; } - r = gdImageRed(src,pxlSrc) - (gdImageRed(src,pxlLeft) - gdImageRed(src,pxlOldLeft)); - g = gdImageGreen(src,pxlSrc) - (gdImageGreen(src,pxlLeft) - gdImageGreen(src,pxlOldLeft)); - b = gdImageBlue(src,pxlSrc) - (gdImageBlue(src,pxlLeft) - gdImageBlue(src,pxlOldLeft)); - a = gdImageAlpha(src,pxlSrc) - (gdImageAlpha(src,pxlLeft) - gdImageAlpha(src,pxlOldLeft)); + pxlLeft = gdTrueColorAlpha(r, g, b, a); + + r = gdImageRed(src,pxlSrc) - (r - gdImageRed(src,pxlOldLeft)); + g = gdImageGreen(src,pxlSrc) - (g - gdImageGreen(src,pxlOldLeft)); + b = gdImageBlue(src,pxlSrc) - (b - gdImageBlue(src,pxlOldLeft)); + a = gdImageAlpha(src,pxlSrc) - (a - gdImageAlpha(src,pxlOldLeft)); if (r>255) { - r = 255; + r = 255; } if (g>255) { @@ -529,5 +553,3 @@ gdImagePtr gdImageRotate (gdImagePtr src, double dAngle, int clrBack, int ignore return rotatedImg; } /* End Rotate function */ - - diff --git a/Build/source/libs/gd/libgd-src/src/gd_ss.c b/Build/source/libs/gd/libgd-src/src/gd_ss.c index 9098c9bc91c..248699e370b 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_ss.c +++ b/Build/source/libs/gd/libgd-src/src/gd_ss.c @@ -18,6 +18,9 @@ #define GD_SS_DBG(s) #ifdef HAVE_LIBPNG +/* + Function: gdImagePngToSink +*/ BGD_DECLARE(void) gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink) { gdIOCtx *out = gdNewSSCtx (NULL, outSink); diff --git a/Build/source/libs/gd/libgd-src/src/gd_tga.c b/Build/source/libs/gd/libgd-src/src/gd_tga.c index 756248afcea..170532478e2 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_tga.c +++ b/Build/source/libs/gd/libgd-src/src/gd_tga.c @@ -12,10 +12,14 @@ #include "gd_errors.h" #include "gdhelpers.h" -/*! \brief Creates a gdImage from a TGA file - * Creates a gdImage from a TGA binary file via a gdIOCtx. - * \param infile Pointer to TGA binary file - * \return gdImagePtr +/* + Function: gdImageCreateFromTga + + Creates a gdImage from a TGA file + + Parameters: + + infile - Pointer to TGA binary file */ BGD_DECLARE(gdImagePtr) gdImageCreateFromTga(FILE *fp) { @@ -27,6 +31,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTga(FILE *fp) return image; } +/* + Function: gdImageCreateFromTgaPtr +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data) { gdImagePtr im; @@ -38,10 +45,13 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data) } -/*! \brief Creates a gdImage from a gdIOCtx - * Creates a gdImage from a gdIOCtx referencing a TGA binary file. - * \param ctx Pointer to a gdIOCtx structure - * \return gdImagePtr +/* + Function: gdImageCreateFromTgaCtx + + Creates a gdImage from a gdIOCtx referencing a TGA binary file. + + Parameters: + ctx - Pointer to a gdIOCtx structure */ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx) { @@ -61,7 +71,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx) tga->bitmap = NULL; tga->ident = NULL; - if (!read_header_tga(ctx, tga)) { + if (read_header_tga(ctx, tga) < 0) { free_tga(tga); return NULL; } @@ -71,7 +81,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx) image_block_size = (tga->width * tga->height) * pixel_block_size; */ - if (read_image_tga(ctx, tga)) { + if (read_image_tga(ctx, tga) < 0) { free_tga(tga); return NULL; } @@ -99,7 +109,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx) if (tga->bits == TGA_BPP_24) { *tpix = gdTrueColor(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret]); bitmap_caret += 3; - } else if (tga->bits == TGA_BPP_32 || tga->alphabits) { + } else if (tga->bits == TGA_BPP_32 && tga->alphabits) { register int a = tga->bitmap[bitmap_caret + 3]; *tpix = gdTrueColorAlpha(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret], gdAlphaMax - (a >> 1)); @@ -159,16 +169,12 @@ int read_header_tga(gdIOCtx *ctx, oTga *tga) printf("wxh: %i %i\n", tga->width, tga->height); #endif - switch(tga->bits) { - case 8: - case 16: - case 24: - case 32: - break; - default: - gd_error("bps %i not supported", tga->bits); + if (!((tga->bits == TGA_BPP_24 && tga->alphabits == 0) + || (tga->bits == TGA_BPP_32 && tga->alphabits == 8))) + { + gd_error_ex(GD_WARNING, "gd-tga: %u bits per pixel with %u alpha bits not supported\n", + tga->bits, tga->alphabits); return -1; - break; } tga->ident = NULL; @@ -179,7 +185,7 @@ int read_header_tga(gdIOCtx *ctx, oTga *tga) return -1; } - gdGetBuf( &( tga->ident ), tga->identsize, ctx ); + gdGetBuf(tga->ident, tga->identsize, ctx); } return 1; @@ -200,8 +206,7 @@ int read_image_tga( gdIOCtx *ctx, oTga *tga ) int buffer_caret = 0; int bitmap_caret = 0; int i = 0; - int j = 0; - uint8_t encoded_pixels; + int encoded_pixels; if(overflow2(tga->width, tga->height)) { return -1; @@ -211,73 +216,70 @@ int read_image_tga( gdIOCtx *ctx, oTga *tga ) return -1; } - if(overflow2(image_block_size, sizeof(uint8_t))) { + if(overflow2(image_block_size, sizeof(int))) { return -1; } - /*! \brief Allocate memmory for image block - * Allocate a chunk of memory for the image block to be passed into. + /*! \todo Add more image type support. */ - tga->bitmap = (int *) gdMalloc(image_block_size * sizeof(uint8_t)); - if (tga->bitmap == NULL) { + if (tga->imagetype != TGA_TYPE_RGB && tga->imagetype != TGA_TYPE_RGB_RLE) return -1; - } - /*! \todo Add image type support - * Add support for this image type. - */ - if (tga->imagetype == TGA_TYPE_INDEXED) { - return -1; - } - - /*! \todo Add image type support - * Add support for this image type. + /*! \brief Allocate memmory for image block + * Allocate a chunk of memory for the image block to be passed into. */ - if (tga->imagetype == TGA_TYPE_INDEXED_RLE) { + tga->bitmap = (int *) gdMalloc(image_block_size * sizeof(int)); + if (tga->bitmap == NULL) return -1; - } - /*! \brief Read in uncompressed RGB TGA - * Chunk load the pixel data from an uncompressed RGB type TGA. - */ - if (tga->imagetype == TGA_TYPE_RGB) { + switch (tga->imagetype) { + case TGA_TYPE_RGB: + /*! \brief Read in uncompressed RGB TGA + * Chunk load the pixel data from an uncompressed RGB type TGA. + */ conversion_buffer = (unsigned char *) gdMalloc(image_block_size * sizeof(unsigned char)); if (conversion_buffer == NULL) { - gdFree(conversion_buffer); return -1; } - gdGetBuf(conversion_buffer, image_block_size, ctx); + if (gdGetBuf(conversion_buffer, image_block_size, ctx) != image_block_size) { + gd_error("gd-tga: premature end of image data\n"); + gdFree(conversion_buffer); + return -1; + } while (buffer_caret < image_block_size) { tga->bitmap[buffer_caret] = (int) conversion_buffer[buffer_caret]; buffer_caret++; } - gdFree( conversion_buffer ); - } + gdFree(conversion_buffer); + break; - /*! \brief Read in RLE compressed RGB TGA - * Chunk load the pixel data from an RLE compressed RGB type TGA. - */ - if (tga->imagetype == TGA_TYPE_RGB_RLE) { + case TGA_TYPE_RGB_RLE: + /*! \brief Read in RLE compressed RGB TGA + * Chunk load the pixel data from an RLE compressed RGB type TGA. + */ decompression_buffer = (uint8_t*) gdMalloc(image_block_size * sizeof(uint8_t)); if (decompression_buffer == NULL) { - gdFree( decompression_buffer ); return -1; } conversion_buffer = (unsigned char *) gdMalloc(image_block_size * sizeof(unsigned char)); if (conversion_buffer == NULL) { + gd_error("gd-tga: premature end of image data\n"); gdFree( decompression_buffer ); - gdFree( conversion_buffer ); return -1; } - gdGetBuf( conversion_buffer, image_block_size, ctx ); + if (gdGetBuf(conversion_buffer, image_block_size, ctx) != image_block_size) { + gdFree(conversion_buffer); + gdFree(decompression_buffer); + return -1; + } buffer_caret = 0; - while( buffer_caret < image_block_size ) { + while( buffer_caret < image_block_size) { decompression_buffer[buffer_caret] = (int)conversion_buffer[buffer_caret]; buffer_caret++; } @@ -285,50 +287,44 @@ int read_image_tga( gdIOCtx *ctx, oTga *tga ) buffer_caret = 0; while( bitmap_caret < image_block_size ) { - + if ((decompression_buffer[buffer_caret] & TGA_RLE_FLAG) == TGA_RLE_FLAG) { - encoded_pixels = ( ( decompression_buffer[ buffer_caret ] & 127 ) + 1 ); + encoded_pixels = ( ( decompression_buffer[ buffer_caret ] & ~TGA_RLE_FLAG ) + 1 ); buffer_caret++; + if ((bitmap_caret + (encoded_pixels * pixel_block_size)) >= image_block_size) { + gdFree( decompression_buffer ); + gdFree( conversion_buffer ); + return -1; + } + for (i = 0; i < encoded_pixels; i++) { - for (j = 0; j < pixel_block_size; j++, bitmap_caret++) { - tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ]; - } + memcpy(tga->bitmap + bitmap_caret, decompression_buffer + buffer_caret, pixel_block_size); + bitmap_caret += pixel_block_size; } buffer_caret += pixel_block_size; + } else { encoded_pixels = decompression_buffer[ buffer_caret ] + 1; buffer_caret++; - for (i = 0; i < encoded_pixels; i++) { - for( j = 0; j < pixel_block_size; j++, bitmap_caret++ ) { - tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ]; - } - buffer_caret += pixel_block_size; + if ((bitmap_caret + (encoded_pixels * pixel_block_size)) >= image_block_size) { + gdFree( decompression_buffer ); + gdFree( conversion_buffer ); + return -1; } + + memcpy(tga->bitmap + bitmap_caret, decompression_buffer + buffer_caret, encoded_pixels * pixel_block_size); + bitmap_caret += (encoded_pixels * pixel_block_size); + buffer_caret += (encoded_pixels * pixel_block_size); } } - gdFree( decompression_buffer ); gdFree( conversion_buffer ); - - } - - /*! \todo Add image type support - * Add support for this image type. - */ - if( tga->imagetype == TGA_TYPE_GREYSCALE ) { - return -1; - } - - /*! \todo Add image type support - * Add support for this image type. - */ - if( tga->imagetype == TGA_TYPE_GREYSCALE_RLE ) { - return -1; + break; } - return 0; + return 1; } /*! \brief Cleans up a TGA structure. @@ -338,15 +334,10 @@ int read_image_tga( gdIOCtx *ctx, oTga *tga ) void free_tga(oTga * tga) { if (tga) { - if (tga->ident) { + if (tga->ident) gdFree(tga->ident); - tga->ident = NULL; - } - if (tga->bitmap) { + if (tga->bitmap) gdFree(tga->bitmap); - tga->bitmap = NULL; - } gdFree(tga); - tga = NULL; } } diff --git a/Build/source/libs/gd/libgd-src/src/gd_tiff.c b/Build/source/libs/gd/libgd-src/src/gd_tiff.c index ec6dd113074..26805ffcc4d 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_tiff.c +++ b/Build/source/libs/gd/libgd-src/src/gd_tiff.c @@ -282,21 +282,27 @@ void tiffWriter(gdImagePtr image, gdIOCtx *out, int bitDepth) bitsPerSample = (bitDepth == 24 || bitDepth == 8) ? 8 : 1; TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, bitsPerSample); + TIFFSetField(tiff, TIFFTAG_XRESOLUTION, (float)image->res_x); + TIFFSetField(tiff, TIFFTAG_YRESOLUTION, (float)image->res_y); + /* build the color map for 8 bit images */ if(bitDepth != 24) { colorMapRed = (uint16 *) gdMalloc(3 * (1 << bitsPerSample)); if (!colorMapRed) { + gdFree(th); return; } colorMapGreen = (uint16 *) gdMalloc(3 * (1 << bitsPerSample)); if (!colorMapGreen) { gdFree(colorMapRed); + gdFree(th); return; } colorMapBlue = (uint16 *) gdMalloc(3 * (1 << bitsPerSample)); if (!colorMapBlue) { gdFree(colorMapRed); gdFree(colorMapGreen); + gdFree(th); return; } @@ -326,10 +332,18 @@ void tiffWriter(gdImagePtr image, gdIOCtx *out, int bitDepth) TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, 1); if(overflow2(width, samplesPerPixel)) { + if (colorMapRed) gdFree(colorMapRed); + if (colorMapGreen) gdFree(colorMapGreen); + if (colorMapBlue) gdFree(colorMapBlue); + gdFree(th); return; } if(!(scan = (char *)gdMalloc(width * samplesPerPixel))) { + if (colorMapRed) gdFree(colorMapRed); + if (colorMapGreen) gdFree(colorMapGreen); + if (colorMapBlue) gdFree(colorMapBlue); + gdFree(th); return; } @@ -371,6 +385,10 @@ void tiffWriter(gdImagePtr image, gdIOCtx *out, int bitDepth) /* Write the scan line to the tiff */ if(TIFFWriteEncodedStrip(tiff, y, scan, width * samplesPerPixel) == -1) { + if (colorMapRed) gdFree(colorMapRed); + if (colorMapGreen) gdFree(colorMapGreen); + if (colorMapBlue) gdFree(colorMapBlue); + gdFree(th); /* error handler here */ gd_error("Could not create TIFF\n"); return; @@ -390,13 +408,15 @@ void tiffWriter(gdImagePtr image, gdIOCtx *out, int bitDepth) } /* - gdImageTiffCtx - -------------- - Write the gd image as a tiff file - Parameters are: - image: gd image structure; - out: the stream where to write - */ + Function: gdImageTiffCtx + + Write the gd image as a tiff file. + + Parameters: + + image - gd image structure; + out - the stream where to write +*/ BGD_DECLARE(void) gdImageTiffCtx(gdImagePtr image, gdIOCtx *out) { int clipx1P, clipy1P, clipx2P, clipy2P; @@ -621,10 +641,12 @@ static int createFromTiffTiles(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot if (!TIFFGetField (tif, TIFFTAG_PLANARCONFIG, &planar)) { planar = PLANARCONFIG_CONTIG; } - TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &im_width); - TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &im_height); - TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width); - TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height); + if (TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &im_width) == 0 || + TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &im_height) == 0 || + TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width) == 0 || + TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height) == 0) { + return FALSE; + } buffer = (unsigned char *) gdMalloc (TIFFTileSize (tif)); if (!buffer) { @@ -646,6 +668,7 @@ static int createFromTiffTiles(TIFF *tif, gdImagePtr im, uint16 bps, uint16 phot } } } + gdFree(buffer); return TRUE; } @@ -761,10 +784,11 @@ static int createFromTiffRgba(TIFF * tif, gdImagePtr im) return GD_SUCCESS; } -/* gdImageCreateFromTiffCtx -** ------------------------ -** Create a gdImage from a TIFF file input from an gdIOCtx - */ +/* + Function: gdImageCreateFromTiffCtx + + Create a gdImage from a TIFF file input from an gdIOCtx. +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) { TIFF *tif; @@ -780,6 +804,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) char save_transparent; int image_type; int ret; + float res_float; gdImagePtr im = NULL; @@ -798,6 +823,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) if (!tif) { gd_error("Cannot open TIFF image"); + gdFree(th); return NULL; } @@ -814,7 +840,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, &bps); /* Unsupported bps, force to RGBA */ - if (bps > 8 && bps != 16) { + if (1/*bps > 8 && bps != 16*/) { force_rgba = TRUE; } @@ -942,7 +968,14 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) goto error; } - if (TIFFGetField (tif, TIFFTAG_ORIENTATION, &orientation)) { + if (TIFFGetField(tif, TIFFTAG_XRESOLUTION, &res_float)) { + im->res_x = (unsigned int)res_float; //truncate + } + if (TIFFGetField(tif, TIFFTAG_YRESOLUTION, &res_float)) { + im->res_y = (unsigned int)res_float; //truncate + } + + if (TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation)) { switch (orientation) { case ORIENTATION_TOPLEFT: case ORIENTATION_TOPRIGHT: @@ -957,12 +990,13 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile) } error: TIFFClose(tif); + gdFree(th); return im; } -/* gdImageCreateFromTIFF -** --------------------- - */ +/* + Function: gdImageCreateFromTIFF +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiff(FILE *inFile) { gdImagePtr im; @@ -973,6 +1007,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiff(FILE *inFile) return im; } +/* + Function: gdImageCreateFromTiffPtr +*/ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffPtr(int size, void *data) { gdImagePtr im; @@ -983,9 +1020,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffPtr(int size, void *data) return im; } -/* gdImageTIFF -** ----------- - */ +/* + Function: gdImageTiff +*/ BGD_DECLARE(void) gdImageTiff(gdImagePtr im, FILE *outFile) { gdIOCtx *out = gdNewFileCtx(outFile); @@ -994,9 +1031,9 @@ BGD_DECLARE(void) gdImageTiff(gdImagePtr im, FILE *outFile) out->gd_free(out); } -/* gdImageTIFFPtr -** -------------- - */ +/* + Function: gdImageTiffPtr +*/ BGD_DECLARE(void *) gdImageTiffPtr(gdImagePtr im, int *size) { void *rv; diff --git a/Build/source/libs/gd/libgd-src/src/gd_topal.c b/Build/source/libs/gd/libgd-src/src/gd_topal.c index 28b6503d063..7ff835a6d36 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_topal.c +++ b/Build/source/libs/gd/libgd-src/src/gd_topal.c @@ -43,8 +43,8 @@ #include "gd.h" #include "gdhelpers.h" -#ifdef HAVE_LIBIMAGEQUANT_H -#include <libimagequant.h> /* if this fails then set -DENABLE_LIQ=NO in cmake or make static libimagequant.a in libimagequant/ */ +#ifdef HAVE_LIBIMAGEQUANT +#include <libimagequant.h> #endif /* (Re)define some defines known by libjpeg */ @@ -1366,16 +1366,18 @@ zeroHistogram (hist3d histogram) /* - Selects quantization method used for subsequent gdImageTrueColorToPalette calls. - See gdPaletteQuantizationMethod enum (e.g. GD_QUANT_NEUQUANT, GD_QUANT_LIQ). - Speed is from 1 (highest quality) to 10 (fastest). - Speed 0 selects method-specific default (recommended). + Function: gdImageTrueColorToPaletteSetMethod - Returns FALSE if the given method is invalid or not available. + Selects quantization method used for subsequent gdImageTrueColorToPalette calls. + See gdPaletteQuantizationMethod enum (e.g. GD_QUANT_NEUQUANT, GD_QUANT_LIQ). + Speed is from 1 (highest quality) to 10 (fastest). + Speed 0 selects method-specific default (recommended). + + Returns FALSE if the given method is invalid or not available. */ BGD_DECLARE(int) gdImageTrueColorToPaletteSetMethod (gdImagePtr im, int method, int speed) { -#ifndef HAVE_LIBIMAGEQUANT_H +#ifndef HAVE_LIBIMAGEQUANT if (method == GD_QUANT_LIQ) { return FALSE; } @@ -1393,11 +1395,13 @@ BGD_DECLARE(int) gdImageTrueColorToPaletteSetMethod (gdImagePtr im, int method, } /* - Chooses quality range that subsequent call to gdImageTrueColorToPalette will aim for. - Min and max quality is in range 1-100 (1 = ugly, 100 = perfect). Max must be higher than min. - If palette cannot represent image with at least min_quality, then image will remain true-color. - If palette can represent image with quality better than max_quality, then lower number of colors will be used. - This function has effect only when GD_QUANT_LIQ method has been selected. + Function: gdImageTrueColorToPaletteSetQuality + + Chooses quality range that subsequent call to gdImageTrueColorToPalette will aim for. + Min and max quality is in range 1-100 (1 = ugly, 100 = perfect). Max must be higher than min. + If palette cannot represent image with at least min_quality, then image will remain true-color. + If palette can represent image with quality better than max_quality, then lower number of colors will be used. + This function has effect only when GD_QUANT_LIQ method has been selected. */ BGD_DECLARE(void) gdImageTrueColorToPaletteSetQuality (gdImagePtr im, int min_quality, int max_quality) { @@ -1410,6 +1414,9 @@ BGD_DECLARE(void) gdImageTrueColorToPaletteSetQuality (gdImagePtr im, int min_qu static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colorsWanted, gdImagePtr *cimP); +/* + Function: gdImageCreatePaletteFromTrueColor +*/ BGD_DECLARE(gdImagePtr) gdImageCreatePaletteFromTrueColor (gdImagePtr im, int dither, int colorsWanted) { gdImagePtr nim; @@ -1419,12 +1426,15 @@ BGD_DECLARE(gdImagePtr) gdImageCreatePaletteFromTrueColor (gdImagePtr im, int di return NULL; } +/* + Function: gdImageTrueColorToPalette +*/ BGD_DECLARE(int) gdImageTrueColorToPalette (gdImagePtr im, int dither, int colorsWanted) { return gdImageTrueColorToPaletteBody(im, dither, colorsWanted, 0); } -#ifdef HAVE_LIBIMAGEQUANT_H +#ifdef HAVE_LIBIMAGEQUANT /** LIQ library needs pixels in RGBA order with alpha 0-255 (opaque 255). This callback is run whenever source rows need to be converted from GD's format. @@ -1506,7 +1516,7 @@ static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colors goto outOfMemory; } for (i = 0; (i < nim->sy); i++) { - nim->pixels[i] = (unsigned char *) gdCalloc (sizeof (unsigned char *), oim->sx); + nim->pixels[i] = (unsigned char *) gdCalloc (sizeof (unsigned char), oim->sx); if (!nim->pixels[i]) { goto outOfMemory; } @@ -1521,6 +1531,9 @@ static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colors nim = gdImageNeuQuant(oim, colorsWanted, oim->paletteQuantizationSpeed ? oim->paletteQuantizationSpeed : 2); if (cimP) { *cimP = nim; + } + if (!nim) { + return FALSE; } else { gdImageCopy(oim, nim, 0, 0, 0, 0, oim->sx, oim->sy); gdImageDestroy(nim); @@ -1529,7 +1542,7 @@ static int gdImageTrueColorToPaletteBody (gdImagePtr oim, int dither, int colors } -#ifdef HAVE_LIBIMAGEQUANT_H +#ifdef HAVE_LIBIMAGEQUANT if (oim->paletteQuantizationMethod == GD_QUANT_DEFAULT || oim->paletteQuantizationMethod == GD_QUANT_LIQ) { liq_attr *attr = liq_attr_create_with_allocator(gdMalloc, gdFree); diff --git a/Build/source/libs/gd/libgd-src/src/gd_transform.c b/Build/source/libs/gd/libgd-src/src/gd_transform.c index 68013ef9319..a126686269d 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_transform.c +++ b/Build/source/libs/gd/libgd-src/src/gd_transform.c @@ -4,6 +4,9 @@ #include "gd.h" +/* + Function: gdImageFlipVertical +*/ BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im) { register int x, y; @@ -23,15 +26,18 @@ BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im) unsigned char p; for (y = 0; y < im->sy / 2; y++) { for (x = 0; x < im->sx; x++) { - p = im->tpixels[y][x]; - im->tpixels[y][x] = im->tpixels[im->sy - 1 - y][x]; - im->tpixels[im->sy - 1 - y][x] = p; + p = im->pixels[y][x]; + im->pixels[y][x] = im->pixels[im->sy - 1 - y][x]; + im->pixels[im->sy - 1 - y][x] = p; } } } return; } +/* + Function: gdImageFlipHorizontal +*/ BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im) { @@ -68,6 +74,9 @@ BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im) } } +/* + Function: gdImageFlipBoth +*/ BGD_DECLARE(void) gdImageFlipBoth(gdImagePtr im) { gdImageFlipVertical(im); diff --git a/Build/source/libs/gd/libgd-src/src/gd_version.c b/Build/source/libs/gd/libgd-src/src/gd_version.c index 222d428ce7b..46725b0dae9 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_version.c +++ b/Build/source/libs/gd/libgd-src/src/gd_version.c @@ -9,25 +9,40 @@ * so that changes in the shared library will automatically be * reflected in executables using it without recompiling them. */ +/* + Function: gdMajorVersion +*/ BGD_DECLARE(int) gdMajorVersion() { return GD_MAJOR_VERSION; } +/* + Function: gdMinorVersion +*/ BGD_DECLARE(int) gdMinorVersion() { return GD_MINOR_VERSION; } +/* + Function: gdReleaseVersion +*/ BGD_DECLARE(int) gdReleaseVersion() { return GD_RELEASE_VERSION; } +/* + Function: gdExtraVersion +*/ BGD_DECLARE(const char *) gdExtraVersion() { return GD_EXTRA_VERSION; } +/* + Function: gdVersionString +*/ BGD_DECLARE(const char *) gdVersionString() { return GD_VERSION_STRING; } diff --git a/Build/source/libs/gd/libgd-src/src/gd_wbmp.c b/Build/source/libs/gd/libgd-src/src/gd_wbmp.c index 53fbdc2d1a8..d9de5916bba 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_wbmp.c +++ b/Build/source/libs/gd/libgd-src/src/gd_wbmp.c @@ -82,15 +82,17 @@ int gd_getin(void *in) return (gdGetC((gdIOCtx *)in)); } -/* gdImageWBMPCtx - * -------------- - * Write the image as a wbmp file - * Parameters are: - * image: gd image structure; - * fg: the index of the foreground color. any other value will be - * considered as background and will not be written - * out: the stream where to write - */ +/* + Function: gdImageWBMPCtx + + Write the image as a wbmp file + + Parameters: + image - gd image structure + fg - the index of the foreground color. any other value will be + considered as background and will not be written + out - the stream where to write +*/ BGD_DECLARE(void) gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out) { int x, y, pos; @@ -242,8 +244,9 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPPtr(int size, void *data) return im; } -/* gdImageWBMP - */ +/* + Function: gdImageWBMP +*/ BGD_DECLARE(void) gdImageWBMP(gdImagePtr im, int fg, FILE *outFile) { gdIOCtx *out = gdNewFileCtx(outFile); @@ -252,8 +255,9 @@ BGD_DECLARE(void) gdImageWBMP(gdImagePtr im, int fg, FILE *outFile) out->gd_free(out); } -/* gdImageWBMPPtr - */ +/* + Function: gdImageWBMPPtr +*/ BGD_DECLARE(void *) gdImageWBMPPtr(gdImagePtr im, int *size, int fg) { void *rv; diff --git a/Build/source/libs/gd/libgd-src/src/gd_webp.c b/Build/source/libs/gd/libgd-src/src/gd_webp.c index fae38610999..98628cfff7f 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_webp.c +++ b/Build/source/libs/gd/libgd-src/src/gd_webp.c @@ -2,78 +2,55 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_LIBWEBP #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include "gd.h" #include "gd_errors.h" - -#ifdef HAVE_LIBVPX -#include "webpimg.h" #include "gdhelpers.h" +#include "webp/decode.h" +#include "webp/encode.h" -extern void gd_YUV420toRGBA(uint8* Y, - uint8* U, - uint8* V, - gdImagePtr im); - -extern void gd_RGBAToYUV420(gdImagePtr im2, - uint8* Y, - uint8* U, - uint8* V); - -const char * gdWebpGetVersionString() -{ - return "not defined"; -} +#define GD_WEBP_ALLOC_STEP (4*1024) -BGD_DECLARE(gdImagePtr) gdImageCreateFromWebp (FILE * inFile) +gdImagePtr gdImageCreateFromWebp (FILE * inFile) { gdImagePtr im; gdIOCtx *in = gdNewFileCtx(inFile); + if (!in) { + return 0; + } im = gdImageCreateFromWebpCtx(in); in->gd_free(in); return im; } -BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpPtr (int size, void *data) + +gdImagePtr gdImageCreateFromWebpPtr (int size, void *data) { - int width, height, ret; - unsigned char *Y = NULL; - unsigned char *U = NULL; - unsigned char *V = NULL; gdImagePtr im; - - ret = WebPDecode(data, size, &Y, &U, &V, &width, &height); - if (ret != webp_success) { - if (Y) free(Y); - if (U) free(U); - if (V) free(V); - gd_error("WebP decode: fail to decode input data"); - return NULL; - } - im = gdImageCreateTrueColor(width, height); - if (!im) { - return NULL; - } - gd_YUV420toRGBA(Y, U, V, im); + gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0); + if (!in) + return 0; + im = gdImageCreateFromWebpCtx(in); + in->gd_free(in); return im; } -#define GD_WEBP_ALLOC_STEP (4*1024) - -BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpCtx (gdIOCtx * infile) +gdImagePtr gdImageCreateFromWebpCtx (gdIOCtx * infile) { - int width, height, ret; - unsigned char *filedata = NULL; + int width, height; + uint8_t *filedata = NULL; + uint8_t *argb = NULL; unsigned char *read, *temp; - unsigned char *Y = NULL; - unsigned char *U = NULL; - unsigned char *V = NULL; size_t size = 0, n; gdImagePtr im; + int x, y; + uint8_t *p; do { temp = gdRealloc(filedata, size+GD_WEBP_ALLOC_STEP); @@ -89,41 +66,136 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromWebpCtx (gdIOCtx * infile) } n = gdGetBuf(read, GD_WEBP_ALLOC_STEP, infile); - size += n; - } while (n>0); - - ret = WebPDecode(filedata, size, &Y, &U, &V, &width, &height); - gdFree(filedata); - if (ret != webp_success) { - if (Y) free(Y); - if (U) free(U); - if (V) free(V); - gd_error("WebP decode: fail to decode input data"); + if (n>0 && n!=EOF) { + size += n; + } + } while (n>0 && n!=EOF); + + if (WebPGetInfo(filedata,size, &width, &height) == 0) { + gd_error("gd-webp cannot get webp info"); + gdFree(temp); return NULL; } + im = gdImageCreateTrueColor(width, height); - gd_YUV420toRGBA(Y, U, V, im); + if (!im) { + gdFree(temp); + return NULL; + } + argb = WebPDecodeARGB(filedata, size, &width, &height); + if (!argb) { + gd_error("gd-webp cannot allocate temporary buffer"); + gdFree(temp); + gdImageDestroy(im); + return NULL; + } + for (y = 0, p = argb; y < height; y++) { + for (x = 0; x < width; x++) { + register uint8_t a = gdAlphaMax - (*(p++) >> 1); + register uint8_t r = *(p++); + register uint8_t g = *(p++); + register uint8_t b = *(p++); + im->tpixels[y][x] = gdTrueColorAlpha(r, g, b, a); + } + } + /* do not use gdFree here, in case gdFree/alloc is mapped to something else than libc */ + free(argb); + gdFree(temp); + im->saveAlphaFlag = 1; return im; } +void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization) +{ + uint8_t *argb; + int x, y; + uint8_t *p; + uint8_t *out; + size_t out_size; + + if (im == NULL) { + return; + } + + if (!gdImageTrueColor(im)) { + gd_error("Paletter image not supported by webp"); + return; + } + + if (quantization == -1) { + quantization = 80; + } + + argb = (uint8_t *)gdMalloc(gdImageSX(im) * 4 * gdImageSY(im)); + if (!argb) { + return; + } + p = argb; + for (y = 0; y < gdImageSY(im); y++) { + for (x = 0; x < gdImageSX(im); x++) { + register int c; + register char a; + c = im->tpixels[y][x]; + a = gdTrueColorGetAlpha(c); + if (a == 127) { + a = 0; + } else { + a = 255 - ((a << 1) + (a >> 6)); + } + *(p++) = gdTrueColorGetRed(c); + *(p++) = gdTrueColorGetGreen(c); + *(p++) = gdTrueColorGetBlue(c); + *(p++) = a; + } + } + out_size = WebPEncodeRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, quantization, &out); + if (out_size == 0) { + gd_error("gd-webp encoding failed"); + goto freeargb; + } + gdPutBuf(out, out_size, outfile); + free(out); + +freeargb: + gdFree(argb); +} + +/* + Function: gdImageWebpEx +*/ BGD_DECLARE(void) gdImageWebpEx (gdImagePtr im, FILE * outFile, int quantization) { gdIOCtx *out = gdNewFileCtx(outFile); + if (out == NULL) { + return; + } gdImageWebpCtx(im, out, quantization); out->gd_free(out); } +/* + Function: gdImageWebp +*/ BGD_DECLARE(void) gdImageWebp (gdImagePtr im, FILE * outFile) { gdIOCtx *out = gdNewFileCtx(outFile); - gdImageWebpCtx(im, out, -1); + if (out == NULL) { + return; + } + gdImageWebpCtx(im, out, -1); out->gd_free(out); } +/* + Function: gdImageWebpPtr +*/ BGD_DECLARE(void *) gdImageWebpPtr (gdImagePtr im, int *size) { void *rv; gdIOCtx *out = gdNewDynamicCtx(2048, NULL); + if (out == NULL) { + return NULL; + } gdImageWebpCtx(im, out, -1); rv = gdDPExtractData(out, size); out->gd_free(out); @@ -131,81 +203,19 @@ BGD_DECLARE(void *) gdImageWebpPtr (gdImagePtr im, int *size) return rv; } +/* + Function: gdImageWebpPtrEx +*/ BGD_DECLARE(void *) gdImageWebpPtrEx (gdImagePtr im, int *size, int quantization) { void *rv; gdIOCtx *out = gdNewDynamicCtx(2048, NULL); + if (out == NULL) { + return NULL; + } gdImageWebpCtx(im, out, quantization); rv = gdDPExtractData(out, size); out->gd_free(out); return rv; } - -/* - * Maps normalized QP (quality) to VP8 QP - */ -int mapQualityToVP8QP(int quality) { -#define MIN_QUALITY 0 -#define MAX_QUALITY 100 -#define MIN_VP8QP 1 -#define MAX_VP8QP 63 - const float scale = MAX_VP8QP - MIN_VP8QP; - const float vp8qp = - scale * (MAX_QUALITY - quality) / (MAX_QUALITY - MIN_QUALITY) + MIN_VP8QP; - if (quality < MIN_QUALITY || quality > MAX_QUALITY) { - gd_error("Wrong quality value %d.", quality); - return -1; - } - - return (int)(vp8qp + 0.5); -} - -/* This routine is based in part on code from Dale Lutz (Safe Software Inc.) - * and in part on demo code from Chapter 15 of "PNG: The Definitive Guide" - * (http://www.cdrom.com/pub/png/pngbook.html). - */ -BGD_DECLARE(void) gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization) -{ - int width = im->sx; - int height = im->sy; - - int yuv_width, yuv_height, yuv_nbytes, ret; - int vp8_quality; - unsigned char *Y = NULL, - *U = NULL, - *V = NULL; - unsigned char *filedata = NULL; - - /* Conversion to Y,U,V buffer */ - yuv_width = (width + 1) >> 1; - yuv_height = (height + 1) >> 1; - yuv_nbytes = width * height + 2 * yuv_width * yuv_height; - - if ((Y = (unsigned char *)gdCalloc(yuv_nbytes, sizeof(unsigned char))) == NULL) { - gd_error("gd-webp error: cannot allocate Y buffer"); - return; - } - vp8_quality = mapQualityToVP8QP(quantization); - - U = Y + width * height; - V = U + yuv_width * yuv_height; - gd_RGBAToYUV420(im, Y, U, V); - - /* Encode Y,U,V and write data to file */ - ret = WebPEncode(Y, U, V, width, height, width, yuv_width, yuv_height, yuv_width, - vp8_quality, &filedata, &yuv_nbytes, NULL); - gdFree(Y); - - if (ret != webp_success) { - if (filedata) { - free(filedata); - } - gd_error("gd-webp error: WebP Encoder failed"); - return; - } - - gdPutBuf (filedata, yuv_nbytes, outfile); - free(filedata); -} - -#endif /* HAVE_LIBVPX */ +#endif /* HAVE_LIBWEBP */ diff --git a/Build/source/libs/gd/libgd-src/src/gd_xbm.c b/Build/source/libs/gd/libgd-src/src/gd_xbm.c index 74d839b2667..58b57203dc6 100644 --- a/Build/source/libs/gd/libgd-src/src/gd_xbm.c +++ b/Build/source/libs/gd/libgd-src/src/gd_xbm.c @@ -180,7 +180,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm(FILE * fd) /* {{{ gdCtxPrintf */ static void gdCtxPrintf(gdIOCtx * out, const char *format, ...) { - char buf[4096]; + char buf[1024]; int len; va_list args; @@ -191,7 +191,13 @@ static void gdCtxPrintf(gdIOCtx * out, const char *format, ...) } /* }}} */ +/* The compiler will optimize strlen(constant) to a constant number. */ +#define gdCtxPuts(out, s) out->putBuf(out, s, strlen(s)) + /* {{{ gdImageXbmCtx */ +/* + Function: gdImageXbmCtx +*/ BGD_DECLARE(void) gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) { int x, y, c, b, sx, sy, p; @@ -215,9 +221,26 @@ BGD_DECLARE(void) gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOC } } - gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); - gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); - gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); + /* Since "name" comes from the user, run it through a direct puts. + * Trying to printf it into a local buffer means we'd need a large + * or dynamic buffer to hold it all. */ + + /* #define <name>_width 1234 */ + gdCtxPuts(out, "#define "); + gdCtxPuts(out, name); + gdCtxPuts(out, "_width "); + gdCtxPrintf(out, "%d\n", gdImageSX(image)); + + /* #define <name>_height 1234 */ + gdCtxPuts(out, "#define "); + gdCtxPuts(out, name); + gdCtxPuts(out, "_height "); + gdCtxPrintf(out, "%d\n", gdImageSY(image)); + + /* static unsigned char <name>_bits[] = {\n */ + gdCtxPuts(out, "static unsigned char "); + gdCtxPuts(out, name); + gdCtxPuts(out, "_bits[] = {\n "); free(name); @@ -231,12 +254,12 @@ BGD_DECLARE(void) gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOC if (gdImageGetPixel(image, x, y) == fg) { c |= b; } - if ((b == 128) || (x == sx && y == sy)) { + if ((b == 128) || (x == sx - 1)) { b = 1; if (p) { - gdCtxPrintf(out, ", "); + gdCtxPuts(out, ", "); if (!(p%12)) { - gdCtxPrintf(out, "\n "); + gdCtxPuts(out, "\n "); p = 12; } } @@ -248,6 +271,6 @@ BGD_DECLARE(void) gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOC } } } - gdCtxPrintf(out, "};\n"); + gdCtxPuts(out, "};\n"); } /* }}} */ diff --git a/Build/source/libs/gd/libgd-src/src/gdfontg.c b/Build/source/libs/gd/libgd-src/src/gdfontg.c index 37178602695..04f3362c99b 100644 --- a/Build/source/libs/gd/libgd-src/src/gdfontg.c +++ b/Build/source/libs/gd/libgd-src/src/gdfontg.c @@ -4382,6 +4382,9 @@ gdFont gdFontGiantRep = { BGD_EXPORT_DATA_PROT gdFontPtr gdFontGiant = &gdFontGiantRep; +/* + Function: gdFontGetGiant +*/ BGD_DECLARE(gdFontPtr) gdFontGetGiant (void) { return gdFontGiant; diff --git a/Build/source/libs/gd/libgd-src/src/gdfontl.c b/Build/source/libs/gd/libgd-src/src/gdfontl.c index a987407aeca..8501b5f7d96 100644 --- a/Build/source/libs/gd/libgd-src/src/gdfontl.c +++ b/Build/source/libs/gd/libgd-src/src/gdfontl.c @@ -4639,6 +4639,9 @@ gdFont gdFontLargeRep = { BGD_EXPORT_DATA_PROT gdFontPtr gdFontLarge = &gdFontLargeRep; +/* + Function: gdFontGetLarge +*/ BGD_DECLARE(gdFontPtr) gdFontGetLarge (void) { diff --git a/Build/source/libs/gd/libgd-src/src/gdfontmb.c b/Build/source/libs/gd/libgd-src/src/gdfontmb.c index 349b2dbde28..566cc6dd15f 100644 --- a/Build/source/libs/gd/libgd-src/src/gdfontmb.c +++ b/Build/source/libs/gd/libgd-src/src/gdfontmb.c @@ -3869,6 +3869,9 @@ gdFont gdFontMediumBoldRep = { BGD_EXPORT_DATA_PROT gdFontPtr gdFontMediumBold = &gdFontMediumBoldRep; +/* + Function: gdFontGetMediumBold +*/ BGD_DECLARE(gdFontPtr) gdFontGetMediumBold (void) { diff --git a/Build/source/libs/gd/libgd-src/src/gdfonts.c b/Build/source/libs/gd/libgd-src/src/gdfonts.c index f7c27250362..f84b2ee7d4e 100644 --- a/Build/source/libs/gd/libgd-src/src/gdfonts.c +++ b/Build/source/libs/gd/libgd-src/src/gdfonts.c @@ -3867,6 +3867,9 @@ gdFont gdFontSmallRep = { BGD_EXPORT_DATA_PROT gdFontPtr gdFontSmall = &gdFontSmallRep; +/* + Function: gdFontGetSmall +*/ BGD_DECLARE(gdFontPtr) gdFontGetSmall (void) { diff --git a/Build/source/libs/gd/libgd-src/src/gdfontt.c b/Build/source/libs/gd/libgd-src/src/gdfontt.c index c9c6f4a31da..3c97c4d376d 100644 --- a/Build/source/libs/gd/libgd-src/src/gdfontt.c +++ b/Build/source/libs/gd/libgd-src/src/gdfontt.c @@ -2590,6 +2590,9 @@ gdFont gdFontTinyRep = { BGD_EXPORT_DATA_PROT gdFontPtr gdFontTiny = &gdFontTinyRep; +/* + Function: gdFontGetTiny +*/ BGD_DECLARE(gdFontPtr) gdFontGetTiny (void) { diff --git a/Build/source/libs/gd/libgd-src/src/gdft.c b/Build/source/libs/gd/libgd-src/src/gdft.c index 03a01593660..e745c6c098d 100644 --- a/Build/source/libs/gd/libgd-src/src/gdft.c +++ b/Build/source/libs/gd/libgd-src/src/gdft.c @@ -92,6 +92,9 @@ static char *font_path(char **fontpath, char *name_list); #define TRUE !FALSE #endif +/* + Function: gdImageStringTTF +*/ BGD_DECLARE(char *) gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string) { @@ -448,12 +451,8 @@ static int useFontConfig(int flag) #ifdef HAVE_LIBFONTCONFIG if (fontConfigFlag) { return (!(flag & gdFTEX_FONTPATHNAME)); - } else -#endif - { - return flag & gdFTEX_FONTCONFIG; - } +#endif return flag & gdFTEX_FONTCONFIG; } @@ -734,8 +733,6 @@ gdft_draw_bitmap (gdCache_head_t * tc_cache, gdImage * im, int fg, + bitmap.num_grays / 2) / (bitmap.num_grays - 1); } else if (bitmap.pixel_mode == ft_pixel_mode_mono) { - tc_key.pixel = ((bitmap.buffer[pc / 8] - << (pc % 8)) & 128) ? GD_NUMCOLORS : 0; /* 2.0.5: mode_mono fix from Giuliano Pochini */ tc_key.pixel = ((bitmap. @@ -771,11 +768,17 @@ gdft_draw_bitmap (gdCache_head_t * tc_cache, gdImage * im, int fg, return (char *) NULL; } +/* + Function: gdFreeFontCache +*/ BGD_DECLARE(void) gdFreeFontCache () { gdFontCacheShutdown (); } +/* + Function: gdFontCacheShutdown +*/ BGD_DECLARE(void) gdFontCacheShutdown () { if (fontCache) { @@ -789,9 +792,11 @@ BGD_DECLARE(void) gdFontCacheShutdown () } } -/********************************************************************/ -/* gdImageStringFT - render a utf8 string onto a gd image */ +/* + Function: gdImageStringFT + Render a utf8 string onto a gd image. +*/ BGD_DECLARE(char *) gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string) { @@ -799,6 +804,9 @@ BGD_DECLARE(char *) gdImageStringFT (gdImage * im, int *brect, int fg, char *fon ptsize, angle, x, y, string, 0); } +/* + Function: gdFontCacheSetup +*/ BGD_DECLARE(int) gdFontCacheSetup (void) { if (fontCache) { @@ -1639,14 +1647,14 @@ static char * font_path(char **fontpath, char *name_list) *fontpath = NULL; fontsearchpath = getenv ("GDFONTPATH"); #ifdef _WIN32 - if (!fontsearchpath) { - char *ffptr = getenv ("SYSTEMROOT"); - if (ffptr) { - fontsearchpath = malloc (strlen(ffptr) + strlen("\\fonts") + 1); - strcpy(fontsearchpath, ffptr); - strcat(fontsearchpath, "\\fonts"); - } - } + if (!fontsearchpath) { + char *ffptr = getenv ("SYSTEMROOT"); + if (ffptr) { + fontsearchpath = malloc (strlen(ffptr) + strlen("\\fonts") + 1); + strcpy(fontsearchpath, ffptr); + strcat(fontsearchpath, "\\fonts"); + } + } #endif if (!fontsearchpath) fontsearchpath = DEFAULT_FONTPATH; @@ -1751,6 +1759,9 @@ static char * font_path(char **fontpath, char *name_list) return NULL; } +/* + Function: gdFTUseFontConfig +*/ BGD_DECLARE(int) gdFTUseFontConfig(int flag) { #ifdef HAVE_LIBFONTCONFIG diff --git a/Build/source/libs/gd/libgd-src/src/gdfx.c b/Build/source/libs/gd/libgd-src/src/gdfx.c index 13b32fe1c06..f145de04802 100644 --- a/Build/source/libs/gd/libgd-src/src/gdfx.c +++ b/Build/source/libs/gd/libgd-src/src/gdfx.c @@ -25,6 +25,9 @@ #define MAXY(x) MAX4(x[1],x[3],x[5],x[7]) #define MINY(x) MIN4(x[1],x[3],x[5],x[7]) +/* + Function: gdImageStringFTCircle +*/ BGD_DECLARE(char *) gdImageStringFTCircle (gdImagePtr im, int cx, @@ -165,9 +168,15 @@ gdImageStringFTCircle (gdImagePtr im, fclose (out); } #endif /* STEP_PNGS */ + + gdImageDestroy (im1); + /* Ready to produce a circle */ im3 = gdImageSquareToCircle (im2, radius); - gdImageDestroy (im1); + if (im3 == NULL) { + gdImageDestroy(im2); + return 0; + } gdImageDestroy (im2); /* Now blend im3 with the destination. Cheat a little. The source (im3) is white-on-black, so we can use the @@ -248,6 +257,9 @@ main (int argc, char *argv[]) #define SUPERBITS1 1 #define SUPERBITS2 2 +/* + Function: gdImageSquareToCircle +*/ BGD_DECLARE(gdImagePtr) gdImageSquareToCircle (gdImagePtr im, int radius) { @@ -259,6 +271,9 @@ gdImageSquareToCircle (gdImagePtr im, int radius) return 0; } im2 = gdImageCreateTrueColor (radius * 2, radius * 2); + if (!im2) { + return 0; + } /* Supersampling for a nicer result */ c = (im2->sx / 2) * SUPER; for (y = 0; (y < im2->sy * SUPER); y++) { @@ -372,16 +387,18 @@ gdImageSubSharpen (int pc, int c, int nc, float inner_coeff, float } /* - * Sharpen function added on 2003-11-19 - * by Paul Troughton (paul<dot>troughton<at>ieee<dot>org) - * Simple 3x3 convolution kernel - * Makes use of seperability - * Faster, but less flexible, than full-blown unsharp masking - * pct is sharpening percentage, and can be greater than 100 - * Silently does nothing to non-truecolor images - * Silently does nothing for pct<0, as not a useful blurring function - * Leaves transparency/alpha-channel untouched - */ + Function: gdImageSharpen + + Sharpen function added on 2003-11-19 + by Paul Troughton (paul<dot>troughton<at>ieee<dot>org) + Simple 3x3 convolution kernel + Makes use of seperability + Faster, but less flexible, than full-blown unsharp masking + pct is sharpening percentage, and can be greater than 100 + Silently does nothing to non-truecolor images + Silently does nothing for pct<0, as not a useful blurring function + Leaves transparency/alpha-channel untouched +*/ BGD_DECLARE(void) gdImageSharpen (gdImagePtr im, int pct) { diff --git a/Build/source/libs/gd/libgd-src/src/gdhelpers.c b/Build/source/libs/gd/libgd-src/src/gdhelpers.c index 3c063d95523..c371e78fa5b 100644 --- a/Build/source/libs/gd/libgd-src/src/gdhelpers.c +++ b/Build/source/libs/gd/libgd-src/src/gdhelpers.c @@ -90,6 +90,9 @@ gdReallocEx (void *ptr, size_t size) return newPtr; } +/* + Function: gdFree +*/ BGD_DECLARE(void) gdFree (void *ptr) { free (ptr); diff --git a/Build/source/libs/gd/libgd-src/src/gdkanji.c b/Build/source/libs/gd/libgd-src/src/gdkanji.c index ab8c0df82df..f05187e4580 100644 --- a/Build/source/libs/gd/libgd-src/src/gdkanji.c +++ b/Build/source/libs/gd/libgd-src/src/gdkanji.c @@ -321,15 +321,18 @@ han2zen (int *p1, int *p2) if (daku) { if ((*p2 >= 74 && *p2 <= 103) || (*p2 >= 110 && *p2 <= 122)) (*p2)++; - else if (*p2 == 131 && *p2 == 69) + else if (*p2 == 131 || *p2 == 69) *p2 = 148; } else if (handaku && *p2 >= 110 && *p2 <= 122) (*p2) += 2; } /* Recast strcpy to handle unsigned chars used below. */ + #define ustrcpy(A,B) (strcpy((char*)(A),(const char*)(B))) +#define ustrncpy(A,B, maxsize) (strncpy((char*)(A),(const char*)(B), maxsize)) + static void do_convert (unsigned char **to_p, unsigned char **from_p, const char *code) { @@ -439,6 +442,7 @@ do_check_and_conv (unsigned char *to, unsigned char *from) unsigned char *tmp_p = &tmp[0]; int p1, p2, i, j; int kanji = TRUE; + int copy_string = FALSE; switch (DetectKanjiCode (from)) { case NEW: @@ -456,12 +460,12 @@ do_check_and_conv (unsigned char *to, unsigned char *from) case NEC: gd_error_ex(GD_DEBUG, "Kanji code is NEC Kanji."); gd_error("cannot convert NEC Kanji."); - ustrcpy (tmp, from); + copy_string = TRUE; kanji = FALSE; break; case EUC: gd_error_ex(GD_DEBUG, "Kanji code is EUC."); - ustrcpy (tmp, from); + copy_string = TRUE; break; case SJIS: gd_error_ex(GD_DEBUG, "Kanji code is SJIS."); @@ -469,21 +473,26 @@ do_check_and_conv (unsigned char *to, unsigned char *from) break; case EUCORSJIS: gd_error_ex(GD_DEBUG, "Kanji code is EUC or SJIS."); - ustrcpy (tmp, from); + copy_string = TRUE; kanji = FALSE; break; case ASCII: gd_error_ex(GD_DEBUG, "This is ASCII string."); - ustrcpy (tmp, from); + copy_string = TRUE; kanji = FALSE; break; default: gd_error_ex(GD_DEBUG, "This string includes unknown code."); - ustrcpy (tmp, from); + copy_string = TRUE; kanji = FALSE; break; } + if (copy_string) { + ustrncpy (tmp, from, BUFSIZ); + tmp[BUFSIZ-1] = '\0'; + } + /* Hankaku Kana ---> Zenkaku Kana */ if (kanji) { j = 0; diff --git a/Build/source/libs/gd/libgd-src/src/gdpp.cxx b/Build/source/libs/gd/libgd-src/src/gdpp.cxx index 64581247b4a..a8101fca29f 100644 --- a/Build/source/libs/gd/libgd-src/src/gdpp.cxx +++ b/Build/source/libs/gd/libgd-src/src/gdpp.cxx @@ -1,272 +1,272 @@ -/* *****************************************************************************
-** $Id$
-** Initial file written and documented by:
-** Kevin Shepherd <kshepherd@php.net> December 2007
-** of Scarlet Line http://www.scarletline.com/
-*******************************************************************************/
-/** \file gdpp.cxx
- \brief Implements the non-trivial methods of GD::Image.
-
- Implementation of the more complex methods defined
- in gdpp.h.
- Notably includes the methods which determine the image file
- format of a file before reading it into memory.
-*/
-#ifdef __cplusplus
-#include "gdpp.h"
-
-namespace GD
- {
- /**
- Load an image from a file, after attempting to
- determine it's image file format.
- Invoke CreateFrom with an already opened
- pointer to a file containing the desired image.
- CreateFrom does not close the file.
- \param[in] in An opened FILE * pointer.
- \return true for success, or false if unable to load the image (most often because the
- file is corrupt or does not contain a recognized image format).
- You can call Width() and Height() member functions of the image to determine its size.
- */
- bool Image::CreateFrom(FILE * in)
- {
- bool rtn;
- int c = fgetc(in);
- ungetc(c, in);
- switch (c)
- {
- /* PNG
- The first eight bytes of a PNG file always contain the following (decimal) values:
- 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
- == .PNG\r\n.\n
- */
-#ifdef HAVE_LIBPNG
- case 0x89: // PNG
- rtn = CreateFromPng(in);
- break;
-#endif
- /* GIF
- 0x47 0x49 0x46
- */
- case 0x47: // GIF
- rtn = CreateFromGif(in);
- break;
-#ifdef HAVE_LIBJPEG
- /* JPEG
- A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0,
- followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
- */
- case 0xFF: // JPEG
- rtn = CreateFromJpeg(in);
- break;
-#endif
- /* WBMP
- WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type
- */
- case 0x00: // WBMP
- rtn = CreateFromWBMP(in);
- break;
- /* GD2
- 0x67 0x64 0x32 0x00
- == GD2\0
- Starts with gd2
- */
- case 0x67: // GD2
- rtn = CreateFromGd2(in);
- break;
- /* GD
- 0xFF 0xFE
- or
- 0xFF 0xFF
- Conflicts with Jpeg
- */
- /* XBM
- #define test_width 16
- #define test_height 7
- */
- case 0x23: // XBM
- rtn = CreateFromXbm(in);
- break;
- default:
- rtn = false;
- break;
- }
- return rtn;
- }
-
- /**
- Load an image from a standard input stream, after attempting to
- determine it's image file format.
- Invoke CreateFrom with an already opened stream
- containing the desired image.
- CreateFrom does not close the stream.
- \param[in] in An opened standard library input stream.
- \return true for success, or false if unable to load the image (most often because the
- file is corrupt or does not contain a recognized image format).
- You can call Width() and Height() member functions of the image to determine its size.
- Example usage, convert anything to gif:
- #include <fstream>
- #include <gdpp.h>
-
- std::ifstream in("image.xxx", std::ios_base::in | std::ios_base::binary );
- GD::Image im;
- im.CreateFrom(in);
- if (im.good())
- {
- std::ofstream out("image.gif", std::ios_base::out | std::ios_base::binary );
- im.Gif(out);
- }
- */
- bool Image::CreateFrom(std::istream & in)
- {
- bool rtn;
- switch (in.peek())
- {
-#ifdef HAVE_LIBPNG
- /* PNG
- The first eight bytes of a PNG file always contain the following (decimal) values:
- 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
- == .PNG\r\n.\n
- */
- case 0x89: // PNG
- rtn = CreateFromPng(in);
- break;
-#endif
-
- /* GIF
- 0x47 0x49 0x46
- */
- case 0x47: // GIF
- rtn = CreateFromGif(in);
- break;
-
-#ifdef HAVE_LIBJPEG
- /* JPEG
- A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0,
- followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
- */
- case 0xFF: // JPEG
- rtn = CreateFromJpeg(in);
- break;
-#endif
-
- /* WBMP
- WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type
- */
- case 0x00: // WBMP
- rtn = CreateFromWBMP(in);
- break;
- /* GD2
- 0x67 0x64 0x32 0x00
- == GD2\0
- Starts with gd2
- */
- case 0x67: // GD2
- rtn = CreateFromGd2(in);
- break;
- /* GD
- 0xFF 0xFE
- or
- 0xFF 0xFF
- Conflicts with Jpeg
- */
- default:
- rtn = false;
- break;
- }
- return rtn;
- }
-
- /**
- Load an image from an in-RAM memory block, after attempting to
- determine it's image format.
- CreateFrom does not de-allocate the memory.
- \param[in] size The byte count of the memory block.
- \param[in] data A pointer to the memory block.
- \return true for success, or false if unable to load the image (most often because the
- formatting is corrupt or does not contain a recognized image format).
- You can call Width() and Height() member functions of the image to determine its size.
- */
- bool Image::CreateFrom(int size, void * data)
- {
- bool rtn;
- switch (((unsigned char * )data)[0])
- {
-
-#ifdef HAVE_LIBPNG
- /* PNG
- The first eight bytes of a PNG file always contain the following (decimal) values:
- 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
- == .PNG\r\n.\n
- */
- case 0x89: // PNG
- rtn = CreateFromPng(size, data);
- break;
-#endif
- /* GIF
- 0x47 0x49 0x46
- */
- case 0x47: // GIF
- rtn = CreateFromGif(size, data);
- break;
-
-#ifdef HAVE_LIBJPEG
- /* JPEG
- A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0,
- followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
- */
- case 0xFF: // JPEG
- rtn = CreateFromJpeg(size, data);
- break;
-#endif
-
- /* WBMP
- WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type
- */
- case 0x00: // WBMP
- rtn = CreateFromWBMP(size, data);
- break;
- /* GD2
- 0x67 0x64 0x32 0x00
- == GD2\0
- Starts with gd2
- */
- case 0x67: // GD2
- rtn = CreateFromGd2(size, data);
- break;
- /* GD
- 0xFF 0xFE
- or
- 0xFF 0xFF
- Conflicts with Jpeg
- */
- default:
- rtn = false;
- break;
- }
- return rtn;
- }
- } // namespace GD
-/**
- Load an image from a standard input stream, regardless of it's image file format.
- You can call Width() and Height() member functions of the image to determine its size.
- Example usage, convert anything to gif:
- #include <fstream>
- #include <gdpp.h>
-
- std::ifstream in("image.xxx", std::ios_base::in | std::ios_base::binary );
- GD::Image im;
- in >> im;
- if (im.good())
- {
- std::ofstream out("image.gif", std::ios_base::out | std::ios_base::binary );
- im.Gif(out);
- }
-*/
-std::istream & operator>> (std::istream & in, GD::Image & img)
- {
- img.CreateFrom(in);
- return in;
- }
-
-#endif /* __cplusplus */
+/* ***************************************************************************** +** $Id$ +** Initial file written and documented by: +** Kevin Shepherd <kshepherd@php.net> December 2007 +** of Scarlet Line http://www.scarletline.com/ +*******************************************************************************/ +/** \file gdpp.cxx + \brief Implements the non-trivial methods of GD::Image. + + Implementation of the more complex methods defined + in gdpp.h. + Notably includes the methods which determine the image file + format of a file before reading it into memory. +*/ +#ifdef __cplusplus +#include "gdpp.h" + +namespace GD + { + /** + Load an image from a file, after attempting to + determine it's image file format. + Invoke CreateFrom with an already opened + pointer to a file containing the desired image. + CreateFrom does not close the file. + \param[in] in An opened FILE * pointer. + \return true for success, or false if unable to load the image (most often because the + file is corrupt or does not contain a recognized image format). + You can call Width() and Height() member functions of the image to determine its size. + */ + bool Image::CreateFrom(FILE * in) + { + bool rtn; + int c = fgetc(in); + ungetc(c, in); + switch (c) + { + /* PNG + The first eight bytes of a PNG file always contain the following (decimal) values: + 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A + == .PNG\r\n.\n + */ +#ifdef HAVE_LIBPNG + case 0x89: // PNG + rtn = CreateFromPng(in); + break; +#endif + /* GIF + 0x47 0x49 0x46 + */ + case 0x47: // GIF + rtn = CreateFromGif(in); + break; +#ifdef HAVE_LIBJPEG + /* JPEG + A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0, + followed by two variable bytes (often hex 00 10), followed by 'JFIF'. + */ + case 0xFF: // JPEG + rtn = CreateFromJpeg(in); + break; +#endif + /* WBMP + WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type + */ + case 0x00: // WBMP + rtn = CreateFromWBMP(in); + break; + /* GD2 + 0x67 0x64 0x32 0x00 + == GD2\0 + Starts with gd2 + */ + case 0x67: // GD2 + rtn = CreateFromGd2(in); + break; + /* GD + 0xFF 0xFE + or + 0xFF 0xFF + Conflicts with Jpeg + */ + /* XBM + #define test_width 16 + #define test_height 7 + */ + case 0x23: // XBM + rtn = CreateFromXbm(in); + break; + default: + rtn = false; + break; + } + return rtn; + } + + /** + Load an image from a standard input stream, after attempting to + determine it's image file format. + Invoke CreateFrom with an already opened stream + containing the desired image. + CreateFrom does not close the stream. + \param[in] in An opened standard library input stream. + \return true for success, or false if unable to load the image (most often because the + file is corrupt or does not contain a recognized image format). + You can call Width() and Height() member functions of the image to determine its size. + Example usage, convert anything to gif: + #include <fstream> + #include <gdpp.h> + + std::ifstream in("image.xxx", std::ios_base::in | std::ios_base::binary ); + GD::Image im; + im.CreateFrom(in); + if (im.good()) + { + std::ofstream out("image.gif", std::ios_base::out | std::ios_base::binary ); + im.Gif(out); + } + */ + bool Image::CreateFrom(std::istream & in) + { + bool rtn; + switch (in.peek()) + { +#ifdef HAVE_LIBPNG + /* PNG + The first eight bytes of a PNG file always contain the following (decimal) values: + 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A + == .PNG\r\n.\n + */ + case 0x89: // PNG + rtn = CreateFromPng(in); + break; +#endif + + /* GIF + 0x47 0x49 0x46 + */ + case 0x47: // GIF + rtn = CreateFromGif(in); + break; + +#ifdef HAVE_LIBJPEG + /* JPEG + A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0, + followed by two variable bytes (often hex 00 10), followed by 'JFIF'. + */ + case 0xFF: // JPEG + rtn = CreateFromJpeg(in); + break; +#endif + + /* WBMP + WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type + */ + case 0x00: // WBMP + rtn = CreateFromWBMP(in); + break; + /* GD2 + 0x67 0x64 0x32 0x00 + == GD2\0 + Starts with gd2 + */ + case 0x67: // GD2 + rtn = CreateFromGd2(in); + break; + /* GD + 0xFF 0xFE + or + 0xFF 0xFF + Conflicts with Jpeg + */ + default: + rtn = false; + break; + } + return rtn; + } + + /** + Load an image from an in-RAM memory block, after attempting to + determine it's image format. + CreateFrom does not de-allocate the memory. + \param[in] size The byte count of the memory block. + \param[in] data A pointer to the memory block. + \return true for success, or false if unable to load the image (most often because the + formatting is corrupt or does not contain a recognized image format). + You can call Width() and Height() member functions of the image to determine its size. + */ + bool Image::CreateFrom(int size, void * data) + { + bool rtn; + switch (((unsigned char * )data)[0]) + { + +#ifdef HAVE_LIBPNG + /* PNG + The first eight bytes of a PNG file always contain the following (decimal) values: + 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A + == .PNG\r\n.\n + */ + case 0x89: // PNG + rtn = CreateFromPng(size, data); + break; +#endif + /* GIF + 0x47 0x49 0x46 + */ + case 0x47: // GIF + rtn = CreateFromGif(size, data); + break; + +#ifdef HAVE_LIBJPEG + /* JPEG + A JFIF-standard file will start with the four bytes (hex) FF D8 FF E0, + followed by two variable bytes (often hex 00 10), followed by 'JFIF'. + */ + case 0xFF: // JPEG + rtn = CreateFromJpeg(size, data); + break; +#endif + + /* WBMP + WBMP Type 0: B/W, Uncompressed bitmap is the only gd supported type + */ + case 0x00: // WBMP + rtn = CreateFromWBMP(size, data); + break; + /* GD2 + 0x67 0x64 0x32 0x00 + == GD2\0 + Starts with gd2 + */ + case 0x67: // GD2 + rtn = CreateFromGd2(size, data); + break; + /* GD + 0xFF 0xFE + or + 0xFF 0xFF + Conflicts with Jpeg + */ + default: + rtn = false; + break; + } + return rtn; + } + } // namespace GD +/** + Load an image from a standard input stream, regardless of it's image file format. + You can call Width() and Height() member functions of the image to determine its size. + Example usage, convert anything to gif: + #include <fstream> + #include <gdpp.h> + + std::ifstream in("image.xxx", std::ios_base::in | std::ios_base::binary ); + GD::Image im; + in >> im; + if (im.good()) + { + std::ofstream out("image.gif", std::ios_base::out | std::ios_base::binary ); + im.Gif(out); + } +*/ +std::istream & operator>> (std::istream & in, GD::Image & img) + { + img.CreateFrom(in); + return in; + } + +#endif /* __cplusplus */ diff --git a/Build/source/libs/gd/libgd-src/src/gdtest.c b/Build/source/libs/gd/libgd-src/src/gdtest.c index 17dfc1bc521..0f8febe077a 100644 --- a/Build/source/libs/gd/libgd-src/src/gdtest.c +++ b/Build/source/libs/gd/libgd-src/src/gdtest.c @@ -50,6 +50,14 @@ main (int argc, char **argv) ref = gdImageCreateFromPng (in); fclose (in); + if (!im) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } + if (!ref) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } printf ("Reference File has %d Palette entries\n", ref->colorsTotal); @@ -65,6 +73,10 @@ main (int argc, char **argv) sprintf (of, "%s.png", argv[1]); #endif out = fopen (of, "wb"); + if (!out) { + fprintf(stderr, "PNG Output file does not exist!\n"); + exit (1); + } gdImagePng (im, out); fclose (out); @@ -75,7 +87,12 @@ main (int argc, char **argv) } im2 = gdImageCreateFromPng (in); fclose (in); - + + if (!im2) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } + CompareImages ("GD->PNG File->GD", ref, im2); unlink (of); @@ -85,6 +102,10 @@ main (int argc, char **argv) iptr = gdImagePngPtr (im, &sz); im2 = gdImageCreateFromPngPtr (sz, iptr); gdFree (iptr); + if (!im2) { + fprintf(stderr, "gdImageCreateFromPngPtr failed.\n"); + exit (1); + } CompareImages ("GD->PNG ptr->GD", ref, im2); gdImageDestroy (im2); @@ -98,6 +119,10 @@ main (int argc, char **argv) sprintf (of, "%s.gd2", argv[1]); #endif out = fopen (of, "wb"); + if (!out) { + fprintf(stderr, "GD2 Output file does not exist!\n"); + exit (1); + } gdImageGd2 (im, out, 128, 2); fclose (out); @@ -108,7 +133,10 @@ main (int argc, char **argv) } im2 = gdImageCreateFromGd2 (in); fclose (in); - + if (!im2) { + fprintf(stderr, "gdImageCreateFromGd2 failed.\n"); + exit (1); + } CompareImages ("GD->GD2 File->GD", ref, im2); unlink (of); @@ -119,7 +147,10 @@ main (int argc, char **argv) im2 = gdImageCreateFromGd2Ptr (sz, iptr); gdFree (iptr); /*printf("Got img2 %d\n",im2); */ - + if (!im2) { + fprintf(stderr, "gdImageCreateFromGd2Ptr failed.\n"); + exit (1); + } CompareImages ("GD->GD2 ptr->GD", ref, im2); gdImageDestroy (im2); @@ -133,6 +164,10 @@ main (int argc, char **argv) sprintf (of, "%s.gd", argv[1]); #endif out = fopen (of, "wb"); + if (!out) { + fprintf(stderr, "GD Output file does not exist!\n"); + exit (1); + } gdImageGd (im, out); fclose (out); @@ -143,7 +178,10 @@ main (int argc, char **argv) } im2 = gdImageCreateFromGd (in); fclose (in); - + if (!im2) { + fprintf(stderr, "gdImageCreateFromGd failed.\n"); + exit (1); + } CompareImages ("GD->GD File->GD", ref, im2); unlink (of); @@ -154,7 +192,11 @@ main (int argc, char **argv) im2 = gdImageCreateFromGdPtr (sz, iptr); gdFree (iptr); /*printf("Got img2 %d\n",im2); */ - + if (!im2) { + fprintf(stderr, "gdImageCreateFromGdPtr failed.\n"); + exit (1); + } + CompareImages ("GD->GD ptr->GD", ref, im2); gdImageDestroy (im2); @@ -188,6 +230,11 @@ main (int argc, char **argv) sprintf (of, "%s.snk", argv[1]); #endif out = fopen (of, "wb"); + if (!out) { + fprintf (stderr, + "GD Sink: ERROR - GD Sink Output file does not exist!\n"); + exit (1); + } imgsnk.sink = fwriteWrapper; imgsnk.context = out; gdImagePngToSink (im, &imgsnk); @@ -199,7 +246,10 @@ main (int argc, char **argv) } else { im2 = gdImageCreateFromPng (in); fclose (in); - + if (!im2) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } CompareImages ("GD Sink", ref, im2); gdImageDestroy (im2); }; @@ -216,7 +266,10 @@ main (int argc, char **argv) } im2 = gdImageCreateFromPng (in); fclose (in); - + if (!im2) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } in = fopen ("test/gdtest.gd2", "rb"); if (!in) { @@ -225,7 +278,10 @@ main (int argc, char **argv) } im3 = gdImageCreateFromGd2Part (in, 200, 300, 150, 100); fclose (in); - + if (!im3) { + fprintf(stderr, "gdImageCreateFromGd2Part failed.\n"); + exit (1); + } CompareImages ("GD2Part (gdtest_200_300_150_100.png, gdtest.gd2(part))", im2, im3); @@ -242,8 +298,15 @@ main (int argc, char **argv) } im2 = gdImageCreateFromPng (in); fclose (in); - + if (!im2) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } im3 = gdImageCreate (100, 60); + if (!im3) { + fprintf(stderr, "gdImageCreate failed.\n"); + exit (1); + } colRed = gdImageColorAllocate (im3, 255, 0, 0); colBlu = gdImageColorAllocate (im3, 0, 0, 255); gdImageFilledRectangle (im3, 0, 0, 49, 30, colRed); @@ -264,7 +327,10 @@ main (int argc, char **argv) } im3 = gdImageCreateFromPng (in); fclose (in); - + if (!im3) { + fprintf(stderr, "gdImageCreateFromPng failed.\n"); + exit (1); + } printf ("[Merged Image has %d colours]\n", im2->colorsTotal); CompareImages ("Merged (gdtest.png, gdtest_merge.png)", im2, im3); @@ -318,6 +384,11 @@ main (int argc, char **argv) exit (1); } im2 = gdImageCreateFromWBMP (in); + fclose (in); + if (!im2) { + fprintf(stderr, "gdImageCreateFromWBMP failed.\n"); + exit (1); + } fprintf(stderr, "WBMP has %d colors\n", gdImageColorsTotal (im2)); fprintf(stderr, "WBMP colors are:\n"); for (i = 0; (i < gdImageColorsTotal (im2)); i++) { @@ -325,11 +396,6 @@ main (int argc, char **argv) gdImageRed (im2, i), gdImageGreen (im2, i), gdImageBlue (im2, i)); } - fclose (in); - if (!im2) { - fprintf(stderr, "gdImageCreateFromWBMP failed.\n"); - exit (1); - } CompareImages ("WBMP test (gdtest.png, gdtest.wbmp)", ref, im2); out = fopen ("test/gdtest_wbmp_to_png.png", "wb"); if (!out) { diff --git a/Build/source/libs/gd/libgd-src/src/gdtestft.c b/Build/source/libs/gd/libgd-src/src/gdtestft.c index e72165bdb56..53945a636cf 100644 --- a/Build/source/libs/gd/libgd-src/src/gdtestft.c +++ b/Build/source/libs/gd/libgd-src/src/gdtestft.c @@ -44,7 +44,7 @@ main (int argc, char *argv[]) #ifdef JISX0208 char *s = "Hello. ‚±‚ñ‚É‚¿‚Í Qyjpqg,"; /* String to draw. */ #else - char *s = "Hello. äöü Qyjpqg,"; /* String to draw. */ + char *s = "Hello. ã“ã‚“ã«ã¡ã¯ Qyjpqg,"; /* String to draw. */ #endif double sz = 40.; diff --git a/Build/source/libs/gd/libgd-src/src/webpimg.c b/Build/source/libs/gd/libgd-src/src/webpimg.c deleted file mode 100644 index cf73d642b65..00000000000 --- a/Build/source/libs/gd/libgd-src/src/webpimg.c +++ /dev/null @@ -1,905 +0,0 @@ -/*===========================================================================* - - Copyright 2010 Google Inc. - - - - This code is licensed under the same terms as WebM: - - Software License Agreement: http://www.webmproject.org/license/software/ - - Additional IP Rights Grant: http://www.webmproject.org/license/additional/ - *===========================================================================*/ - -/* - * Encoding/Decoding of WebP still image compression format. - * - * 1. WebPDecode: Takes an array of bytes (string) corresponding to the WebP - * encoded image and generates output in the YUV format with - * the color components U, V subsampled to 1/2 resolution along - * each dimension. - * - * 2. YUV420toRGBA: Converts from YUV (with color subsampling) such as produced - * by the WebPDecode routine into 32 bits per pixel RGBA data - * array. This data array can be directly used by the Leptonica - * Pix in-memory image format. - * - * 3. WebPEncode: Takes a Y, U, V data buffers (with color components U and V - * subsampled to 1/2 resolution) and generates the WebP string - * - * 4. RGBAToYUV420: Generates Y, U, V data (with color subsampling) from 32 bits - * per pixel RGBA data buffer. The resulting YUV data can be - * directly fed into the WebPEncode routine. - * - * 5. AdjustColorspace: - * - * 6. AdjustColorspaceBack: - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gd.h" -#include "gd_errors.h" -#ifdef HAVE_LIBVPX -#include "webpimg.h" - -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> - -#include "vpx/vpx_decoder.h" -#include "vpx/vp8dx.h" -#include "vpx/vpx_encoder.h" -#include "vpx/vp8cx.h" -#include "gd.h" - -/*---------------------------------------------------------------------* - * color conversions * - *---------------------------------------------------------------------*/ - -#ifndef inline -# define inline __inline -#endif -static inline int clip(float v, int a, int b) { - return (v > b) ? b : (v < 0) ? 0 : (int)(v); -} -enum { - COLOR_RED = 0, - COLOR_GREEN = 1, - COLOR_BLUE = 2, - ALPHA_CHANNEL = 3 -}; - -/* endian neutral extractions of RGBA from a 32 bit pixel */ -static const uint32 RED_SHIFT = - 8 * (sizeof(uint32) - 1 - COLOR_RED); /* 24 */ -static const uint32 GREEN_SHIFT = - 8 * (sizeof(uint32) - 1 - COLOR_GREEN); /* 16 */ -static const uint32 BLUE_SHIFT = - 8 * (sizeof(uint32) - 1 - COLOR_BLUE); /* 8 */ -static const uint32 ALPHA_SHIFT = - 8 * (sizeof(uint32) - 1 - ALPHA_CHANNEL); /* 0 */ - -static inline int GetRed(const uint32* rgba) { - return gdTrueColorGetRed(*rgba); -} - -static inline int GetGreen(const uint32* rgba) { - return gdTrueColorGetGreen(*rgba); -} - -static inline int GetBlue(const uint32* rgba) { - return gdTrueColorGetBlue(*rgba); -} - -enum { YUV_FRAC = 16 }; - -static inline int clip_uv(int v) { - v = (v + (257 << (YUV_FRAC + 2 - 1))) >> (YUV_FRAC + 2); - return ((v & ~0xff) == 0) ? v : v < 0 ? 0u : 255u; -} - - -/* YUV <-----> RGB conversions */ -/* The exact naming is Y'CbCr, following the ITU-R BT.601 standard. - * More information at: http://en.wikipedia.org/wiki/YCbCr - */ -static inline int GetLumaY(int r, int g, int b) { - const int kRound = (1 << (YUV_FRAC - 1)) + (16 << YUV_FRAC); - // Y = 0.2569 * R + 0.5044 * G + 0.0979 * B + 16 - const int luma = 16839 * r + 33059 * g + 6420 * b; - return (luma + kRound) >> YUV_FRAC; -} - -static inline int GetLumaYfromPtr(uint32* rgba) { - const int r = GetRed(rgba); - const int g = GetGreen(rgba); - const int b = GetBlue(rgba); - return GetLumaY(r, g, b); -} - -static inline int GetChromaU(int r, int g, int b) { - // U = -0.1483 * R - 0.2911 * G + 0.4394 * B + 128 - return clip_uv(-9719 * r - 19081 * g + 28800 * b); -} - -static inline int GetChromaV(int r, int g, int b) { - // V = 0.4394 * R - 0.3679 * G - 0.0715 * B + 128 - return clip_uv(+28800 * r - 24116 * g - 4684 * b); -} - -/* Converts YUV to RGB and writes into a 32 bit pixel in endian - * neutral fashion - */ -enum { RGB_FRAC = 16, RGB_HALF = (1 << RGB_FRAC) / 2, - RGB_RANGE_MIN = -227, RGB_RANGE_MAX = 256 + 226 }; - -static int init_done = 0; -static int16_t kVToR[256], kUToB[256]; -static int32_t kVToG[256], kUToG[256]; -static uint8_t kClip[RGB_RANGE_MAX - RGB_RANGE_MIN]; - -static void InitTables() { - int i; - for (i = 0; i < 256; ++i) { - kVToR[i] = (89858 * (i - 128) + RGB_HALF) >> RGB_FRAC; - kUToG[i] = -22014 * (i - 128) + RGB_HALF; - kVToG[i] = -45773 * (i - 128); - kUToB[i] = (113618 * (i - 128) + RGB_HALF) >> RGB_FRAC; - } - for (i = RGB_RANGE_MIN; i < RGB_RANGE_MAX; ++i) { - const int j = ((i - 16) * 76283 + RGB_HALF) >> RGB_FRAC; - kClip[i - RGB_RANGE_MIN] = (j < 0) ? 0 : (j > 255) ? 255 : j; - } - - init_done = 1; -} - -static void ToRGB(int y, int u, int v, uint32* const dst) { - const int r_off = kVToR[v]; - const int g_off = (kVToG[v] + kUToG[u]) >> RGB_FRAC; - const int b_off = kUToB[u]; - const int r = kClip[y + r_off - RGB_RANGE_MIN]; - const int g = kClip[y + g_off - RGB_RANGE_MIN]; - const int b = kClip[y + b_off - RGB_RANGE_MIN]; - *dst = (r << RED_SHIFT) | (g << GREEN_SHIFT) | (b << BLUE_SHIFT); -} - -static inline uint32 get_le32(const uint8* const data) { - return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); -} - -/* Returns the difference (in dB) between two images represented in YUV format - * - * Input: - * Y1/U1/V1: The Y/U/V data of the first image - * Y2/U2/V2: The Y/U/V data of the second image - * - * Returns the PSNR (http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio) - * value computed bewteen the two images - */ -double GetPSNRYuv(const uint8* Y1, - const uint8* U1, - const uint8* V1, - const uint8* Y2, - const uint8* U2, - const uint8* V2, - int y_width, - int y_height) { - int x, y, row_idx; - const int uv_width = ((y_width + 1) >> 1); - const int uv_height = ((y_height + 1) >> 1); - double sse = 0., count = 0.; - for (y = 0; y < y_height; ++y) { - count += y_width; - row_idx = y * y_width; - for (x = 0; x < y_width; ++x) { - double diff = Y1[row_idx + x] - Y2[row_idx + x]; - sse += diff * diff; - } - } - for (y = 0; y < uv_height; ++y) { - count += 2 * uv_width; - row_idx = y * uv_width; - for (x = 0; x < uv_width; ++x) { - const double diff_U = U1[row_idx + x] - U2[row_idx + x]; - const double diff_V = V1[row_idx + x] - V2[row_idx + x]; - sse += diff_U * diff_U + diff_V * diff_V; - } - } - return -4.3429448 * log(sse / (255. * 255. * count)); -} - -/* Returns the difference (in dB) between two images. One represented - * using Y,U,V vectors and the other is webp image data. - * Input: - * Y1/U1/V1: The Y/U/V data of the first image - * imgdata: data buffer containing webp image - * imgdata_size: size of the imgdata buffer - * - * Returns the PSNR value computed bewteen the two images - */ -double WebPGetPSNR(const uint8* Y1, - const uint8* U1, - const uint8* V1, - uint8* imgdata, - int imgdata_size) { - uint8* Y2 = NULL; - uint8* U2 = NULL; - uint8* V2 = NULL; - int w = 0, h = 0; - double psnr = 0; - - WebPDecode(imgdata, - imgdata_size, - &Y2, - &U2, - &V2, - &w, - &h); - - psnr = GetPSNRYuv(Y1, U1, V1, Y2, U2, V2, w, h); - free(Y2); - - return psnr; -} - -/*---------------------------------------------------------------------* - * Reading WebP * - *---------------------------------------------------------------------*/ - -/* RIFF layout is: - * 0ffset tag - * 0...3 "RIFF" 4-byte tag - * 4...7 size of image data (including metadata) starting at offset 8 - * 8...11 "WEBP" our form-type signature - * 12..15 "VP8 " 4-byte tags, describing the raw video format used - * 16..19 size of the raw WebP image data, starting at offset 20 - * 20.... the WebP bytes - * There can be extra chunks after the "VP8 " chunk (ICMT, ICOP, ...) - * All 32-bits sizes are in little-endian order. - * Note: chunk data must be padded to multiple of 2 in size - */ - -int SkipRiffHeader(const uint8** data_ptr, int *data_size_ptr) { - /* 20 bytes RIFF header 10 bytes VP8 header */ - const int kHeaderSize = (20 + 10); - uint32 chunk_size = 0xffffffffu; - - if (*data_size_ptr >= kHeaderSize && !memcmp(*data_ptr, "RIFF", 4)) { - if (memcmp(*data_ptr + 8, "WEBP", 4)) { - return 0; /* wrong image file signature */ - } else { - const uint32 riff_size = get_le32(*data_ptr + 4); - if (memcmp(*data_ptr + 12, "VP8 ", 4)) { - return 0; /* invalid compression format */ - } - chunk_size = get_le32(*data_ptr + 16); - if ((chunk_size > riff_size + 8) || (chunk_size & 1)) { - return 0; /* inconsistent size information. */ - } - /* We have a RIFF container. Skip it. */ - *data_ptr += 20; - *data_size_ptr -= 20; - } - } - return chunk_size; -} - -/* Generate RGBA row from an YUV row (with width upsampling of chrome data) - * Input: - * 1, 2, 3. y_src, u_src, v_src - Pointers to input Y, U, V row data - * respectively. We reuse these variables, they iterate over all pixels in - * the row. - * 4. y_width: width of the Y image plane (aka image width) - * Output: - * 5. rgb_dst: pointer to the output rgb row. We reuse this variable, it - * iterates over all pixels in the row. - */ -static void YUV420toRGBLine(uint8* y_src, - uint8* u_src, - uint8* v_src, - int y_width, - uint32* rgb_dst) { - int x; - for (x = 0; x < (y_width >> 1); ++x) { - const int U = u_src[0]; - const int V = v_src[0]; - ToRGB(y_src[0], U, V, rgb_dst); - ToRGB(y_src[1], U, V, rgb_dst + 1); - ++u_src; - ++v_src; - y_src += 2; - rgb_dst += 2; - } - if (y_width & 1) { /* Rightmost pixel */ - ToRGB(y_src[0], (*u_src), (*v_src), rgb_dst); - } -} - -/* Converts from YUV (with color subsampling) such as produced by the WebPDecode - * routine into 32 bits per pixel RGBA data array. This data array can be - * directly used by the Leptonica Pix in-memory image format. - * Input: - * 1, 2, 3. Y, U, V: the input data buffers - * 4. pixwpl: the desired words per line corresponding to the supplied - * output pixdata. - * 5. width, height: the dimensions of the image whose data resides in Y, - * U, V. - * Output: - * 6. pixdata: the output data buffer. Caller should allocate - * height * pixwpl bytes of memory before calling this routine. - */ -void YUV420toRGBA(uint8* Y, - uint8* U, - uint8* V, - int words_per_line, - int width, - int height, - uint32* pixdata) { - int y_width = width; - int y_stride = y_width; - int uv_width = ((y_width + 1) >> 1); - int uv_stride = uv_width; - int y; - - if (!init_done) - InitTables(); - - /* note that the U, V upsampling in height is happening here as the U, V - * buffers sent to successive odd-even pair of lines is same. - */ - for (y = 0; y < height; ++y) { - YUV420toRGBLine(Y + y * y_stride, - U + (y >> 1) * uv_stride, - V + (y >> 1) * uv_stride, - width, - pixdata + y * words_per_line); - } -} - -void gd_YUV420toRGBA(uint8* Y, - uint8* U, - uint8* V, - gdImagePtr im) { - int width = im->sx; - int height = im->sy; - int y_width = width; - int y_stride = y_width; - int uv_width = ((y_width + 1) >> 1); - int uv_stride = uv_width; - int y; - - /* output im must be truecolor */ - if (!im->trueColor) { - return; - } - - if (!init_done) - InitTables(); - - /* note that the U, V upsampling in height is happening here as the U, V - * buffers sent to successive odd-even pair of lines is same. - */ - for (y = 0; y < height; ++y) { - YUV420toRGBLine(Y + y * y_stride, - U + (y >> 1) * uv_stride, - V + (y >> 1) * uv_stride, - width, - (uint32 *)im->tpixels[y]); - } -} - -static WebPResult VPXDecode(const uint8* data, - int data_size, - uint8** p_Y, - uint8** p_U, - uint8** p_V, - int* p_width, - int* p_height) { - vpx_codec_ctx_t dec; - vp8_postproc_cfg_t ppcfg; - WebPResult result = webp_failure; - - if (!data || data_size <= 10 || !p_Y || !p_U || !p_V - || *p_Y != NULL || *p_U != NULL || *p_V != NULL) { - return webp_failure; - } - - if (vpx_codec_dec_init(&dec, - &vpx_codec_vp8_dx_algo, NULL, 0) != VPX_CODEC_OK) { - return webp_failure; - } - - ppcfg.post_proc_flag = VP8_NOFILTERING; - vpx_codec_control(&dec, VP8_SET_POSTPROC, &ppcfg); - - - if (vpx_codec_decode(&dec, data, data_size, NULL, 0) == VPX_CODEC_OK) { - vpx_codec_iter_t iter = NULL; - vpx_image_t* const img = vpx_codec_get_frame(&dec, &iter); - if (img) { - int y_width = img->d_w; - int y_height = img->d_h; - int y_stride = y_width; - int uv_width = (y_width + 1) >> 1; - int uv_stride = uv_width; - int uv_height = ((y_height + 1) >> 1); - int y; - - *p_width = y_width; - *p_height = y_height; - if ((*p_Y = (uint8 *)(calloc(y_stride * y_height - + 2 * uv_stride * uv_height, - sizeof(uint8)))) != NULL) { - *p_U = *p_Y + y_height * y_stride; - *p_V = *p_U + uv_height * uv_stride; - for (y = 0; y < y_height; ++y) { - memcpy(*p_Y + y * y_stride, - img->planes[0] + y * img->stride[0], - y_width); - } - for (y = 0; y < uv_height; ++y) { - memcpy(*p_U + y * uv_stride, - img->planes[1] + y * img->stride[1], - uv_width); - memcpy(*p_V + y * uv_stride, - img->planes[2] + y * img->stride[2], - uv_width); - } - result = webp_success; - } - } - } - vpx_codec_destroy(&dec); - - return result; -} - -WebPResult WebPDecode(const uint8* data, - int data_size, - uint8** p_Y, - uint8** p_U, - uint8** p_V, - int* p_width, - int* p_height) { - - const uint32 chunk_size = SkipRiffHeader(&data, &data_size); - if (!chunk_size) { - return webp_failure; /* unsupported RIFF header */ - } - - return VPXDecode(data, data_size, p_Y, p_U, p_V, p_width, p_height); -} - -/*---------------------------------------------------------------------* - * Writing WebP * - *---------------------------------------------------------------------*/ - -/* Takes a pair of RGBA row data as input and generates 2 rows of Y data and one - * row of subsampled U, V data as output - * Input: - * 1, 2. rgb_line1, rgb_line2 - input rgba rows - * 3. width - image width - * Outout: - * 4, 5, 6: Output Y, U, V row - */ -static void RGBALinepairToYUV420(uint32* rgb_line1, - uint32* rgb_line2, - int width, - uint8* Y_dst1, - uint8* Y_dst2, - uint8* u_dst, - uint8* v_dst) { - int x; - for (x = (width >> 1); x > 0; --x) { - const int sum_r = - GetRed(rgb_line1 + 0) + GetRed(rgb_line1 + 1) + - GetRed(rgb_line2 + 0) + GetRed(rgb_line2 + 1); - const int sum_g = - GetGreen(rgb_line1 + 0) + GetGreen(rgb_line1 + 1) + - GetGreen(rgb_line2 + 0) + GetGreen(rgb_line2 + 1); - const int sum_b = - GetBlue(rgb_line1 + 0) + GetBlue(rgb_line1 + 1) + - GetBlue(rgb_line2 + 0) + GetBlue(rgb_line2 + 1); - - Y_dst1[0] = GetLumaYfromPtr(rgb_line1 + 0); - Y_dst1[1] = GetLumaYfromPtr(rgb_line1 + 1); - Y_dst2[0] = GetLumaYfromPtr(rgb_line2 + 0); - Y_dst2[1] = GetLumaYfromPtr(rgb_line2 + 1); - - *u_dst++ = GetChromaU(sum_r, sum_g, sum_b); - *v_dst++ = GetChromaV(sum_r, sum_g, sum_b); - - rgb_line1 += 2; - rgb_line2 += 2; - Y_dst1 += 2; - Y_dst2 += 2; - } - - if (width & 1) { /* rightmost pixel. */ - const int sum_r = GetRed(rgb_line1) + GetRed(rgb_line2); - const int sum_g = GetGreen(rgb_line1) + GetGreen(rgb_line2); - const int sum_b = GetBlue(rgb_line1) + GetBlue(rgb_line2); - - Y_dst1[0] = GetLumaYfromPtr(rgb_line1); - Y_dst2[0] = GetLumaYfromPtr(rgb_line2); - *u_dst = GetChromaU(2 * sum_r, 2 * sum_g, 2 * sum_b); - *v_dst = GetChromaV(2 * sum_r, 2 * sum_g, 2 * sum_b); - } -} - -/* Generates Y, U, V data (with color subsampling) from 32 bits - * per pixel RGBA data buffer. The resulting YUV data can be directly fed into - * the WebPEncode routine. - * Input: - * 1. pixdatainput rgba data buffer - * 2. words per line corresponding to pixdata - * 3, 4. image width and height respectively - * Output: - * 5, 6, 7. Output YUV data buffers - */ -void gd_RGBAToYUV420(gdImagePtr im2, - uint8* Y, - uint8* U, - uint8* V) { - int y_width = im2->sx; - int y_height = im2->sy; - int y_stride = y_width; - int uv_width = ((y_width + 1) >> 1); - int uv_stride = uv_width; - int y; - gdImagePtr im = NULL; - int free_im = 0; - - if (!im2->trueColor) { - /* Todo: Replace the color/YUV functions with our own and simplify - that should boost the conversion a bit as well, not only for - palette image. */ - im = gdImageCreateTrueColor(im2->sx, im2->sy); - if (!im) { - gd_error("gd-webp error: cannot convert palette input to truecolor"); - return; - } - gdImageCopy(im, im2, 0, 0, 0, 0, im->sx, im->sy); - free_im = 1; - } else { - im = im2; - } - for (y = 0; y < (y_height >> 1); ++y) { - RGBALinepairToYUV420((uint32 *)im->tpixels[2 * y], - (uint32 *)im->tpixels[2 * y + 1], - y_width, - Y + 2 * y * y_stride, - Y + (2 * y + 1) * y_stride, - U + y * uv_stride, - V + y * uv_stride); - } - if (y_height & 1) { - RGBALinepairToYUV420((uint32 *)im->tpixels[y_height - 1], - (uint32 *)im->tpixels[y_height - 1], - y_width, - Y + (y_height - 1) * y_stride, - Y + (y_height - 1) * y_stride, - U + (y_height >> 1) * uv_stride, - V + (y_height >> 1) * uv_stride); - } - if (free_im) { - gdImageDestroy(im); - } -} - -/* Generates Y, U, V data (with color subsampling) from 32 bits - * per pixel RGBA data buffer. The resulting YUV data can be directly fed into - * the WebPEncode routine. - * Input: - * 1. pixdatainput rgba data buffer - * 2. words per line corresponding to pixdata - * 3, 4. image width and height respectively - * Output: - * 5, 6, 7. Output YUV data buffers - */ -void RGBAToYUV420(uint32* pixdata, - int words_per_line, - int width, - int height, - uint8* Y, - uint8* U, - uint8* V) { - int y_width = width; - int y_height = height; - int y_stride = y_width; - int uv_width = ((y_width + 1) >> 1); - int uv_stride = uv_width; - int y; - - for (y = 0; y < (y_height >> 1); ++y) { - RGBALinepairToYUV420(pixdata + 2 * y * words_per_line, - pixdata + (2 * y + 1) * words_per_line, - y_width, - Y + 2 * y * y_stride, - Y + (2 * y + 1) * y_stride, - U + y * uv_stride, - V + y * uv_stride); - } - if (y_height & 1) { - RGBALinepairToYUV420(pixdata + (y_height - 1) * words_per_line, - pixdata + (y_height - 1) * words_per_line, - y_width, - Y + (y_height - 1) * y_stride, - Y + (y_height - 1) * y_stride, - U + (y_height >> 1) * uv_stride, - V + (y_height >> 1) * uv_stride); - } -} - -static int codec_ctl(vpx_codec_ctx_t *enc, - enum vp8e_enc_control_id id, - int value) { - const vpx_codec_err_t res = vpx_codec_control_(enc, id, value); - if (res != VPX_CODEC_OK) { - return webp_failure; - } - return webp_success; -} - -static void SetupParams(vpx_codec_enc_cfg_t* cfg, - int QP) { - cfg->g_threads = 2; - cfg->rc_min_quantizer = QP; - cfg->rc_max_quantizer = QP; - cfg->kf_mode = VPX_KF_FIXED; -} - -/* VPXEncode: Takes a Y, U, V data buffers (with color components U and V - * subsampled to 1/2 resolution) and generates the VPX string. - * Output VPX string is placed in the *p_out buffer. container_size - * indicates number of bytes to be left blank at the beginning of - * *p_out buffer to accommodate for a container header. - * - * Return: success/failure - */ -static WebPResult VPXEncode(const uint8* Y, - const uint8* U, - const uint8* V, - int y_width, - int y_height, - int y_stride, - int uv_width, - int uv_height, - int uv_stride, - int QP, - int container_size, - unsigned char** p_out, - int* p_out_size_bytes) { - vpx_codec_iface_t* iface = &vpx_codec_vp8_cx_algo; - vpx_codec_err_t res; - vpx_codec_enc_cfg_t cfg; - vpx_codec_ctx_t enc; - WebPResult result = webp_failure; - vpx_image_t img; - - *p_out = NULL; - *p_out_size_bytes = 0; - - - /* validate input parameters. */ - if (!p_out || !Y || !U || !V - || y_width <= 0 || y_height <= 0 || uv_width <= 0 || uv_height <= 0 - || y_stride < y_width || uv_stride < uv_width - || QP < 0 || QP > 63) { - return webp_failure; - } - - res = vpx_codec_enc_config_default(iface, &cfg, 0); - if (res != VPX_CODEC_OK) { - return webp_failure; - } - - SetupParams(&cfg, QP); - cfg.g_w = y_width; - cfg.g_h = y_height; - - res = vpx_codec_enc_init(&enc, iface, &cfg, 0); - - if (res == VPX_CODEC_OK) { - codec_ctl(&enc, VP8E_SET_CPUUSED, 3); - codec_ctl(&enc, VP8E_SET_NOISE_SENSITIVITY, 0); - codec_ctl(&enc, VP8E_SET_SHARPNESS, 0); - codec_ctl(&enc, VP8E_SET_ENABLEAUTOALTREF, 0); - codec_ctl(&enc, VP8E_SET_ARNR_MAXFRAMES, 0); - codec_ctl(&enc, VP8E_SET_ARNR_TYPE, 0); - codec_ctl(&enc, VP8E_SET_ARNR_STRENGTH, 0); - codec_ctl(&enc, VP8E_SET_STATIC_THRESHOLD, 0); - codec_ctl(&enc, VP8E_SET_TOKEN_PARTITIONS, 2); - - vpx_img_wrap(&img, IMG_FMT_I420, - y_width, y_height, 16, (uint8*)(Y)); - img.planes[PLANE_Y] = (uint8*)(Y); - img.planes[PLANE_U] = (uint8*)(U); - img.planes[PLANE_V] = (uint8*)(V); - img.stride[PLANE_Y] = y_stride; - img.stride[PLANE_U] = uv_stride; - img.stride[PLANE_V] = uv_stride; - - res = vpx_codec_encode(&enc, &img, 0, 1, 0, VPX_DL_BEST_QUALITY); - - if (res == VPX_CODEC_OK) { - vpx_codec_iter_t iter = NULL; - const vpx_codec_cx_pkt_t* pkt = vpx_codec_get_cx_data(&enc, &iter); - if (pkt != NULL) { - *p_out = (unsigned char*)(calloc(container_size + pkt->data.frame.sz, - 1)); - - memcpy(*p_out + container_size, - (const void*)(pkt->data.frame.buf), - pkt->data.frame.sz); - *p_out_size_bytes = container_size + pkt->data.frame.sz; - - result = webp_success; - } - } - } - - vpx_codec_destroy(&enc); - - return result; -} - -WebPResult WebPEncode(const uint8* Y, - const uint8* U, - const uint8* V, - int y_width, - int y_height, - int y_stride, - int uv_width, - int uv_height, - int uv_stride, - int QP, - unsigned char** p_out, - int* p_out_size_bytes, - double *psnr) { - - const int kRiffHeaderSize = 20; - - if (VPXEncode(Y, U, V, - y_width, y_height, y_stride, - uv_width, uv_height, uv_stride, - QP, kRiffHeaderSize, - p_out, p_out_size_bytes) != webp_success) { - return webp_failure; - } else { - /* Write RIFF header */ - const int img_size_bytes = *p_out_size_bytes - kRiffHeaderSize; - const int chunk_size = (img_size_bytes + 1) & ~1; /* make size even */ - const int riff_size = chunk_size + 12; - const uint8_t kRiffHeader[20] = { 'R', 'I', 'F', 'F', - (riff_size >> 0) & 255, - (riff_size >> 8) & 255, - (riff_size >> 16) & 255, - (riff_size >> 24) & 255, - 'W', 'E', 'B', 'P', - 'V', 'P', '8', ' ', - (chunk_size >> 0) & 255, - (chunk_size >> 8) & 255, - (chunk_size >> 16) & 255, - (chunk_size >> 24) & 255 }; - memcpy(*p_out, kRiffHeader, kRiffHeaderSize); - - if (psnr) { - *psnr = WebPGetPSNR(Y, U, V, *p_out, *p_out_size_bytes); - } - - return webp_success; - } -} - -void AdjustColorspace(uint8* Y, uint8* U, uint8* V, int width, int height) { - int y_width = width; - int y_height = height; - int y_stride = y_width; - int uv_width = ((y_width + 1) >> 1); - int uv_height = ((y_height + 1) >> 1); - int uv_stride = uv_width; - int x, y; - /* convert luma */ - for (y = 0; y < y_height; ++y) { - uint8* const Yrow = Y + y * y_stride; - for (x = 0; x < y_width; ++x) { - /* maps [0..255] to [16..235] */ - Yrow[x] = ((Yrow[x] * 55 + 32) >> 6) + 16; - } - } - /* convert chroma */ - for (y = 0; y < uv_height; ++y) { - uint8* const Urow = U + y * uv_stride; - uint8* const Vrow = V + y * uv_stride; - for (x = 0; x < uv_width; ++x) { - /* maps [0..255] to [16..240] */ - Urow[x] = (((Urow[x] - 127) * 7) >> 3) + 128; - Vrow[x] = (((Vrow[x] - 127) * 7) >> 3) + 128; - } - } -} - -void AdjustColorspaceBack(uint8* Y, uint8* U, uint8* V, int width, int height) { - int y_width = width; - int y_height = height; - int y_stride = y_width; - int uv_width = ((y_width + 1) >> 1); - int uv_height = ((y_height + 1) >> 1); - int uv_stride = uv_width; - int x, y; - /* convert luma */ - for (y = 0; y < y_height; ++y) { - uint8* const Yrow = Y + y * y_stride; - for (x = 0; x < y_width; ++x) { - /* maps [16..235] to [0..255] */ - const int v = ((Yrow[x] - 16) * 149 + 64) >> 7; - Yrow[x] = (v < 0) ? 0 : (v > 255) ? 255u : v; - } - } - /* convert chroma */ - for (y = 0; y < uv_height; ++y) { - uint8* const Urow = U + y * uv_stride; - uint8* const Vrow = V + y * uv_stride; - for (x = 0; x < uv_width; ++x) { - /* maps [0..255] to [16..240] */ - const int ru = (((Urow[x] - 128) * 73) >> 6) + 128; - const int rv = (((Vrow[x] - 128) * 73) >> 6) + 128; - Urow[x] = (ru < 0) ? 0 : (ru > 255) ? 255u : ru; - Vrow[x] = (rv < 0) ? 0 : (rv > 255) ? 255u : rv; - } - } -} - -WebPResult WebPGetInfo(const uint8* data, - int data_size, - int *width, - int *height) { - const uint32 chunk_size = SkipRiffHeader(&data, &data_size); - - if (width) *width = 0; - if (height) *height = 0; - - if (!chunk_size) { - return webp_failure; /* unsupported RIFF header */ - } - - /* Validate raw video data */ - if (data_size < 10) { - return webp_failure; /* not enough data */ - } - - /* check signature */ - if (data[3] != 0x9d || data[4] != 0x01 || data[5] != 0x2a) { - return webp_failure; /* Wrong signature. */ - } else { - const uint32 bits = data[0] | (data[1] << 8) | (data[2] << 16); - - if ((bits & 1)) { /* Not a keyframe. */ - return webp_failure; - } else { - const int profile = (bits >> 1) & 7; - const int show_frame = (bits >> 4) & 1; - const uint32 partition_length = (bits >> 5); - - if (profile > 3) { - return webp_failure; /* unknown profile */ - } - if (!show_frame) { - return webp_failure; /* first frame is invisible! */ - } - if (partition_length >= chunk_size) { - return webp_failure; /* inconsistent size information. */ - } else { - const int w = ((data[7] << 8) | data[6]) & 0x3fff; - const int h = ((data[9] << 8) | data[8]) & 0x3fff; - if (width) *width = w; - if (height) *height = h; - - return webp_success; - } - } - } - return webp_failure; -} -#endif /* HAVE_LIBVPX */ diff --git a/Build/source/libs/gd/libgd-src/src/webpimg.h b/Build/source/libs/gd/libgd-src/src/webpimg.h deleted file mode 100644 index 8a05429a73c..00000000000 --- a/Build/source/libs/gd/libgd-src/src/webpimg.h +++ /dev/null @@ -1,181 +0,0 @@ -/*===========================================================================* - - Copyright 2010 Google Inc. - - - - This code is licensed under the same terms as WebM: - - Software License Agreement: http://www.webmproject.org/license/software/ - - Additional IP Rights Grant: http://www.webmproject.org/license/additional/ - *===========================================================================*/ - -/* - * Encoding/Decoding of WebP still image compression format. - * - * 1. WebPDecode: Takes an array of bytes (string) corresponding to the WebP - * encoded image and generates output in the YUV format with - * the color components U, V subsampled to 1/2 resolution along - * each dimension. - * - * 2. YUV420toRGBA: Converts from YUV (with color subsampling) such as produced - * by the WebPDecode routine into 32 bits per pixel RGBA data - * array. This data array can be directly used by the Leptonica - * Pix in-memory image format. - * - * 3. WebPEncode: Takes a Y, U, V data buffers (with color components U and V - * subsampled to 1/2 resolution) and generates the WebP string - * - * 4. RGBAToYUV420: Generates Y, U, V data (with color subsampling) from 32 bits - * per pixel RGBA data buffer. The resulting YUV data can be - * directly fed into the WebPEncode routine. - * - * 5. AdjustColorspace: - * - * 6. AdjustColorspaceBack: - */ - -#ifndef THIRD_PARTY_VP8_VP8IMG_H_ -#define THIRD_PARTY_VP8_VP8IMG_H_ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef unsigned char uint8; -typedef unsigned int uint32; -typedef enum WebPResultType { - webp_success = 0, - webp_failure = -1 -} WebPResult; - -/* Takes an array of bytes (string) corresponding to the WebP - * encoded image and generates output in the YUV format with - * the color components U, V subsampled to 1/2 resolution along - * each dimension. - * Input: - * 1. data: the WebP data stream (array of bytes) - * 2. data_size: count of bytes in the WebP data stream - * - * Output: - * 3. p_Y/p_U/p_V : pointer to the Y/U/V data buffer (this routine will - * allocate memory for the buffer, fill the buffer with - * appropriate data and transfer owner ship of the buffer - * to caller. Caller is reponsible for freeing the memory). - * Note that the memory for Y, U, V buffers is alloacted - * in one chunk, hence one should call free(*p_Y) only. - * Do not try to free the U and V buffers. - * - * 6. p_width: this routine returns the width of the decoded image here - * 7. p_height: this routine returns the width of the decoded image here - * Return: success/failure - */ -WebPResult WebPDecode(const uint8* data, - int data_size, - uint8** p_Y, - uint8** p_U, - uint8** p_V, - int* p_width, - int* p_height); - -/* WebPEncode: Takes a Y, U, V data buffers (with color components U and V - * subsampled to 1/2 resolution) and generates the WebP string. - * Input: - * 1, 2, 3. Y, U, V: The input YUV data buffers - * 4, 5. y_width, y_height: The width and height of the image whose data - * is in Y, U, V. This matches the Y plane. The U - * and V planes typically have 1/2 width and - * height. - * 6. y_stride: The width (in bytes) of one row of Y data. This may not - * match width if there is end of row padding (e.g., for 32 - * bit row aligment). - * 7. QP: the quantization parameter. This parameter controls the - * compression vs quality tradeoff. Use smaller numbers for better - * quality (compression will be lesser) and vice versa. 20 is a - * good optimal value. - * Output: - * 8. p_out: the output array of bytes corresponding to the encoded WebP - * image. This routine allocates memory for the buffer, fills it - * with appropriate values and transfers ownership to caller. - * Caller responsible for freeing of memory. - * Return: success/failure - */ -WebPResult WebPEncode(const uint8* Y, - const uint8* U, - const uint8* V, - int y_width, - int y_height, - int y_stride, - int uv_width, - int uv_height, - int uv_stride, - int QP, - unsigned char** p_out, - int* p_out_size_bytes, - double* psnr); - -/* Converts from YUV (with color subsampling) such as produced by the WebPDecode - * routine into 32 bits per pixel RGBA data array. This data array can be - * directly used by the Leptonica Pix in-memory image format. - * Input: - * 1, 2, 3. Y, U, V: the input data buffers - * 4. pixwpl: the desired words per line corresponding to the supplied - * output pixdata. - * 5. width, height: the dimensions of the image whose data resides in Y, - * U, V. - * Output: - * 6. pixdata: the output data buffer. Caller should allocate - * height * pixwpl bytes of memory before calling this routine. - */ -void YUV420toRGBA(uint8* Y, - uint8* U, - uint8* V, - int words_per_line, - int width, - int height, - uint32* pixdata); - -/* Generates Y, U, V data (with color subsampling) from 32 bits - * per pixel RGBA data buffer. The resulting YUV data can be directly fed into - * the WebPEncode routine. - * Input: - * 1. pix data input rgba data buffer - * 2. words per line corresponding to pixdata - * 3, 4. image width and height respectively - * Output: - * 5, 6, 7. Output YUV data buffers - */ -void RGBAToYUV420(uint32* pixdata, - int words_per_line, - int width, - int height, - uint8* Y, - uint8* U, - uint8* V); - -/* This function adjust from YUV420J (jpeg decoding) to YUV420 (webp input) - * Hints: http://en.wikipedia.org/wiki/YCbCr - */ -void AdjustColorspace(uint8* Y, uint8* U, uint8* V, int width, int height); - -/* Inverse function: convert from YUV420 to YUV420J */ -void AdjustColorspaceBack(uint8* Y, uint8* U, uint8* V, int width, int height); - -/* Checks WebP image header and outputs height and width information of - * the image - * - * Input: - * 1. data: the WebP data stream (array of bytes) - * 2. data_size: count of bytes in the WebP data stream - * - * Outut: - * width/height: width and height of the image - * - * Return: success/failure - */ -WebPResult WebPGetInfo(const uint8* data, - int data_size, - int *width, - int *height); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* THIRD_PARTY_VP8_VP8IMG_H_ */ diff --git a/Build/source/libs/gd/libgd-src/src/webpng.c b/Build/source/libs/gd/libgd-src/src/webpng.c index 74231795d10..6faa9097674 100644 --- a/Build/source/libs/gd/libgd-src/src/webpng.c +++ b/Build/source/libs/gd/libgd-src/src/webpng.c @@ -2,242 +2,296 @@ #include "config.h" #endif -/* Bring in the gd library functions */ -#include "gd.h" - /* Bring in standard I/O and string manipulation functions */ +#include <stdarg.h> +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif #include <stdio.h> -#include <stdlib.h> /* for atoi() */ +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H #include <string.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif -#ifdef _WIN32 -#include <process.h> -int -getpid () +#ifdef __clang__ +/* Workaround broken clang behavior: https://llvm.org/bugs/show_bug.cgi?id=20144 */ +#undef strcmp +#endif + +/* Bring in the gd library functions */ +#include "gd.h" + +static const char argv0[] = "webpng"; + +static void usage(const char *msg) { - return _getpid (); + /* If the command failed, output an explanation. */ + fprintf(msg == NULL ? stdout : stderr, + "Usage: %s [-i y|n] [-l] [-t index|none] [-d] [-a] pngname.png\n" + " -i <y|n> Turns on/off interlace\n" + " -l Prints the table of color indexes\n" + " -t <index> Set the transparent color to the specified index (0-255 or \"none\")\n" + " -d Reports the dimensions and other characteristics of the image\n" + " -a Prints all alpha channels that are not 100%% opaque\n" + "\n" + "If you specify '-' as the input file, stdin/stdout will be used as input/output.\n", + argv0); + if (msg) + fprintf(stderr, "\nError: %s\n", msg); + exit(msg == NULL ? 0 : 1); } -#else -#include <unistd.h> /* for getpid(), unlink() */ -#endif + +static void err(const char *fmt, ...) +{ + va_list ap; + int e = errno; + + fprintf(stderr, "%s: error: ", argv0); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + if (e) + fprintf(stderr, ": %s", strerror(e)); + fputs("\n", stderr); + + exit(1); +} + int -main (int argc, char **argv) +main(int argc, char **argv) { FILE *in; FILE *out; - char outFn[20]; - int useStdinStdout = 0; + const char *infile; + char *tmpfile; + int i; + int use_stdin_stdout = 0; + + int interlace = -100; + int list_color_table = 0; + int trans_col = -1; + int report_details = 0; + int print_alpha = 0; /* Declare our image pointer */ gdImagePtr im = 0; - int i; - /* We'll clear 'no' once we know the user has made a - reasonable request. */ - int no = 1; /* We'll set 'write' once we know the user's request requires that the image be written back to disk. */ int write = 0; - /* C programs always get at least one argument; we want at - least one more (the image), more in practice. */ - if (argc < 2 || !strcmp (argv[1], "--help")) { - no = 1; - goto usage; - } + int got_a_flag = 0; - /* The last argument should be the image. Open the file. */ - if (strcmp ("-", argv[argc - 1]) == 0) { - /* - is synonymous with STDIN */ - useStdinStdout = 1; - in = stdin; - } else { - in = fopen (argv[argc - 1], "rb"); - } - if (!in) { - fprintf(stderr, "can't open file %s.\n", argv[argc - 1]); - exit (1); - } - /* Now load the image. */ -#ifdef HAVE_LIBPNG - im = gdImageCreateFromPng (in); -#else - fprintf(stderr, "No PNG library support.\n"); -#endif - fclose (in); - /* If the load failed, it must not be a PNG file. */ - if (!im) { - fprintf (stderr, - "Error: %s is not a valid PNG file.\n", argv[argc - 1]); - exit (1); - } /* Consider each argument in turn. */ - for (i = 1; (i < (argc - 1)); i++) { - /* -i turns on and off interlacing. */ - if (!strcmp (argv[i], "--help")) { - /* Every program should use this for help! :) */ - no = 1; - goto usage; - } else if (!strcmp (argv[i], "-i")) { - if (i == (argc - 2)) { - fprintf(stderr, "-i specified without y or n.\n"); - no = 1; - goto usage; - } - if (!strcmp (argv[i + 1], "y")) { - /* Set interlace. */ - gdImageInterlace (im, 1); - } else if (!strcmp (argv[i + 1], "n")) { - /* Clear interlace. */ - gdImageInterlace (im, 0); - } else { - fprintf(stderr, "Error: -i specified without y or n.\n"); - no = 1; - goto usage; - } - i++; - no = 0; + opterr = 0; + while ((i = getopt(argc, argv, "i:lt:da")) != -1) { + got_a_flag = 1; + switch (i) { + case 'i': + /* -i turns on and off interlacing. */ + if (strcmp(optarg, "y") == 0) + interlace = 1; + else if (strcmp(optarg, "n") == 0) + interlace = 0; + else + usage("-i specified without y or n"); write = 1; - } else if (!strcmp (argv[i], "-t")) { + break; + + case 'l': + /* List the colors in the color table. */ + list_color_table = 1; + break; + + case 't': /* Set transparent index (or none). */ - int index; - if (i == (argc - 2)) { - fprintf (stderr, - "Error: -t specified without a color table index.\n"); - no = 1; - goto usage; - } - if (!strcmp (argv[i + 1], "none")) { + if (strcmp(optarg, "none") == 0) { /* -1 means not transparent. */ - gdImageColorTransparent (im, -1); + trans_col = -1; } else { - /* OK, get an integer and set the index. */ - index = atoi (argv[i + 1]); - gdImageColorTransparent (im, index); + /* XXX: Should check for errors. */ + trans_col = atoi(optarg); + if (trans_col < 0 || trans_col > 255) + err("-t has to be in the range of 0 and 255 (inclusive)"); } - i++; write = 1; - no = 0; - } else if (!strcmp (argv[i], "-l")) { - /* List the colors in the color table. */ - int j; - if (!im->trueColor) { - /* Tabs used below. */ - printf ("Index Red Green Blue Alpha\n"); - for (j = 0; (j < gdImageColorsTotal (im)); j++) { - /* Use access macros to learn colors. */ - printf ("%d %d %d %d %d\n", - j, - gdImageRed (im, j), - gdImageGreen (im, j), - gdImageBlue (im, j), gdImageAlpha (im, j)); - } - } else { - printf ("Truecolor image, no palette entries to list.\n"); - } - no = 0; - } else if (!strcmp (argv[i], "-d")) { + break; + + case 'd': /* Output dimensions, etc. */ - int t; - printf ("Width: %d Height: %d Colors: %d\n", - gdImageSX (im), gdImageSY (im), gdImageColorsTotal (im)); - t = gdImageGetTransparent (im); - if (t != (-1)) { - printf ("First 100%% transparent index: %d\n", t); - } else { - /* -1 means the image is not transparent. */ - printf ("First 100%% transparent index: none\n"); - } - if (gdImageGetInterlaced (im)) { - printf ("Interlaced: yes\n"); - } else { - printf ("Interlaced: no\n"); - } - no = 0; - } else if (!strcmp (argv[i], "-a")) { + report_details = 1; + break; + + case 'a': /* Alpha channel info -- thanks to Wez Furlong */ - int maxx, maxy, x, y, alpha, pix, nalpha = 0; + print_alpha = 1; + break; + + case 'h': + usage(NULL); + break; + default: + case '?': + if (optind < argc && strcmp(argv[optind], "--help") == 0) + usage(NULL); + usage("unknown option"); + break; + } + } + + if (got_a_flag == 0) + usage("missing operation flag"); + + if (argc == optind) + usage("missing filename"); + else if (argc != optind + 1) + usage("can only specify one file"); + + infile = argv[optind]; + if (strcmp(infile, "-") == 0) { + /* - is synonymous with STDIN */ + use_stdin_stdout = 1; + in = stdin; + } else + in = fopen(infile, "rb"); + + if (!in) + err("can't open file %s", infile); + + /* Now load the image. */ + im = gdImageCreateFromPng(in); + fclose(in); + /* If the load failed, it must not be a PNG file. */ + if (!im) + err("%s is not a valid PNG file", infile); + + if (list_color_table) { + /* List the colors in the color table. */ + if (!im->trueColor) { + int j; + /* Tabs used below. */ + printf("Index Red Green Blue Alpha\n"); + for (j = 0; j < gdImageColorsTotal(im); ++j) { + /* Use access macros to learn colors. */ + printf("%d %d %d %d %d\n", j, + gdImageRed(im, j), + gdImageGreen(im, j), + gdImageBlue(im, j), + gdImageAlpha(im, j)); + } + } else + printf("Truecolor image, no palette entries to list.\n"); + } + + if (report_details) { + /* Output dimensions, etc. */ + int t; + printf("Width: %d Height: %d Colors: %d\n", + gdImageSX(im), + gdImageSY(im), + gdImageColorsTotal(im)); - maxx = gdImageSX (im); - maxy = gdImageSY (im); + /* -1 means the image is not transparent. */ + t = gdImageGetTransparent(im); + if (t != -1) + printf("First 100%% transparent index: %d\n", t); + else + printf("First 100%% transparent index: none\n"); - printf ("alpha channel information:\n"); + if (gdImageGetInterlaced(im)) + printf("Interlaced: yes\n"); + else + printf("Interlaced: no\n"); + } + + if (print_alpha) { + /* Alpha channel info -- thanks to Wez Furlong */ + int maxx, maxy, x, y, alpha, pix, nalpha = 0; - if (im->trueColor) { - for (y = 0; y < maxy; y++) { - for (x = 0; x < maxx; x++) { - pix = gdImageGetPixel (im, x, y); - alpha = gdTrueColorGetAlpha (pix); + maxx = gdImageSX(im); + maxy = gdImageSY(im); - if (alpha > gdAlphaOpaque) { - /* Use access macros to learn colors. */ - printf ("%d %d %d %d\n", - gdTrueColorGetRed (pix), - gdTrueColorGetGreen (pix), - gdTrueColorGetBlue (pix), alpha); - nalpha++; - } + printf("alpha channel information:\n"); + if (im->trueColor) { + for (y = 0; y < maxy; y++) { + for (x = 0; x < maxx; x++) { + pix = gdImageGetPixel(im, x, y); + alpha = gdTrueColorGetAlpha(pix); + + if (alpha > gdAlphaOpaque) { + /* Use access macros to learn colors. */ + printf("%d %d %d %d\n", + gdTrueColorGetRed(pix), + gdTrueColorGetGreen(pix), + gdTrueColorGetBlue(pix), + alpha); + nalpha++; } + } - } else - printf ("NOT a true color image\n"); - no = 0; - printf ("%d alpha channels\n", nalpha); + } + } else + printf("NOT a true color image\n"); - } else { - fprintf(stderr, "Unknown argument: %s\n", argv[i]); - break; - } + printf("%d alpha channels\n", nalpha); } -usage: - if (no) { - /* If the command failed, output an explanation. */ - fprintf (stderr, - "Usage: webpng [-i y|n ] [-l] [-t index|none ] [-d] pngname.png\n" - " -i [y|n] Turns on/off interlace\n" - " -l Prints the table of color indexes\n" - " -t [index] Set the transparent color to the specified index (0-255 or \"none\")\n" - " -d Reports the dimensions and other characteristics of the image.\n" - " -a Prints all alpha channels that are not 100%% opaque.\n" - "\n" - "If you specify '-' as the input file, stdin/stdout will be used input/output.\n"); + + /* If no modifications requested, break out. */ + if (write == 0) { + gdImageDestroy(im); + return 0; } - if (write) { - if (useStdinStdout) { - out = stdout; - } else { - /* Open a temporary file. */ - - /* "temp.tmp" is not good temporary filename. */ - sprintf (outFn, "webpng.tmp%d", getpid ()); - out = fopen (outFn, "wb"); - - if (!out) { - fprintf(stderr, "Unable to write to %s -- exiting\n", outFn); - exit (1); - } - } - /* Write the new PNG. */ -#ifdef HAVE_LIBPNG - gdImagePng (im, out); -#else - fprintf(stderr, "No PNG library support.\n"); -#endif - if (!useStdinStdout) { - fclose (out); - /* Erase the old PNG. */ - unlink (argv[argc - 1]); - /* Rename the new to the old. */ - if (rename (outFn, argv[argc - 1]) != 0) { - perror ("rename"); - exit (1); - } - } + if (interlace == 1) + gdImageInterlace(im, 1); + else if (interlace == 0) + gdImageInterlace(im, 0); + + if (trans_col != -100) + gdImageColorTransparent(im, trans_col); + + if (use_stdin_stdout) { + out = stdout; + } else { + /* Open a temporary file. */ + size_t filelen = strlen(infile); + size_t len = filelen + 8; + int outfd; + + tmpfile = malloc(len); + if (tmpfile == NULL) + err("could not create a tempfile"); + memcpy(tmpfile, infile, filelen); + strcpy(tmpfile + filelen, ".XXXXXX"); + + outfd = mkstemp(tmpfile); + if (outfd == -1) + err("could not open %s", tmpfile); + + out = fdopen(outfd, "wb"); + if (!out) + err("could not open %s", tmpfile); } - /* Delete the image from memory. */ - if (im) { - gdImageDestroy (im); + + /* Write the new PNG. */ + gdImagePng(im, out); + + if (!use_stdin_stdout) { + fclose(out); + /* Erase the old PNG. */ + unlink(infile); + /* Rename the new to the old. */ + if (rename(tmpfile, infile) != 0) + err("unable to rename %s to %s", infile, tmpfile); } + + /* Delete the image from memory. */ + gdImageDestroy(im); + /* All's well that ends well. */ return 0; } |