### Manage Memory Buffers with PKAlloc and PKAllocAligned Source: https://context7.com/4creators/jxrlib/llms.txt Provides examples for standard and SIMD-aligned memory allocation within JXRLib. It highlights the use of PKAlloc/PKFree for general buffers and PKAllocAligned/PKFreeAligned for performance-critical cache-aligned memory. ```c #include int memory_example() { ERR err = WMP_errSuccess; void* pBuffer = NULL; size_t bufferSize = 1024 * 1024; err = PKAlloc(&pBuffer, bufferSize); if (err == WMP_errSuccess) { PKFree(&pBuffer); } void* pAlignedBuffer = NULL; size_t alignment = 128; err = PKAllocAligned(&pAlignedBuffer, bufferSize, alignment); if (err == WMP_errSuccess) { PKFreeAligned(&pAlignedBuffer); } return 0; } ``` -------------------------------- ### Query Pixel Format Information with PixelFormatLookup Source: https://context7.com/4creators/jxrlib/llms.txt Demonstrates how to use PixelFormatLookup to retrieve metadata for a given pixel format GUID and perform reverse lookups using TIFF parameters. It extracts details like bit depth, channel count, and alpha channel presence. ```c #include void print_pixel_format_info(PKPixelFormatGUID* pGUID) { PKPixelInfo PI = {0}; PI.pGUIDPixFmt = pGUID; ERR err = PixelFormatLookup(&PI, LOOKUP_FORWARD); if (err == WMP_errSuccess) { printf("Channels: %zu\n", PI.cChannel); printf("Bit depth: %d\n", PI.bdBitDepth); printf("Bits per unit: %u\n", PI.cbitUnit); printf("Has alpha: %s\n", (PI.grBit & PK_pixfmtHasAlpha) ? "yes" : "no"); printf("Premultiplied: %s\n", (PI.grBit & PK_pixfmtPreMul) ? "yes" : "no"); printf("BGR order: %s\n", (PI.grBit & PK_pixfmtBGR) ? "yes" : "no"); printf("Photometric interpretation: %u\n", PI.uInterpretation); printf("Samples per pixel: %u\n", PI.uSamplePerPixel); printf("Bits per sample: %u\n", PI.uBitsPerSample); printf("Sample format: %u\n", PI.uSampleFormat); } } ``` -------------------------------- ### PixelFormatLookup - Query Pixel Format Information Source: https://context7.com/4creators/jxrlib/llms.txt Look up detailed information about supported pixel formats including bit depth, channel count, and TIFF compatibility. This function allows for both forward lookup (GUID to pixel info) and backward lookup (TIFF parameters to GUID). ```APIDOC ## PixelFormatLookup - Query Pixel Format Information ### Description Look up detailed information about supported pixel formats including bit depth, channel count, and TIFF compatibility. ### Method N/A (This is a library function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Input Structure (PKPixelInfo) - **pGUIDPixFmt** (PKPixelFormatGUID*) - Input for forward lookup, output for backward lookup - Pointer to a GUID structure. - **cChannel** (size_t) - Output - Number of color channels. - **bdBitDepth** (int) - Output - Bit depth per channel. - **cbitUnit** (unsigned int) - Output - Bits per pixel unit. - **grBit** (unsigned int) - Output - Pixel format flags (e.g., PK_pixfmtHasAlpha, PK_pixfmtPreMul, PK_pixfmtBGR). - **uInterpretation** (unsigned int) - Input for backward lookup, output for forward lookup - TIFF photometric interpretation. - **uSamplePerPixel** (unsigned int) - Input for backward lookup, output for forward lookup - Number of samples per pixel. - **uBitsPerSample** (unsigned int) - Input for backward lookup, output for forward lookup - Bits per sample. - **uSampleFormat** (unsigned int) - Input for backward lookup, output for forward lookup - Sample format. #### Lookup Type (Enum) - **LOOKUP_FORWARD**: GUID to pixel info. - **LOOKUP_BACKWARD_TIF**: TIFF parameters to GUID. ### Request Example ```c #include void print_pixel_format_info(PKPixelFormatGUID* pGUID) { PKPixelInfo PI = {0}; PI.pGUIDPixFmt = pGUID; // Forward lookup: GUID -> pixel info ERR err = PixelFormatLookup(&PI, LOOKUP_FORWARD); if (err == WMP_errSuccess) { printf("Channels: %zu\n", PI.cChannel); printf("Bit depth: %d\n", PI.bdBitDepth); printf("Bits per unit: %u\n", PI.cbitUnit); printf("Has alpha: %s\n", (PI.grBit & PK_pixfmtHasAlpha) ? "yes" : "no"); printf("Premultiplied: %s\n", (PI.grBit & PK_pixfmtPreMul) ? "yes" : "no"); printf("BGR order: %s\n", (PI.grBit & PK_pixfmtBGR) ? "yes" : "no"); // TIFF-related info printf("Photometric interpretation: %u\n", PI.uInterpretation); printf("Samples per pixel: %u\n", PI.uSamplePerPixel); printf("Bits per sample: %u\n", PI.uBitsPerSample); printf("Sample format: %u\n", PI.uSampleFormat); } } int main() { // Common pixel formats printf("=== 24bppRGB ===\n"); PKPixelFormatGUID rgb24 = GUID_PKPixelFormat24bppRGB; print_pixel_format_info(&rgb24); printf("\n=== 32bppBGRA ===\n"); PKPixelFormatGUID bgra32 = GUID_PKPixelFormat32bppBGRA; print_pixel_format_info(&bgra32); printf("\n=== 128bppRGBAFloat ===\n"); PKPixelFormatGUID rgba128f = GUID_PKPixelFormat128bppRGBAFloat; print_pixel_format_info(&rgba128f); printf("\n=== 8bppGray ===\n"); PKPixelFormatGUID gray8 = GUID_PKPixelFormat8bppGray; print_pixel_format_info(&gray8); // Backward lookup: TIFF params -> GUID PKPixelInfo tiffPI = {0}; tiffPI.uSamplePerPixel = 3; tiffPI.uBitsPerSample = 8; tiffPI.uSampleFormat = 1; tiffPI.uInterpretation = 2; // RGB tiffPI.grBit = 0; ERR err = PixelFormatLookup(&tiffPI, LOOKUP_BACKWARD_TIF); if (err == WMP_errSuccess) { printf("\nTIFF lookup found matching format\n"); } return 0; } ``` ### Response #### Success Response (WMP_errSuccess) - **PKPixelInfo** (struct) - Populated with pixel format details. #### Response Example ```json { "Channels": 3, "Bit depth": 8, "Bits per unit": 24, "Has alpha": "no", "Premultiplied": "no", "BGR order": "yes", "Photometric interpretation": 2, "Samples per pixel": 3, "Bits per sample": 8, "Sample format": 1 } ``` ``` -------------------------------- ### Map Pixel Format Codes to C API GUIDs Source: https://context7.com/4creators/jxrlib/llms.txt This snippet demonstrates how to map integer pixel format codes to their corresponding PKPixelFormatGUID pointers used within the jxrlib C API. It serves as a lookup reference for developers implementing image processing pipelines. ```c const PKPixelFormatGUID* pixelFormats[] = { &GUID_PKPixelFormat24bppBGR, // 0 &GUID_PKPixelFormatBlackWhite, // 1 &GUID_PKPixelFormat8bppGray, // 2 &GUID_PKPixelFormat16bppGray, // 3 // ... and so on }; ``` -------------------------------- ### Create Codec Factory with PKCreateCodecFactory Source: https://context7.com/4creators/jxrlib/llms.txt Initializes a factory object for creating JPEG XR encoders and decoders. It takes the SDK version and returns a codec factory pointer. This factory can then be used to create specific codecs (encoder, decoder) and format converters. ```c #include int main() { ERR err = WMP_errSuccess; PKCodecFactory* pCodecFactory = NULL; PKImageEncode* pEncoder = NULL; PKImageDecode* pDecoder = NULL; // Create codec factory err = PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION); if (err != WMP_errSuccess) { printf("Failed to create codec factory: %d\n", err); return 1; } // Create JPEG XR encoder err = pCodecFactory->CreateCodec(&IID_PKImageWmpEncode, (void**)&pEncoder); if (err != WMP_errSuccess) { printf("Failed to create encoder: %d\n", err); pCodecFactory->Release(&pCodecFactory); return 1; } // Create decoder from file (convenience method) err = pCodecFactory->CreateDecoderFromFile("input.jxr", &pDecoder); if (err != WMP_errSuccess) { printf("Failed to create decoder: %d\n", err); } // Create format converter for pixel format conversion PKFormatConverter* pConverter = NULL; err = pCodecFactory->CreateFormatConverter(&pConverter); // Cleanup if (pEncoder) pEncoder->Release(&pEncoder); if (pDecoder) pDecoder->Release(&pDecoder); if (pConverter) pConverter->Release(&pConverter); pCodecFactory->Release(&pCodecFactory); return 0; } ``` -------------------------------- ### Create Stream Factory with PKCreateFactory Source: https://context7.com/4creators/jxrlib/llms.txt Initializes a factory object for managing file and memory streams. It requires the SDK version and returns a factory pointer. This factory can then be used to create various stream types, including file streams for reading/writing and memory streams. ```c #include int main() { ERR err = WMP_errSuccess; PKFactory* pFactory = NULL; struct WMPStream* pStream = NULL; // Create factory with SDK version err = PKCreateFactory(&pFactory, PK_SDK_VERSION); if (err != WMP_errSuccess) { printf("Failed to create factory: %d\n", err); return 1; } // Create file stream for writing err = pFactory->CreateStreamFromFilename(&pStream, "output.jxr", "wb"); if (err != WMP_errSuccess) { printf("Failed to create stream: %d\n", err); pFactory->Release(&pFactory); return 1; } // Use stream for encoding... // Create file stream for reading struct WMPStream* pReadStream = NULL; err = pFactory->CreateStreamFromFilename(&pReadStream, "input.jxr", "rb"); // Create memory stream struct WMPStream* pMemStream = NULL; U8 buffer[1024 * 1024]; // 1MB buffer err = pFactory->CreateStreamFromMemory(&pMemStream, buffer, sizeof(buffer)); // Cleanup pFactory->Release(&pFactory); return 0; } ``` -------------------------------- ### Command-Line Pixel Format Configuration Source: https://context7.com/4creators/jxrlib/llms.txt Reference for pixel format codes used with the -c command-line option in jxrlib. ```APIDOC ## Supported Pixel Formats ### Description This reference table lists the pixel format codes used for the -c command-line option when processing JPEG XR images. ### Parameters #### Query Parameters - **-c** (integer) - Required - The pixel format code as defined in the reference table (e.g., 0 for 24bppBGR, 15 for 128bppRGBFloat). ### Reference Table | Code | Format Name | Bits | Channels | Description | | :--- | :--- | :--- | :--- | :--- | | 0 | 24bppBGR | 24 | 3 | BGR (BMP default) | | 1 | 1bppBlackWhite | 1 | 1 | Monochrome | | 2 | 8bppGray | 8 | 1 | Grayscale | | 15 | 128bppRGBFloat | 128 | 3 | Float RGB (HDR) | | 28 | 128bppRGBAFloat | 128 | 4 | Float RGBA (HDR) | ### Usage Example `jxrlib_tool -c 15 input.jxr output.bmp` ``` -------------------------------- ### Convert Pixel Format with PKFormatConverter Source: https://context7.com/4creators/jxrlib/llms.txt Illustrates using the PKFormatConverter API to convert pixel formats between different image representations. This is useful during encoding or decoding operations to ensure compatibility. ```c #include int convert_pixel_format() { ERR err = WMP_errSuccess; PKCodecFactory* pCodecFactory = NULL; PKImageDecode* pDecoder = NULL; PKFormatConverter* pConverter = NULL; Call(PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION)); // Load image Call(pCodecFactory->CreateDecoderFromFile("input.jxr", &pDecoder)); // Create converter Call(pCodecFactory->CreateFormatConverter(&pConverter)); // Initialize with target pixel format (24bppRGB) Call(pConverter->Initialize(pConverter, pDecoder, ".bmp", GUID_PKPixelFormat24bppRGB)); // Get converted pixel format info PKPixelFormatGUID targetFormat, sourceFormat; Call(pConverter->GetPixelFormat(pConverter, &targetFormat)); Call(pConverter->GetSourcePixelFormat(pConverter, &sourceFormat)); // Get converted image size I32 width, height; Call(pConverter->GetSize(pConverter, &width, &height)); // Get resolution Float resX, resY; Call(pConverter->GetResolution(pConverter, &resX, &resY)); // Copy with format conversion U32 cbStride = width * 3; // 24bpp = 3 bytes per pixel U8* pbPixels = NULL; Call(PKAllocAligned((void**)&pbPixels, cbStride * height, 128)); PKRect rect = {0, 0, width, height}; Call(pConverter->Copy(pConverter, &rect, pbPixels, cbStride)); // Enumerate available format conversions const PKPixelFormatGUID* pTargetFormat; for (U32 i = 0; ; i++) { err = PKFormatConverter_EnumConversions(&sourceFormat, i, &pTargetFormat); if (err != WMP_errSuccess) break; // pTargetFormat is a valid conversion target } Cleanup: PKFreeAligned((void**)&pbPixels); if (pConverter) pConverter->Release(&pConverter); if (pDecoder) pDecoder->Release(&pDecoder); if (pCodecFactory) pCodecFactory->Release(&pCodecFactory); return (int)err; } ``` -------------------------------- ### Encode Image to JPEG XR (C) Source: https://context7.com/4creators/jxrlib/llms.txt This C function demonstrates how to use the PKImageEncode API to encode an image file into the JPEG XR format. It handles initialization of the encoder, setting compression parameters, loading the source image, performing format conversion, and writing the encoded output. The quality of the compression can be adjusted. ```c #include int encode_image(const char* inputFile, const char* outputFile, float quality) { ERR err = WMP_errSuccess; PKFactory* pFactory = NULL; PKCodecFactory* pCodecFactory = NULL; PKImageEncode* pEncoder = NULL; PKImageDecode* pDecoder = NULL; PKFormatConverter* pConverter = NULL; struct WMPStream* pOutputStream = NULL; // Initialize factories Call(PKCreateFactory(&pFactory, PK_SDK_VERSION)); Call(PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION)); // Create output stream Call(pFactory->CreateStreamFromFilename(&pOutputStream, outputFile, "wb")); // Create encoder with codec parameters CWMIStrCodecParam wmiSCP = {0}; wmiSCP.bVerbose = FALSE; wmiSCP.cfColorFormat = YUV_444; // Chroma format wmiSCP.bdBitDepth = BD_LONG; wmiSCP.bfBitstreamFormat = FREQUENCY; // Frequency mode for progressive wmiSCP.bProgressiveMode = TRUE; wmiSCP.olOverlap = OL_ONE; // One level overlap wmiSCP.uiDefaultQPIndex = 1; // Quantization (1 = lossless) Call(pCodecFactory->CreateCodec(&IID_PKImageWmpEncode, (void**)&pEncoder)); Call(pEncoder->Initialize(pEncoder, pOutputStream, &wmiSCP, sizeof(wmiSCP))); // Load source image (BMP/TIFF decoder) Call(pCodecFactory->CreateDecoderFromFile(inputFile, &pDecoder)); // Get source image properties I32 width, height; Float resX, resY; PKPixelFormatGUID pixelFormat; Call(pDecoder->GetSize(pDecoder, &width, &height)); Call(pDecoder->GetResolution(pDecoder, &resX, &resY)); Call(pDecoder->GetPixelFormat(pDecoder, &pixelFormat)); // Create format converter Call(pCodecFactory->CreateFormatConverter(&pConverter)); Call(pConverter->Initialize(pConverter, pDecoder, ".jxr", pixelFormat)); // Configure encoder Call(pEncoder->SetPixelFormat(pEncoder, pixelFormat)); Call(pEncoder->SetSize(pEncoder, width, height)); Call(pEncoder->SetResolution(pEncoder, resX, resY)); // Set quality-based quantization if (quality < 1.0f) { pEncoder->WMP.wmiSCP.uiDefaultQPIndex = (U8)(1 + (1.0f - quality) * 254); } // Encode image PKRect rect = {0, 0, width, height}; pEncoder->WriteSource = PKImageEncode_WriteSource; Call(pEncoder->WriteSource(pEncoder, pConverter, &rect)); Cleanup: if (pConverter) pConverter->Release(&pConverter); if (pDecoder) pDecoder->Release(&pDecoder); if (pEncoder) pEncoder->Release(&pEncoder); if (pCodecFactory) pCodecFactory->Release(&pCodecFactory); if (pFactory) pFactory->Release(&pFactory); return (int)err; } ``` -------------------------------- ### Decode JPEG XR Image with PKImageDecode Source: https://context7.com/4creators/jxrlib/llms.txt Demonstrates high-level decoding of JPEG XR images using the PKImageDecode API. Supports region decoding and thumbnail extraction. It takes an input file path and an output file path as arguments. ```c #include int decode_image(const char* inputFile, const char* outputFile) { ERR err = WMP_errSuccess; PKFactory* pFactory = NULL; PKCodecFactory* pCodecFactory = NULL; PKImageDecode* pDecoder = NULL; PKImageEncode* pOutputEncoder = NULL; PKFormatConverter* pConverter = NULL; struct WMPStream* pOutputStream = NULL; // Initialize factories Call(PKCreateFactory(&pFactory, PK_SDK_VERSION)); Call(PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION)); // Create decoder from JPEG XR file Call(pCodecFactory->CreateDecoderFromFile(inputFile, &pDecoder)); // Get image properties I32 width, height; Float resX, resY; PKPixelFormatGUID pixelFormat; Call(pDecoder->GetSize(pDecoder, &width, &height)); Call(pDecoder->GetResolution(pDecoder, &resX, &resY)); Call(pDecoder->GetPixelFormat(pDecoder, &pixelFormat)); printf("Image size: %d x %d\n", width, height); printf("Resolution: %.2f x %.2f DPI\n", resX, resY); // Configure decoder for region decode (optional) pDecoder->WMP.wmiI.cROILeftX = 0; pDecoder->WMP.wmiI.cROITopY = 0; pDecoder->WMP.wmiI.cROIWidth = width; pDecoder->WMP.wmiI.cROIHeight = height; // Configure thumbnail decode (optional) // 0 = full, 2 = 1/4, 4 = 1/16 pDecoder->WMP.wmiI.cThumbnailWidth = width; pDecoder->WMP.wmiI.cThumbnailHeight = height; // Configure alpha mode (0 = no alpha, 1 = alpha only, 2 = image + alpha) pDecoder->WMP.wmiSCP.uAlphaMode = 2; // Create format converter for output Call(pCodecFactory->CreateFormatConverter(&pConverter)); Call(pConverter->Initialize(pConverter, pDecoder, ".bmp", pixelFormat)); // Allocate output buffer and decode U32 cbStride = ((width * 24 + 7) >> 3); // 24bpp stride U8* pbPixels = NULL; Call(PKAllocAligned((void**)&pbPixels, cbStride * height, 128)); PKRect rect = {0, 0, width, height}; Call(pConverter->Copy(pConverter, &rect, pbPixels, cbStride)); // Output pixels are now in pbPixels buffer // Save to file or process as needed... Cleanup: PKFreeAligned((void**)&pbPixels); if (pConverter) pConverter->Release(&pConverter); if (pDecoder) pDecoder->Release(&pDecoder); if (pCodecFactory) pCodecFactory->Release(&pCodecFactory); if (pFactory) pFactory->Release(&pFactory); return (int)err; } ``` -------------------------------- ### Memory Management Functions Source: https://context7.com/4creators/jxrlib/llms.txt Functions for allocating and freeing memory for image buffers. Supports standard allocation and aligned allocation for SIMD operations. ```APIDOC ## Memory Management Functions ### Description Allocate and free memory for image buffers with optional alignment for SIMD operations. ### Method N/A (This is a library function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### PKAlloc - **pBuffer** (void**) - Output - Pointer to the allocated buffer. - **bufferSize** (size_t) - Input - The size of the buffer to allocate in bytes. #### PKFree - **pBuffer** (void**) - Input/Output - Pointer to the buffer to free. Will be set to NULL after freeing. #### PKAllocAligned - **pBuffer** (void**) - Output - Pointer to the allocated aligned buffer. - **bufferSize** (size_t) - Input - The size of the buffer to allocate in bytes. - **alignment** (size_t) - Input - The required alignment in bytes. #### PKFreeAligned - **pBuffer** (void**) - Input/Output - Pointer to the aligned buffer to free. Will be set to NULL after freeing. ### Request Example ```c #include int memory_example() { ERR err = WMP_errSuccess; // Standard allocation (calloc-based, zero-initialized) void* pBuffer = NULL; size_t bufferSize = 1024 * 1024; // 1MB err = PKAlloc(&pBuffer, bufferSize); if (err != WMP_errSuccess) { printf("Allocation failed\n"); return 1; } // Use buffer... memset(pBuffer, 0xFF, bufferSize); // Free standard allocation PKFree(&pBuffer); // pBuffer is set to NULL // Aligned allocation (for SIMD operations) void* pAlignedBuffer = NULL; size_t alignment = 128; // 128-byte alignment for cache lines err = PKAllocAligned(&pAlignedBuffer, bufferSize, alignment); if (err != WMP_errSuccess) { printf("Aligned allocation failed\n"); return 1; } // Verify alignment if (((size_t)pAlignedBuffer % alignment) == 0) { printf("Buffer is properly aligned to %zu bytes\n", alignment); } // Free aligned allocation PKFreeAligned(&pAlignedBuffer); // pAlignedBuffer is set to NULL return 0; } ``` ### Response #### Success Response (WMP_errSuccess) - **pBuffer** (void*) - Pointer to the allocated memory. - **pAlignedBuffer** (void*) - Pointer to the allocated aligned memory. #### Response Example ```json { "message": "Memory allocated successfully." } ``` ``` -------------------------------- ### PKFormatConverter - Pixel Format Conversion Source: https://context7.com/4creators/jxrlib/llms.txt Convert between different pixel formats during encoding or decoding operations. ```APIDOC ## PKFormatConverter - Pixel Format Conversion ### Description Convert between different pixel formats during encoding or decoding operations. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters Not applicable (C function parameters) ### Request Example ```c #include int convert_pixel_format() { ERR err = WMP_errSuccess; PKCodecFactory* pCodecFactory = NULL; PKImageDecode* pDecoder = NULL; PKFormatConverter* pConverter = NULL; Call(PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION)); // Load image Call(pCodecFactory->CreateDecoderFromFile("input.jxr", &pDecoder)); // Create converter Call(pCodecFactory->CreateFormatConverter(&pConverter)); // Initialize with target pixel format (24bppRGB) Call(pConverter->Initialize(pConverter, pDecoder, ".bmp", GUID_PKPixelFormat24bppRGB)); // Get converted pixel format info PKPixelFormatGUID targetFormat, sourceFormat; Call(pConverter->GetPixelFormat(pConverter, &targetFormat)); Call(pConverter->GetSourcePixelFormat(pConverter, &sourceFormat)); // Get converted image size I32 width, height; Call(pConverter->GetSize(pConverter, &width, &height)); // Get resolution Float resX, resY; Call(pConverter->GetResolution(pConverter, &resX, &resY)); // Copy with format conversion U32 cbStride = width * 3; // 24bpp = 3 bytes per pixel U8* pbPixels = NULL; Call(PKAllocAligned((void**)&pbPixels, cbStride * height, 128)); PKRect rect = {0, 0, width, height}; Call(pConverter->Copy(pConverter, &rect, pbPixels, cbStride)); // Enumerate available format conversions const PKPixelFormatGUID* pTargetFormat; for (U32 i = 0; ; i++) { err = PKFormatConverter_EnumConversions(&sourceFormat, i, &pTargetFormat); if (err != WMP_errSuccess) break; // pTargetFormat is a valid conversion target } Cleanup: PKFreeAligned((void**)&pbPixels); if (pConverter) pConverter->Release(&pConverter); if (pDecoder) pDecoder->Release(&pDecoder); if (pCodecFactory) pCodecFactory->Release(&pCodecFactory); return (int)err; } ``` ### Response Not applicable (C function returns an error code) #### Success Response (0) Indicates successful execution. #### Response Example ``` 0 ``` ``` -------------------------------- ### PKImageDecode - Decode JPEG XR Images Source: https://context7.com/4creators/jxrlib/llms.txt High-level decoder API for reading JPEG XR images with support for region decoding and thumbnails. ```APIDOC ## PKImageDecode - Decode JPEG XR Images ### Description High-level decoder API for reading JPEG XR images with support for region decoding and thumbnails. ### Method Not applicable (C function) ### Endpoint Not applicable (C function) ### Parameters Not applicable (C function parameters) ### Request Example ```c #include int decode_image(const char* inputFile, const char* outputFile) { ERR err = WMP_errSuccess; PKFactory* pFactory = NULL; PKCodecFactory* pCodecFactory = NULL; PKImageDecode* pDecoder = NULL; PKImageEncode* pOutputEncoder = NULL; PKFormatConverter* pConverter = NULL; struct WMPStream* pOutputStream = NULL; // Initialize factories Call(PKCreateFactory(&pFactory, PK_SDK_VERSION)); Call(PKCreateCodecFactory(&pCodecFactory, WMP_SDK_VERSION)); // Create decoder from JPEG XR file Call(pCodecFactory->CreateDecoderFromFile(inputFile, &pDecoder)); // Get image properties I32 width, height; Float resX, resY; PKPixelFormatGUID pixelFormat; Call(pDecoder->GetSize(pDecoder, &width, &height)); Call(pDecoder->GetResolution(pDecoder, &resX, &resY)); Call(pDecoder->GetPixelFormat(pDecoder, &pixelFormat)); printf("Image size: %d x %d\n", width, height); printf("Resolution: %.2f x %.2f DPI\n", resX, resY); // Configure decoder for region decode (optional) pDecoder->WMP.wmiI.cROILeftX = 0; pDecoder->WMP.wmiI.cROITopY = 0; pDecoder->WMP.wmiI.cROIWidth = width; pDecoder->WMP.wmiI.cROIHeight = height; // Configure thumbnail decode (optional) // 0 = full, 2 = 1/4, 4 = 1/16 pDecoder->WMP.wmiI.cThumbnailWidth = width; pDecoder->WMP.wmiI.cThumbnailHeight = height; // Configure alpha mode (0 = no alpha, 1 = alpha only, 2 = image + alpha) pDecoder->WMP.wmiSCP.uAlphaMode = 2; // Create format converter for output Call(pCodecFactory->CreateFormatConverter(&pConverter)); Call(pConverter->Initialize(pConverter, pDecoder, ".bmp", pixelFormat)); // Allocate output buffer and decode U32 cbStride = ((width * 24 + 7) >> 3); // 24bpp stride U8* pbPixels = NULL; Call(PKAllocAligned((void**)&pbPixels, cbStride * height, 128)); PKRect rect = {0, 0, width, height}; Call(pConverter->Copy(pConverter, &rect, pbPixels, cbStride)); // Output pixels are now in pbPixels buffer // Save to file or process as needed... Cleanup: PKFreeAligned((void**)&pbPixels); if (pConverter) pConverter->Release(&pConverter); if (pDecoder) pDecoder->Release(&pDecoder); if (pCodecFactory) pCodecFactory->Release(&pCodecFactory); if (pFactory) pFactory->Release(&pFactory); return (int)err; } ``` ### Response Not applicable (C function returns an error code) #### Success Response (0) Indicates successful execution. #### Response Example ``` 0 ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.