VOGONS

Common searches


SCALER xBRZ (SDL1)

Topic actions

First post, by ZenJu

User metadata
Rank Newbie
Rank
Newbie

Hi,

I have been busy lately implementing high quality image scaling support for a different emulator, MAME, which in its raw form has only very basic image enhancements like scanlines, ect.
At first I thought I should go for HQx which I believed to be the state of the art, only to learn shortly after, that there is a new far superior image scaling technique available, that can be used in real-time emulation:

http://board.byuu.org/viewtopic.php?f=10&t=2248

Based on Hyllians xBR filter I created a modified scaler version, named xBRZ, with further graphical advancements, full support for multi-core CPUs and 64 bit architectures.

In case you have not seen this type of filter before, here is a comparison between HQx and xBRZ (click images to show in full size):

original: 0cEbus.png HQx: cDQZSs.png xBRZ: 5de2qs.png

original: msKiCs.png HQx: RXpN5s.png xBRZ: 9vrZRs.png

If you want to see how xBRZ scaling looks in comparison to HQx on different images, have a look at the "ScalerTest" application (download link below) and just drag&drop your own test images. This little app also allows for some xBRZ parameter tuning - so if someone finds a better setup than what is currently the default, let me know!

But let's get to the main point: I would *love* to see support for xBRZ in DOSBox!

From a technical standpoint it's not trivial. xBRZ's API takes full images as input and output, rather than operating on individual lines only like all the scalers implemented in DOSBox currently do. I saw in the source code that DOSBox is using special rewrites of these algorithms for single line scaling.

xBRZ on the other hand supports processing image slices, which can be used for concurrent image scaling. On modern multi-core CPUs this allows for tremendous speedups: In it's raw form xBRZ shows similar performance characteristics like HQx. However when taking advantage of multithreading it scales by factors faster while providing a much better result at the same time.

I went ahead and implemented a working prototype of xBRZ into DOSBox. It is based on DOSBox 0.74 with support for save states.

The source code is implementing the xBRZ scaler from my other project HqMame:
https://sourceforge.net/projects/hqmame/

Due to the technical issues mentioned above, a few considerations apply:
(Note: the updated version v3 will automatically apply these setttings. So you can simply copy the .exe into your Dosbox directory and start it.)

dosbox.conf should be setup with the following configuation:

output=surface fullresolution=original scaler=none aspect=false fullscreen=true […]
Show full quote

output=surface
fullresolution=original
scaler=none
aspect=false
fullscreen=true

The reasons are the following:

  • The xBRZ scaling is implemented only for output "surface". Additionally it requires a 32-bit output device with BGRA byte order. I believe this is the default screen mode today.

    xBRZ works the following way:
    1. it lets DOSBox scale the raw low resolution image into a temporary buffer.

    2. it calulates a scaling factor. E.g. if output screen width is 1024 pixel and the raw image with is 320 pixel, then we ideally need a scaling factor of 3.2. This factor is rounded to 3 and a 3xBRZ scaling is applied.

    3. the xBRZ-scaled image is scaled into the output surface using a nearest neighbor algorithm. Since both images are "roughly" the same size, this can be done with minimal quality drawbacks, but more importantly, this step is very fast (and is also executed in parallel on all available CPU cores)

Due to this approach we need to make sure that the raw image is not scaled => "scaler=none".

Additionally DOSBox' aspect ratio correction introduces some artifacts to the raw image by duplicating every few lines in order to stretch. For the DOSBox version below we do not need this, since the nearest neighbor scaling in step 3 preserves input aspect ratio correctly when scaling to full screen size (=> no black bars anymore if you have a 16:10 monitor and a 320x200 dos game!). => let xBRZ do the complete scaling => "aspect=false"

Since the DOSBox prototype calculates the best scaling factor automatically (up to 5x scaling!) you will get the best quality if the output screen size matches your desktop resolution => "fullresolution=original"

Note that the scaling factor can become quite high. E.g. you have a 1680 desktop width and a game has 320 raw image width, then this gives a required scaling factor of 5.25, so 5xBRZ will be used. This sounds much, but from my extensive performance measurements I learned that the bottleneck of the xBRZ scaler is not the output image size, but the input image size. So 5xBRZ is not significantly slower than 2xBRZ, but of course looks much better.

I hope that my prototype can give some motivation to "officially" implement the xBRZ scaler into DOSBox. If you have technical questions about the scaler, feel free to ask me.

Until then, have fun with the prototype!

Best, Zenju

xBRZ scaler source code for C++:
http://sourceforge.net/projects/xbrz/files/xBRZ/

Compare different scalers (HQx, xBR, xBRZ, nearest neighbor) for your own sample images:
http://sourceforge.net/projects/xbrz/files/ScalerTest.zip

DOSBox v0.74 + xBRZ + Save States support:
http://sourceforge.net/projects/xbrz/files/DOSBox/

Last edited by ZenJu on 2015-01-11, 20:19. Edited 14 times in total.

https://sourceforge.net/projects/xbrz
https://freefilesync.org

Reply 1 of 109, by kolano

User metadata
Rank Oldbie
Rank
Oldbie

I'm confused by the need for "multi-core CPUs and 64 bit architectures", isn't xBR implemented as a GPU shader? I guess it's that this is implemented as a scaler rather than a shader here.

Any chance of a shader implementation that would work in the revs that support shaders?

Reply 2 of 109, by VileR

User metadata
Rank l33t
Rank
l33t

The best way to get your code reviewed/tested would be a patch (diff) against clean SVN, rather than the whole source tree with the save states thing mixed in.

I'm not a huge fan of this type of scaling (prefer the CRT-like shaders myself), but I like what it does to text mode. This would be nice as a truetype font...

Attachments

  • vganice.png
    Filename
    vganice.png
    File size
    13.37 KiB
    Views
    14873 views
    File license
    Fair use/fair dealing exception

[ WEB ] - [ BLOG ] - [ TUBE ] - [ CODE ]

Reply 3 of 109, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

Great addition, as I just mentioned in the other thread we (actually Marzo of the Exult team) recently added xbr to Exult.
And yes, a diff against SVN WITHOUT the save state stuff is much more helpful. I wouldn't touch it with the savestate stuff.

Last edited by Dominus on 2012-12-11, 11:46. Edited 1 time in total.

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 4 of 109, by ykhwong

User metadata
Rank Oldbie
Rank
Oldbie
kolano wrote:

I'm confused by the need for "multi-core CPUs and 64 bit architectures", isn't xBR implemented as a GPU shader? I guess it's that this is implemented as a scaler rather than a shader here.

I noticed that this xBRZ patch enables Intel threading building blocks or tbb.

Attachments

  • Filename
    xBRZ.diff
    File size
    10.8 KiB
    Downloads
    388 downloads
    File license
    Fair use/fair dealing exception

Reply 5 of 109, by kolano

User metadata
Rank Oldbie
Rank
Oldbie

I believe that there are currently 3 implementations of xBR, with different degrees of corner rounding (i.e. v3.7a, v3.7b, v3.7c). Which one is used here?

The upcoming versions of xBR with additional anti-aliasing and anti-de-dithering checks look nice. Still hoping for something that will eventually de-dither into something pseudo-transparent.

Reply 6 of 109, by ZenJu

User metadata
Rank Newbie
Rank
Newbie

The prototype source code has two dependencies, one to Intel TBB, the other to xBRZ. xBRZ is using the idea of xBR but besides that has a completely different implementation. The goal was to support multithreaded execution and to improve certain visual aspects of the scaler.

Here's a comparison of xBR vs xBRZ of the latest test images I got from Hyllian:

xBR: 3INLbs.png xBRZ: keM1Js.png

xBR: FhiA3s.png xBRZ: Oaxoss.png

https://sourceforge.net/projects/xbrz
https://freefilesync.org

Reply 7 of 109, by VileR

User metadata
Rank l33t
Rank
l33t

Hmm, is there a way to independently check the 5x factor using my own test images? The scaler test program allows only 4x or lower (and my monitor's resolution is too low for the patch to kick into 5x).

[ WEB ] - [ BLOG ] - [ TUBE ] - [ CODE ]

Reply 9 of 109, by tauro

User metadata
Rank Member
Rank
Member

Hi people,

I'm new to this forum.

I was trying to compile ZenJu's version on Ubuntu 12.04 i686, but I got stucked. I'm not a programmer, so I'm asking you please to help me.

I'm posting the make output as an attachment.

Any help would be greatly appreciated.

Attachments

  • Filename
    make-output.txt
    File size
    14.12 KiB
    Downloads
    276 downloads
    File license
    Fair use/fair dealing exception

Reply 10 of 109, by ZenJu

User metadata
Rank Newbie
Rank
Newbie

Ubuntu 12.04 i686

AFAIK 12.04 uses GCC 4.6, but for the code above you need at least 4.7; upgrading to the most recent Ubuntu should do.

https://sourceforge.net/projects/xbrz
https://freefilesync.org

Reply 11 of 109, by kolano

User metadata
Rank Oldbie
Rank
Oldbie

Is anyone aware of a shader version of xBR compatible with DOSBox? I know it's been reformatted for a variety of emulators, but not sure which emulators shader handlers might align with DOSBox's.

Reply 12 of 109, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

With lockstock dosbox NO shader will work, since it doesn't have support for that (rightfully since afaik shaders are not exactly cross platform).

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 13 of 109, by tauro

User metadata
Rank Member
Rank
Member

Quote:
Ubuntu 12.04 i686

AFAIK 12.04 uses GCC 4.6, but for the code above you need at least 4.7; upgrading to the most recent Ubuntu should do.

Oh, what a pity. I'm not going to leave 12.04 as it is stable.

What if I install 12.10 in a virtual machine, then compile. If the binary works, will it work in 12.04 as well?

Reply 14 of 109, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

Look at the error log. It tells you how to compile it with your gcc

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 15 of 109, by tauro

User metadata
Rank Member
Rank
Member

Look at the error log. It tells you how to compile it with your gcc

Can that be done? I don't know how to. I looked the log, it says something about adding -std=c++0x, is that it? I wouldn't know how to.

Would anybody please help?

Thanks in advance

Reply 16 of 109, by robertmo

User metadata
Rank l33t++
Rank
l33t++

HQx is still far superior than xBZR cause it can detect and than filter similar colors. So it would be good if that technique was added to xBZR too. Compare the large clay bottle below.

Attachments

  • Filename
    kyrandia2_HQx.png
    File size
    403.55 KiB
    Downloads
    357 downloads
    File license
    Fair use/fair dealing exception
  • Filename
    kyrandia2_xBZR.png
    File size
    252.59 KiB
    Downloads
    387 downloads
    File license
    Fair use/fair dealing exception

Reply 17 of 109, by ykhwong

User metadata
Rank Oldbie
Rank
Oldbie

The current version of TBB is not supported on Windows 2000 at all. Is there any alternative to the template library? I am not sure if OpenMP can do it in the same way. Does using the openmp with task granularity work?(http://software.intel.com/en-us/articles/gran … lel-performance)

Visual Studio compiles the code in xbrz.cpp fine, but gcc does not. Tested with gcc 4.7.2 with c++11 support. MSVC seems to be more lenient than other compilers when dealing with templates.

Reply 18 of 109, by ZenJu

User metadata
Rank Newbie
Rank
Newbie

TBB is not supported on Windows 2000 at all. Is there any alternative to the template library

I do not think there is a simple substitute for TBB. But instead of looking for other libraries for task based parallelism I would simply drop support for Windows 2000. At this point the market share is below a promille!

Visual Studio compiles the code in xbrz.cpp fine, but gcc does not

Indeed, I fixed the problems and uploaded the new version as "xBRZ.zip" above. It compiles fine on GCC now, except for a spurious compiler warning about an "uninitialized variable" which is a compiler bug and can be ignored. (and I'm not talking about compiler bugs lightly).

I also updated "Dosbox Source.7z" to reflect the latest binary above.

https://sourceforge.net/projects/xbrz
https://freefilesync.org