### Example Usage of libpng Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Provides examples of how to use the libpng library. The 'example.c' file is recommended as a starting point due to its extensive comments and comprehensive coverage of common use cases. Other examples can be found in 'pngtest.c' and the 'contrib' directory. ```C /* example.c */ /* pngtest.c */ ``` -------------------------------- ### Example Usage of libpng Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-1.2.29.txt Provides examples of how to use the libpng library for PNG file operations. The 'example.c' file is a heavily commented starting point for most users. ```C /* * example.c * Example of using libpng */ // Include necessary headers #include #include #include int main() { // Example code for reading or writing PNG files would go here. // This is a placeholder to indicate where example code would be. printf("libpng example placeholder\n"); return 0; } ``` -------------------------------- ### Build AGG Examples (Basic) Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/X11/readme.txt Builds the basic examples for the Anti-Grain Geometry (AGG) project, which do not require extra dependencies. This involves navigating to the examples directory and running the make clean and make commands. ```Shell cd (AGGDIRECTORY)/examples/X11 make clean make ``` -------------------------------- ### Build Individual AGG Example Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/BeOS/readme.txt Allows building specific examples from the Anti-Grain Geometry project one by one. Replace `aa_demo` with the desired example name. ```Shell make aa_demo ``` -------------------------------- ### GPL Interactive Program Notice Example Source: https://github.com/koreader/crengine/blob/master/android/res/raw/license.txt This example shows a short notice that an interactive program should display upon startup, informing users about its version, copyright, warranty status, and how to view redistribution conditions, as per the GNU General Public License. ```Text Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Build AGG Examples (Default) Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/BeOS/readme.txt Builds the default examples for the Anti-Grain Geometry project that do not require extra dependencies. This involves navigating to the examples directory and running `make clean` followed by `make`. ```Shell cd (AGGDIRECTORY)/examples/BeOS make clean make ``` -------------------------------- ### Build AGG Examples (Basic) Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_sdl/readme.txt Builds the basic examples for the Anti-Grain Geometry (AGG) project that do not require extra dependencies. This involves navigating to the examples directory and running make commands. ```Shell cd (AGGDIRECTORY)/examples/sdl make clean make ``` -------------------------------- ### CR3 Installation Rules (Unix) Source: https://github.com/koreader/crengine/blob/master/cr3wx/CMakeLists.txt This snippet details the installation process for the CR3 executable and its associated data files on Unix-like systems. It specifies runtime destinations for the executable and installs CSS, hyphenation patterns, and skins. ```cmake IF (UNIX) INSTALL( TARGETS cr3 RUNTIME DESTINATION bin ) INSTALL( DIRECTORY ../cr3qt/data DESTINATION share/cr3 FILES_MATCHING PATTERN "*.css" ) INSTALL( DIRECTORY ../cr3qt/data/hyph DESTINATION share/cr3 FILES_MATCHING PATTERN "*.pdb" ) INSTALL( DIRECTORY ../cr3qt/data/hyph DESTINATION share/cr3 FILES_MATCHING PATTERN "*.pattern" ) INSTALL( DIRECTORY ../cr3qt/data/skins DESTINATION share/cr3/skins ) ELSE() INSTALL( TARGETS cr3 RUNTIME DESTINATION . ) INSTALL( DIRECTORY ../cr3qt/data/ DESTINATION . FILES_MATCHING PATTERN "*.css" ) INSTALL( DIRECTORY ../cr3qt/data/hyph DESTINATION . FILES_MATCHING PATTERN "*.pdb" ) INSTALL( DIRECTORY ../cr3qt/data/hyph DESTINATION . FILES_MATCHING PATTERN "*.pattern" ) INSTALL( DIRECTORY ../cr3qt/data/skins DESTINATION . ) ENDIF(UNIX) ``` -------------------------------- ### Build All AGG Examples Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/BeOS/readme.txt Builds all available examples for the Anti-Grain Geometry project, including those with and without dependencies. This is accomplished by running `make all`. ```Shell make all ``` -------------------------------- ### Install Targets and Data for Unix Source: https://github.com/koreader/crengine/blob/master/cr3qt/CMakeLists.txt This section outlines the installation process for Unix-like systems. It installs man pages, the 'cr3' executable to the bin directory, and various data files including CSS, hyphenation patterns, textures, backgrounds, changelog, and desktop integration files into the share/cr3 directory. ```cmake INSTALL(FILES ${man_gz} DESTINATION "share/man/man1" PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) INSTALL( TARGETS cr3 RUNTIME DESTINATION bin ) INSTALL( DIRECTORY data/ DESTINATION share/cr3 FILES_MATCHING PATTERN "*.css" PATTERN "skins" EXCLUDE PATTERN "docs" EXCLUDE) INSTALL( DIRECTORY data/hyph DESTINATION share/cr3 FILES_MATCHING PATTERN "*.pdb" ) INSTALL( DIRECTORY data/hyph DESTINATION share/cr3 FILES_MATCHING PATTERN "*.pattern" ) #INSTALL( DIRECTORY data/skins DESTINATION share/cr3/skins ) INSTALL( DIRECTORY data/textures DESTINATION share/cr3 ) INSTALL( DIRECTORY data/backgrounds DESTINATION share/cr3 ) #INSTALL( FILES ${CR3_MAN_PAGES} DESTINATION share/doc/cr3 ) INSTALL( FILES ${CR3_CHANGELOG} DESTINATION share/doc/cr3 ) INSTALL( FILES ${QM_FILES} DESTINATION share/cr3/i18n ) INSTALL( FILES src/desktop/cr3.desktop DESTINATION share/applications ) INSTALL( FILES src/desktop/cr3.png DESTINATION share/pixmaps ) INSTALL( FILES src/desktop/cr3.xpm DESTINATION share/pixmaps ) ``` -------------------------------- ### Install Man Pages and Pkg-Config Files Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Installs man pages for libpng and configures pkg-config files (`.pc`) and the `libpng-config` script for Unix-like systems. ```cmake if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) # Install man pages if(NOT PNG_MAN_DIR) set(PNG_MAN_DIR "share/man") endif() install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3) install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5) # Install pkg-config files if(NOT WIN32 OR CYGWIN OR MINGW) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin) endif(NOT WIN32 OR CYGWIN OR MINGW) endif() ``` -------------------------------- ### Build Individual AGG Example Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_carbon/readme.txt This snippet shows how to build a specific example from the Anti-Grain Geometry project. Instead of building all examples, you can compile individual ones by invoking 'make' with the example's name. ```bash make aa_demo ``` ```bash make aa_test ``` -------------------------------- ### Build AGG Examples with GPC Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/X11/readme.txt Builds the AGG example that requires the GPC library. This is done by executing the 'make gpc' command within the examples directory. ```Shell cd (AGGDIRECTORY)/examples/X11 make gpc ``` -------------------------------- ### Install libpng Libraries and Export Files Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Installs the libpng targets (shared and static libraries) to their respective destinations. It also handles the creation and installation of import libraries for Cygwin/MinGW and symlinks for shared libraries on non-Windows systems. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) install(TARGETS ${PNG_LIB_TARGETS} ${PNG_EXPORT_RULE} RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(PNG_SHARED) # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin if(CYGWIN OR MINGW) get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE}) CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif(CYGWIN OR MINGW) if(NOT WIN32) get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE}) CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif(NOT WIN32) endif(PNG_SHARED) if(PNG_STATIC) if(NOT WIN32 OR CYGWIN OR MINGW) get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE}) CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif(NOT WIN32 OR CYGWIN OR MINGW) endif() endif() ``` -------------------------------- ### CREngine Window Skin Example Source: https://github.com/koreader/crengine/blob/master/cr3gui/data/cr3skin-format.txt Provides an example of a window skin definition for CREngine, illustrating how to set properties for the window frame, title, and client area, including text and background styles. ```XML <size minvalue="0,48" maxvalue="0,0"/> <text color="#000000" face="Arial Narrow, Arial, DejaVu Sans" size="30" bold="true" italic="false" valign="center" halign="center"/> <background image="cr3_menu_title.png" color="#FFFFFF"/> <border widths="4,4,4,4"/> <!--icon image="filename" valign="" halign=""--> ``` -------------------------------- ### Build AGG Examples (macOS Carbon) Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_carbon/readme.txt This snippet demonstrates how to build the Anti-Grain Geometry examples on macOS using the Carbon framework. It involves navigating to the examples directory and executing 'make clean' followed by 'make'. ```bash cd (AGGDIRECTORY)/examples/macosx_carbon make clean make ``` -------------------------------- ### Build All AGG Examples Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/X11/readme.txt Builds all available examples for the Anti-Grain Geometry (AGG) project, including those with and without dependencies. This is accomplished with a single 'make all' command. ```Shell cd (AGGDIRECTORY)/examples/X11 make all ``` -------------------------------- ### Build AGG Examples with Freetype Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/BeOS/readme.txt Builds AGG examples that require the Freetype Library. This is achieved by running `make freetype` in the examples directory. ```Shell make freetype ``` -------------------------------- ### Install libpng Configuration Executables Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Installs the `libpng-config` executable for Unix-like systems (non-Windows) to the 'bin' directory. ```cmake if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL ) if(NOT WIN32 OR CYGWIN OR MINGW) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin) endif(NOT WIN32 OR CYGWIN OR MINGW) endif() ``` -------------------------------- ### Build AGG Examples with Freetype Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/X11/readme.txt Builds AGG examples that require the Freetype Library. This is achieved by running a specific make command after navigating to the examples directory. ```Shell cd (AGGDIRECTORY)/examples/X11 make freetype ``` -------------------------------- ### Build All AGG Examples Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_sdl/readme.txt Builds all available examples for the Anti-Grain Geometry (AGG) project, including those with and without dependencies. ```Shell make all ``` -------------------------------- ### Build Individual AGG Example Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/X11/readme.txt Allows for building individual AGG examples one by one by specifying the example name directly with the make command. This provides flexibility in building specific functionalities. ```Shell cd (AGGDIRECTORY)/examples/X11 make aa_demo ``` -------------------------------- ### Inflate Lookup Table Example Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/algorithm.txt Illustrates a scaled-down example of the inflate lookup table structure, showing how symbols are mapped to their decoded values and the number of bits to consume. It demonstrates the concept of table entries pointing to other tables for longer symbols. ```Text Symbols: A: 0 B: 10 C: 1100 D: 11010 E: 11011 F: 11100 G: 11101 H: 11110 I: 111110 J: 111111 First table (3 bits): 000: A,1 001: A,1 010: A,1 011: A,1 100: B,2 101: B,2 110: -> table X (gobble 3 bits) 111: -> table Y (gobble 3 bits) Table X (2 bits): 00: C,1 01: C,1 10: D,2 11: E,2 Table Y (3 bits): 000: F,2 001: F,2 010: G,2 011: G,2 100: H,2 101: H,2 110: I,3 111: J,3 ``` -------------------------------- ### Configure Unix-like Installation Paths Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Sets installation directories for libraries, headers, and executables on non-Windows platforms (UNIX, CYGWIN, MINGW). It also defines linker flags and configures PC-in files for pkg-config. ```cmake if(NOT WIN32 OR CYGWIN OR MINGW) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}) set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) set(includedir ${CMAKE_INSTALL_PREFIX}/include) set(LIBS "-lz -lm") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY) CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY) CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config) endif(NOT WIN32 OR CYGWIN OR MINGW) ``` -------------------------------- ### Build and Install PocketBook Executable Source: https://github.com/koreader/crengine/blob/master/cr3gui/CMakeLists.txt Builds the 'cr3-pb.app' executable for the PocketBook GUI, linking it with 'crengine', 'tinydict', and other necessary libraries. It includes an optional step to strip the binary and then installs it as a runtime target. ```cmake elseif (${GUI} STREQUAL CRGUI_PB) ADD_EXECUTABLE(cr3-pb.app ${CR3_SOURCES}) TARGET_LINK_LIBRARIES(cr3-pb.app crengine tinydict ${EXTRA_LIBS} ${STD_LIBS}) if (DEFINED CMAKE_STRIP) MESSAGE("Strip command: ${CMAKE_STRIP} ${CMAKE_BINARY_DIR}/cr3gui/cr3-pb.app" ) EXECUTE_PROCESS( COMMAND ${CMAKE_STRIP} ${CMAKE_BINARY_DIR}/cr3gui/cr3-pb.app ) endif (DEFINED CMAKE_STRIP) INSTALL( TARGETS cr3-pb.app RUNTIME DESTINATION ${CR3_BIN_DESTINATION} ) ``` -------------------------------- ### Install Man Pages and Pkgconfig Files (CMake) Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/scripts/CMakeLists.txt This CMake snippet focuses on installing man pages and pkgconfig files for the project. It specifies the source files and their destination directories, ensuring proper integration with system package management. ```cmake install(FILES libpng.3 libpngpf.3 DESTINATION man/man3) install(FILES png.5 DESTINATION man/man5) install(FILES ${PNG_BINARY_DIR}/libpng.pc DESTINATION lib/pkgconfig) install(FILES ${PNG_BINARY_DIR}/libpng-config DESTINATION bin) install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION lib/pkgconfig) install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin) ``` -------------------------------- ### CR3Skin XML Structure Example Source: https://github.com/koreader/crengine/blob/master/cr3gui/data/cr3skin-format.txt Demonstrates the basic structure of a cr3skin.xml file, including the root tag and examples of window, menu, and scroll elements with their attributes like id, base, and specific properties. ```XML ... ... ... ... ... ... ... ... ... ``` -------------------------------- ### Build AGG Examples with GPC Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/BeOS/readme.txt Builds the AGG example that requires the GPC library. This is done by executing `make gpc`. ```Shell make gpc ``` -------------------------------- ### Build and Install Default Executable Source: https://github.com/koreader/crengine/blob/master/cr3gui/CMakeLists.txt Builds the default 'cr3' executable, linking it with 'crengine', 'tinydict', and other necessary libraries. It includes an optional step to strip the binary and then installs it as a runtime target. ```cmake else() ADD_EXECUTABLE(cr3 ${CR3_SOURCES}) TARGET_LINK_LIBRARIES(cr3 crengine tinydict ${EXTRA_LIBS} ${STD_LIBS}) if (DEFINED CMAKE_STRIP) MESSAGE("Strip command: ${CMAKE_STRIP} ${CMAKE_BINARY_DIR}/cr3gui/cr3" ) EXECUTE_PROCESS( COMMAND ${CMAKE_STRIP} ${CMAKE_BINARY_DIR}/cr3gui/cr3 ) endif (DEFINED CMAKE_STRIP) INSTALL( TARGETS cr3 RUNTIME DESTINATION ${CR3_BIN_DESTINATION} ) ``` -------------------------------- ### Writing a PNG Row Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Demonstrates how to write a single row of PNG data using libpng. It shows the basic setup for a row pointer. ```C png_bytep row_pointer = row; png_write_row(png_ptr, row_pointer); ``` -------------------------------- ### Building zlib in Developer Studio Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/projects/visualc6/README.txt Provides step-by-step instructions for building the zlib library within Microsoft Developer Studio, including opening the workspace, setting the active configuration, cleaning, and building the project. ```text 1) On the main menu, select "File | Open Workspace". Open "zlib.dsw". 2) Select "Build | Set Active Configuration". Choose the configuration you wish to build. 3) Select "Build | Clean". 4) Select "Build | Build ... (F7)". Ignore warning messages about not being able to find certain include files (e.g. alloc.h). 5) If you built one of the sample programs (example or minigzip), select "Build | Execute ... (Ctrl+F5)". ``` -------------------------------- ### Get WinFNT Header Source: https://github.com/koreader/crengine/blob/master/thirdparty/freetype/docs/reference/ft2-base_interface.html Used with the winfonts driver to examine the 'charset' field of the FT_WinFNT_HeaderRec structure to determine the font's encoding. For example, FT_WIN_ID_CP1251 indicates Windows code page 1251. ```c FT_Get_WinFNT_Header( face, &header ); // header.charset can be FT_WIN_ID_CP1251 (204) for Russian ``` -------------------------------- ### Get Interlace Pass Pixel Spacing Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Macros to retrieve the starting column and row, and the step (spacing) between pixels for a given interlacing pass. These are used to map pixels from sub-images to their correct positions in the output image. ```c png_uint_32 x = PNG_PASS_START_COL(pass); png_uint_32 y = PNG_PASS_START_ROW(pass); png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass); ``` -------------------------------- ### C: Include necessary header files for zlib and file I/O Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html Includes standard C header files for input/output operations (stdio.h), string manipulation (string.h), assertions (assert.h), and the zlib library (zlib.h). These headers provide definitions for functions like fopen, fread, fwrite, fclose, strcmp, assert, deflateInit, deflate, deflateEnd, inflateInit, inflate, and inflateEnd. ```C #include #include #include #include "zlib.h" ``` -------------------------------- ### Libpng I/O Initialization for Writing Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Shows how to initialize the I/O functions for writing a PNG file using libpng. It highlights the requirement to open the file in binary mode when using the default fwrite() function. ```C png_init_io(png_ptr, fp); ``` -------------------------------- ### Build AGG Examples with GPC Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_sdl/readme.txt Builds AGG examples that require the GPC library. This command enables the compilation of the gpc_test example. ```Shell make gpc ``` -------------------------------- ### C: Initialize zlib compression state Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html Initializes the zlib state for compression using deflateInit(). This function must be called before the first use of deflate(). The zalloc, zfree, and opaque fields in the z_stream structure should be initialized, typically to Z_NULL to use default memory allocation routines. ```C int ret, flush; unsigned have; z_stream strm; char in[CHUNK]; char out[CHUNK]; // Initialize deflate state strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, level); if (ret == Z_STREAM_ERROR) // Handle error: invalid compression level if (ret == Z_DATA_ERROR) // Handle error: data error in compression if (ret == Z_MEM_ERROR) // Handle error: memory allocation failed if (ret != Z_OK) // Handle other initialization errors ``` -------------------------------- ### Libpng Input I/O Setup Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-1.2.29.txt Illustrates how to initialize libpng's input I/O using the standard C fread function. It requires a FILE pointer opened in binary mode. The documentation also notes that this function can be omitted if custom I/O methods are used. ```C png_init_io(png_ptr, fp); ``` -------------------------------- ### Build Individual AGG Example Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_sdl/readme.txt Builds a specific example for the Anti-Grain Geometry (AGG) project by its name. This allows for targeted compilation of individual examples. ```Shell make aa_demo ``` ```Shell make aa_test ``` -------------------------------- ### Initialize libpng I/O Functions Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-1.2.29.txt Sets up the input/output functions for libpng, typically associating a FILE pointer for writing. ```c png_init_io(png_ptr, fp); ``` -------------------------------- ### Build AGG Examples with Freetype Source: https://github.com/koreader/crengine/blob/master/thirdparty/agg/examples/macosx_sdl/readme.txt Builds AGG examples that require the Freetype Library. This command specifically enables the compilation of examples like freetype_test, trans_curve1_ft, and trans_curve2_ft. ```Shell make freetype ``` -------------------------------- ### Initialize deflate state Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html Initializes the deflate state structure with allocation functions and compression level. It checks for successful allocation and valid arguments, ensuring compatibility between the zlib header and the linked library. ```c /* allocate deflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, level); if (ret != Z_OK) return ret; ``` -------------------------------- ### C: Allocate and Initialize Inflate State Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html This C code snippet shows the allocation and initialization of the inflate state. It sets zalloc, zfree, and opaque to Z_NULL, and initializes avail_in and next_in to zero and Z_NULL respectively, indicating no initial input data. The inflateInit function is called to prepare the state for decompression. ```c /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit(&strm); if (ret != Z_OK) return ret; ``` -------------------------------- ### Initialize PNG Input/Output Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Configures the input I/O for libpng to read from a specified file pointer (`fp`). This function assumes the file has been opened in binary mode. ```c png_init_io(png_ptr, fp); ``` -------------------------------- ### Install PNG Libraries and Headers (CMake) Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/scripts/CMakeLists.txt This snippet details the CMake commands for installing PNG libraries and header files. It includes conditional installation of static PNG libraries and specifies destinations for header files and man pages. ```cmake install_targets(/lib ${PNG_LIB_NAME}) if(PNG_STATIC) install_targets(/lib ${PNG_LIB_NAME_STATIC}) endif(PNG_STATIC) install(FILES png.h pngconf.h DESTINATION include) install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME}) ``` -------------------------------- ### Handling Deflate Output and File Writing Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html Calculates the amount of output produced by deflate, writes it to a destination file, and handles potential file I/O errors by cleaning up the compression stream. ```C have = CHUNK - strm.avail_out; if (fwrite(out, 1, have, dest) != have || ferror(dest)) { (void)deflateEnd(&strm); return Z_ERRNO; } ``` -------------------------------- ### Set Default Install Library Directory Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Sets the default installation directory for libraries to 'lib' if it has not been defined. ```cmake # libpng is a library so default to 'lib' if(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR lib) endif(NOT DEFINED CMAKE_INSTALL_LIBDIR) ``` -------------------------------- ### Install Targets and Data for macOS Source: https://github.com/koreader/crengine/blob/master/cr3qt/CMakeLists.txt This section defines the installation rules for macOS. It specifies the runtime destination for the 'cr3' executable, installs CSS files, hyphenation patterns, textures, and backgrounds into the application's resource directory, and places internationalization files and menu nibs. ```cmake INSTALL( TARGETS cr3 RUNTIME DESTINATION Contents/MacOS ) INSTALL( DIRECTORY data/ DESTINATION Contents/Resources FILES_MATCHING PATTERN "*.css" PATTERN "skins" EXCLUDE PATTERN "docs" EXCLUDE) INSTALL( DIRECTORY data/hyph DESTINATION Contents/Resources FILES_MATCHING PATTERN "*.pdb" ) INSTALL( DIRECTORY data/hyph DESTINATION Contents/Resources FILES_MATCHING PATTERN "*.pattern" ) #INSTALL( DIRECTORY data/skins DESTINATION share/cr3/skins ) INSTALL( DIRECTORY data/textures DESTINATION Contents/Resources ) INSTALL( DIRECTORY data/backgrounds DESTINATION Contents/Resources ) #INSTALL( FILES ${CR3_MAN_PAGES} DESTINATION share/doc/cr3 ) INSTALL( FILES ${QM_FILES} DESTINATION Contents/Resources/i18n ) INSTALL( DIRECTORY ${QT_INCLUDE_DIR}/../src/gui/mac/qt_menu.nib DESTINATION Contents/Resources ) INSTALL( FILES src/desktop/Info.plist DESTINATION Contents ) INSTALL( FILES src/desktop/PkgInfo DESTINATION Contents ) #INSTALL( FILES src/desktop/cr3.png DESTINATION share/pixmaps ) #INSTALL( FILES src/desktop/cr3.xpm DESTINATION share/pixmaps ) ``` -------------------------------- ### Install libpng Headers Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Installs the public libpng header files to the 'include' directory and a subdirectory named after the library (e.g., 'include/libpng'). ```cmake if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) install(FILES ${libpng_public_hdrs} DESTINATION include) install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME}) endif() ``` -------------------------------- ### C: Clean Up and Return from Deflate Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html This C code snippet illustrates the final steps after compression, including deallocating the deflate state using deflateEnd to prevent memory leaks and returning Z_OK to indicate success. ```c (void)deflateEnd(&strm); return Z_OK; } ``` -------------------------------- ### Install Targets and Data for Other Platforms Source: https://github.com/koreader/crengine/blob/master/cr3qt/CMakeLists.txt This section provides generic installation rules for platforms not covered by the macOS or Unix specific blocks. It installs the 'cr3' executable to the root destination, along with CSS files, hyphenation patterns, textures, backgrounds, and internationalization files directly into the root directory or subdirectories. ```cmake INSTALL( TARGETS cr3 RUNTIME DESTINATION . ) INSTALL( DIRECTORY data/ DESTINATION . FILES_MATCHING PATTERN "*.css" ) INSTALL( DIRECTORY data/hyph DESTINATION . FILES_MATCHING PATTERN "*.pdb" ) INSTALL( DIRECTORY data/hyph DESTINATION . FILES_MATCHING PATTERN "*.pattern" ) #INSTALL( DIRECTORY data/skins DESTINATION . ) INSTALL( FILES ${QM_FILES} DESTINATION i18n ) INSTALL( DIRECTORY data/textures DESTINATION . ) INSTALL( DIRECTORY data/backgrounds DESTINATION . ) ``` -------------------------------- ### Main routine for zpipe compression/decompression Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html The main function for the zpipe utility, this C code handles command-line arguments to perform either compression or decompression. If no arguments are given, it compresses data from stdin to stdout. If '-d' is provided, it decompresses. Otherwise, it displays a usage message. ```C /* compress or decompress from stdin to stdout */ int main(int argc, char **argv) { int ret; /* do compression if no arguments */ if (argc == 1) { ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); if (ret != Z_OK) zerr(ret); return ret; } /* do decompression if -d specified */ else if (argc == 2 && strcmp(argv[1], "-d") == 0) { ret = inf(stdin, stdout); if (ret != Z_OK) zerr(ret); return ret; } /* otherwise, report usage */ else { fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr); return 1; } } ``` -------------------------------- ### Initialize PNG Read Structure Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Demonstrates the basic initialization of a PNG read structure using libpng functions. It includes error checking for the structure allocation. ```c png_structp png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, user_error_fn, user_warning_fn); if (!png_ptr) return (ERROR); png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); return (ERROR); } ``` -------------------------------- ### Libpng Initialization Functions Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Preferred methods for creating and initializing libpng structures, offering better isolation, version checking, and custom error handling compared to older functions. ```c png_structp png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_error_fn png_error_fn, png_error_fn png_warning_fn); png_structp png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_error_fn png_error_fn, png_error_fn png_warning_fn); png_infop png_create_info_struct(png_structp png_ptr); ``` -------------------------------- ### Install CMake Export File Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Installs a CMake export file (`libpng.cmake`) which allows other CMake projects to easily import the libpng targets. ```cmake if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL ) install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake) endif() ``` -------------------------------- ### Configure PocketBook GUI Backend Source: https://github.com/koreader/crengine/blob/master/CMakeLists.txt This section handles the configuration for the PocketBook GUI (CRGUI_PB). It sets specific preprocessor definitions for PocketBook compatibility, including flags for lbook, CR_POCKETBOOK, and inversion for selection marks. It then adds the crengine and cr3gui subdirectories and searches for the inkview.h header file, including its directory if found. ```cmake message("Will make CR3GUI for PocketBook") ADD_DEFINITIONS( -DLBOOK=1 -DCR_POCKETBOOK=1 ${CRGUI_DEFS} -DCR_USE_INVERT_FOR_SELECTION_MARKS=1 -DENABLE_UPDATE_MODE_SETTING=1) ADD_DEFINITIONS( -DCR_INTERNAL_PAGE_ORIENTATION=0 ) ADD_SUBDIRECTORY(crengine) ADD_SUBDIRECTORY(cr3gui) FIND_PATH (INKVIEW_INCLUDE_DIR inkview.h) IF (INKVIEW_DIR) include_directories(${INKVIEW_DIR}) ELSE (INKVIEW_DIR) message("inkview.h not found") ENDIF (INKVIEW_DIR) ``` -------------------------------- ### Initialize PNG Write Structure Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Sets up the necessary structures for writing PNG files. This involves opening a file, creating write structures (`png_create_write_struct`), and info structures (`png_create_info_struct`). Error handling is also configured using `setjmp`. ```c FILE *fp = fopen(file_name, "wb"); if (!fp) return (ERROR); png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, user_error_fn, user_warning_fn); if (!png_ptr) return (ERROR); png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); return (ERROR); } if (setjmp(png_jmpbuf(png_ptr))) { ``` -------------------------------- ### Install Localization Files (Win32) Source: https://github.com/koreader/crengine/blob/master/cr3gui/CMakeLists.txt Installs compiled message catalog files (.mo) for localization on the Win32 GUI platform. These files are typically placed in a specific directory for internationalization support. ```cmake INSTALL( DIRECTORY data/hyph/ DESTINATION crengine/hyph FILES_MATCHING PATTERN "*.pdb" ) INSTALL( DIRECTORY data/hyph/ DESTINATION crengine/hyph FILES_MATCHING PATTERN "*.pattern" ) INSTALL( DIRECTORY data/devices/${DEVICE_NAME}/skins/default/ DESTINATION crengine/skin ) INSTALL( DIRECTORY data/devices/${DEVICE_NAME}/keymaps/ DESTINATION crengine ) INSTALL( DIRECTORY data/manual/ DESTINATION crengine/manual ) INSTALL( DIRECTORY ${CMAKE_BINARY_DIR}/cr3gui/po/ DESTINATION cr3/i18n FILES_MATCHING PATTERN "*.mo" ) ``` -------------------------------- ### Build libpng on BeOS Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/projects/beos/x86-static.txt This section outlines the steps to build the libpng library on BeOS. It mentions potential warnings during the compilation of pnggccrd.c and provides instructions for installing the compiled library and header files. ```Shell 1) build Note: As of version 1.0.10, you'll get a fair number of warnings when you compile pnggccrd.c. As far as I know, these are harmless, but it would be better if someone fixed them. 2) copy and png.h, pngconf.h somewhere; /boot/home/config/include (which you'll have to make) is a good choice 3) copy libpng.a to /boot/home/config/lib 4) build your libpng.a applications (remember to include libz.a as well when you link) ``` -------------------------------- ### CREngine Menu Skin Example Source: https://github.com/koreader/crengine/blob/master/cr3gui/data/cr3skin-format.txt Demonstrates the skinning of a menu in CREngine, including attributes for item counts and shortcut visibility, and defining styles for menu items, selected items, and shortcuts. ```XML <size minvalue="0,40" maxvalue="0,40"/> <text color="#FFFFFF" face="Arial Narrow, Arial, DejaVu Sans" size="38" bold="true" italic="false" valign="center" halign="center"/> <background color="#555555"/> <border widths="4,4,4,4"/> <!--icon image="filename" valign="" halign=""--> ``` -------------------------------- ### Build Static PNG Library Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/CMakeLists.txt Configures and builds a static library for PNG, linking it with zlib and math libraries. Includes Windows-specific prefix handling. ```cmake set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static) add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources}) list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC}) if(MSVC) # msvc does not append 'lib' - do it here to have consistent name set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib") endif() target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY}) ``` -------------------------------- ### Get PNG oFFs Chunk Offset Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Retrieves the offset data from the oFFs chunk of a PNG file. It provides functions to get the x and y offsets in microns or inches. Returns 0 if the data is not present or invalid. ```c x_offset = png_get_x_offset_microns(png_ptr, info_ptr); y_offset = png_get_y_offset_microns(png_ptr, info_ptr); x_offset = png_get_x_offset_inches(png_ptr, info_ptr); y_offset = png_get_y_offset_inches(png_ptr, info_ptr); ``` -------------------------------- ### C: Process Deflate Output Buffer Source: https://github.com/koreader/crengine/blob/master/thirdparty/zlib/examples/zlib_how.html This C code snippet demonstrates how to check if the deflate() function has more output by examining the avail_out buffer. It handles the case where the output buffer is exactly filled, requiring a subsequent call to determine completion. ```c while (strm.avail_out == 0); assert(strm.avail_in == 0); /* all input will be used */ ``` -------------------------------- ### Initialize Progressive PNG Reader Source: https://github.com/koreader/crengine/blob/master/thirdparty/libpng/libpng-manual.txt Initializes the libpng library for progressive PNG reading. This involves creating the PNG read structure and info structure, setting up error handling with setjmp, and registering callback functions for progressive reading events. ```c int initialize_png_reader() { png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, user_error_fn, user_warning_fn); if (!png_ptr) return (ERROR); info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); return (ERROR); } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return (ERROR); } png_set_progressive_read_fn(png_ptr, (void *)user_ptr, info_callback, row_callback, end_callback); return 0; } ``` -------------------------------- ### FT_Incremental_FuncsRec Structure Definition Source: https://github.com/koreader/crengine/blob/master/thirdparty/freetype/docs/reference/ft2-incremental.html Defines a table of functions for accessing font data incrementally. It includes callbacks for getting and freeing glyph data, and optionally for getting glyph metrics. This structure is used within the FT_Incremental_InterfaceRec. ```C typedef struct FT_Incremental_FuncsRec_ { FT_Incremental_GetGlyphDataFunc get_glyph_data; FT_Incremental_FreeGlyphDataFunc free_glyph_data; FT_Incremental_GetGlyphMetricsFunc get_glyph_metrics; } FT_Incremental_FuncsRec; ```