summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-04 17:16:24 +0200
committerwm4 <wm4@nowhere>2012-10-16 07:26:31 +0200
commit2db0d229efc1ba53e33bb3c110ec591246f0c83a (patch)
tree245814087df323d9366005582a3d6b19244b3d2f
parentffd6219ecdc12dc77b29cb95dea93bbb73258742 (diff)
downloadmpv-2db0d229efc1ba53e33bb3c110ec591246f0c83a.tar.bz2
mpv-2db0d229efc1ba53e33bb3c110ec591246f0c83a.tar.xz
libvo: remove eosd_packer.c
This contains about the same code as bitmap_packer.c. eosd_packer.c was added first, and then not merged for a year - then it was added as bitmap_packer.c with slightly different and incompatible interface. Now replacing eosd_packer.c with bitmap_packer.c is finally done. So much wasted work...
-rw-r--r--Makefile1
-rw-r--r--libvo/eosd_packer.c255
-rw-r--r--libvo/eosd_packer.h74
3 files changed, 0 insertions, 330 deletions
diff --git a/Makefile b/Makefile
index 9c782e27fe..1bfccf04ea 100644
--- a/Makefile
+++ b/Makefile
@@ -247,7 +247,6 @@ SRCS_COMMON = asxparser.c \
libmpdemux/mp_taglists.c \
libmpdemux/video.c \
libvo/osd.c \
- libvo/eosd_packer.c \
libvo/bitmap_packer.c \
osdep/numcores.c \
osdep/io.c \
diff --git a/libvo/eosd_packer.c b/libvo/eosd_packer.c
deleted file mode 100644
index 8f831d512e..0000000000
--- a/libvo/eosd_packer.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Common code for packing EOSD images into larger surfaces.
- *
- * This file is part of mplayer2.
- *
- * mplayer2 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mplayer2 is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with mplayer2; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <libavutil/common.h>
-#include "talloc.h"
-#include "mp_msg.h"
-#include "eosd_packer.h"
-
-// Initial size of EOSD surface in pixels (x*x)
-#define EOSD_SURFACE_INITIAL_SIZE 256
-
-// Allocate an eosd_packer, which can be used to layout and cache the list of
-// EOSD images contained in a mp_eosd_images_t into a flat surface.
-// It can be free'd with talloc_free().
-// Don't forget to call eosd_init() before using it.
-struct eosd_packer *eosd_packer_create(void *talloc_ctx) {
- return talloc_zero(talloc_ctx, struct eosd_packer);
-}
-
-// Call this when you need to completely reinitialize the EOSD state, e.g. when
-// when your EOSD surface was deleted.
-// max_width and max_height are the maximum surface sizes that should be
-// allowed.
-void eosd_packer_reinit(struct eosd_packer *state, uint32_t max_width,
- uint32_t max_height)
-{
- state->max_surface_width = max_width;
- state->max_surface_height = max_height;
- state->surface.w = 0;
- state->surface.h = 0;
- state->targets_count = 0;
-}
-
-#define HEIGHT_SORT_BITS 4
-static int size_index(struct eosd_target *r)
-{
- unsigned int h = r->source.y1;
- int n = av_log2_16bit(h);
- return (n << HEIGHT_SORT_BITS)
- + (- 1 - (h << HEIGHT_SORT_BITS >> n) & (1 << HEIGHT_SORT_BITS) - 1);
-}
-
-/* Pack the given rectangles into an area of size w * h.
- * The size of each rectangle is read from .source.x1/.source.y1.
- * The height of each rectangle must be at least 1 and less than 65536.
- * The .source rectangle is then set corresponding to the packed position.
- * 'scratch' must point to work memory for num_rects+16 ints.
- * Return 0 on success, -1 if the rectangles did not fit in w*h.
- *
- * The rectangles are placed in rows in order approximately sorted by
- * height (the approximate sorting is simpler than a full one would be,
- * and allows the algorithm to work in linear time). Additionally, to
- * reduce wasted space when there are a few tall rectangles, empty
- * lower-right parts of rows are filled recursively when the size of
- * rectangles in the row drops past a power-of-two threshold. So if a
- * row starts with rectangles of size 3x50, 10x40 and 5x20 then the
- * free rectangle with corners (13, 20)-(w, 50) is filled recursively.
- */
-static int pack_rectangles(struct eosd_target *rects, int num_rects,
- int w, int h, int *scratch)
-{
- int bins[16 << HEIGHT_SORT_BITS];
- int sizes[16 << HEIGHT_SORT_BITS] = {};
- for (int i = 0; i < num_rects; i++)
- sizes[size_index(rects + i)]++;
- int idx = 0;
- for (int i = 0; i < 16 << HEIGHT_SORT_BITS; i += 1 << HEIGHT_SORT_BITS) {
- for (int j = 0; j < 1 << HEIGHT_SORT_BITS; j++) {
- bins[i + j] = idx;
- idx += sizes[i + j];
- }
- scratch[idx++] = -1;
- }
- for (int i = 0; i < num_rects; i++)
- scratch[bins[size_index(rects + i)]++] = i;
- for (int i = 0; i < 16; i++)
- bins[i] = bins[i << HEIGHT_SORT_BITS] - sizes[i << HEIGHT_SORT_BITS];
- struct {
- int size, x, bottom;
- } stack[16] = {{15, 0, h}}, s = {};
- int stackpos = 1;
- int y;
- while (stackpos) {
- y = s.bottom;
- s = stack[--stackpos];
- s.size++;
- while (s.size--) {
- int maxy = -1;
- int obj;
- while ((obj = scratch[bins[s.size]]) >= 0) {
- int bottom = y + rects[obj].source.y1;
- if (bottom > s.bottom)
- break;
- int right = s.x + rects[obj].source.x1;
- if (right > w)
- break;
- bins[s.size]++;
- rects[obj].source.x0 = s.x;
- rects[obj].source.x1 += s.x;
- rects[obj].source.y0 = y;
- rects[obj].source.y1 += y;
- num_rects--;
- if (maxy <= 0)
- stack[stackpos++] = s;
- s.x = right;
- maxy = FFMAX(maxy, bottom);
- }
- if (maxy > 0)
- s.bottom = maxy;
- }
- }
- return num_rects ? -1 : 0;
-}
-
-// padding to reduce interpolation artifacts when doing scaling & filtering
-#define EOSD_PADDING 0
-
-// Release all previous images, and packs the images in imgs into state. The
-// caller must check the change variables:
-// *out_need_reposition == true: sub-image positions changed
-// *out_need_upload == true: upload all sub-images again
-// *out_need_reallocate == true: resize the EOSD texture to state->surface.w/h
-// Logical implications: need_reallocate => need_upload => need_reposition
-void eosd_packer_generate(struct eosd_packer *state, mp_eosd_images_t *imgs,
- bool *out_need_reposition, bool *out_need_upload,
- bool *out_need_reallocate)
-{
- int i;
- ASS_Image *img = imgs->imgs;
- ASS_Image *p;
- struct eosd_surface *sfc = &state->surface;
-
- *out_need_reposition = imgs->bitmap_pos_id != state->last_bitmap_pos_id;
- *out_need_upload = imgs->bitmap_id != state->last_bitmap_id;
- *out_need_reallocate = false;
-
- state->last_bitmap_pos_id = imgs->bitmap_pos_id;
- state->last_bitmap_id = imgs->bitmap_id;
-
- // eosd_reinit() was probably called, force full reupload.
- if (state->targets_count == 0 && img)
- *out_need_upload = true;
-
- if (!(*out_need_reposition) && !(*out_need_upload))
- return; // Nothing changed, no need to redraw
-
- state->targets_count = 0;
-
- *out_need_reposition = true;
-
- if (!img)
- return; // There's nothing to render!
-
- if (!(*out_need_upload))
- goto eosd_skip_upload;
-
- *out_need_upload = true;
- while (1) {
- for (p = img, i = 0; p; p = p->next) {
- if (p->w <= 0 || p->h <= 0)
- continue;
- // Allocate new space for surface/target arrays
- if (i >= state->targets_size) {
- state->targets_size = FFMAX(state->targets_size * 2, 512);
- state->targets =
- talloc_realloc_size(state, state->targets,
- state->targets_size
- * sizeof(*state->targets));
- state->scratch =
- talloc_realloc_size(state, state->scratch,
- (state->targets_size + 16)
- * sizeof(*state->scratch));
- }
- state->targets[i].source.x1 = p->w + EOSD_PADDING;
- state->targets[i].source.y1 = p->h + EOSD_PADDING;
- i++;
- }
- if (pack_rectangles(state->targets, i, sfc->w, sfc->h,
- state->scratch) >= 0)
- break;
- int w = FFMIN(FFMAX(sfc->w * 2, EOSD_SURFACE_INITIAL_SIZE),
- state->max_surface_width);
- int h = FFMIN(FFMAX(sfc->h * 2, EOSD_SURFACE_INITIAL_SIZE),
- state->max_surface_height);
- if (w == sfc->w && h == sfc->h) {
- mp_msg(MSGT_VO, MSGL_ERR, "[eosd] EOSD bitmaps do not fit on "
- "a surface with the maximum supported size\n");
- return;
- }
- sfc->w = w;
- sfc->h = h;
- *out_need_reallocate = true;
- }
- if (*out_need_reallocate) {
- mp_msg(MSGT_VO, MSGL_V, "[eosd] Allocate a %dx%d surface for "
- "EOSD bitmaps.\n", sfc->w, sfc->h);
- }
-
-eosd_skip_upload:
- for (p = img; p; p = p->next) {
- if (p->w <= 0 || p->h <= 0)
- continue;
- struct eosd_target *target = &state->targets[state->targets_count];
- target->source.x1 -= EOSD_PADDING;
- target->source.y1 -= EOSD_PADDING;
- target->dest.x0 = p->dst_x;
- target->dest.y0 = p->dst_y;
- target->dest.x1 = p->w + p->dst_x;
- target->dest.y1 = p->h + p->dst_y;
- target->color = p->color;
- target->ass_img = p;
- state->targets_count++;
- }
-}
-
-// Calculate the bounding box of all sub-rectangles in the EOSD surface that
-// will be used for EOSD rendering.
-// If the bounding box is empty, return false.
-bool eosd_packer_calculate_source_bb(struct eosd_packer *state,
- struct eosd_rect *out_bb)
-{
- struct eosd_rect bb = { state->surface.w, state->surface.h, 0, 0 };
-
- for (int n = 0; n < state->targets_count; n++) {
- struct eosd_rect s = state->targets[n].source;
- bb.x0 = FFMIN(bb.x0, s.x0);
- bb.y0 = FFMIN(bb.y0, s.y0);
- bb.x1 = FFMAX(bb.x1, s.x1);
- bb.y1 = FFMAX(bb.y1, s.y1);
- }
-
- // avoid degenerate bounding box if empty
- bb.x0 = FFMIN(bb.x0, bb.x1);
- bb.y0 = FFMIN(bb.y0, bb.y1);
-
- *out_bb = bb;
- return state->targets_count > 0;
-}
diff --git a/libvo/eosd_packer.h b/libvo/eosd_packer.h
deleted file mode 100644
index 228057d3c4..0000000000
--- a/libvo/eosd_packer.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is part of mplayer2.
- *
- * mplayer2 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mplayer2 is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with mplayer2; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef MPLAYER_EOSD_PACKER_H
-#define MPLAYER_EOSD_PACKER_H
-
-#include <inttypes.h>
-#include <stdbool.h>
-
-#include "sub/ass_mp.h"
-#include "sub/dec_sub.h"
-
-// Pool of surfaces
-struct eosd_surface {
- //void *native_surface;
- int w;
- int h;
-};
-
-struct eosd_rect {
- int x0, y0, x1, y1;
-};
-
-// List of surfaces to be rendered
-struct eosd_target {
- struct eosd_rect source; // position in EOSD surface
- struct eosd_rect dest; // position on screen
- uint32_t color; // libass-style color of the image
- // NOTE: This must not be accessed after you return from your VO's
- // VOCTRL_DRAW_EOSD call - libass will free or reuse the associated
- // memory. Feel free to set this to NULL to make erroneous accesses to
- // this member fail early.
- ASS_Image *ass_img;
-};
-
-struct eosd_packer {
- struct eosd_surface surface;
- struct eosd_target *targets;
- int targets_count; // number of valid elements in targets
- int targets_size; // number of allocated elements in targets
-
- uint32_t max_surface_width;
- uint32_t max_surface_height;
-
- int *scratch;
- int last_bitmap_id;
- int last_bitmap_pos_id;
-};
-
-struct eosd_packer *eosd_packer_create(void *talloc_ctx);
-void eosd_packer_reinit(struct eosd_packer *state, uint32_t max_width,
- uint32_t max_height);
-void eosd_packer_generate(struct eosd_packer *state, mp_eosd_images_t *imgs,
- bool *out_need_reposition, bool *out_need_upload,
- bool *out_need_reallocate);
-bool eosd_packer_calculate_source_bb(struct eosd_packer *state,
- struct eosd_rect *out_bb);
-
-#endif /* MPLAYER_EOSD_PACKER_H */