dav1d colorspace chroma location handling, better threading on old versions

This commit is contained in:
DataHoarder 2023-08-10 12:44:43 +02:00
parent 120df4a734
commit 060d4e23ce
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
3 changed files with 31 additions and 1 deletions

View file

@ -0,0 +1,16 @@
#include "libdav1d.h"
#include <math.h>
#define DAV1D_VERSION_AT_LEAST(x,y) \
(DAV1D_API_VERSION_MAJOR > (x) || DAV1D_API_VERSION_MAJOR == (x) && DAV1D_API_VERSION_MINOR >= (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
void set_threading(Dav1dSettings* s, int threads) {
#if DAV1D_VERSION_AT_LEAST(6,0)
#else
s->n_tile_threads = MIN(floor(sqrt(threads)), DAV1D_MAX_TILE_THREADS);
s->n_frame_threads = MIN(ceil(threads / s->n_tile_threads), DAV1D_MAX_FRAME_THREADS);
#endif
}

View file

@ -4,7 +4,8 @@ package libdav1d
/*
#cgo pkg-config: dav1d
#include <dav1d/dav1d.h>
#cgo LDFLAGS: -lm
#include "libdav1d.h"
*/
import "C"
import (
@ -57,6 +58,7 @@ func NewDecoder(r io.Reader, settings map[string]any) (d *Decoder, err error) {
}
C.dav1d_default_settings(&d.settings)
C.set_threading(&d.settings, C.int(runtime.NumCPU()))
if ret := C.dav1d_open(&d.ctx, &d.settings); ret != 0 {
return nil, fmt.Errorf("error %d", ret)
}
@ -201,6 +203,15 @@ func (d *Decoder) pictureToFrame() (frame.Frame, error) {
properties.FullColorRange = true
}
properties.ColorSpace.ChromaSamplePosition = color.ChromaSamplePositionUnspecified
if d.picture.seq_hdr.chr == C.DAV1D_CHR_UNKNOWN {
properties.ColorSpace.ChromaSamplePosition = color.ChromaSamplePositionCenter
} else if d.picture.seq_hdr.chr == C.DAV1D_CHR_VERTICAL {
properties.ColorSpace.ChromaSamplePosition = color.ChromaSamplePositionLeft
} else if d.picture.seq_hdr.chr == C.DAV1D_CHR_COLOCATED {
properties.ColorSpace.ChromaSamplePosition = color.ChromaSamplePositionTopLeft
}
defer C.dav1d_picture_unref(&d.picture)
if bitDepth > 8 { //16-bit

View file

@ -0,0 +1,3 @@
#include <dav1d/dav1d.h>
void set_threading(Dav1dSettings* s, int threads);