- libdvbsub: port usefull code from Neutrino-MP to make dvbsub nice again

Signed-off-by: J. Krieg <bellum07@googlemail.com>
Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
svenhoefer
2017-10-12 12:26:02 +02:00
committed by Thilo Graf
parent 47b247472c
commit 8bdcfb263d
2 changed files with 55 additions and 8 deletions

View File

@@ -87,12 +87,16 @@ fb_pixel_t * simple_resize32(uint8_t * orgin, uint32_t * colors, int nb_colors,
fb_pixel_t *cr,*l;
int i,j,k,ip;
#ifndef HAVE_SPARK_HARDWARE
cr = (fb_pixel_t *) malloc(dx*dy*sizeof(fb_pixel_t));
if(cr == NULL) {
printf("Error: malloc\n");
return NULL;
}
#else
cr = CFrameBuffer::getInstance()->getBackBufferPointer();
#endif
l = cr;
for(j = 0; j < dy; j++, l += dx)
@@ -111,19 +115,29 @@ fb_pixel_t * simple_resize32(uint8_t * orgin, uint32_t * colors, int nb_colors,
void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
{
int i;
#ifndef HAVE_SPARK_HARDWARE
int stride = CFrameBuffer::getInstance()->getScreenWidth(true);
#if 0
int wd = CFrameBuffer::getInstance()->getScreenWidth();
int xstart = CFrameBuffer::getInstance()->getScreenX();
int yend = CFrameBuffer::getInstance()->getScreenY() + CFrameBuffer::getInstance()->getScreenHeight();
int ystart = CFrameBuffer::getInstance()->getScreenY();
#endif
uint32_t *sublfb = CFrameBuffer::getInstance()->getFrameBufferPointer();
#endif
#if 0
dbgconverter("cDvbSubtitleBitmaps::Draw: %d bitmaps, x= %d, width= %d yend=%d stride %d\n", Count(), xstart, wd, yend, stride);
#endif
int sw = CFrameBuffer::getInstance()->getScreenWidth(true);
int sh = CFrameBuffer::getInstance()->getScreenHeight(true);
#if 0
double xc = (double) CFrameBuffer::getInstance()->getScreenWidth(true)/(double) 720;
double yc = (double) CFrameBuffer::getInstance()->getScreenHeight(true)/(double) 576;
xc = yc; //FIXME should we scale also to full width ?
int xf = int(xc * (double) 720);
#endif
for (i = 0; i < Count(); i++) {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0)
@@ -135,6 +149,7 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
int height = sub.rects[i]->h;
int xoff, yoff;
#if 0
int nw = int(width == 1280 ? ((double) width / xc) : ((double) width * xc));
int nh = int((double) height * yc);
@@ -147,14 +162,26 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
if(yoff < ystart)
yoff = ystart;
}
#endif
int h2 = (width == 1280) ? 720 : 576;
xoff = sub.rects[i]->x * sw / width;
yoff = sub.rects[i]->y * sh / h2;
int nw = width * sw / width;
int nh = height * sh / h2;
dbgconverter("cDvbSubtitleBitmaps::Draw: #%d at %d,%d size %dx%d colors %d (x=%d y=%d w=%d h=%d) \n", i+1,
sub.rects[i]->x, sub.rects[i]->y, sub.rects[i]->w, sub.rects[i]->h, sub.rects[i]->nb_colors, xoff, yoff, nw, nh);
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0)
fb_pixel_t * newdata = simple_resize32 (sub.rects[i]->pict.data[0], colors, sub.rects[i]->nb_colors, width, height, nw, nh);
#else
fb_pixel_t * newdata = simple_resize32 (sub.rects[i]->data[0], colors, sub.rects[i]->nb_colors, width, height, nw, nh);
#endif
#ifdef HAVE_SPARK_HARDWARE
// CFrameBuffer::getInstance()->waitForIdle();
CFrameBuffer::getInstance()->blit2FB(newdata, nw, nh, xoff, yoff, 0, 0);
#else
fb_pixel_t * ptr = newdata;
for (int y2 = 0; y2 < nh; y2++) {
int y = (yoff + y2) * stride;
@@ -162,6 +189,7 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
*(sublfb + xoff + x2 + y) = *ptr++;
}
free(newdata);
#endif
if(min_x > xoff)
min_x = xoff;
@@ -172,11 +200,13 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y)
if(max_y < (yoff + nh))
max_y = yoff + nh;
}
if(Count())
dbgconverter("cDvbSubtitleBitmaps::Draw: finish, min/max screen: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
dbgconverter("\n");
}
static int screen_w, screen_h, screen_x, screen_y;
// --- cDvbSubtitleConverter -------------------------------------------------
cDvbSubtitleConverter::cDvbSubtitleConverter(void)
@@ -207,10 +237,10 @@ cDvbSubtitleConverter::cDvbSubtitleConverter(void)
//if(DebugConverter)
// av_log_set_level(AV_LOG_INFO);
min_x = CFrameBuffer::getInstance()->getScreenWidth();
min_y = CFrameBuffer::getInstance()->getScreenHeight();
max_x = CFrameBuffer::getInstance()->getScreenX();
max_y = CFrameBuffer::getInstance()->getScreenY();
screen_w = min_x = CFrameBuffer::getInstance()->getScreenWidth();
screen_h = min_y = CFrameBuffer::getInstance()->getScreenHeight();
screen_x = max_x = CFrameBuffer::getInstance()->getScreenX();
screen_y = max_y = CFrameBuffer::getInstance()->getScreenY();
Timeout.Set(0xFFFF*1000);
}
@@ -256,6 +286,11 @@ void cDvbSubtitleConverter::Clear(void)
dbgconverter("cDvbSubtitleConverter::Clear: x=% d y= %d, w= %d, h= %d\n", min_x, min_y, max_x-min_x, max_y-min_y);
if(running && (max_x-min_x > 0) && (max_y-min_y > 0)) {
CFrameBuffer::getInstance()->paintBackgroundBoxRel (min_x, min_y, max_x-min_x, max_y-min_y);
/* reset area to clear */
min_x = screen_w;
min_y = screen_h;
max_x = screen_x;
max_y = screen_h;
//CFrameBuffer::getInstance()->paintBackground();
}
}
@@ -342,6 +377,7 @@ int cDvbSubtitleConverter::Action(void)
if (Delta <= MAXDELTA) {
if (Delta <= SHOW_DELTA) {
dbgconverter("cDvbSubtitleConverter::Action: PTS: %012llx STC: %012llx (%lld) timeout: %d bmp %d/%d\n", sb->Pts(), STC, Delta, sb->Timeout(), bitmaps->Count(), sb->Index() + 1);
dbgconverter("cDvbSubtitleConverter::Action: Got %d bitmaps, showing #%d\n", bitmaps->Count(), sb->Index() + 1);
if (running) {
Clear();
@@ -356,7 +392,10 @@ int cDvbSubtitleConverter::Action(void)
WaitMs = int((Delta > SHOW_DELTA) ? Delta - SHOW_DELTA : Delta);
}
else
{
dbgconverter("deleted because delta (%lld) > MAXDELTA (%d)\n", Delta, MAXDELTA);
bitmaps->Del(sb, true);
}
} else {
if (Timeout.TimedOut()) {
dbgconverter("cDvbSubtitleConverter::Action: timeout, elapsed %lld\n", Timeout.Elapsed());