SCALER xBRZ (SDL1)

Here you can discuss the development of patches.

SCALER xBRZ (SDL1)

Postby ZenJu » 2012-12-10 @ 19:34

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: Image HQx: Image xBRZ: Image

original: Image HQx: Image xBRZ: Image

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


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/fi ... erTest.zip

DOSBox v0.74 + xBRZ + Save States support:
http://sourceforge.net/projects/xbrz/files/DOSBox/
Last edited by ZenJu on 2015-1-11 @ 20:19, edited 14 times in total.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: xBRZ - High quality image scaling support for DOSBox

Postby kolano » 2012-12-10 @ 19:50

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?
User avatar
kolano
Oldbie
 
Posts: 527
Joined: 2010-12-26 @ 21:03

Re: xBRZ - High quality image scaling support for DOSBox

Postby VileRancour » 2012-12-10 @ 21:33

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...
You do not have the required permissions to view the files attached to this post.
web  /   (NEW) blog   /   tube
User avatar
VileRancour
Oldbie
 
Posts: 1610
Joined: 2003-5-14 @ 22:11
Location: 1-01-80 0:00a

Re: xBRZ - High quality image scaling support for DOSBox

Postby Dominus » 2012-12-10 @ 21:43

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.
User avatar
Dominus
DOSBox Moderator
 
Posts: 7578
Joined: 2002-10-03 @ 09:54
Location: Vienna or Ludwigsburg

Re: xBRZ - High quality image scaling support for DOSBox

Postby ykhwong » 2012-12-11 @ 08:00

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.
You do not have the required permissions to view the files attached to this post.
ykhwong
Oldbie
 
Posts: 627
Joined: 2004-3-17 @ 15:35

Re: xBRZ - High quality image scaling support for DOSBox

Postby kolano » 2012-12-11 @ 08:26

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.
User avatar
kolano
Oldbie
 
Posts: 527
Joined: 2010-12-26 @ 21:03

Re: xBRZ - High quality image scaling support for DOSBox

Postby ZenJu » 2012-12-11 @ 11:41

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: Image xBRZ: Image

xBR: Image xBRZ: Image
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: xBRZ - High quality image scaling support for DOSBox

Postby VileRancour » 2012-12-11 @ 12:37

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  /   (NEW) blog   /   tube
User avatar
VileRancour
Oldbie
 
Posts: 1610
Joined: 2003-5-14 @ 22:11
Location: 1-01-80 0:00a

Re: xBRZ - High quality image scaling support for DOSBox

Postby ZenJu » 2012-12-11 @ 15:44

check the 5x factor

I've unlocked the 5x factor in the test app and updated the attachment.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: xBRZ - High quality image scaling support for DOSBox

Postby tauro » 2013-1-12 @ 19:04

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.
You do not have the required permissions to view the files attached to this post.
User avatar
tauro
Newbie
 
Posts: 42
Joined: 2013-1-12 @ 18:53

Re: xBRZ - High quality image scaling support for DOSBox

Postby ZenJu » 2013-1-12 @ 19:16

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.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: xBRZ - High quality image scaling support for DOSBox

Postby kolano » 2013-1-12 @ 20:28

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.
User avatar
kolano
Oldbie
 
Posts: 527
Joined: 2010-12-26 @ 21:03

Re: xBRZ - High quality image scaling support for DOSBox

Postby Dominus » 2013-1-12 @ 20:51

With lockstock dosbox NO shader will work, since it doesn't have support for that (rightfully since afaik shaders are not exactly cross platform).
User avatar
Dominus
DOSBox Moderator
 
Posts: 7578
Joined: 2002-10-03 @ 09:54
Location: Vienna or Ludwigsburg

Re: xBRZ - High quality image scaling support for DOSBox

Postby tauro » 2013-1-12 @ 23:41

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?
User avatar
tauro
Newbie
 
Posts: 42
Joined: 2013-1-12 @ 18:53

Re: xBRZ - High quality image scaling support for DOSBox

Postby Dominus » 2013-1-13 @ 00:02

Look at the error log. It tells you how to compile it with your gcc
User avatar
Dominus
DOSBox Moderator
 
Posts: 7578
Joined: 2002-10-03 @ 09:54
Location: Vienna or Ludwigsburg

Re: xBRZ - High quality image scaling support for DOSBox

Postby tauro » 2013-1-13 @ 00:07

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
User avatar
tauro
Newbie
 
Posts: 42
Joined: 2013-1-12 @ 18:53

Re: xBRZ - High quality image scaling support for DOSBox

Postby robertmo » 2013-1-13 @ 12:31

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.
You do not have the required permissions to view the files attached to this post.
User avatar
robertmo
l33t
 
Posts: 4383
Joined: 2003-6-18 @ 10:35

Re: xBRZ - High quality image scaling support for DOSBox

Postby ykhwong » 2013-2-10 @ 03:44

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/article ... erformance)

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.
ykhwong
Oldbie
 
Posts: 627
Joined: 2004-3-17 @ 15:35

Re: xBRZ - High quality image scaling support for DOSBox

Postby ZenJu » 2013-2-11 @ 11:34

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!

Code: Select all
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.
User avatar
ZenJu
Newbie
 
Posts: 36
Joined: 2010-7-04 @ 12:05

Re: xBRZ - High quality image scaling support for DOSBox

Postby ykhwong » 2013-2-11 @ 13:39

Great job. Thanks. :)
ykhwong
Oldbie
 
Posts: 627
Joined: 2004-3-17 @ 15:35

Next

Return to DOSBox Patches

Who is online

Users browsing this forum: No registered users and 0 guests