Blame src/libbluray/decoders/overlay.h

Packit 5e46da
/*
Packit 5e46da
 * This file is part of libbluray
Packit 5e46da
 * Copyright (C) 2010-2017  Petri Hintukainen <phintuka@users.sourceforge.net>
Packit 5e46da
 *
Packit 5e46da
 * This library is free software; you can redistribute it and/or
Packit 5e46da
 * modify it under the terms of the GNU Lesser General Public
Packit 5e46da
 * License as published by the Free Software Foundation; either
Packit 5e46da
 * version 2.1 of the License, or (at your option) any later version.
Packit 5e46da
 *
Packit 5e46da
 * This library is distributed in the hope that it will be useful,
Packit 5e46da
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5e46da
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 5e46da
 * Lesser General Public License for more details.
Packit 5e46da
 *
Packit 5e46da
 * You should have received a copy of the GNU Lesser General Public
Packit 5e46da
 * License along with this library. If not, see
Packit 5e46da
 * <http://www.gnu.org/licenses/>.
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
#ifndef BD_OVERLAY_H_
Packit 5e46da
#define BD_OVERLAY_H_
Packit 5e46da
Packit 5e46da
#ifdef __cplusplus
Packit 5e46da
extern "C" {
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
#include <stdint.h>
Packit 5e46da
Packit 5e46da
#define BD_OVERLAY_INTERFACE_VERSION 2
Packit 5e46da
Packit 5e46da
typedef enum {
Packit 5e46da
    BD_OVERLAY_PG = 0,  /* Presentation Graphics plane */
Packit 5e46da
    BD_OVERLAY_IG = 1,  /* Interactive Graphics plane (on top of PG plane) */
Packit 5e46da
} bd_overlay_plane_e;
Packit 5e46da
Packit 5e46da
typedef enum {
Packit 5e46da
    /* following events are executed immediately */
Packit 5e46da
    BD_OVERLAY_INIT  = 0,    /* init overlay plane. Size and position of plane in x,y,w,h */
Packit 5e46da
    BD_OVERLAY_CLOSE = 1,    /* close overlay plane */
Packit 5e46da
Packit 5e46da
    /* following events can be processed immediately, but changes
Packit 5e46da
     * should not be flushed to display before next FLUSH event
Packit 5e46da
     */
Packit 5e46da
    BD_OVERLAY_CLEAR = 2,    /* clear plane */
Packit 5e46da
    BD_OVERLAY_DRAW  = 3,    /* draw bitmap (x,y,w,h,img,palette,crop) */
Packit 5e46da
    BD_OVERLAY_WIPE  = 4,    /* clear area (x,y,w,h) */
Packit 5e46da
    BD_OVERLAY_HIDE  = 5,    /* overlay is empty and can be hidden */
Packit 5e46da
Packit 5e46da
    BD_OVERLAY_FLUSH = 6,    /* all changes have been done, flush overlay to display at given pts */
Packit 5e46da
Packit 5e46da
} bd_overlay_cmd_e;
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * Compressed YUV overlays
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
typedef struct bd_pg_palette_entry_s {
Packit 5e46da
    uint8_t Y;
Packit 5e46da
    uint8_t Cr;
Packit 5e46da
    uint8_t Cb;
Packit 5e46da
    uint8_t T;
Packit 5e46da
} BD_PG_PALETTE_ENTRY;
Packit 5e46da
Packit 5e46da
typedef struct bd_pg_rle_elem_s {
Packit 5e46da
    uint16_t len;
Packit 5e46da
    uint16_t color;
Packit 5e46da
} BD_PG_RLE_ELEM;
Packit 5e46da
Packit 5e46da
typedef struct bd_overlay_s {
Packit 5e46da
    int64_t  pts;
Packit 5e46da
    uint8_t  plane; /* bd_overlay_plane_e */
Packit 5e46da
    uint8_t  cmd;   /* bd_overlay_cmd_e */
Packit 5e46da
Packit 5e46da
    uint8_t  palette_update_flag; /* only palette was changed */
Packit 5e46da
Packit 5e46da
    uint16_t x;
Packit 5e46da
    uint16_t y;
Packit 5e46da
    uint16_t w;
Packit 5e46da
    uint16_t h;
Packit 5e46da
Packit 5e46da
    const BD_PG_PALETTE_ENTRY * palette;
Packit 5e46da
    const BD_PG_RLE_ELEM      * img;
Packit 5e46da
Packit 5e46da
} BD_OVERLAY;
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
  RLE images are reference-counted. If application caches rle data for later use,
Packit 5e46da
  it needs to use bd_refcnt_inc() and bd_refcnt_dec().
Packit 5e46da
*/
Packit 5e46da
Packit 5e46da
void bd_refcnt_inc(const void *);
Packit 5e46da
void bd_refcnt_dec(const void *);
Packit 5e46da
Packit 5e46da
#if 0
Packit 5e46da
BD_OVERLAY *bd_overlay_copy(const BD_OVERLAY *src)
Packit 5e46da
{
Packit 5e46da
    BD_OVERLAY *ov = malloc(sizeof(*ov));
Packit 5e46da
    memcpy(ov, src, sizeof(*ov));
Packit 5e46da
    if (ov->palette) {
Packit 5e46da
        ov->palette = malloc(256 * sizeof(BD_PG_PALETTE_ENTRY));
Packit 5e46da
        memcpy((void*)ov->palette, src->palette, 256 * sizeof(BD_PG_PALETTE_ENTRY));
Packit 5e46da
    }
Packit 5e46da
    if (ov->img) {
Packit 5e46da
        bd_refcnt_inc(ov->img);
Packit 5e46da
    }
Packit 5e46da
    return ov;
Packit 5e46da
}
Packit 5e46da
Packit 5e46da
void bd_overlay_free(BD_OVERLAY **pov)
Packit 5e46da
{
Packit 5e46da
    if (pov && *pov) {
Packit 5e46da
        BD_OVERLAY *ov = *pov;
Packit 5e46da
        void *p = (void*)ov->palette;
Packit 5e46da
        bd_refcnt_dec(ov->img);
Packit 5e46da
        X_FREE(p);
Packit 5e46da
        ov->palette = NULL;
Packit 5e46da
        X_FREE(*pov);
Packit 5e46da
    }
Packit 5e46da
}
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * ARGB overlays
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
typedef enum {
Packit 5e46da
    /* following events are executed immediately */
Packit 5e46da
    BD_ARGB_OVERLAY_INIT  = 0,    /* init overlay plane. Size and position of plane in x,y,w,h */
Packit 5e46da
    BD_ARGB_OVERLAY_CLOSE = 1,    /* close overlay */
Packit 5e46da
Packit 5e46da
    /* following events can be processed immediately, but changes
Packit 5e46da
     * should not be flushed to display before next FLUSH event
Packit 5e46da
     */
Packit 5e46da
    BD_ARGB_OVERLAY_DRAW  = 3,    /* draw image */
Packit 5e46da
    BD_ARGB_OVERLAY_FLUSH = 6,    /* all changes have been done, flush overlay to display at given pts */
Packit 5e46da
} bd_argb_overlay_cmd_e;
Packit 5e46da
Packit 5e46da
typedef struct bd_argb_overlay_s {
Packit 5e46da
    int64_t  pts;
Packit 5e46da
    uint8_t  plane; /* bd_overlay_plane_e */
Packit 5e46da
    uint8_t  cmd;   /* bd_argb_overlay_cmd_e */
Packit 5e46da
Packit 5e46da
    /* following fileds are used only when not using application-allocated
Packit 5e46da
     * frame buffer
Packit 5e46da
     */
Packit 5e46da
Packit 5e46da
    /* destination clip on the overlay plane */
Packit 5e46da
    uint16_t x;
Packit 5e46da
    uint16_t y;
Packit 5e46da
    uint16_t w;
Packit 5e46da
    uint16_t h;
Packit 5e46da
    uint16_t stride;       /* buffer stride */
Packit 5e46da
Packit 5e46da
    const uint32_t * argb; /* 'h' lines, line length 'stride' pixels */
Packit 5e46da
Packit 5e46da
} BD_ARGB_OVERLAY;
Packit 5e46da
Packit 5e46da
/*
Packit 5e46da
 * Application-allocated frame buffer for ARGB overlays
Packit 5e46da
 *
Packit 5e46da
 * When using application-allocated frame buffer DRAW events are
Packit 5e46da
 * executed by libbluray.
Packit 5e46da
 * Application needs to handle only OPEN/FLUSH/CLOSE events.
Packit 5e46da
 *
Packit 5e46da
 * DRAW events can still be used for optimizations.
Packit 5e46da
 */
Packit 5e46da
typedef struct bd_argb_buffer_s {
Packit 5e46da
    /* optional lock / unlock functions
Packit 5e46da
     *  - Set by application
Packit 5e46da
     *  - Called when buffer is accessed or modified
Packit 5e46da
     */
Packit 5e46da
    void (*lock)  (struct bd_argb_buffer_s *);
Packit 5e46da
    void (*unlock)(struct bd_argb_buffer_s *);
Packit 5e46da
Packit 5e46da
    /* ARGB frame buffers
Packit 5e46da
     * - Allocated by application (BD_ARGB_OVERLAY_INIT).
Packit 5e46da
     * - Buffer can be freed after BD_ARGB_OVERLAY_CLOSE.
Packit 5e46da
     * - buffer can be replaced in overlay callback or lock().
Packit 5e46da
     */
Packit 5e46da
Packit 5e46da
    uint32_t *buf[4]; /* [0] - PG plane, [1] - IG plane. [2], [3] reserved for stereoscopic overlay. */
Packit 5e46da
Packit 5e46da
    /* size of buffers
Packit 5e46da
     * - Set by application
Packit 5e46da
     * - If the buffer size is smaller than the size requested in BD_ARGB_OVERLAY_INIT,
Packit 5e46da
     *   the buffer points only to the dirty area.
Packit 5e46da
     */
Packit 5e46da
    int width;
Packit 5e46da
    int height;
Packit 5e46da
Packit 5e46da
    /* dirty area of frame buffers
Packit 5e46da
     * - Updated by library before lock() call.
Packit 5e46da
     * - Reset after each BD_ARGB_OVERLAY_FLUSH.
Packit 5e46da
     */
Packit 5e46da
    struct {
Packit 5e46da
        uint16_t x0, y0, x1, y1;
Packit 5e46da
    } dirty[2]; /* [0] - PG plane, [1] - IG plane */
Packit 5e46da
Packit 5e46da
} BD_ARGB_BUFFER;
Packit 5e46da
Packit 5e46da
#ifdef __cplusplus
Packit 5e46da
}
Packit 5e46da
#endif
Packit 5e46da
Packit 5e46da
#endif // BD_OVERLAY_H_