### Define Installation Rules Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/sharedlib/CMakeLists.txt Specifies installation paths for libraries, tools, and optional PDB files. ```cmake install(TARGETS jpeg EXPORT ${CMAKE_PROJECT_NAME}Targets INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin) if(WITH_TOOLS) install(TARGETS cjpeg djpeg jpegtran RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin) endif() if(MSVC_LIKE AND CMAKE_C_LINKER_SUPPORTS_PDB) install(FILES "$" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin OPTIONAL) endif() ``` -------------------------------- ### Install libjpeg-turbo Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Install libjpeg-turbo using the build system. The installation directory can be customized using CMAKE_INSTALL_PREFIX and other directory variables. ```bash make install ``` ```bash nmake install ``` -------------------------------- ### Define example compression and decompression tests Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Configures tests for the example application, including MD5 comparison dependencies. ```cmake unset(EXAMPLE_12BIT_ARG) if(sample_bits EQUAL 12) set(EXAMPLE_12BIT_ARG "-precision;12") endif() add_test(NAME example-${sample_bits}bit-${libtype}-compress COMMAND example${suffix} compress -q 95 ${EXAMPLE_12BIT_ARG} ${testout}-example.jpg) add_test(NAME example-${sample_bits}bit-${libtype}-compress-cmp COMMAND md5cmp ${MD5_JPEG_EXAMPLE_COMPRESS} ${testout}-example.jpg) set_tests_properties(example-${sample_bits}bit-${libtype}-compress-cmp PROPERTIES DEPENDS example-${sample_bits}bit-${libtype}-compress) add_test(NAME example-${sample_bits}bit-${libtype}-decompress COMMAND example${suffix} decompress ${EXAMPLE_12BIT_ARG} ${JPEGIMG} ${testout}-example.ppm) add_test(NAME example-${sample_bits}bit-${libtype}-decompress-cmp COMMAND md5cmp ${MD5_PPM_EXAMPLE_DECOMPRESS} ${testout}-example.ppm) set_tests_properties(example-${sample_bits}bit-${libtype}-decompress-cmp PROPERTIES DEPENDS example-${sample_bits}bit-${libtype}-decompress) ``` -------------------------------- ### Build libjpeg-turbo Installer with Make (MinGW) Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Use this command to build the installer package when using MinGW on Windows. Navigate to the build directory first. ```bash cd {build_directory} make installer ``` -------------------------------- ### Build libjpeg-turbo Installer with NMake (Windows) Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Use this command to build the installer package when using NMake on Windows. Ensure you are in the build directory. ```bash cd {build_directory} nmake installer ``` -------------------------------- ### Configure Default Installation Prefix Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Sets the default installation prefix based on the operating system and compiler architecture. ```cmake if(WIN32) if(MSVC_LIKE) set(CMAKE_INSTALL_DEFAULT_PREFIX "c:/${CMAKE_PROJECT_NAME}") else() set(CMAKE_INSTALL_DEFAULT_PREFIX "c:/${CMAKE_PROJECT_NAME}-gcc") endif() if(BITS EQUAL 64) set(CMAKE_INSTALL_DEFAULT_PREFIX "${CMAKE_INSTALL_DEFAULT_PREFIX}64") endif() else() if(NOT CMAKE_INSTALL_DEFAULT_PREFIX) set(CMAKE_INSTALL_DEFAULT_PREFIX /opt/${CMAKE_PROJECT_NAME}) endif() endif() if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_DEFAULT_PREFIX}" CACHE PATH "Directory into which to install ${CMAKE_PROJECT_NAME} (default: ${CMAKE_INSTALL_DEFAULT_PREFIX})" FORCE) endif() message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Report Installation Directories Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Defines a macro to display installation directory paths and marks them as advanced in the CMake cache. ```cmake macro(report_directory var) if(CMAKE_INSTALL_${var} STREQUAL CMAKE_INSTALL_FULL_${var}) message(STATUS "CMAKE_INSTALL_${var} = ${CMAKE_INSTALL_${var}}") else() message(STATUS "CMAKE_INSTALL_${var} = ${CMAKE_INSTALL_${var}} (${CMAKE_INSTALL_FULL_${var}})") endif() mark_as_advanced(CLEAR CMAKE_INSTALL_${var}) endmacro() set(DIRLIST "BINDIR;DATAROOTDIR;DOCDIR;INCLUDEDIR;LIBDIR") if(UNIX) list(APPEND DIRLIST "MANDIR") endif() foreach(dir ${DIRLIST}) ``` -------------------------------- ### Install JNA JAR File Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/jna/CMakeLists.txt Installs the created turbojpeg-jna JAR file to the configured Java installation directory, marked as a 'java' component. ```cmake install_jar(turbojpeg-jna DESTINATION ${CMAKE_INSTALL_JAVADIR} COMPONENT java) mark_as_advanced(CLEAR CMAKE_INSTALL_JAVADIR) ``` -------------------------------- ### Start JPEG Compression Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Initiates the compression cycle, initializing state and emitting the JPEG header. Use TRUE for a complete datastream. ```c jpeg_start_compress(&cinfo, TRUE); ``` -------------------------------- ### Perfect rotation example Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/usage.txt This example demonstrates how to achieve a perfect rotation using jpegtran with -rot 90 -perfect. If a perfect rotation is not available, it falls back to an approximated one via djpeg and pnmflip. ```bash jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg ``` -------------------------------- ### Set Default Java Installation Directory Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/jna/CMakeLists.txt Configures the default directory for installing Java JAR files if not explicitly defined. Uses standard installation directories. ```cmake if(NOT DEFINED CMAKE_INSTALL_DEFAULT_JAVADIR) set(CMAKE_INSTALL_DEFAULT_JAVADIR "/java") endif() GNUInstallDirs_set_install_dir(JAVADIR "The directory into which Java classes should be installed") GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_JAVADIR CMAKE_INSTALL_JAVADIR) set(CMAKE_INSTALL_JAVADIR ${CMAKE_INSTALL_JAVADIR} PARENT_SCOPE) set(CMAKE_INSTALL_FULL_JAVADIR ${CMAKE_INSTALL_FULL_JAVADIR} PARENT_SCOPE) if(NOT CMAKE_INSTALL_JAVADIR) message(FATAL_ERROR "CMAKE_INSTALL_JAVADIR cannot be blank") endif() report_directory(JAVADIR) ``` -------------------------------- ### Validate Installation Directories Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Ensures required installation directory variables are set to avoid configuration failures or incorrect installation paths. ```cmake if(NOT dir STREQUAL "DATAROOTDIR" AND NOT CMAKE_INSTALL_${dir}) message(FATAL_ERROR "CMAKE_INSTALL_${dir} cannot be blank") endif() report_directory(${dir}) endforeach() ``` -------------------------------- ### Fuzz Target Installation Directory Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/fuzz/CMakeLists.txt Defines and checks the FUZZ_BINDIR variable, which specifies the installation directory for fuzz targets. This variable must be set by the user. ```cmake set(FUZZ_BINDIR "" CACHE PATH "Directory into which fuzz targets should be installed") if(NOT FUZZ_BINDIR) message(FATAL_ERROR "FUZZ_BINDIR must be specified.") endif() message(STATUS "FUZZ_BINDIR = ${FUZZ_BINDIR}") ``` -------------------------------- ### Define Default Directory Layout Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Sets default subdirectory paths for documentation, Java classes, and libraries when using the default installation prefix. ```cmake if(CMAKE_INSTALL_PREFIX STREQUAL "${CMAKE_INSTALL_DEFAULT_PREFIX}") set(CMAKE_INSTALL_DEFAULT_DATAROOTDIR "") set(CMAKE_INSTALL_DEFAULT_DOCDIR "/doc") set(CMAKE_INSTALL_DEFAULT_JAVADIR "/classes") if(UNIX AND NOT APPLE) if(BITS EQUAL 64) set(CMAKE_INSTALL_DEFAULT_LIBDIR "lib64") elseif(CMAKE_C_COMPILER_ABI MATCHES "ELF X32") set(CMAKE_INSTALL_DEFAULT_LIBDIR "libx32") else() set(CMAKE_INSTALL_DEFAULT_LIBDIR "lib32") endif() endif() endif() ``` -------------------------------- ### Create Mac disk image package Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Create a Mac package/disk image. Requires pkgbuild and productbuild, typically installed on OS X/macOS 10.7 and later. ```bash make dmg ``` -------------------------------- ### Define Custom Quantization Tables with cjpeg Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/wizard.txt Use the -qtables switch to specify a file containing custom quantization tables. The file should contain 1 to 4 tables, each with 64 decimal values. Comments starting with '#' are supported. ```text # Quantization tables given in Annex K (Clause K.1) of # Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994. # 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 ``` -------------------------------- ### Set RPATH for shared libraries Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Configures the installation RPATH when shared libraries are enabled. ```cmake if(ENABLE_SHARED) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) endif() ``` -------------------------------- ### Build libjpeg-turbo with Visual C++ (Command Line) Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Build libjpeg-turbo using Visual C++ from the command line with NMake. This generates static libraries and DLLs. ```bash cd {build_directory} cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release [additional CMake flags] {source_directory} nmake ``` -------------------------------- ### Configure Command Line File Handling Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/src/jconfig.txt This option, when defined, allows both input and output files to be specified on the command line. If undefined, it defaults to using stdout and optionally stdin, which may be necessary on systems with limited binary I/O capabilities. ```c #undef TWO_FILE_COMMANDLINE ``` -------------------------------- ### Build libjpeg-turbo with Visual C++ (IDE) Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Configure the build for Visual Studio IDE by selecting the appropriate CMake generator. Open ALL_BUILD.vcproj to build. ```bash cd {build_directory} cmake -G"Visual Studio 10" [additional CMake flags] {source_directory} ``` -------------------------------- ### 32-bit MinGW Build CMake and Make Commands Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Execute CMake with the toolchain file and then run make for a 32-bit MinGW build. ```bash cd {build_directory} cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \ -DCMAKE_INSTALL_PREFIX={install_path} \ [additional CMake flags] {source_directory} make ``` -------------------------------- ### Build libjpeg-turbo on Unix-like Systems Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Use these commands to build libjpeg-turbo on Unix and Unix-like systems. This generates static and shared libraries. ```bash cd {build_directory} cmake -G"Unix Makefiles" [additional CMake flags] {source_directory} make ``` -------------------------------- ### jpeg_simple_progression Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Configures simple progressive entropy coding. This is a simplified setup for progressive JPEG. ```APIDOC ## jpeg_simple_progression ### Description Sets up simple progressive entropy coding for the JPEG compressor. ### Method ```c void jpeg_simple_progression (j_compress_ptr cinfo) ``` ### Parameters * **cinfo** (j_compress_ptr) - Pointer to the compression control structure. ``` -------------------------------- ### Initialize JPEG Compression Parameters Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Set image dimensions, color components, and colorspace before calling jpeg_set_defaults. ```c cinfo.image_width = Width; cinfo.image_height = Height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); ``` -------------------------------- ### Enable TurboJPEG JNA Interface Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Add this flag to the CMake command line to build and install the TurboJPEG/JNA interface for Java applications. ```bash -DWITH_JNA={path_to_JNA_JAR_file} ``` -------------------------------- ### Configure CMake with cmake-gui Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Use cmake-gui for a graphical interface to configure CMake options. Run this from the build directory after initial configuration. ```bash cmake-gui {source_directory} ``` -------------------------------- ### Initialize CMake and Project Settings Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Sets the minimum required CMake version and initializes default compiler flags for release builds. ```cmake cmake_minimum_required(VERSION 3.15...3.28) if(CMAKE_EXECUTABLE_SUFFIX) set(CMAKE_EXECUTABLE_SUFFIX_TMP ${CMAKE_EXECUTABLE_SUFFIX}) endif() set(CMAKE_C_FLAGS_RELEASE_INITIALIZED_TO_DEFAULT 1) if(CMAKE_C_FLAGS_RELEASE) set(CMAKE_C_FLAGS_RELEASE_INITIALIZED_TO_DEFAULT 0) endif() set(CMAKE_C_FLAGS_RELWITHDEBINFO_INITIALIZED_TO_DEFAULT 1) if(CMAKE_C_FLAGS_RELWITHDEBINFO) set(CMAKE_C_FLAGS_RELWITHDEBINFO_INITIALIZED_TO_DEFAULT 0) endif() project(libjpeg-turbo C) ``` -------------------------------- ### tjGreenOffset Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/turbojpeg/group___turbo_j_p_e_g.html Array of green offsets (in samples) for a given pixel format. Specifies the number of samples the green component is offset from the start of the pixel. ```APIDOC ## tjGreenOffset ### Description Green offset (in samples) for a given pixel format. This specifies the number of samples that the green component is offset from the start of the pixel. ### Type const int tjGreenOffset[TJ_NUMPF] ### Usage If an 8-bit-per-component pixel of format TJPF_BGRX is stored in `unsigned char pixel[]`, then the green component is `pixel[tjGreenOffset[TJPF_BGRX]]`. ### Note The offset is -1 if the pixel format does not have a green component. ``` -------------------------------- ### tjBlueOffset Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/turbojpeg/group___turbo_j_p_e_g.html Array of blue offsets (in samples) for a given pixel format. Specifies the number of samples the blue component is offset from the start of the pixel. ```APIDOC ## tjBlueOffset ### Description Blue offset (in samples) for a given pixel format. This specifies the number of samples that the blue component is offset from the start of the pixel. ### Type const int tjBlueOffset[TJ_NUMPF] ### Usage If an 8-bit-per-component pixel of format TJPF_BGRX is stored in `unsigned char pixel[]`, then the blue component is `pixel[tjBlueOffset[TJPF_BGRX]]`. ### Note The offset is -1 if the pixel format does not have a blue component. ``` -------------------------------- ### Define Build Tools and Executables Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/sharedlib/CMakeLists.txt Configures and builds the cjpeg, djpeg, and jpegtran utilities if WITH_TOOLS is enabled. ```cmake if(WITH_TOOLS) if(WIN32) set(USE_SETMODE "-DUSE_SETMODE") endif() set(CDJPEG_COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPNG_SUPPORTED -DSPNG_STATIC -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}") add_executable(cjpeg ../src/cjpeg.c ../src/cdjpeg.c ../src/rdbmp.c ../src/rdgif.c ../src/wrapper/rdpng-8.c ../src/wrapper/rdpng-12.c ../src/wrapper/rdpng-16.c ${ZLIB_SOURCES} ${SPNG_SOURCES} ../src/wrapper/rdppm-8.c ../src/wrapper/rdppm-12.c ../src/wrapper/rdppm-16.c ../src/rdswitch.c ../src/rdtarga.c) set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS ${CDJPEG_COMPILE_FLAGS}) target_link_libraries(cjpeg jpeg) if(SPNG_LIBRARY) target_link_libraries(cjpeg ${SPNG_LIBRARY}) endif() if(NOT WITH_SYSTEM_SPNG AND ZLIB_LIBRARY) target_link_libraries(cjpeg ${ZLIB_LIBRARY}) endif() add_executable(djpeg ../src/djpeg.c ../src/cdjpeg.c ../src/wrapper/rdcolmap-8.c ../src/wrapper/rdcolmap-12.c ../src/rdswitch.c ../src/wrbmp.c ../src/wrapper/wrgif-8.c ../src/wrapper/wrgif-12.c ../src/wrapper/wrpng-8.c ../src/wrapper/wrpng-12.c ../src/wrapper/wrpng-16.c ${ZLIB_SOURCES} ${SPNG_SOURCES} ../src/wrapper/wrppm-8.c ../src/wrapper/wrppm-12.c ../src/wrapper/wrppm-16.c ../src/wrtarga.c) set_property(TARGET djpeg PROPERTY COMPILE_FLAGS ${CDJPEG_COMPILE_FLAGS}) target_link_libraries(djpeg jpeg) if(SPNG_LIBRARY) target_link_libraries(djpeg ${SPNG_LIBRARY}) endif() if(NOT WITH_SYSTEM_SPNG AND ZLIB_LIBRARY) target_link_libraries(djpeg ${ZLIB_LIBRARY}) endif() add_executable(jpegtran ../src/jpegtran.c ../src/cdjpeg.c ../src/rdswitch.c ../src/transupp.c) target_link_libraries(jpegtran jpeg) set_property(TARGET jpegtran PROPERTY COMPILE_FLAGS "${USE_SETMODE}") endif() ``` -------------------------------- ### tjAlphaOffset Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/turbojpeg/group___turbo_j_p_e_g.html Array of alpha offsets (in samples) for a given pixel format. Specifies the number of samples the alpha component is offset from the start of the pixel. ```APIDOC ## tjAlphaOffset ### Description Alpha offset (in samples) for a given pixel format. This specifies the number of samples that the alpha component is offset from the start of the pixel. ### Type const int tjAlphaOffset[TJ_NUMPF] ### Usage If an 8-bit-per-component pixel of format TJPF_BGRA is stored in `unsigned char pixel[]`, then the alpha component is `pixel[tjAlphaOffset[TJPF_BGRA]]`. ### Note The offset is -1 if the pixel format does not have an alpha component. ``` -------------------------------- ### Define Build Options Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Configures various build-time features and library emulation modes for libjpeg-turbo. ```cmake option(ENABLE_SHARED "Build shared libraries" TRUE) boolean_number(ENABLE_SHARED) option(ENABLE_STATIC "Build static libraries" TRUE) boolean_number(ENABLE_STATIC) option(REQUIRE_SIMD "Generate a fatal error if SIMD extensions are not available for this platform (default is to fall back to a non-SIMD build)" FALSE) boolean_number(REQUIRE_SIMD) option(WITH_ARITH_DEC "Include arithmetic decoding support when emulating the libjpeg v6b API/ABI" TRUE) boolean_number(WITH_ARITH_DEC) option(WITH_ARITH_ENC "Include arithmetic encoding support when emulating the libjpeg v6b API/ABI" TRUE) boolean_number(WITH_ARITH_ENC) if(CMAKE_C_COMPILER_ABI MATCHES "ELF X32") unset(WITH_JNA) else() set(WITH_JNA "" CACHE PATH "Build TurboJPEG Java Native Access interfaces (TurboJPEG/JNA) using the specified JNA JAR path (implies ENABLE_SHARED=1 and WITH_TURBOJPEG=1)") if(WITH_JNA AND NOT EXISTS ${WITH_JNA}) message(FATAL_ERROR "${WITH_JNA} does not exist.") endif() endif() option(WITH_JPEG7 "Emulate libjpeg v7 API/ABI (this makes ${CMAKE_PROJECT_NAME} backward-incompatible with libjpeg v6b)" FALSE) boolean_number(WITH_JPEG7) option(WITH_JPEG8 "Emulate libjpeg v8 API/ABI (this makes ${CMAKE_PROJECT_NAME} backward-incompatible with libjpeg v6b)" FALSE) boolean_number(WITH_JPEG8) option(WITH_SIMD "Include SIMD extensions, if available for this platform" TRUE) boolean_number(WITH_SIMD) option(WITH_TURBOJPEG "Include the TurboJPEG API library and associated command-line tools/test programs" TRUE) boolean_number(WITH_TURBOJPEG) option(WITH_TOOLS "Build command-line tools (Disabling this disables WITH_TESTS)" TRUE) boolean_number(WITH_TOOLS) option(WITH_TESTS "Enable regression tests, and build associated test programs (WARNING: Disable this at your own risk. If a build is not validated with the regression tests, then it is the responsibility of the builder to ensure, via other means, that the build produces mathematically correct results.)" TRUE) boolean_number(WITH_TESTS) if(NOT WITH_TOOLS) set(WITH_TESTS 0) endif() option(WITH_FUZZ "Build fuzz targets" FALSE) option(WITH_PROFILE "Enable low-level JPEG algorithm performance profiling (useful for SIMD module development but not suitable for production)" FALSE) ``` -------------------------------- ### Create Debian package Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Generate a Debian-style binary package for libjpeg-turbo. Requires dpkg. ```bash make deb ``` -------------------------------- ### Configure Static Library Targets Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Sets up static library targets and associated test/tool executables when ENABLE_STATIC is enabled. ```cmake if(ENABLE_STATIC) add_library(turbojpeg-static STATIC ${TURBOJPEG_SOURCES}) if(SPNG_LIBRARY) target_link_libraries(turbojpeg-static ${SPNG_LIBRARY}) endif() if(NOT WITH_SYSTEM_SPNG AND ZLIB_LIBRARY) target_link_libraries(turbojpeg-static ${ZLIB_LIBRARY}) endif() set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS "-DBMP_SUPPORTED -DPNG_SUPPORTED -DSPNG_STATIC -DPPM_SUPPORTED") if(NOT MSVC_LIKE) set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg) endif() if(WITH_TESTS) add_executable(tjunittest-static src/tjunittest.c src/tjutil.c src/md5/md5.c src/md5/md5hl.c) target_link_libraries(tjunittest-static turbojpeg-static) endif() if(WITH_TOOLS) add_executable(tjbench-static src/tjbench.c src/tjutil.c) target_link_libraries(tjbench-static turbojpeg-static) if(UNIX) target_link_libraries(tjbench-static m) endif() endif() endif() ``` -------------------------------- ### jpeg_abort_decompress Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Aborts a decompression cycle, allowing the JPEG object to be reused. This is useful if you need to stop decompression midway and potentially start a new decompression process with the same object. ```APIDOC ## jpeg_abort_decompress ### Description Aborts the current decompression cycle, releasing resources but keeping the JPEG object intact for potential reuse. This is an alternative to `jpeg_destroy_decompress` if you intend to decompress another image. ### Parameters - **cinfo** (*j_decompress_ptr*): Pointer to the decompression structure. ### Notes If you no longer need the JPEG object, `jpeg_destroy_decompress` should be used instead. ``` -------------------------------- ### 64-bit MinGW Toolchain Configuration Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Create a toolchain.cmake file for a 64-bit MinGW build on Un*x systems. Specify system, processor, C compiler, and resource compiler. ```cmake set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR AMD64) set(CMAKE_C_COMPILER {mingw_binary_path}/x86_64-w64-mingw32-gcc) set(CMAKE_RC_COMPILER {mingw_binary_path}/x86_64-w64-mingw32-windres) ``` -------------------------------- ### Decompress libjpeg Fuzzer Target Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/fuzz/CMakeLists.txt Defines the 'decompress_libjpeg_fuzzer' executable target, compiling 'decompress_libjpeg.cc' and linking against the fuzzer library and static JPEG library. It is then installed to the fuzz binary directory. ```cmake add_executable(decompress_libjpeg_fuzzer${FUZZER_SUFFIX} decompress_libjpeg.cc) target_link_libraries(decompress_libjpeg_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY} jpeg-static) install(TARGETS decompress_libjpeg_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION ${FUZZ_BINDIR} COMPONENT bin) ``` -------------------------------- ### Fuzz Target Macro Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/fuzz/CMakeLists.txt A CMake macro to simplify the creation of fuzz target executables. It defines an executable, links it with the fuzzer library and turbojpeg-static, and installs it to the specified fuzz binary directory. ```cmake macro(add_fuzz_target target source_file) add_executable(${target}_fuzzer${FUZZER_SUFFIX} ${source_file}) target_link_libraries(${target}_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY} turbojpeg-static) install(TARGETS ${target}_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION ${FUZZ_BINDIR} COMPONENT bin) endmacro() ``` -------------------------------- ### TurboJPEG Initialization Options Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/turbojpeg/group___turbo_j_p_e_g.html Enumeration for initializing TurboJPEG instances for different operations. ```APIDOC ## Enum TJINIT ### Description Initialization options for `tjInitCompress()`, `tjInitDecompress()`, and `tjInitTransform()`. ### Values - **TJINIT_COMPRESS**: Initialize for compression. - **TJINIT_DECOMPRESS**: Initialize for decompression. - **TJINIT_TRANSFORM**: Initialize for lossless transform. ``` -------------------------------- ### Scan Script Example: Partially Interleaved Sequential JPEG Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/wizard.txt This scan script generates a partially interleaved sequential JPEG file. The first scan includes only Y, and the second includes Cb and Cr. ```text 0; # Y only in first scan 1 2; # Cb and Cr in second scan ``` -------------------------------- ### Configure CMake with ccmake Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Use ccmake for interactive text-based configuration of CMake options. Run this from the build directory after initial configuration. ```bash ccmake {source_directory} ``` -------------------------------- ### Start JPEG Decompression Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Call jpeg_start_decompress to initialize internal state and prepare for returning data. This function may take a while for multi-pass modes. After this call, final output dimensions and colormap information are available. ```c jpeg_start_decompress(&cinfo); ``` -------------------------------- ### Create Linux source RPM package Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Create a Red Hat-style source RPM package from a pristine source tarball. Requires RPM v4 or later. ```bash make srpm ``` -------------------------------- ### Create Tables-Only JPEG File with libjpeg Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Use jpeg_write_tables to generate a JPEG datastream containing only tables (SOI, DQT, DHT, EOI markers). This is done after setting up compression parameters but before starting image compression. ```c jpeg_write_tables(&cinfo); ``` -------------------------------- ### Configure Tools and Documentation Targets Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Defines executable targets for tools and documentation generation when WITH_TOOLS is enabled. ```cmake if(WITH_TOOLS) add_executable(tjbench src/tjbench.c src/tjutil.c) target_link_libraries(tjbench turbojpeg) if(UNIX) target_link_libraries(tjbench m) endif() endif() add_custom_target(tjdoc COMMAND doxygen -s ../doc/doxygen.config WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src) endif() ``` -------------------------------- ### Configure Test Environment and Additional Checksums Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Sets up test environment variables and defines additional MD5 checksums, including conditional logic for floating-point contract settings. ```cmake else() set(cjpeg cjpeg) set(djpeg djpeg) set(jpegtran jpegtran) set(testout testout${suffix}) set(SRCIMG ${TESTIMAGES}/testorig.ppm) set(ext ppm) set(EXT PPM) set(JPEGIMG ${TESTIMAGES}/testorig.jpg) set(MD5_JPEG_RGB_ISLOW 1d44a406f61da743b5fd31c0a9abdca3) set(MD5_JPEG_RGB_ISLOW2 b811e5ad807beb9384e51ef6a47f715d) set(MD5_PPM_RGB_ISLOW 00a257f5393fef8821f2b88ac7421291) set(MD5_BMP_RGB_ISLOW_565 f07d2e75073e4bb10f6c6f4d36e2e3be) set(MD5_BMP_RGB_ISLOW_565D 4cfa0928ef3e6bb626d7728c924cfda4) set(MD5_JPEG_422_IFAST_OPT 2540287b79d913f91665e660303ab2c8) set(MD5_PPM_422_IFAST 35bd6b3f833bad23de82acea847129fa) set(MD5_JPEG_440_ISLOW 538bc02bd4b4658fd85de6ece6cbeda6) set(MD5_PPM_440_ISLOW 11e7eab7ef7ef3276934bb7e7b6bb377) set(MD5_PPM_422M_IFAST 8dbc65323d62cca7c91ba02dd1cfa81d) set(MD5_BMP_422M_IFAST_565 3294bd4d9a1f2b3d08ea6020d0db7065) set(MD5_BMP_422M_IFAST_565D da98c9c7b6039511be4a79a878a9abc1) set(MD5_JPEG_420_IFAST_Q100_PROG 0ba15f9dab81a703505f835f9dbbac6d) set(MD5_PPM_420_Q100_IFAST 5a732542015c278ff43635e473a8a294) set(MD5_PPM_420M_Q100_IFAST ff692ee9323a3b424894862557c092f1) set(MD5_JPEG_GRAY_ISLOW 72b51f894b8f4a10b3ee3066770aa38d) set(MD5_PPM_GRAY_ISLOW 8d3596c56eace32f205deccc229aa5ed) set(MD5_PPM_GRAY_ISLOW_RGB 116424ac07b79e5e801f00508eab48ec) set(MD5_BMP_GRAY_ISLOW_565 12f78118e56a2f48b966f792fedf23cc) set(MD5_BMP_GRAY_ISLOW_565D bdbbd616441a24354c98553df5dc82db) set(MD5_JPEG_420S_ISLOW_OPT 388708217ac46273ca33086b22827ed8) set(MD5_JPEG_3x2_FLOAT_PROG_SSE 343e3f8caf8af5986ebaf0bdc13b5c71) set(MD5_PPM_3x2_FLOAT_SSE 1a75f36e5904d6fc3a85a43da9ad89bb) set(MD5_JPEG_3x2_FLOAT_PROG_NO_FP_CONTRACT 9bca803d2042bd1eb03819e2bf92b3e5) set(MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT f6bfab038438ed8f5522fbd33595dcdc) set(MD5_JPEG_3x2_FLOAT_PROG_FP_CONTRACT ${MD5_JPEG_3x2_FLOAT_PROG_NO_FP_CONTRACT}) if(CMAKE_C_COMPILER_ID MATCHES "Clang") set(MD5_PPM_3x2_FLOAT_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT}) else() set(MD5_PPM_3x2_FLOAT_FP_CONTRACT 0e917a34193ef976b679a6b069b1be26) endif() set(MD5_JPEG_3x2_FLOAT_PROG_387 1657664a410e0822c924b54f6f65e6e9) set(MD5_PPM_3x2_FLOAT_387 cb0a1f027f3d2917c902b5640214e025) set(MD5_JPEG_3x2_FLOAT_PROG_MSVC 7999ce9cd0ee9b6c7043b7351ab7639d) set(MD5_PPM_3x2_FLOAT_MSVC 28cdc448a6b75e97892f0e0f8d4b21f3) ``` -------------------------------- ### Aborting and Restarting Display Pass Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt If a significant amount of data arrives before a display pass can be completed, you can abort the current pass and start a new one with the updated information. This is detected by checking the return code of jpeg_consume_input() or jpeg_input_complete(). ```c jpeg_finish_output() and then start a new pass with jpeg_start_output() ``` -------------------------------- ### Run libjpeg-turbo Regression Tests (Windows NMake) Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/BUILDING.md Execute this command in a Windows command prompt to run the standard regression tests. This verifies mathematical compatibility with libjpeg v6b and TurboJPEG API functionality. ```batch nmake test ``` -------------------------------- ### jpeg_read_header Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/doc/libjpeg.txt Reads the header of a JPEG image to obtain image dimensions and other information. This function should be called before setting decompression parameters or starting decompression. It's important to note that default decompression parameters are set by each call to jpeg_read_header(). ```APIDOC ## jpeg_read_header ### Description Reads the JPEG datastream header markers up to the beginning of the compressed data. On return, image dimensions and other information are stored in the JPEG object. This information can be consulted before selecting decompression parameters. ### Parameters - `cinfo` (struct jpeg_decompress_struct *) - A pointer to the decompression structure. - `require_image` (boolean) - If TRUE, an error is raised if the file is not a valid JPEG file. ### Request Example ```c jpeg_read_header(&cinfo, TRUE); ``` ### Response On return, the `cinfo` structure is updated with image information such as dimensions, colorspace, etc. ``` -------------------------------- ### Include Package Information Source: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/CMakeLists.txt Loads additional package configuration scripts. ```cmake include(cmakescripts/PackageInfo.cmake) ```