dav1d colorspace chroma location handling, better threading on old versions
This commit is contained in:
parent
120df4a734
commit
060d4e23ce
16
decoder/libdav1d/libdav1d.c
Normal file
16
decoder/libdav1d/libdav1d.c
Normal 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
|
||||
}
|
|
@ -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
|
||||
|
|
3
decoder/libdav1d/libdav1d.h
Normal file
3
decoder/libdav1d/libdav1d.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#include <dav1d/dav1d.h>
|
||||
|
||||
void set_threading(Dav1dSettings* s, int threads);
|
Loading…
Reference in a new issue