Fixed handling the bitmap color depth for scaled subtitles

This commit is contained in:
Klaus Schmidinger 2011-04-17 14:40:58 +02:00
parent c670c0645f
commit 914b04c1d2
5 changed files with 29 additions and 10 deletions

View File

@ -1268,6 +1268,7 @@ Reinhard Nissl <rnissl@gmx.de>
for reporting a problem with horizontal scaling of subtitles for reporting a problem with horizontal scaling of subtitles
for fixing a buffer overflow in cFont::Bidi() for fixing a buffer overflow in cFont::Bidi()
for avoiding an unecessary call to Recordings.ResetResume() for avoiding an unecessary call to Recordings.ResetResume()
for debugging a problem in handling the bitmap color depth for scaled subtitles
Richard Robson <richard_robson@beeb.net> Richard Robson <richard_robson@beeb.net>
for reporting freezing replay if a timer starts while in Transfer Mode from the for reporting freezing replay if a timer starts while in Transfer Mode from the

View File

@ -6573,8 +6573,8 @@ Video Disk Recorder Revision History
- Fixed cUnbufferedFile::Seek() in case it is compiled without USE_FADVISE (thanks - Fixed cUnbufferedFile::Seek() in case it is compiled without USE_FADVISE (thanks
to Juergen Lock). to Juergen Lock).
- Fixed the Language header of the Serbian translation file (thanks to Ville Skyttä). - Fixed the Language header of the Serbian translation file (thanks to Ville Skyttä).
- Added anti-aliasing when upscaling bitmaps (improves the display of SD subtitles - Added anti-aliasing when upscaling bitmaps, which improves the display of SD subtitles
when replayed on an HD OSD). when replayed on an HD OSD (thanks to Reinhard Nissl for his help in debugging).
- Renamed cBitmap::Scale() to Scaled(), because it doesn't modify the bitmap itself, - Renamed cBitmap::Scale() to Scaled(), because it doesn't modify the bitmap itself,
but rather returns a scaled copy. but rather returns a scaled copy.
- Fixed the description of cReceiver in PLUGINS.html, regarding detaching a receiver - Fixed the description of cReceiver in PLUGINS.html, regarding detaching a receiver

View File

@ -7,7 +7,7 @@
* Original author: Marco Schlüßler <marco@lordzodiac.de> * Original author: Marco Schlüßler <marco@lordzodiac.de>
* With some input from the "subtitle plugin" by Pekka Virtanen <pekka.virtanen@sci.fi> * With some input from the "subtitle plugin" by Pekka Virtanen <pekka.virtanen@sci.fi>
* *
* $Id: dvbsubtitle.c 2.16 2011/03/27 15:02:12 kls Exp $ * $Id: dvbsubtitle.c 2.17 2011/04/17 14:34:05 kls Exp $
*/ */
@ -655,11 +655,26 @@ void cDvbSubtitleBitmaps::AddBitmap(cBitmap *Bitmap)
void cDvbSubtitleBitmaps::Draw(cOsd *Osd) void cDvbSubtitleBitmaps::Draw(cOsd *Osd)
{ {
bool Scale = !(DoubleEqual(osdFactorX, 1.0) && DoubleEqual(osdFactorY, 1.0));
bool AntiAlias = true;
if (Scale && osdFactorX > 1.0 || osdFactorY > 1.0) {
// Upscaling requires 8bpp:
int Bpp[MAXOSDAREAS];
for (int i = 0; i < numAreas; i++) {
Bpp[i] = areas[i].bpp;
areas[i].bpp = 8;
}
if (Osd->CanHandleAreas(areas, numAreas) != oeOk) {
for (int i = 0; i < numAreas; i++)
Bpp[i] = areas[i].bpp = Bpp[i];
AntiAlias = false;
}
}
if (Osd->SetAreas(areas, numAreas) == oeOk) { if (Osd->SetAreas(areas, numAreas) == oeOk) {
for (int i = 0; i < bitmaps.Size(); i++) { for (int i = 0; i < bitmaps.Size(); i++) {
cBitmap *b = bitmaps[i]; cBitmap *b = bitmaps[i];
if (!(DoubleEqual(osdFactorX, 1.0) && DoubleEqual(osdFactorY, 1.0))) if (Scale)
b = b->Scaled(osdFactorX, osdFactorY); b = b->Scaled(osdFactorX, osdFactorY, AntiAlias);
Osd->DrawBitmap(int(round(b->X0() * osdFactorX)), int(round(b->Y0() * osdFactorY)), *b); Osd->DrawBitmap(int(round(b->X0() * osdFactorX)), int(round(b->Y0() * osdFactorY)), *b);
if (b != bitmaps[i]) if (b != bitmaps[i])
delete b; delete b;

6
osd.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: osd.c 2.20 2011/03/27 11:52:12 kls Exp $ * $Id: osd.c 2.21 2011/04/17 14:25:07 kls Exp $
*/ */
#include "osd.h" #include "osd.h"
@ -806,7 +806,7 @@ void cBitmap::ShrinkBpp(int NewBpp)
} }
} }
cBitmap *cBitmap::Scaled(double FactorX, double FactorY) cBitmap *cBitmap::Scaled(double FactorX, double FactorY, bool AntiAlias)
{ {
// Fixed point scaling code based on www.inversereality.org/files/bitmapscaling.pdf // Fixed point scaling code based on www.inversereality.org/files/bitmapscaling.pdf
// by deltener@mindtremors.com // by deltener@mindtremors.com
@ -814,7 +814,7 @@ cBitmap *cBitmap::Scaled(double FactorX, double FactorY)
b->Replace(*this); // copy palette b->Replace(*this); // copy palette
int RatioX = (Width() << 16) / b->Width(); int RatioX = (Width() << 16) / b->Width();
int RatioY = (Height() << 16) / b->Height(); int RatioY = (Height() << 16) / b->Height();
if (FactorX <= 1.0 && FactorY <= 1.0) { if (!AntiAlias || FactorX <= 1.0 && FactorY <= 1.0) {
// Downscaling - no anti-aliasing: // Downscaling - no anti-aliasing:
tIndex *DestRow = b->bitmap; tIndex *DestRow = b->bitmap;
int SourceY = 0; int SourceY = 0;

7
osd.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: osd.h 2.12 2011/03/27 11:51:48 kls Exp $ * $Id: osd.h 2.13 2011/04/17 14:24:32 kls Exp $
*/ */
#ifndef __OSD_H #ifndef __OSD_H
@ -273,8 +273,11 @@ public:
///< the 2^NewBpp most frequently used colors as defined in the current palette. ///< the 2^NewBpp most frequently used colors as defined in the current palette.
///< If NewBpp is not smaller than the bitmap's current color depth, ///< If NewBpp is not smaller than the bitmap's current color depth,
///< or if it is not one of 4bpp or 2bpp, nothing happens. ///< or if it is not one of 4bpp or 2bpp, nothing happens.
cBitmap *Scaled(double FactorX, double FactorY); cBitmap *Scaled(double FactorX, double FactorY, bool AntiAlias = false);
///< Creates a copy of this bitmap, scaled by the given factors. ///< Creates a copy of this bitmap, scaled by the given factors.
///< If AntiAlias is true and either of the factors is greater than 1.0,
///< anti-aliasing is applied. This will also set the color depth of the
///< returned bitmap to 8bpp.
///< The caller must delete the returned bitmap once it is no longer used. ///< The caller must delete the returned bitmap once it is no longer used.
}; };