﻿# rocJPEG output buffers: channel pitch follows the selected layout, not image width alone

Allocate rocJPEG destinations from parsed component metadata and requested planar, interleaved or native layout, preserving each channel pitch for downstream GPU readers.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-rocjpeg-output-layout-channel-pitch-not-image-width/
Language: en

## Begin with parsed component metadata

An image loader assumes every decoded JPEG becomes a tightly packed color image and allocates from full-image dimensions alone. Native output can instead preserve a subsampled layout, and planar color output separates channels. The [image-information guide](https://rocm.docs.amd.com/projects/rocJPEG/en/latest/how-to/rocjpeg-retrieve-image-info.html) documents retrieving components, subsampling and their extents. Retain those results with the requested output format before constructing destination buffers or passing storage to a downstream GPU kernel.

## Treat output selection as a layout contract

The [decoding guide](https://rocm.docs.amd.com/projects/rocJPEG/en/latest/how-to/rocjpeg-decoding-a-jpeg-stream.html) distinguishes native, luma-only, planar and interleaved outputs. The number and arrangement of destination channels follow that selection and, for native output, the source subsampling. A pointer to the first channel does not automatically describe every other channel or imply that the next pixel is laid out as the downstream model expects. Preserve the channel arrangement explicitly at the interface boundary.

## Keep pitch separate from logical width

The destination descriptor carries channel pointers and pitches. Allocate each required channel with its supported shape and row stride, then carry that stride into consumers instead of reconstructing it from the image width. A correct allocation can still be read incorrectly when a preprocessing kernel ignores its layout. Test the interface using visibly distinct channel values so that an accidental planar-versus-interleaved interpretation cannot hide behind a nearly uniform image.

## Check support before interpreting a failed decode

The [format and architecture reference](https://rocm.docs.amd.com/projects/rocJPEG/en/latest/reference/rocjpeg-formats-and-architectures.html) describes supported subsampling and hardware capabilities. Parsed input metadata is not proof that the selected decoder configuration can process that input. Preserve failure status separately from allocation errors and from a successful decode with incorrectly interpreted output. Avoid silently changing the requested layout without updating the consumer's expectation and associated diagnostic record.

## Validate batches per destination image

A batch can contain different component shapes, so build and verify every destination descriptor against its own image metadata and selected format. Do not reuse the first image's allocation assumptions merely because the decoder call accepts an array. The existing [image-coordinate guide](/journal/data-guide-image-exif-box-coordinate/) and [byte-pitch guide](/journal/guide-perf-memcpy2d-byte-pitch/) provide context. A useful decoding contract preserves per-image format, component extents, channel arrangement and pitch, keeping decode success distinct from correctly delivered model pixels.
