| Summary: | SDL_LockTexture returns a wrong pitch for format NV21 and streaming textures | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Michele Caini <michele.caini> |
| Component: | render | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 2.0.7 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
|
Description
Michele Caini
2018-01-03 18:10:45 UTC
The pitch is the amount to offset a pointer to the beginning of a row of pixels to get to the next row of pixels. For NV12 and NV21 you need to go width bytes to get to the next row. The format is special in that there is additional data at the end of the Y plane for chroma, but the meaning of pitch is the same and is correct. Uhm. It sounds confusing actually. On Android, the pitch of an NV21 image grabbed from the camera is 1.5 times the width. That's how I spotted the difference in SDL. That's because it considers 12 bits per pixel as a whole probably and not w*h plus two planes at the end. That being said, in SDL one cannot use pitch*h to know the size of the storage pointed by the returned void pointer when using an opaque texture with SDL_LockTexture. How should I do to know the actual size of the storage thus? Pitch * h is only valid for single plane formats. For multi-plane formats you'll need to know the format in order to know the size of the storage. Do you have code that needs to know how big the storage is but doesn't know how to interpret the pixel data? Keep in mind that the pitch could actually be different from the width, e.g. for images with row alignment restrictions or odd widths. I'm grabbing frames from the android camera and rendering some of them on a streaming texture. The idea was to separate the two layers and use opaque textures on which to memcopy pixels with no reasoning at all in the specific system. However, I can push down the size of the image somehow, not a problem actually. Honestly, I was now curious to understand how things work under the hood. This "issue" gave me the chance to dig into the code of SDL and it's interesting, but I've not (yet?) the skills to fully understand everything. Thank you for your help and answers, really appreciated. Keep on working on SDL for it's really an amazing library. Chapeau. You're welcome! It might help to think about the pitch as the distance in bytes from one row of pixels in an image to the next row of pixels. SDL started out only supporting single plane images and adding YUV formats was done later. That's why you'll see libraries that specifically deal with YUV formats will often have a pitch for each plane, as they may be different, and it's best not to make assumptions. Cheers! |