MSX1 entry 5th in Assembly 2009 extreme graphics compo

Page 2/2
1 |

By ARTRAG

Enlighted (6832)

ARTRAG's picture

10-08-2009, 19:05

About dithering and the 8 pixel/2 colors limit you really should have a look at this converter:

http://www.msx.org/modules.php?op=modload&name=Downloads&file=index&req=visit&lid=859

It uses simple Floyd-Steinberg + screen 2 limits, but it seems very good to me (both in execution speed and results)
Probably it could be extended to 8 pixel/4 colors without too much effort.

( C code is included )

By Marq

Champion (387)

Marq's picture

10-08-2009, 19:37

From a technical standpoint everything is nice and clean when dealing with two pages that can be swapped with name table base address, ie. 16x24 characters or 128x192 pixels. For bigger images - or more precisely larger amount of characters - the corresponding color table and possibly the pattern table too need to be updated (we update both, at least for now). Each added column of 24 chars eats up one column from the nametable-swapped image too, so 2 columns x 24 chars x 8 bytes x 2 tables = 768 bytes need to be copied for each additional column. Using pure OUTI during blank and OUTI+NOP+NOP during the screen refresh we can output more or less 3k during one frame, which yields a pitiful 4 column increase (20x24 or 160x192). Not even close to full screen and I didn't manage to get even those 4 columns out of MSX1 in practice, while MSX2 was more than happy to do it with pure OUTI.

Using the fast port commands and compiling a big specific code array for each image would help to some extent, but overall we're out of luck. Even such painful tweaking wouldn't yield one column more. Updating only the color table is a double-edged sword: we could get an image as big as 25x24 characters (200x192) but on the other hand the image quality would drop. So the best solution seems to be to craft the fullscreen images so that these different types of characters (nametable flipped, static, full updated and colortable updated) are used in accordance with the image properties. A truly generic solution is limited to 20x24 as far as I know but who says we can't have images with flat areas and repetition Smile

By yzi

Champion (444)

yzi's picture

10-08-2009, 20:05

ARTRAG: I did look at Jannone's online converter, and it produces very nice results for normal screen 2. I also made a 2-color converter first and then extended it to four combined/interlaced colors for every 8 pixels. I haven't looked at that C source, but at least starting from my own initial 2-color converter it did take quite a lot of effort to extend it to 4 colors / 8 pixels so that it works well. The single most significant discovery was to use a windowing function instead of just adding errors together.

I don't know, maybe the Jannone converter uses a windowing function as well? Anyway, one of my primary motivations was to have fun trying out diffrent algorithms. Wink

By ARTRAG

Enlighted (6832)

ARTRAG's picture

10-08-2009, 20:18

If you know jannone's work, well have a glance to my C, it can go to 4 color/8 pixels very neatly.
jannone's dithering (that my C has just optimized) is floyd's one with this steps:

a) find the "best" 8 pixel line that can be represented by screen 2 for that 8 pixel section of the image
b) compute the quantization error on the 8 pixels
c) spread the quantization error in the 8 current pixel line, in th adjacent pixel on teh right an on the 8 pixel line on the bottom (according to floyd window of weghts)
d) move to the next 8 pixels and go to a) - keeping into account the errors spread by step c)

By yzi

Champion (444)

yzi's picture

10-08-2009, 21:35

ARTRAG: Thanks, interesting. During step a), do you spread errors from pixel to pixel inside the 8 pixel line? If you don't, it's sort of like a hybrid between simple thresholding and Floyd-Steinberg error propagation.

In my algorithm, I do the dithering more pedantically. There's a selection of dithering algorithms like Floyd-Steinberg (I prefer lighter than "correct" weights to tame down excessive color spreading) and ordered dithering. Inside each 8-pixel line, full dithering is performed, and this is done for every possible good 4-color "palette" (colors resulting from bad combinations like black+white have been left out), and the best palette is selected according to the selected aesthetic criteria function. As one of the dithering/color reduction functions, I also have simple thresholding, i.e. no dithering. The converter also has an optional "pre-dithering" phase where the whole image can be dithered down without considering the 8 pixel limitations.

See, it's good that I didn't look at Jannone's sources before trying to solve the problem. Wink Because I came up with something different. I could add the Jannone variation as one of the dithering algorithms in the converter though.

Does the Jannone version use "correct" Floyd-Steinberg weights, i.e. 7/16, 3/16, 5/16, 1/16? I experimented with differently scaled weights and ended up using something like 20 or 24 as the denominator, instead of 16.

By ARTRAG

Enlighted (6832)

ARTRAG's picture

10-08-2009, 21:54

in step a) there is no spreading, we only find the best representation of the 8 pixels (including errors already spread by other passes on other 8 pixels lines) according to screen 2 restrictions.

yes, weights are standard.

By [D-Tail]

Ascended (8258)

[D-Tail]'s picture

10-08-2009, 22:02

yzi: you could also go for a slightly different error diffusion kernel, such as:

[  #   a ]
[ 16-a 0 ] * 1/16

In my graduation project, I got very reasonable results from that, with a around 12.

By ARTRAG

Enlighted (6832)

ARTRAG's picture

11-08-2009, 11:11

@ yzi
Actually even if it seems not, the algorithm is in the end a true Floyd dithering.
I think i was wrong telling that we do not do spreading into the 8 pixels while doing the search...
time has passed, sorry, better checking the code yourself next time

Tongue

Page 2/2
1 |