mirror of
https://github.com/mpv-player/mpv
synced 2025-01-07 15:40:43 +00:00
f72eb5b394
Until now, subtitle renderers could export SUBBITMAP_INDEXED, which is a 8 bit per pixel with palette format. sd_lavc.c was the only renderer doing this, and the result was converted to RGBA in every use-case (except maybe when the subtitles were hidden.) Change it so that sd_lavc.c converts to RGBA on its own. This simplifies everything a bit, and the palette handling can be removed from the common code. This is also preparation for making subtitle images refcounted. The "caching" in img_convert.c is a PITA in this respect, and needs to be redone. So getting rid of some img_convert.c code is a positive side- effect. Also related to refcounted subtitles is packing them into a single mp_image. Fewer objects to refcount is easier, and for the libass format the same will be done. The plan is to remove manual packing from the VOs which need single images entirely.
70 lines
2.3 KiB
C
70 lines
2.3 KiB
C
#ifndef MPLAYER_PACK_RECTANGLES_H
|
|
#define MPLAYER_PACK_RECTANGLES_H
|
|
|
|
struct pos {
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
struct bitmap_packer {
|
|
int w;
|
|
int h;
|
|
int w_max;
|
|
int h_max;
|
|
int padding;
|
|
int count;
|
|
struct pos *in;
|
|
struct pos *result;
|
|
int used_width;
|
|
int used_height;
|
|
|
|
// internal
|
|
int *scratch;
|
|
int asize;
|
|
};
|
|
|
|
struct sub_bitmaps;
|
|
|
|
#define PACKER_MAX_WH 65536
|
|
|
|
// Clear all internal state. Leave the following fields: w_max, h_max
|
|
void packer_reset(struct bitmap_packer *packer);
|
|
|
|
// Get the bounding box used for bitmap data (including padding).
|
|
// The bounding box doesn't exceed (0,0)-(packer->w,packer->h).
|
|
void packer_get_bb(struct bitmap_packer *packer, struct pos out_bb[2]);
|
|
|
|
/* Reallocate packer->in for at least to desired number of items.
|
|
* Also sets packer->count to the same value.
|
|
*/
|
|
void packer_set_size(struct bitmap_packer *packer, int size);
|
|
|
|
/* To use this, set packer->count to number of rectangles, w_max and h_max
|
|
* to maximum output rectangle size, and w and h to start size (may be 0).
|
|
* Write input sizes in packer->in.
|
|
* Resulting packing will be written in packer->result.
|
|
* w and h will be increased if necessary for successful packing.
|
|
* There is a strong guarantee that w and h will be powers of 2 (or set to 0).
|
|
* Return value is -1 if packing failed because w and h were set to max
|
|
* values but that wasn't enough, 1 if w or h was increased, and 0 otherwise.
|
|
*/
|
|
int packer_pack(struct bitmap_packer *packer);
|
|
|
|
/* Like above, but packer->count will be automatically set and
|
|
* packer->in will be reallocated if needed and filled from the
|
|
* given image list.
|
|
*/
|
|
int packer_pack_from_subbitmaps(struct bitmap_packer *packer,
|
|
struct sub_bitmaps *b);
|
|
|
|
// Copy the (already packed) sub-bitmaps from b to the image in data.
|
|
// data must point to an image that is at least (packer->w, packer->h) big.
|
|
// The image has the given stride (bytes between (x, y) to (x, y + 1)), and the
|
|
// pixel format used by both the sub-bitmaps and the image uses pixel_stride
|
|
// bytes per pixel (bytes between (x, y) to (x + 1, y)).
|
|
// If packer->padding is set, the padding borders are cleared with 0.
|
|
void packer_copy_subbitmaps(struct bitmap_packer *packer, struct sub_bitmaps *b,
|
|
void *data, int pixel_stride, int stride);
|
|
|
|
#endif
|