Files
gx 8cc5a5acfb Phase 3b: PNG icon overlays через libpng + alpha_blit_rgba_nv12
Live-validated на rtsp://192.168.88.23:554/cfc-grid с иконками
temp_outside.png и offline.png из cuda_grid_icons volume.

Содержимое:

- cugrid.h/cugrid.cu — cfc_cugrid_blit_rgba_nv12 (Y+UV α-blend) +
  два новых kernel'я blit_rgba_y/uv (BT.709 limited-range RGB→YUV
  conversion, 4:2:0 chroma 2x2 averaging).
- overlay.h — cfc_overlay_create_png + cfc_overlay_png_size +
  cfc_overlay_update_png.
- overlay.c — libpng decode (paletted/gray/16-bit → 8-bit RGBA),
  cuMemAlloc atlas в VRAM, cuMemcpyHtoD один раз, draw_png через
  cfc_cugrid_blit_rgba_nv12.
- CMakeLists.txt — find_package(PNG REQUIRED) + PNG::PNG в link.
- examples/grid_record — флаг --icon path,x,y[,alpha] (несколько раз
  можно). Атлас грузится один раз при старте.

PNG из cuda_grid_icons volume переиспользуются (offline, temp_outside,
grafana_gpu, и пр.). PNG decode'ятся одинаково — paletted, RGBA, gray.

Phase 3c (text rendering через FreeType + font atlas) — отдельный
commit. Атлас text'а тоже окажется в VRAM как RGBA через тот же
cfc_cugrid_blit_rgba_nv12 — kernels уже готовы.
2026-06-03 05:34:07 +01:00

105 lines
4.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* cuframes-composer — CUDA kernels для grid-композиции NV12 кадров.
*
* Извлечено из vf_cuda_grid (FFmpeg out-of-tree filter), под LGPL-2.1+.
* Все операции работают на NV12-кадрах:
* - Y plane: full resolution, 1 byte per pixel
* - UV plane: half resolution, 2 bytes per pixel (interleaved U,V)
*
* Все операции:
* - Принимают CUstream (NULL = default stream)
* - Не аллоцируют память (caller выделяет dst буфер заранее)
* - Idempotent для re-use (composer вызывает на каждом кадре)
*
* Lifecycle:
* cfc_cugrid_init() один раз при старте композитора (no-op для CUDA, но
* резервирован под cuModuleLoad если перейдём на PTX)
*
* Лицензия: LGPL-2.1+
*/
#ifndef CUFRAMES_COMPOSER_CUGRID_H
#define CUFRAMES_COMPOSER_CUGRID_H
#include <cuda.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Lazy init (no-op в текущей реализации; зарезервировано под future PTX module). */
int cfc_cugrid_init(void);
/* Заполнить прямоугольник на NV12 кадре solid color'ом с alpha-блендингом.
*
* dst_y, dst_uv — указатели на Y и UV plane соответственно.
* pitch_y, pitch_uv — pitch в bytes (для NV12 обычно равны и кратны 256).
* x, y, w, h — прямоугольник в full-res пикселях (chroma usually пишется
* автоматически на половинном rastr'е).
* w и h должны быть чётными (требование 4:2:0 subsampling'а).
* color_y/u/v — компоненты цвета в BT.709 limited range (Y: 16-235, UV: 16-240).
* Для чёрного: Y=16, U=128, V=128.
* alpha — 0..255 (0 = transparent, 255 = opaque).
*
* Возвращает 0 при успехе.
*/
int cfc_cugrid_fill_nv12(
CUstream stream,
CUdeviceptr dst_y, int pitch_y,
CUdeviceptr dst_uv, int pitch_uv,
int x, int y, int w, int h,
int color_y, int color_u, int color_v, int alpha
);
/* Blit RGBA atlas → NV12 frame с α-blending.
*
* BT.709 limited-range conversion (R/G/B → Y/U/V). UV pixel = среднее 2x2
* пикселей RGBA (4:2:0 chroma subsampling).
*
* dst_y/uv, pitch_y/uv — NV12 destination.
* dst_x, dst_y_off — позиция top-left на dst (full-res, чётные).
* atlas — CUdeviceptr RGBA байт (4 байта/пиксель,
* R,G,B,A interleaved).
* atlas_w, atlas_h — размер atlas в пикселях.
* atlas_pitch — pitch atlas в байтах.
* extra_alpha — 0..255, общий множитель прозрачности (для
* анимаций fade-in/fade-out).
*/
int cfc_cugrid_blit_rgba_nv12(
CUstream stream,
CUdeviceptr dst_y, int dst_pitch_y,
CUdeviceptr dst_uv, int dst_pitch_uv,
int dst_x, int dst_y_off,
CUdeviceptr atlas, int atlas_w, int atlas_h, int atlas_pitch,
int extra_alpha
);
/* Resize NV12 src → rect (dst_x, dst_y, dst_w, dst_h) на NV12 dst.
*
* Bilinear interpolation на Y и UV. Y и UV plane src'а должны быть одним
* allocation'ом (NV12 layout) или хотя бы иметь корректные указатели каждый.
*
* src_y, src_uv — src указатели.
* src_w, src_h — размер src в full-res пикселях.
* src_pitch_y/uv — pitch'ы (для NV12 cuframes pitch_y == pitch_uv).
* dst_y, dst_uv — dst указатели.
* dst_pitch_y/uv — pitch'ы dst NV12 кадра.
* dst_x, dst_y_off, — координата top-left прямоугольника на dst (full-res пиксели).
* dst_w, dst_h dst_x и dst_y_off, dst_w, dst_h ДОЛЖНЫ быть чётными
* (для UV/chroma subsampling'а).
*/
int cfc_cugrid_resize_nv12(
CUstream stream,
CUdeviceptr src_y, int src_w, int src_h, int src_pitch_y,
CUdeviceptr src_uv, int src_pitch_uv,
CUdeviceptr dst_y, int dst_pitch_y,
CUdeviceptr dst_uv, int dst_pitch_uv,
int dst_x, int dst_y_off, int dst_w, int dst_h
);
#ifdef __cplusplus
}
#endif
#endif /* CUFRAMES_COMPOSER_CUGRID_H */