### Build Example Executable (CMake) Source: https://github.com/minnyres/cximage/blob/main/zlib/CMakeLists.txt This CMake code defines an executable target named 'example' using the 'example.c' source file. It then links this executable against the 'zlib' library. Finally, it registers 'example' as a test case using the `add_test` command. This setup allows for building and testing a basic application that utilizes the zlib library. ```cmake add_executable(example example.c) target_link_libraries(example zlib) add_test(example example) ``` -------------------------------- ### Quantization Table File Format Example (cjpeg) Source: https://github.com/minnyres/cximage/blob/main/jpeg/wizard.txt This snippet illustrates the expected format for a custom quantization table file used with cjpeg's -qtables switch. The file should contain decimal values for 64 elements per table, supporting comments starting with '#' and arbitrary whitespace. It shows examples for luminance (table 0) and chrominance (table 1) tables. ```text # Quantization tables given in JPEG spec, section K.1 # This is table 0 (the luminance table): 16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56 14 17 22 29 51 87 80 62 18 22 37 56 68 109 103 77 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99 # This is table 1 (the chrominance table): 17 18 24 47 99 99 99 99 18 21 26 66 99 99 99 99 24 26 56 99 99 99 99 99 47 66 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 ``` -------------------------------- ### Install Pkgconfig Files (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt This section details the installation of pkgconfig files (`.pc`) for the PNG library. It configures a template file, generates the pkgconfig file, and uses the `_png_generate_symlink_code` macro to install it. ```cmake if(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR lib) endif(NOT DEFINED CMAKE_INSTALL_LIBDIR) 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) _png_generate_symlink_code(PNG_PC_INSTALL_CODE ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc) install(CODE ${PNG_PC_INSTALL_CODE}) ``` -------------------------------- ### Install zlib Artifacts (CMake) Source: https://github.com/minnyres/cximage/blob/main/zlib/CMakeLists.txt This CMake section defines the installation rules for the 'zlib' library and its associated files. It specifies the installation destinations for the runtime binaries, archives, and libraries. Additionally, it handles the installation of public header files to the 'include' directory and the 'zlib.3' man page to 'share/man/man3', contingent on specific `SKIP_INSTALL_*` variables not being set. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) install(TARGETS zlib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) endif() if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include) endif() if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES zlib.3 DESTINATION share/man/man3) endif() ``` -------------------------------- ### Install libpng Man Pages and pkg-config Files (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt Installs man pages (libpng.3, libpngpf.3, png.5) and pkg-config files (.pc files) for libpng. Configuration files and executables are also installed into 'bin' and 'pkgconfig' directories respectively. Dependencies include SKIP_INSTALL_FILES and SKIP_INSTALL_ALL. ```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 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() ``` -------------------------------- ### Install libpng Configuration Executables (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt Installs the libpng-config and PNGLIB_NAME-config executables, which provide configuration information for pkg-config. These are installed into the 'bin' directory. Dependencies include SKIP_INSTALL_EXECUTABLES and SKIP_INSTALL_ALL. ```cmake if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL ) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin) ``` -------------------------------- ### Unix Basic Installation Source: https://github.com/minnyres/cximage/blob/main/jpeg/install.txt Standard commands for building and installing the IJG software on a Unix-like system. Assumes the presence of a 'configure' script. It's recommended to preview installation commands with 'make -n install'. ```shell ./configure make make test make install ``` -------------------------------- ### CXImage Sample Access Example (C) Source: https://github.com/minnyres/cximage/blob/main/jpeg/structure.txt Provides an example of how to access a specific sample value within the component-wise image data structure using indices for color component, row, and column. ```c GETJSAMPLE(image[colorcomponent][row][col]) ``` -------------------------------- ### Build 64-bit Example and minigzip (CMake) Source: https://github.com/minnyres/cximage/blob/main/zlib/CMakeLists.txt This section conditionally defines 64-bit versions of the 'example' and 'minigzip' executables if the `HAVE_OFF64_T` flag is defined. It compiles the respective C source files and links them against 'zlib'. The `set_target_properties` command is used to define `_FILE_OFFSET_BITS=64` for these executables, enabling support for large file offsets. They are also registered as tests. ```cmake if(HAVE_OFF64_T) add_executable(example64 example.c) target_link_libraries(example64 zlib) set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") add_test(example64 example64) add_executable(minigzip64 minigzip.c) target_link_libraries(minigzip64 zlib) set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") endif() ``` -------------------------------- ### Start JPEG Decompression (C) Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt This code shows how to initiate the JPEG decompression process after setting the desired decompression parameters. The `jpeg_start_decompress` function prepares the library for returning decompressed data and makes final output image dimensions and colormaps available. ```c jpeg_start_decompress(&cinfo); ``` -------------------------------- ### Install Config Script (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt This CMake code configures and installs the `libpng-config` script. It uses a template file and the `_png_generate_symlink_code` macro to ensure the script is correctly placed and accessible. ```cmake configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY) _png_generate_symlink_code(PNG_CONFIG_INSTALL_CODE ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config ${CMAKE_CURRENT_BINARY_DIR}/libpng-config) install(CODE ${PNG_CONFIG_INSTALL_CODE}) ``` -------------------------------- ### Install Shared libpng Library (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt Installs the shared libpng library, its import library, and generates symlinks for compatibility. This includes handling runtime, library, and archive destinations, with specific logic for Cygwin and non-Windows platforms. Dependencies include PNG_SHARED and related CMake variables. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) if(PNG_SHARED) install(TARGETS ${PNG_LIB_NAME} ${PNG_EXPORT_RULE} RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin if(CYGWIN) _png_generate_symlink_code(PNG_SHARED_IMPLIB_INSTALL_CODE ${PNGLIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}) install(CODE ${PNG_SHARED_IMPLIB_INSTALL_CODE}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() if(NOT WIN32) IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY) _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}) install(CODE ${PNG_SHARED_INSTALL_CODE}) install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) ELSE(CMAKE_LIBRARY_OUTPUT_DIRECTORY) _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE ${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX} libpng${CMAKE_SHARED_LIBRARY_SUFFIX}) install(CODE ${PNG_SHARED_INSTALL_CODE}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) ENDIF(CMAKE_LIBRARY_OUTPUT_DIRECTORY) endif() endif() endif() ``` -------------------------------- ### Unix Preview Installation Source: https://github.com/minnyres/cximage/blob/main/jpeg/install.txt Command to preview the installation steps without actually performing them on a Unix-like system. This helps verify the file locations before committing to the installation. ```shell make -n install ``` -------------------------------- ### Initialize JPEG Compression Process Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Starts the JPEG compression cycle by initializing internal state, allocating storage, and emitting the JPEG header. The 'TRUE' parameter ensures a complete JPEG interchange datastream. This function should be called after setting all necessary source image information and parameters. ```c jpeg_start_compress(&cinfo, TRUE); ``` -------------------------------- ### Install libpng Headers (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt Installs the public libpng header files into the 'include' directory and a sub-directory named after the library. This ensures proper header inclusion for projects using libpng. Dependencies include SKIP_INSTALL_HEADERS and SKIP_INSTALL_ALL. ```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}) ``` -------------------------------- ### Install Static libpng Library (CMake) Source: https://github.com/minnyres/cximage/blob/main/png/CMakeLists.txt Installs the static libpng library and generates symlinks for compatibility on non-Windows platforms (excluding Cygwin). This includes handling library and archive destinations. Dependencies include PNG_STATIC and related CMake variables. ```cmake if(PNG_STATIC) install(TARGETS ${PNG_LIB_NAME_STATIC} ${PNG_EXPORT_RULE} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(NOT WIN32 OR CYGWIN) IF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}) install(CODE ${PNG_STATIC_INSTALL_CODE}) install(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) ELSE(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE ${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} libpng${CMAKE_STATIC_LIBRARY_SUFFIX}) install(CODE ${PNG_STATIC_INSTALL_CODE}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION ${CMAKE_INSTALL_LIBDIR}) ENDIF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) endif() endif() ``` -------------------------------- ### JPEG Compression Outline (C) Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Provides a high-level overview of the steps involved in performing JPEG compression using the IJG library. This includes initialization, setting parameters, and writing scanlines. ```c /* Allocate and initialize a JPEG compression object */ jpeg_compress_struct cinfo; jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); /* Specify the destination for the compressed data (eg, a file) */ FILE* outfile = fopen("output.jpg", "wb"); jpeg_stdio_dest(&cinfo, outfile); /* Set parameters for compression, including image size & colorspace */ cinfo.image_width = width; /* Image width and height */ cinfo.image_height = height; cinfo.input_components = 3; /* Number of color components per pixel */ cinfo.in_color_space = JCS_RGB; /* Colorspace of input image */ jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, 85, TRUE); /* Example quality setting */ /* Start the compression process */ jpeg_start_compress(&cinfo); /* Write scanlines to the compressed file */ JSAMPROW row_pointer; while (cinfo.next_scanline < cinfo.image_height) { /* Assume row_pointer is filled with image data for the current scanline */ jpeg_write_scanlines(&cinfo, &row_pointer, 1); } /* Finish compression and release memory */ jpeg_finish_compress(&cinfo); fclose(outfile); jpeg_destroy_compress(&cinfo); ``` -------------------------------- ### Configure Script with Options (Unix) Source: https://github.com/minnyres/cximage/blob/main/jpeg/install.txt Demonstrates how to run the 'configure' script with various options to customize the build process for the IJG software. Options include disabling/enabling shared libraries, specifying the C compiler, and setting compiler flags. ```shell ./configure --disable-shared ``` ```shell ./configure --disable-static ``` ```shell ./configure CC='cc' ``` ```shell ./configure CC='cc -Aa' ``` ```shell ./configure CFLAGS='-O2' ``` -------------------------------- ### libpng Info Callback Function Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Callback function executed by libpng when enough data has been read to parse the PNG header. It's used for initial setup, setting transformations, and preparing for row data processing. It requires calling `png_start_read_image()` or `png_read_update_info()`. ```c void info_callback(png_structp png_ptr, png_infop info) { /* Do any setup here, including setting any of the transformations mentioned in the Reading PNG files section. For now, you _must_ call either png_start_read_image() or png_read_update_info() after all the transformations are set (even if you don't set any). You may start getting rows before png_process_data() returns, so this is your last chance to prepare for that. This is where you turn on interlace handling, assuming you don't want to do it yourself. If you need to you can stop the processing of your original input data at this point by calling png_process_data_pause. This returns the number of unprocessed bytes from the last png_process_data call - it is up to you to ensure that the next call sees these bytes again. If you don't want to bother with this you can get libpng to cache the unread bytes by setting the 'save' parameter (see png.h) but then libpng will have to copy the data internally. */ } ``` -------------------------------- ### Default ZLIB/IJG Compression Parameters Source: https://github.com/minnyres/cximage/blob/main/mng/CHANGES.txt Adds and initializes default ZLIB and IJG compression parameters. Routines for getting and setting these defaults are also implemented, providing control over compression. ```c /* added default IJG compression parameters and such */ /* moved init of default zlib parms to "mng_hlapi.c" */ /* added init of default IJG parms */ /* added support for get/set of zlib/IJG default parms */ ``` -------------------------------- ### Libpng Compatibility Macro Definitions (C) Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Provides examples of how older macro names are mapped to the new `_SUPPORTED` convention for compatibility. `PNG_INCH_CONVERSIONS` is shown to enable `PNG_INCH_CONVERSIONS_SUPPORTED`, and other `_NOT_SUPPORTED` macros are illustrated for disabling features. ```c Compatibility with the old names is provided as follows: PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED And the following definitions disable the corresponding feature: PNG_SETJMP_NOT_SUPPORTED disables SETJMP PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV ``` -------------------------------- ### ZLIB/IJG Parameter Get/Set Routines Source: https://github.com/minnyres/cximage/blob/main/mng/CHANGES.txt Implements routines for getting and setting default ZLIB and IJG compression parameters. This allows users to fine-tune compression settings for MNG and JNG processing. ```c /* Added get/set routines for default ZLIB/IJG parameters */ ``` -------------------------------- ### CXImage Destination Manager Struct Example Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Structure definition for a data destination manager in CXImage. It includes pointers and counts for managing the output buffer. This structure is used to define how compressed data is written to a buffer or stream. ```c JOCTET * next_output_byte; /* => next byte to write in buffer */ size_t free_in_buffer; /* # of byte spaces remaining in buffer */ ``` -------------------------------- ### Custom JPEG Error Handling Example (C) Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Illustrates how to override default JPEG error handling routines to customize message output and behavior. This example shows overriding specific methods in the jpeg_error_mgr struct to achieve custom error handling without replacing the entire jerror.c module. It demonstrates accessing JPEG object and error manager data, and potentially embedding these structures within larger custom structures. ```c /* Example demonstrating overriding JPEG error handling methods */ #include #include #include "jpeglib.h" // Structure to hold custom error manager data typedef struct { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer; // For longjmp } my_error_mgr; // Override error_exit routine void my_error_exit (j_common_ptr cinfo) { my_error_mgr *myerr = (my_error_mgr *) cinfo->err; fprintf(stderr, "JPEGLIB ERROR: %s\n", myerr->pub.jpeg_message_table[myerr->pub.msg_code]); longjmp(myerr->setjmp_buffer, 1); } // Override output_message routine (optional, for custom output) void my_output_message (j_common_ptr cinfo) { my_error_mgr *myerr = (my_error_mgr *) cinfo->err; // Example: send messages to a specific log file or buffer fprintf(stderr, "Custom output: %s\n", myerr->pub.jpeg_message_table[myerr->pub.msg_code]); } // Override format_message routine (optional, for custom message formatting) void my_format_message (j_common_ptr cinfo, char * buffer) { // Implement custom message formatting logic here // For example, adding timestamps or severity levels my_error_mgr *myerr = (my_error_mgr *) cinfo->err; sprintf(buffer, "[Custom Format] Code %d: %s", myerr->pub.msg_code, myerr->pub.jpeg_message_table[myerr->pub.msg_code]); } // Override emit_message routine (optional, for controlling warnings/trace) void my_emit_message (j_common_ptr cinfo, int msg_level) { if (msg_level < 0) { // Warning fprintf(stderr, "Warning received: %d\n", msg_level); // Optionally call the default output or a custom one // cinfo->err->output_message(cinfo); } else { // Trace message // Handle trace messages based on msg_level } } int main() { struct jpeg_decompress_struct cinfo; my_error_mgr jerr; // Initialize error handler cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; // Optionally override other methods: // jerr.pub.output_message = my_output_message; // jerr.pub.format_message = my_format_message; // jerr.pub.emit_message = my_emit_message; // Set up the jump buffer for error handling if (setjmp(jerr.setjmp_buffer)) { fprintf(stderr, "Application regained control after JPEG error.\n"); // Clean up JPEG object if necessary jpeg_destroy(&cinfo); return 1; } // JPEG decompression or compression logic here... // Example of simulating an error: // jerr.pub.msg_code = JERR_UNKNOWN_SYSTEM_OPTION; // jerr.pub.error_exit((j_common_ptr)&cinfo); fprintf(stdout, "JPEG processing completed successfully (or error handled).\n"); return 0; } ``` -------------------------------- ### JPEG Compression Workflow Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt This outlines the typical sequence of function calls for compressing an image using the JPEG library. It involves initializing a compression object, supplying image data, and finalizing the compression process. The same object can be reused for multiple compressions. ```c jpeg_finish_compress(...); /* Release the JPEG compression object */ ``` -------------------------------- ### CxImage::Startup Protected Function Source: https://github.com/minnyres/cximage/blob/main/doc/doxy/html/group___protected.html The Startup function is a protected and inherited function used to initialize the internal structures of CxImage. It takes an optional image type argument. ```cpp void CxImage::Startup( uint32_t imagetype = 0 ) ``` -------------------------------- ### JPEG Decompression Workflow Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt This describes the standard procedure for decompressing a JPEG image. It includes allocating and initializing a decompression object, specifying the data source, reading the header to get image information, setting parameters, and then reading scanlines until decompression is complete. ```c /* Allocate and initialize a JPEG decompression object */ /* Specify the source of the compressed data (eg, a file) */ /* Call jpeg_read_header() to obtain image info */ /* Set parameters for decompression */ jpeg_start_decompress(...); while (scan lines remain to be read) jpeg_read_scanlines(...); jpeg_finish_decompress(...); /* Release the JPEG decompression object */ ``` -------------------------------- ### Create and Initialize Images (C++) Source: https://context7.com/minnyres/cximage/llms.txt Illustrates how to create new images, fill them with solid colors, create images from raw pixel data, and copy existing images with selective copying of pixels or alpha channels. It also shows how to retrieve basic image information. These operations require the CxImage library. ```cpp // Create empty 24-bit RGB image CxImage image(800, 600, 24, CXIMAGE_FORMAT_BMP); // Fill with solid color RGBQUAD blue = {255, 0, 0, 0}; // BGR format for (uint32_t y = 0; y < 600; y++) { for (uint32_t x = 0; x < 800; x++) { image.SetPixelColor(x, y, blue); } } // Create from raw pixel array uint8_t* rawPixels = new uint8_t[800 * 600 * 3]; // ... fill rawPixels with RGB data ... CxImage fromArray; fromArray.CreateFromArray(rawPixels, 800, 600, 24, 800 * 3, false); // Copy constructor with selective copying CxImage original(_T("source.jpg"), CXIMAGE_FORMAT_JPG); CxImage copyPixels(original, true, false, false); // pixels only CxImage copyAlpha(original, false, false, true); // alpha only CxImage fullCopy(original); // everything // Get image information printf("Image: %dx%d, %d bpp, %s\n", image.GetWidth(), image.GetHeight(), image.GetBpp(), image.IsValid() ? "valid" : "invalid"); ``` -------------------------------- ### Write JPEG COM Marker with Text Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Demonstrates how to write a JPEG comment (COM) marker containing user-supplied text. This function is called after starting compression and before writing scanlines. It takes the JPEG object, marker type, text, and text length as parameters. ```c jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text)); ``` -------------------------------- ### JPEG Library Memory Allocation Example (C) Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Demonstrates how to allocate memory for structures within the JPEG library using the memory manager. It shows the use of alloc_small for small allocations and mentions alloc_large for larger ones, specifying the memory pool (JPOOL_IMAGE or JPOOL_PERMANENT). ```c ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size); // Use JPOOL_PERMANENT to get storage that lasts as long as the JPEG object. // Use alloc_large instead of alloc_small for anything bigger than a few Kbytes. ``` -------------------------------- ### Initialize libpng I/O Functions Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Sets up the standard I/O functions for libpng, typically using fwrite. It associates the previously opened file pointer with the libpng write structure. If custom I/O is needed, refer to libpng customization. ```c png_init_io(png_ptr, fp); ``` -------------------------------- ### HP-UX Manual Configuration without ANSI C Source: https://github.com/minnyres/cximage/blob/main/jpeg/install.txt For pre-7.05 HP-UX systems or when using a non-ANSI C compiler, use 'makefile.unix'. Do not add '-Aa' to CFLAGS, or run configure without the CC option. ```makefile # Do not add -Aa to CFLAGS ``` -------------------------------- ### Read JPEG Scanlines Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt Reads decompressed image data in scanlines after JPEG decompression has started. It takes the maximum number of scanlines to read and returns the actual number read. The process should be repeated until the entire image is processed. Ensure a loop is used as the buffer may not be filled completely in a single call. ```c while (cinfo.output_scanline < cinfo.output_height) { jpeg_read_scanlines(&cinfo, buffer, max_scanlines_to_read); } ``` -------------------------------- ### Include libpng Header File Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt This is the fundamental step to begin using the libpng library in your C/C++ application. It makes all the necessary declarations and definitions available for PNG manipulation. ```c #include ``` -------------------------------- ### Consuming Input Data in JPEG Decoding (C/C++) Source: https://github.com/minnyres/cximage/blob/main/jpeg/libjpeg.txt This snippet demonstrates the use of `jpeg_consume_input()` to decode input data in advance of display needs. It lists the possible return values indicating different events during input processing, such as reaching the start of a scan (SOS) or the end of the image (EOI). This function helps manage data flow and buffer buildup. ```c jpeg_consume_input(); /* Possible return values: JPEG_REACHED_SOS: reached an SOS marker (the start of a new scan) JPEG_REACHED_EOI: reached the EOI marker (end of image) JPEG_ROW_COMPLETED: completed reading one MCU row of compressed data JPEG_SCAN_COMPLETED: completed reading last MCU row of current scan JPEG_SUSPENDED: suspended before completing any of the above */ ``` -------------------------------- ### Initialize File I/O for Writing PNG Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Opens a file in binary write mode for libpng to write to. Ensures the file is opened correctly before proceeding with libpng operations. This is a prerequisite for using libpng's writing functions. ```c FILE *fp = fopen(file_name, "wb"); if (!fp) return (ERROR); ``` -------------------------------- ### C++ Batch Image Processing Pipeline with CxImage Source: https://context7.com/minnyres/cximage/llms.txt This C++ code defines a function `BatchProcessImages` that iterates through a list of image files. For each file, it loads the image using CxImage, applies a series of processing steps (resizing, EXIF rotation, histogram stretching, brightness/contrast adjustment, sharpening, saturation, and median filtering), and saves an optimized version and a thumbnail. It includes error handling for loading and saving operations. The `main` function provides an example of how to use `BatchProcessImages`. ```cpp #include "ximage.h" #include #include void BatchProcessImages(const std::vector& files) { for (size_t i = 0; i < files.size(); i++) { printf("Processing %s (%zu/%zu)...\n", files[i].c_str(), i + 1, files.size()); // Load image CxImage image(files[i].c_str(), CXIMAGE_FORMAT_JPG); if (!image.IsValid()) { fprintf(stderr, "Failed to load %s: %s\n", files[i].c_str(), image.GetLastError()); continue; } // Processing pipeline // Step 1: Resize to standard dimensions if (image.GetWidth() > 1920 || image.GetHeight() > 1080) { image.Resample2(1920, 1080, CxImage::IM_BICUBIC2, CxImage::OM_REPEAT); } // Step 2: Auto-rotate based on EXIF #if CXIMAGE_SUPPORT_EXIF image.RotateExif(); #endif // Step 3: Enhance image image.HistogramStretch(0, 0.01); // Stretch histogram image.Light(5, 10); // Slight brightness/contrast image.UnsharpMask(2.0f, 0.5f, 0); // Sharpen image.Saturate(10, 1); // Increase saturation // Step 4: Reduce noise image.Median(3); // Median filter // Step 5: Save optimized version image.SetJpegQualityF(85.0f); std::string outfile = "processed_" + files[i]; if (!image.Save(outfile.c_str(), CXIMAGE_FORMAT_JPG)) { fprintf(stderr, "Failed to save %s: %s\n", outfile.c_str(), image.GetLastError()); } // Step 6: Create thumbnail CxImage thumb(image, true, false, false); RGBQUAD white = {255, 255, 255, 0}; thumb.Thumbnail(320, 240, white); std::string thumbfile = "thumb_" + files[i]; thumb.SetJpegQualityF(75.0f); thumb.Save(thumbfile.c_str(), CXIMAGE_FORMAT_JPG); printf(" Saved: %s and %s\n", outfile.c_str(), thumbfile.c_str()); } printf("Batch processing complete: %zu files processed\n", files.size()); } int main() { std::vector imageFiles = { "photo1.jpg", "photo2.jpg", "photo3.jpg", "photo4.jpg" }; BatchProcessImages(imageFiles); return 0; } ``` -------------------------------- ### MakeBitmap Source: https://github.com/minnyres/cximage/blob/main/doc/doxy/html/class_cx_image.html Creates an HBITMAP from the image. Allows specifying a device context and transparency. ```APIDOC ## POST /MakeBitmap ### Description Creates an HBITMAP from the image. ### Method POST ### Endpoint /MakeBitmap ### Parameters #### Request Body - **hdc** (HDC) - Optional - The device context. Defaults to NULL. - **bTransparency** (bool) - Optional - Flag indicating whether to use transparency. Defaults to false. ### Request Example { "hdc": "HDC_HANDLE", "bTransparency": true } ### Response #### Success Response (200) - **HBITMAP** (handle) - The handle to the created HBITMAP. #### Response Example { "HBITMAP": "HBITMAP_HANDLE" } ``` -------------------------------- ### Initialize PNG Read Structure and Info Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Demonstrates the initialization of libpng structures for reading a PNG file. It includes error checking for the allocation of the info structure and the destruction of the read structure upon failure. This is a fundamental step before any I/O operations. ```c png_infop end_info = png_create_info_struct(png_ptr); if (!end_info) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return (ERROR); } ``` -------------------------------- ### cjpeg Scan Script Example (Progressive Successive Approximation) Source: https://github.com/minnyres/cximage/blob/main/jpeg/wizard.txt An example of a progressive scan script using successive approximation, similar to the default behavior of 'cjpeg -progressive' for YCbCr images. It progressively refines the image quality by sending different bits of the coefficients in stages. ```jpegscan # Initial DC scan for Y,Cb,Cr (lowest bit not sent) 0,1,2: 0-0, 0, 1 ; # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits: 0: 1-5, 0, 2 ; # Send all Cr,Cb AC coefficients, minus lowest bit: 2: 1-63, 0, 1 ; 1: 1-63, 0, 1 ; # Send remaining Y AC coefficients, minus 2 lowest bits: 0: 6-63, 0, 2 ; # Send next-to-lowest bit of all Y AC coefficients: 0: 1-63, 2, 1 ; # At this point we've sent all but the lowest bit of all coefficients. # Send lowest bit of DC coefficients 0,1,2: 0-0, 1, 0 ; # Send lowest bit of AC coefficients 2: 1-63, 1, 0 ; 1: 1-63, 1, 0 ; # Y AC lowest bit scan is last; it's usually the largest scan 0: 1-63, 1, 0 ; ``` -------------------------------- ### Manage Alpha Channel and Transparency with CxImage C++ Source: https://context7.com/minnyres/cximage/llms.txt Demonstrates creating images with alpha channels, setting alpha gradients, checking alpha status, performing alpha operations like inversion and mirroring, extracting alpha masks, copying alpha from other images, creating alpha from transparency colors, managing palette alpha, and removing alpha channels. It requires the CxImage library. ```cpp // Create image with alpha channel CxImage image(400, 300, 24, CXIMAGE_FORMAT_PNG); image.AlphaCreate(); // Set alpha gradient for (int y = 0; y < 300; y++) { for (int x = 0; x < 400; x++) { uint8_t alpha = (uint8_t)((x * 255) / 400); image.AlphaSet(x, y, alpha); RGBQUAD color = {255, 128, 0, alpha}; image.SetPixelColor(x, y, color, true); } } // Check alpha channel status if (image.AlphaIsValid()) { printf("Alpha channel present\n"); printf("Max alpha value: %d\n", image.AlphaGetMax()); } // Alpha operations image.AlphaInvert(); // Invert alpha image.AlphaMirror(); // Mirror alpha horizontally image.AlphaFlip(); // Flip alpha vertically image.AlphaSet(128); // Set uniform alpha // Extract alpha to separate image CxImage alphaMask; image.AlphaSplit(&alphaMask); alphaMask.Save(_T("alpha_mask.png"), CXIMAGE_FORMAT_PNG); // Copy alpha from another image CxImage source(_T("transparent.png"), CXIMAGE_FORMAT_PNG); CxImage dest(_T("opaque.jpg"), CXIMAGE_FORMAT_JPG); dest.AlphaCopy(source); // Create alpha from transparency color dest.SetTransColor({255, 255, 255, 0}); // White = transparent dest.AlphaFromTransparency(); // Palette alpha (for indexed images) dest.AlphaPaletteEnable(true); dest.AlphaPaletteClear(); // Remove alpha channel image.AlphaStrip(); // Remove completely image.AlphaDelete(); // Delete but keep structure image.Save(_T("transparent.png"), CXIMAGE_FORMAT_PNG); ``` -------------------------------- ### CxMemFile Constructors Source: https://github.com/minnyres/cximage/blob/main/doc/doxy/html/class_cx_mem_file.html Documentation for the constructors of the CxMemFile class. ```APIDOC ## CxMemFile Constructors ### CxMemFile(BYTE *pBuffer = NULL, DWORD size = 0) **Description**: Constructs a CxMemFile object. It can optionally be initialized with a pre-existing buffer and size. ### ~CxMemFile() **Description**: Destructor for the CxMemFile class. Handles cleanup of resources. ``` -------------------------------- ### cjpeg Scan Script Example (Progressive Spectral Selection) Source: https://github.com/minnyres/cximage/blob/main/jpeg/wizard.txt An example of a progressive scan script using only spectral selection. It includes an interleaved DC scan for Y, Cb, and Cr, followed by AC scans for Y, Cb, and Cr, gradually increasing the range of coefficients included. ```jpegscan # Interleaved DC scan for Y,Cb,Cr: 0,1,2: 0-0, 0, 0 ; # AC scans: 0: 1-2, 0, 0 ; 0: 3-5, 0, 0 ; 1: 1-63, 0, 0 ; 2: 1-63, 0, 0 ; 0: 6-9, 0, 0 ; 0: 10-63, 0, 0 ; ``` -------------------------------- ### C: Initialize PNG Read Structure and Info Structure Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt This C code snippet shows the initialization of `png_struct` and `png_info` structures required for reading PNG files using libpng. It includes error checking for structure allocation failures and demonstrates passing version information and custom error handling functions. ```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) return (ERROR); ``` -------------------------------- ### Get PNG Modification Time Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Retrieves the modification time of the PNG file. This information is stored in the tIME chunk. ```c png_get_tIME(png_ptr, info_ptr, &mod_time); ``` -------------------------------- ### Get PNG Gamma Information Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Retrieves the gamma value of the PNG file. Both floating-point and fixed-point versions of the gamma retrieval function are available. ```c png_get_gAMA(png_ptr, info_ptr, &file_gamma); png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma); ``` -------------------------------- ### Get PNG Gamma Information Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Retrieves the gamma value at which the PNG file is written. This function reads the gAMA chunk from the PNG info structure. ```c png_get_gAMA(png_ptr, info_ptr, &gamma); ``` -------------------------------- ### Get PNG Offset Information Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Retrieves the x and y offset values from a PNG file, along with the unit type for these offsets. This information is specified in the oFFs chunk. ```c png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, &unit_type); ``` -------------------------------- ### Load and Detect Image Format (C++) Source: https://context7.com/minnyres/cximage/llms.txt Demonstrates loading an image with automatic format detection, checking the format of a file before loading, and loading an image from a memory buffer. It also shows how to load all frames from an animated GIF. This functionality requires the CxImage library and basic C++ file I/O. ```cpp #include "ximage.h" // Load with automatic format detection CxImage image; if (!image.Load(_T("photo.jpg"), CXIMAGE_FORMAT_JPG)) { fprintf(stderr, "Error loading image: %s\n", image.GetLastError()); return 1; } // Check format before loading CxFile file; file.Open(_T("unknown.dat"), _T("rb")); if (image.CheckFormat(&file, CXIMAGE_FORMAT_PNG)) { printf("File is a valid PNG\n"); file.Seek(0, SEEK_SET); image.Decode(&file, CXIMAGE_FORMAT_PNG); } file.Close(); // Load from memory buffer FILE* fp = fopen("image.png", "rb"); fseek(fp, 0, SEEK_END); long size = ftell(fp); fseek(fp, 0, SEEK_SET); uint8_t* buffer = new uint8_t[size]; fread(buffer, 1, size, fp); fclose(fp); CxImage memImage(buffer, size, CXIMAGE_FORMAT_PNG); if (memImage.IsValid()) { printf("Loaded %dx%d image from memory\n", memImage.GetWidth(), memImage.GetHeight()); } delete[] buffer; // Load all frames from animated GIF CxImage gif; gif.SetRetreiveAllFrames(true); gif.Load(_T("animation.gif"), CXIMAGE_FORMAT_GIF); printf("Animation contains %d frames\n", gif.GetNumFrames()); ``` -------------------------------- ### Get PNG Histogram Data Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Retrieves the histogram data for the palette from a PNG file. The histogram provides a count for each palette entry, indicated by the hIST chunk. ```c png_get_hIST(png_ptr, info_ptr, &hist); ``` -------------------------------- ### Get PNG Header Version Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Allows checking the version of the `png.h` header file used during compilation. This is useful for ensuring compatibility between the compiled application and the libpng library. ```c png_uint_32 application_vn = PNG_LIBPNG_VER; ``` -------------------------------- ### CMake Configuration for zlib Source: https://github.com/minnyres/cximage/blob/main/zlib/CMakeLists.txt Initializes CMake, sets project name, and configures build options for the zlib library. It checks for and enables shared library builds if not explicitly defined. Includes standard CMake modules for system checks. ```cmake cmake_minimum_required(VERSION 2.4.4) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) project(zlib C) if(NOT DEFINED BUILD_SHARED_LIBS) option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON) endif() include(CheckTypeSize) include(CheckFunctionExists) include(CheckIncludeFile) include(CheckCSourceCompiles) enable_testing() ``` -------------------------------- ### Create libpng Read/Write Structures Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Provides functions for creating and initializing libpng structures, offering advantages like version error checking and custom error handling during initialization. These are preferred over older `png_read_init` and `png_write_init` functions. ```c png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER, png_user_error_ptr, png_error_fn, png_warn_fn); png_infop info_ptr = png_create_info_struct(png_ptr); ``` -------------------------------- ### Get PNG Physical Resolution Source: https://github.com/minnyres/cximage/blob/main/png/libpng-manual.txt Retrieves the physical resolution of a PNG image in the x and y directions, along with the unit type for the resolution. This data is defined in the pHYs chunk. ```c png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); ```