mirror of
https://github.com/qrtc/ffmpeg-dev-go.git
synced 2025-10-04 07:17:36 +08:00
2023-10-17 15:38:39 CST W42D2
This commit is contained in:
203
avutil_imgutils.go
Normal file
203
avutil_imgutils.go
Normal file
@@ -0,0 +1,203 @@
|
||||
package ffmpeg
|
||||
|
||||
/*
|
||||
#include <libavutil/imgutils.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// AvImageFillMaxPixsteps computes the max pixel step for each plane of an image with a
|
||||
// format described by pixdesc.
|
||||
func AvImageFillMaxPixsteps(maxPixsteps, maxPixstepComps []int32, pixdesc *AvPixFmtDescriptor) {
|
||||
if len(maxPixsteps) != 4 {
|
||||
panic("maxPixsteps need len = 4")
|
||||
}
|
||||
if len(maxPixstepComps) != 4 {
|
||||
panic("maxPixstepComps need len = 4")
|
||||
}
|
||||
C.av_image_fill_max_pixsteps((*C.int)(&maxPixsteps[0]), (*C.int)(&maxPixstepComps[0]),
|
||||
(*C.struct_AVPixFmtDescriptor)(pixdesc))
|
||||
}
|
||||
|
||||
// AvImageGetLinesize computes the size of an image line with format pix_fmt and width
|
||||
// width for the plane plane.
|
||||
func AvImageGetLinesize(pixFmt AvPixelFormat, width, plane int32) int32 {
|
||||
return (int32)(C.av_image_get_linesize((C.enum_AVPixelFormat)(pixFmt),
|
||||
(C.int)(width), (C.int)(plane)))
|
||||
}
|
||||
|
||||
// AvImageFillLinesizes fills plane linesizes for an image with pixel format pix_fmt and width width.
|
||||
func AvImageFillLinesizes(linesizes []int32, pixFmt AvPixelFormat, width int32) int32 {
|
||||
if len(linesizes) != 4 {
|
||||
panic("linesizes need len = 4")
|
||||
}
|
||||
return (int32)(C.av_image_fill_linesizes((*C.int)(&linesizes[0]),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(width)))
|
||||
}
|
||||
|
||||
// AvImageFillPlaneSizes fills plane sizes for an image with pixel format pix_fmt and height height.
|
||||
func AvImageFillPlaneSizes(size []uint, pixFmt AvPixelFormat, height int32, linesizes []int) int32 {
|
||||
if len(size) != 4 {
|
||||
panic("size need len = 4")
|
||||
}
|
||||
if len(linesizes) != 4 {
|
||||
panic("linesizes need len = 4")
|
||||
}
|
||||
return (int32)(C.av_image_fill_plane_sizes((*C.size_t)(unsafe.Pointer(&size[0])),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(height), (*C.ptrdiff_t)(unsafe.Pointer(&linesizes[0]))))
|
||||
}
|
||||
|
||||
// AvImageFillPointers fills plane data pointers for an image with pixel format pix_fmt and height height.
|
||||
func AvImageFillPointers(data []*uint8, pixFmt AvPixelFormat,
|
||||
height int32, ptr *uint8, linesizes []int32) int32 {
|
||||
if len(data) != 4 {
|
||||
panic("data need len = 4")
|
||||
}
|
||||
if len(linesizes) != 4 {
|
||||
panic("linesizes need len = 4")
|
||||
}
|
||||
return (int32)(C.av_image_fill_pointers((**C.uint8_t)(unsafe.Pointer(&data[0])),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(height), (*C.uint8_t)(ptr),
|
||||
(*C.int)(&linesizes[0])))
|
||||
}
|
||||
|
||||
// AvImageAlloc allocates an image with size w and h and pixel format pix_fmt, and
|
||||
// fill pointers and linesizes accordingly.
|
||||
func AvImageAlloc(pointers []*uint8, linesizes []int32, w, h int32,
|
||||
pixFmt AvPixelFormat, align int32) int32 {
|
||||
if len(pointers) != 4 {
|
||||
panic("pointers need len = 4")
|
||||
}
|
||||
if len(linesizes) != 4 {
|
||||
panic("linesizes need len = 4")
|
||||
}
|
||||
return (int32)(C.av_image_alloc((**C.uint8_t)(unsafe.Pointer(&pointers[0])),
|
||||
(*C.int)(&linesizes[0]),
|
||||
(C.int)(w), (C.int)(h), (C.enum_AVPixelFormat)(pixFmt), (C.int)(align)))
|
||||
}
|
||||
|
||||
// AvImageCopyPlane copies image plane from src to dst.
|
||||
func AvImageCopyPlane(dst *uint8, dstLinesize int32, src *uint8,
|
||||
srcLinesize int32, bytewidth, height int32) {
|
||||
C.av_image_copy_plane((*C.uint8_t)(dst), (C.int)(dstLinesize),
|
||||
(*C.uint8_t)(src), (C.int)(srcLinesize),
|
||||
(C.int)(bytewidth), (C.int)(height))
|
||||
}
|
||||
|
||||
// AvImageCopy copies image in src_data to dst_data.
|
||||
func AvImageCopy(dstData []*uint8, dstLinesizes []int32, srcData []*uint8, srcLinesizes []int32,
|
||||
pixFmt AvPixelFormat, width, height int32) {
|
||||
if len(dstData) != 4 {
|
||||
panic("dstData need len = 4")
|
||||
}
|
||||
if len(dstLinesizes) != 4 {
|
||||
panic("dstLinesizes need len = 4")
|
||||
}
|
||||
if len(srcData) != 4 {
|
||||
panic("srcData need len = 4")
|
||||
}
|
||||
if len(srcLinesizes) != 4 {
|
||||
panic("srcLinesizes need len = 4")
|
||||
}
|
||||
C.av_image_copy((**C.uint8_t)(unsafe.Pointer(&dstData[0])),
|
||||
(*C.int)(&dstLinesizes[0]),
|
||||
(**C.uint8_t)(unsafe.Pointer(&srcData[0])),
|
||||
(*C.int)(&srcLinesizes[0]),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(width), (C.int)(height))
|
||||
}
|
||||
|
||||
// AvImageCopyUcFrom copies image data located in uncacheable (e.g. GPU mapped) memory.
|
||||
func AvImageCopyUcFrom(dstData []*uint8, dstLinesizes []int, srcData []*uint8, srcLinesizes []int,
|
||||
pixFmt AvPixelFormat, width, height int32) {
|
||||
if len(dstData) != 4 {
|
||||
panic("dstData need len = 4")
|
||||
}
|
||||
if len(dstLinesizes) != 4 {
|
||||
panic("dstLinesizes need len = 4")
|
||||
}
|
||||
if len(srcData) != 4 {
|
||||
panic("srcData need len = 4")
|
||||
}
|
||||
if len(srcLinesizes) != 4 {
|
||||
panic("srcLinesizes need len = 4")
|
||||
}
|
||||
C.av_image_copy_uc_from((**C.uint8_t)(unsafe.Pointer(&dstData[0])),
|
||||
(*C.ptrdiff_t)(unsafe.Pointer(&dstLinesizes[0])),
|
||||
(**C.uint8_t)(unsafe.Pointer(&srcData[0])),
|
||||
(*C.ptrdiff_t)(unsafe.Pointer(&srcLinesizes[0])),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(width), (C.int)(height))
|
||||
}
|
||||
|
||||
// AvImageFillArrays setups the data pointers and linesizes based on the specified image
|
||||
// parameters and the provided array.
|
||||
func AvImageFillArrays(dstData []*uint8, dstLinesize []int32, src *uint8,
|
||||
pixFmt AvPixelFormat, width, height, align int32) {
|
||||
if len(dstData) != 4 {
|
||||
panic("dstData need len = 4")
|
||||
}
|
||||
if len(dstLinesize) != 4 {
|
||||
panic("dstLinesize need len = 4")
|
||||
}
|
||||
C.av_image_fill_arrays((**C.uint8_t)(unsafe.Pointer(&dstData[0])),
|
||||
(*C.int)(&dstLinesize[0]),
|
||||
(*C.uint8_t)(src),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(width), (C.int)(height), (C.int)(align))
|
||||
}
|
||||
|
||||
// AvImageGetBufferSize Return the size in bytes of the amount of data required to store an
|
||||
// image with the given parameters.
|
||||
func AvImageGetBufferSize(pixFmt AvPixelFormat, width, height, align int32) int32 {
|
||||
return (int32)(C.av_image_get_buffer_size((C.enum_AVPixelFormat)(pixFmt),
|
||||
(C.int)(width), (C.int)(height), (C.int)(align)))
|
||||
}
|
||||
|
||||
// av_image_copy_to_buffer
|
||||
func av_image_copy_to_buffer(dst *uint8, dstSize int32, srcData []*uint8, srcLinesize []int32,
|
||||
pixFmt AvPixelFormat, width, height, align int32) {
|
||||
if len(srcData) != 4 {
|
||||
panic("srcData need len = 4")
|
||||
}
|
||||
if len(srcLinesize) != 4 {
|
||||
panic("srcLinesize need len = 4")
|
||||
}
|
||||
C.av_image_copy_to_buffer((*C.uint8_t)(dst), (C.int)(dstSize),
|
||||
(**C.uint8_t)(unsafe.Pointer(&srcData[0])), (*C.int)(&srcLinesize[0]),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.int)(width), (C.int)(height), (C.int)(align))
|
||||
}
|
||||
|
||||
// AvImageCheckSize checks if the given dimension of an image is valid, meaning that all
|
||||
// bytes of the image can be addressed with a signed int.
|
||||
func AvImageCheckSize(w, h uint32, logOffset int32, logCtx unsafe.Pointer) int32 {
|
||||
return (int32)(C.av_image_check_size((C.uint)(w), (C.uint)(h), (C.int)(logOffset), logCtx))
|
||||
}
|
||||
|
||||
// AvImageCheckSize2 checks if the given dimension of an image is valid, meaning that all
|
||||
// bytes of a plane of an image with the specified pix_fmt can be addressed with a signed int.
|
||||
func AvImageCheckSize2(w, h uint32, maxPixels int64, pixFmt AvPixelFormat,
|
||||
logOffset int32, logCtx unsafe.Pointer) int32 {
|
||||
return (int32)(C.av_image_check_size2((C.uint)(w), (C.uint)(h),
|
||||
(C.int64_t)(maxPixels), (C.enum_AVPixelFormat)(pixFmt),
|
||||
(C.int)(logOffset), logCtx))
|
||||
}
|
||||
|
||||
// AvImageCheckSar checks if the given sample aspect ratio of an image is valid.
|
||||
func AvImageCheckSar(w, h uint32, sar AvRational) int32 {
|
||||
return (int32)(C.av_image_check_sar((C.uint)(w), (C.uint)(h), (C.struct_AVRational)(sar)))
|
||||
}
|
||||
|
||||
// AvImageFillBlack overwrites the image data with black.
|
||||
func AvImageFillBlack(dstData []*uint8, dstLinesize []int,
|
||||
pixFmt AvPixelFormat, _range AvColorRange, width, height int32) int32 {
|
||||
if len(dstData) != 4 {
|
||||
panic("dstData need len = 4")
|
||||
}
|
||||
if len(dstLinesize) != 4 {
|
||||
panic("dstLinesize need len = 4")
|
||||
}
|
||||
return (int32)(C.av_image_fill_black((**C.uint8_t)(unsafe.Pointer(&dstData[0])),
|
||||
(*C.ptrdiff_t)(unsafe.Pointer(&dstLinesize[0])),
|
||||
(C.enum_AVPixelFormat)(pixFmt), (C.enum_AVColorRange)(_range),
|
||||
(C.int)(width), (C.int)(height)))
|
||||
}
|
Reference in New Issue
Block a user