[FFmpeg-devel] [PATCH v10 4/6] libavcodec/dnxucdec: DNxUncompressed decoder
Michael Niedermayer
michael at niedermayer.cc
Wed Oct 9 19:13:21 EEST 2024
On Fri, Oct 04, 2024 at 11:07:33PM +0200, Martin Schitter wrote:
[...]
> +static int half_add_alpha(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
> +{
> + /* ffmpeg doesn't provide RGB half bit depth without alpha channel right now
> + * we simply add an opaque alpha layer as workaround */
> +
> + int lw;
> + const size_t soh = 2;
> + const uint16_t opaque = 0x3c00;
> +
> + lw = frame->width;
> +
> + for(int y = 0; y < frame->height; y++){
> + for(int x = 0; x < frame->width; x++){
> + memcpy(&frame->data[0][soh*4*(lw*y + x)], &pkt->data[soh*3*(lw*y + x)], soh*3);
> + memcpy(&frame->data[0][soh*(4*(lw*y + x) + 3)], &opaque, soh);
opaque is in native byte order within 16bit, pkt->data is a byte array
copying them together cannot be right
also as this is a LE pixfmt, the 2nd part should be wrong
> + }
> + }
> + return pkt->size;
> +}
> +
> +/* DNxUncompressed utilizes a very dense bitpack representation of 10bit and 12bit pixel data.
> +
> +Lines of Image data, which look like in their ordinary 8bit counterpart, contain the most
> +significant upper bits of the pixel data. These sections alternate with shorter segments in
> +which the complementary least significant bits of information get packed in a gapless sequence.
> +
> ++----------------------+ +----------------------+ +------------------------+ +----------~
> +| 8 m.s.bits of R[1] | | 8 m.s.bits of G[1] | | 8 m.s.bits of B[1] | | msb R[2] ... one line
> ++----------------------+ +----------------------+ +------------------------+ +----------~
> +
> ++---------------------------------------------------------------+ +-----------~
> +| +------------+ +------------+ +------------+ +--------------+ | | +--------~
> +| | 2 lsb R[2] | | 2 lsb B[1] | | 2 lsb G[1] | | 2 lsb R[1] | | | | G[3]lsb ... LSB bits for line
> +| +------------+ +------------+ +------------+ +--------------+ | | +--------~
> ++---------------------------- one byte ------------------------ + +-----------~
> +
> +next line of MSB bytes... */
> +
> +static int unpack_rg10(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
> +{
> + int lw, msp, pack, lsp, p_off;
> + uint16_t r,g,b;
> +
> + lw = frame->width;
> +
> + for(int y = 0; y < frame->height; y++){
> + for(int x = 0; x < frame->width; x++){
> + msp = pkt->data[y*3*(lw + lw/4) + 3*x];
> + p_off = y*(3*(lw + lw/4)) + 3*lw + 3*x/4;
> + pack = pkt->data[p_off];
> + lsp = (pack >> (3*x%4)*2) & 0x3;
I would suggest & instead of % because if the compiler doesnt optimize the modulo
then it is the slower operation
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
It is a danger to trust the dream we wish for rather than
the science we have, -- Dr. Kenneth Brown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241009/0f57ed36/attachment.sig>
More information about the ffmpeg-devel
mailing list