Enhanced mode 1 pictures

discussion of beeb/electron applications, languages, utils and educational s/w
User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Enhanced mode 1 pictures

Post by davidb » Mon Sep 28, 2015 10:59 pm

I've invaded a number of other threads with this effort, so I've started a new thread for the inevitable picture disks I'm creating as the image conversion tools are slowly improved. I still haven't seen an image that really shows off this trick. Maybe on the next disk...

Image
Image
Attachments
palette-2015-09-29a.png
palette-2015-09-29a.png (9.15 KiB) Viewed 1107 times
2015-09-29-palette.zip
(82.46 KiB) Downloaded 69 times
palette-2015-09-29.png
palette-2015-09-29.png (10.07 KiB) Viewed 1107 times

User avatar
aerworuld
Posts: 1712
Joined: Tue Sep 25, 2012 8:40 pm
Location: Basingstoke, Hampshire
Contact:

Re: Enhanced mode 1 pictures

Post by aerworuld » Tue Sep 29, 2015 6:38 am

Very nice! =D>

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Tue Sep 29, 2015 7:43 am

Thanks, Stuart! :)

User avatar
sPhilMainwaring
Posts: 264
Joined: Tue Jan 15, 2013 7:57 pm
Location: Mid Wales
Contact:

Re: Enhanced mode 1 pictures

Post by sPhilMainwaring » Tue Sep 29, 2015 8:51 am

So is this MODE 2 colours at MODE 1 resolution?

steve3000
Posts: 1957
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: Enhanced mode 1 pictures

Post by steve3000 » Tue Sep 29, 2015 9:32 am

Looks like changing the 4 colours in use for each line? (from the 8 colour palette)

Looks good!

How do you do your image palette conversion/optimisation?

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Tue Sep 29, 2015 9:59 am

The picture viewer displays 4 colours out of the standard palette of 8 per scanline. Colour choice is done using one of two different tools: one is very simple and just aims for the nearest colour in the standard palette, with a bit of bias towards certain colours; the other tries harder to choose colours or combinations of colours that match those in the original image.

Certainly, better schemes are possible. It might be interesting to treat alternate scanlines slightly differently, to allow complementary colours to be chosen. It would also be good to replace individual pixels of a colour outside the 4 colour palette with those of the nearest colour in the palette; for example, in a black-red-yellow-green palette, replacing magenta pixels with red ones and cyan pixels with green.

In the end, some artistic license is required to make the most of existing images. If you were to create images from scratch in a pixel editor, you could be even more creative. :)

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Tue Sep 29, 2015 11:01 pm

I have some work to do on my Floyd–Steinberg dithering, but hopefully you get the idea.
ImageImageImageImageImageImage
I only allow one colour change per line, but could probably manage 2 even with a full width image.
The final image is what you would get choosing only four colours for the whole screen with the BBC Micro Image converter (which I really like). I hope the author Francis? adds support for this method of converting images. EDIT: added PSU picture, still only changing 1 colour per line.
Attachments
bbc_psu_eg.png
bbc_psu_eg.png (49.31 KiB) Viewed 1107 times
beeb_4_col.png
beeb_4_col.png (19.34 KiB) Viewed 1107 times
bbc_out.png
bbc_out.png (21.77 KiB) Viewed 1107 times
bbc_in.jpg
bbc_in.jpg (9.22 KiB) Viewed 1107 times
parrot_out.png
parrot_out.png (12.91 KiB) Viewed 1107 times
parrot_in.jpg
parrot_in.jpg (11.97 KiB) Viewed 1107 times
Last edited by tricky on Wed Sep 30, 2015 7:00 pm, edited 1 time in total.

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Tue Sep 29, 2015 11:12 pm

Those look very good indeed, tricky! :D

Meanwhile, I went through a lot of photos looking for ones that look OK after being converted with the current tools I'm using and compiled another disk.

Image
Image
Image

The third one is interesting because it naturally exhibits the kind of alternating scanline colours that I mentioned above, doing green then cyan in some areas. It's remarkable that certain colours only appear on certain scanlines, giving the impression that there are more than four colours in use on any particular horizontal line! :)
Attachments
2015-09-30-palette.zip
(63.61 KiB) Downloaded 55 times
palette-2015-09-30c.png
palette-2015-09-30c.png (10.28 KiB) Viewed 1107 times
palette-2015-09-30b.png
palette-2015-09-30b.png (14.65 KiB) Viewed 1107 times
palette-2015-09-30a.png
palette-2015-09-30a.png (9.09 KiB) Viewed 1107 times

User avatar
danielj
Posts: 6779
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: Enhanced mode 1 pictures

Post by danielj » Wed Sep 30, 2015 6:04 am

Very impressed with all of these!

d.

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Wed Sep 30, 2015 7:57 am

Thanks, Daniel. :)

It would be interesting to play with dithering and error diffusion techniques for mode 0 images. The same code works for these, too, it's just that you need to encode the images differently for display in that mode and write the appropriate palette register values to memory for the display routine to retrieve.

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Wed Sep 30, 2015 8:41 am

I was thinking about mode 0 and it is a shame that the extra resolution is horizontal.
I think partial palette programming might work well in mode 0, but I don't think my image foo is up to it-it is about equal to my music foo ;)

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Wed Sep 30, 2015 6:58 pm

I was just doing the maths (finally) and I think you are correct, on the beeb you can change all four colours with I think only a maximum of two pixels the wrong colour and by carefully choosing the order of palette programming, that can be avoided, or I guess just by not using the last colour to be programmed in the first two pixels of a line, which of course it easy ;)

User avatar
oss003
Posts: 2852
Joined: Tue Jul 14, 2009 11:57 am
Location: Netherlands
Contact:

Re: Enhanced mode 1 pictures

Post by oss003 » Wed Sep 30, 2015 7:09 pm

WOW ..... very impressive guys =D> =D>

Can't wait to see a MODE 0 picture in colour.

Greetings
Kees

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Wed Sep 30, 2015 10:40 pm

Sorry, got my maths wrong!
There is actually time to reprogram TWO colours per scan line, which is a blow as I have just finished converting my converter to four colours per line!
I'll code the converter and displayer tomorrow and post some more images, maybe even an ssd.

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Wed Sep 30, 2015 11:48 pm

Just looking at this briefly this evening as paulb has been working on an improved version of his conversion tool. It all looks very promising. I'm not very optimistic about pictures in mode 0, but you never know what surprises may await us if we run the tools over enough images. :lol:

paulb
Posts: 811
Joined: Mon Jan 20, 2014 9:02 pm
Contact:

Re: Enhanced mode 1 pictures

Post by paulb » Thu Oct 01, 2015 6:06 pm

Playing around with some sample images...

Image

This one I modified to add extra colours:

Image

I'm sure I could be doing the dithering a lot more thoroughly, but the images convert a lot better than they used to with my previously over-thought (but not as good) conversion algorithm. :)
Attachments
MountainPanicCoverArt-modified.png
A modified version of the Mountain Panic artwork. Apologies in advance to the artist!
MountainPanicCoverArt-modified.png (20.28 KiB) Viewed 1107 times
bbc-crop_out.png
That BBC Micro brochure picture, acquired from the PDF and cropped.
bbc-crop_out.png (18.86 KiB) Viewed 1107 times

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Fri Oct 02, 2015 1:04 am

Here is a two colour change per line parrot. The first image is the original, then what it should look like on the beeb, finally, what it looks like in b-Em/beebem - I have a bug at the top. I have also attached a zip with the .ssd (I haven't tried it on a real beeb yet).ImageImageImagePS I should have turned the cursor off in LOADER.
Attachments
parrot3.zip
(15.68 KiB) Downloaded 89 times
parrot3_bem.png
parrot3_bem.png (26.82 KiB) Viewed 1107 times
parrot3_eg.png
parrot3_eg.png (39.92 KiB) Viewed 1107 times
parrot3.png
parrot3.png (132.62 KiB) Viewed 1107 times

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Fri Oct 02, 2015 8:10 am

Looking good! :D

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Fri Oct 02, 2015 8:36 pm

Here is a disk with timing tweaked for a real beeb, it cycles through a few sample images. Please let me know if it flickers.
There are still some bugs in the converter, mostly at the top of the images, and the algorithm has plenty of room for improvement, but it does show that swapping two colours per line does work.
The LOADER program sets the horizontal sync pulse width to 9 as my main LCD won't sync on 8 - delete VDU 23,3 if it causes you problems.
Attachments
ImageViewer.zip
(63.66 KiB) Downloaded 73 times

User avatar
jbnbeeb
Posts: 430
Joined: Sat Apr 03, 2010 8:16 pm
Contact:

Re: Enhanced mode 1 pictures

Post by jbnbeeb » Fri Oct 02, 2015 9:22 pm

Will try on a real beeb this wkd.

Nice looking images - tricky are your last two posts Mode 1 or 0?

AND

questions for Tricky and Davidb

a) what source image do you feed to the Beeb (or Elk) program? i.e. what is the format (resolution, no. of colours)
b) do you run any code PC side to manipulate the image before it is displayed on Beeb/Elk side
c) can you describe the algorithm/s used to decide what colours to use per line
d) can you upload the source code (preferably commented :) ) ?

Well done to you both. =D> =D> =D> I reckon you're pushing boundaries on the Acorn 8 bits; I think similar (probably more fancy due to h/w) tricks have been done on the C64 with odd screen modes and dithering.
I'm going to ..
ABUG Cambridge Sept 7th-9th Sept 2018
Image

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Fri Oct 02, 2015 10:42 pm

For the Electron code itself, the source images need to be 320x256 in the standard 8 colours.

On the PC side, the make_picture.py script will scale larger images down and reduce the colours to only 4 per scanline. If paulb doesn't publish his script separately, I'll try to include it with my tools, but it works in a similar way. The make_picture.py script encodes the image data in the form that is needed for mode 1.

I think I described my algorithm in an earlier message. paulb would have to describe his, though the code he wrote is deceptively short for what it does.

I put the code in a Mercurial repository. I'll update it later tonight.

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Fri Oct 02, 2015 11:34 pm

I can reproduce the parrot image in Elkulator using my code, so I'm happy about that. :) I had to do some things to the parrot3_eg.png image first, but then it could be processed by my conversion script.

Where did the parrot picture come from, by the way?

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Sat Oct 03, 2015 12:25 am

My conversion only takes tga files as it is the same code I have used for the last 20 years. It takes the to left 320x256, cropping the right and reducing to a multiple of 4, so that it doesn't require a border color, but currently doesn't reduce the width of the screen, maybe tomorrow. The bottom is padded with black, I us it should be centred, but isn't yet.
The source can be any bit depth as it uses a Floyd-something algorithm to dither the image.
To pick the colours, I use sum of squared errors in r,g and b and just try all combinations of the current line with all combinations of the next for "preview" quality and takes a couple of seconds in c, it can run with any lookahead, but I haven't decided if anything more than 2 is useful and as that takes about 15 second unoptimised on my old desktop, it is long enough.
I output a tga of what the image should look like and two files ready for beebasm to include, one with two sets of palette info and one with the image.
The parrot was just on my disc, I'm unsure where it came from, it might have been a really old cover disc, I'm not sure.
Mine are mode 1.I will post the source once I have debugged it as it still goes mad on some images; and you know comments and I are strangers :O
Does the electron palette programming differently to the beeb? Or do i have time to change 4 colours and just can't work out how?

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Sat Oct 03, 2015 12:00 pm

The Electron palette in a 4 colour mode only uses 2 registers, mapped to the addresses FE08 and FE09, so I just need to read the contents of 2 locations in RAM (which will cause the CPU to stall if done during the display period) and write to the registers. 12 bits are needed to represent the 4 colours so I can't just use one location to hold the palette unless I optimise the palette entries, which really isn't worth it for my code. In a 2 colour mode, I could easily do that.

From the EAUG (page 215), the two registers look like this, with the red, green and blue components for each logical colour stored in inverted form (0 enable, 1 disable):

Code: Select all

FE08: B3 B2 B1 B0 G3 G2 X  X
FE09: X  X  G1 G0 R3 R2 R1 R0
So, to make colour 0 black, you have to set the bits containing R0, G0 and B0.

If I try to run similar code in RAM, the instructions are accessed at half the speed. Memory accesses are the same when done from ROM or RAM, but there may not really be enough time to change both registers. I could understand if you are short of time when having to change 4 of them. Even if you optimised the number of locations that hold the palette data, you would still need to unpack the data and write to 4 palette registers as I understand it. Does that make sense?

Edit: If you have to write to 4 registers per colour, if I'm reading the AUG correctly, then the situation looks even worse! I suppose you could take advantage of the "nasty" effects that the guide mentions and write to fewer registers, but then you'd need to optimise the data even further. :(

User avatar
tricky
Posts: 3164
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Enhanced mode 1 pictures

Post by tricky » Sat Oct 03, 2015 3:33 pm

That makes sense, yes, four writes per "colour", I use something like:

Code: Select all

.wait_for_vsync
	lda #SysIntVSync
	sta SysViaIFR
.wait_vsync
	bit SysViaIFR
	beq wait_vsync
The bit takes 4 cycles and the last beq, 3, meaning that I have a "random" element of less than 6 cycles. I could probably make this better by more precise cycle counting and get it down to knowing exactly when the vsync starts, but that wouldn't get me another 24 cycles for another colour.

Code: Select all

.write_palette_entries
	STA VideoULAPalette
	EOR #&10
	STA VideoULAPalette
	EOR #&40
	STA VideoULAPalette
	EOR #&10
	STA VideoULAPalette

	TYA
	STA VideoULAPalette
	EOR #&10
	STA VideoULAPalette
	EOR #&40
	STA VideoULAPalette
	EOR #&10
	STA VideoULAPalette
Changing both colours takes 46 cycles, but a bit less from first register write to last.
There are 128 cycles per scanline, with 80 of them visible, leaving 48 cycles to change the palette and allow for which of the 7 cycles in the BEQ+BIT the vsync starts. As I haven't seen any flicker, I either have my maths wrong, or don't use the changed colour in the first/last byte!

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Sat Oct 03, 2015 6:25 pm

Another set of images to look at. This disk has a screen containing information about the code. :)

Image
Image
Image
Attachments
palette-2015-10-03c.png
palette-2015-10-03c.png (8.67 KiB) Viewed 1107 times
palette-2015-10-03b.png
palette-2015-10-03b.png (20.06 KiB) Viewed 1107 times
palette-2015-10-03a.png
palette-2015-10-03a.png (18.41 KiB) Viewed 1107 times
2015-10-03-palette.zip
ROM and disk images.
(91.52 KiB) Downloaded 85 times

User avatar
jgharston
Posts: 3409
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Enhanced mode 1 pictures

Post by jgharston » Sat Oct 03, 2015 7:12 pm

I just get the screen filling and Bad key.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
paulv
Posts: 3748
Joined: Tue Jan 25, 2011 6:37 pm
Location: Leicestershire
Contact:

Re: Enhanced mode 1 pictures

Post by paulv » Sat Oct 03, 2015 7:35 pm

jgharston wrote:I just get the screen filling and Bad key.
I get the same. I see bad key and every image loads one after the other with no waiting and no palette jiggery pokery either.

Paul

User avatar
davidb
Posts: 2293
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: Enhanced mode 1 pictures

Post by davidb » Sat Oct 03, 2015 7:36 pm

jgharston wrote:I just get the screen filling and Bad key.
That's odd. What system configuration are you using?

User avatar
oss003
Posts: 2852
Joined: Tue Jul 14, 2009 11:57 am
Location: Netherlands
Contact:

Re: Enhanced mode 1 pictures

Post by oss003 » Sat Oct 03, 2015 7:45 pm

Hi David,

Elkulator is working fine, great pictures!!! =D> =D>

Greetings
Kees

Post Reply