Image2Mode7 - general image to teletext converter

discussion of beeb/electron applications, languages, utils and educational s/w
User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Image2Mode7 - general image to teletext converter

Post by kieranhj » Tue Sep 20, 2016 9:25 pm

Hey everyone,

As part of my MODE 7 explorations I've written a general purpose image to teletext convertor. It's early days, and command-line only I'm afraid, but I thought I would share it on here for testing & feedback and to see what people might be able to do with it.

Executable is attached in the zip. Usage for the app is as follows:

Code: Select all

 image2mode7: MODE 7 image convertor.

Usage : image2mode7 [options] (Sep 20 2016, 21:48:19)

    -i           0            Input filename
    -o           0            Output filename
    -sat         64           Saturation threshold (below this colour is considered grey)
    -val         64           Value threshold (below this colour is considered black)
    -black       64           Black threshold (grey below this considered pure black - above is colour brightness ramp)
    -white       128          White threshold (grey above this considered pure white - below is colour brightness ramp)
    -nohold      false        Disallow Hold Graphics control code
    -nofill      false        Disallow New Background control code
    -test        false        Save test image (post-quantisation) before Teletext conversion
    -inf         false        Save inf file for image
    -v           false        Verbose output
    -url         false        Spit out URL for edit.tf
Where second column is the default value. Output filename is optional (otherwise just adds .bin to input filename.) Takes jpg & png format as input only.

Here are some examples (not sure if this is going to put the pics inline or not!)
bbc_in.jpg
bbc_in.jpg (9.22 KiB) Viewed 412 times
bbc_mode7.PNG
parrot3.png
parrot3.png (132.62 KiB) Viewed 412 times
parrot3_mode7.PNG
palette-2015-10-16.png
palette-2015-10-16.png (26.7 KiB) Viewed 412 times
mode0_mode7.PNG
105_0588.JPG
dylan_mode7.PNG
Note this is a hard problem to solve so lower your expectations for what can be achieved!! I cannot claim full credit for the work as this is based on an algorithm created by Julian Brown for the VIA/Neurotypical demo from a few years ago. I dusted it off, got it working, rewrote it to understand it better, and speed it up a bit, then added support for the Hold Graphics mode. Source is on GitHub buried in a branch but I will post a clean repo for it.

The algorithm does sometimes produce weird and funky sequences of control codes, so could do with some further investigation and debugging, but overall it seems to work. Given the command-line parameters are a bit opaque, it could do with a lovely Windows app with real-time preview to tweak the values with sliders but I don't really write Windows apps (oh, the irony.)

I'll post more about how the algorithm works tomorrow (getting a bit late now) but enjoy and let me know if you manage to produce anything fun with it.

Note that the current version of Image2BBC_ImportTTX tool has a bug which doesn't handle Hold Graphics properly, so you may end up with black character gaps. Use your favourite emulator, e.g. B-Em or jsbeeb, for better preview or use the -url option to spit out an edit.tf URL and just paste it into your browser.
Attachments
image2mode7_v1.zip
Image to Mode 7 conversion utility
(283.83 KiB) Downloaded 137 times
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

User avatar
lurkio
Posts: 1564
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by lurkio » Tue Sep 20, 2016 10:40 pm

Intriguing, but what are the system requirements for running this utility?

I'm guessing 64-bit Windows with Visual Studio 2015 runtime?

What I know for sure is that the utility doesn't seem to work for me on my Virtualboxed Win7 32-bit, on which I can't install the Visual Studio runtime for some reason (the installer errors out).

Btw, here's the link to the VIA/Neurotypical demo you mentioned, which is jawdropping!:
:shock:

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Wed Sep 21, 2016 5:56 am

Hey Lurkio,

Please bear with me, it's been a while since I had to figure out distributing Windoes exes (usually it's just a BBC SSD image :) ). It was built as x86 but you are correct that was on a 64-bit Windows 10 machine with VS 2015. I'll check the various compatibility options and see if I can get it down to a more sensible lowest-common denominator of 32-bit Win 7, that would be more sensible.

The Neurotyoical demo is cool but requires a GoMMC to pull the data off fast enough. I think we can get most of the way there using a regular floppy, although maybe not with sampled sound, which is a data hog.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

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

Re: Image2Mode7 - general image to teletext converter

Post by tricky » Wed Sep 21, 2016 7:01 pm

This looks excellent, especially supporting hold.
You could try statically linking to the runtime, it will make the exe bigger, but hopefully not 13MB bigger.
In the mean time, the runtime redists can be found here: https://www.microsoft.com/en-us/downloa ... x?id=48145
The x86 (32bit) was enough to get me running on win7 64bit, off to play now.

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

Re: Image2Mode7 - general image to teletext converter

Post by tricky » Wed Sep 21, 2016 7:51 pm

I've been having a play and it does a great job.
For my main use, I would give it an image 78x75 or 80x75 using only the eight beeb colours.
I had a thought for a couple of possible tweaks if you feel like trying them:

You could allow separated graphics to give a "darker" colour.

You could try the three vertical offsets and possibly the two horizontal to see which gives the closest result.

For me, it would be handy to have a 1:1 option, as my starting images will often be approximately 78/80x75.

Thanks again, great tool.

User avatar
lurkio
Posts: 1564
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by lurkio » Wed Sep 21, 2016 8:06 pm

Okay, I managed to nab some time on a Win64 PC. :-& :wink:

Here's my masterpiece:
  • 1.png
Joking aside, this is an amazing result!

You can also see my masterpiece online here, output using the utility's "-url" switch -- and it's worth drawing attention to the edit.tf site again for anyone who wasn't aware of it. I certainly wasn't. It too is amazing.

Thanks for all these audio-visual treats you're bringing us, Kieran!

=D>

User avatar
simonm
Posts: 185
Joined: Mon May 09, 2016 2:40 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by simonm » Wed Sep 21, 2016 8:55 pm

Nice, Kieran! Interesting idea on the separated graphics. I wondered if some dithering options might be of use also?
I have literally no idea how you achieved this, cant even begin to think of how you'd decide where to put colour codes etc. :)

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Wed Sep 21, 2016 9:50 pm

Hey all,

Glad you like it and have managed to get some results out. Love the Mona Lisa pic. :)

I tried to setup a Win7 VM for testing but my Dell laptop is trolling me with display driver issues (the VM works but I can't see anything, gah!) I will rebuild with all static linking turned on to see if that helps but won't be tonight.

A quick overview of the algorithm (which is different to Julian's original):
  • 1. Quantise image to MODE 7 colours (3-bit palette)
    2. Shrink image to 78xH or Wx75 (whichever fits)
    3. For each character cell in the current line choose one of the following:
    • a. Graphics character
      b. Change colour
      c. Toggle background fill (black background or new background)
      d. Toggle hold graphics mode
    4. Calculate the error from the desire image for that character cell
    5. Add the accumulated error for the rest of the line, if that character were to be to selected, by updating the teletext "state" and choosing the best character for cell X+1
    6. Choose the character with the lowest total accumulated error
    7. Repeat for every line
The comp-sci minded amongst you will notice this is a recursive algorithm that tries every possible combination of graphic character and control code to find the closest match to the desired image. Julian came up with a very nice way of encoding this so it doesn't take thousands of years - you're not actually searching all possible combinations because the possible states in any given character cell can only be determined by the ones preceding it on the line - you can't arbitrarily change all state independently in each cell.

The colour quantisation scheme is as follows per pixel:
  • 1. Turn RGB into HSV
    2. If saturation is low then assume this is "grey"
    3. If grey then map to a colour ramp from black -> blue -> cyan -> white based on black/white params
    4. If colour then map to nearest 3-bit BBC palette value or black if brightness below threshold
The reason I did this was because otherwise greys map to either black or white and look really harsh. I also don't do any dithering because the pixel resolution is so low it doesn't actually help the quality of the image and actually make things worse because you can't have arbitrary pixels in different colours in MODE 7.

Tricky - I can easily add a 'no quant' flag if you're passing in BBC palletised images already, ditto a 'no scale' flag (although I only support 78x75 as you need at least one control code before you can display graphics.)

Julian's original algo did support separated graphics but I removed this whilst I was getting it going. I will think about how it might go back in but does add complications to Hold Graphics mode as that state is remembered separately for the replacement character, believe it or not. I like the idea of it being an intermediate "colour" between foreground & background though.

What did you mean about the vertical & horizontal offsets? How were you imagining this working?

I have some more tweaks and different approaches to look at anyway to try and increase image "quality". I'll keep everyone posted. :D
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

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

Re: Image2Mode7 - general image to teletext converter

Post by tricky » Wed Sep 21, 2016 10:47 pm

I don't think it needs a -noquant flag as I assume it will just pick the right colours anyway after a few milliseconds processing.

I was suggesting that if the image was resized to 77x73 instead of 78x75, then you could try generating the six different images that would correspond with the six possible offsets within a character.

The idea was that if the colours happened to line up more with character boundaries in one than the others then that image would probably encode better, you could either pick automatically or just export all 6.

Without this option, you don't need a 1:1 option and even with the pick best of six images, if you didn't resize images close to 78x75 you still wouldn't need it.

When you were comparing the quality of dithered images, were you dithering to 3 bit and then encoding, or encoding whilst calculating the error against the original full colour (but low res) image?

If you look at the changing palette per scan line images, some of the electron ones look like what I got converting to 3 bit and then dithering as opposed to the beeb encoder I wrote which compares the output image to the original.

Some images do not dither well, while others aren't so bad, but as you say, I expect more would look worse at such a low resolution.

User avatar
simonm
Posts: 185
Joined: Mon May 09, 2016 2:40 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by simonm » Fri Sep 23, 2016 11:27 am

Just a thought, but would it be better to do the 3 bit colour quantization after the resize? This might preserve more image detail.
Similarly perhaps dithering at the colour quantization step might retain more dynamic range.
I noticed Julians via demo used dithering to a fairly decent effect is all.

joachim
Posts: 134
Joined: Wed Jun 21, 2006 1:20 am
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by joachim » Fri Sep 23, 2016 3:38 pm

simonm wrote:Just a thought, but would it be better to do the 3 bit colour quantization after the resize? This might preserve more image detail.
Similarly perhaps dithering at the colour quantization step might retain more dynamic range.
I noticed Julians via demo used dithering to a fairly decent effect is all.
Best (but most algorithmically complicated) would be to not have a quantization step at all, but compare the possible teletext renderings directly to the full-colour image. (Ideally using a distance function that understands dithering.)

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Fri Sep 23, 2016 9:10 pm

joachim wrote:
simonm wrote:Just a thought, but would it be better to do the 3 bit colour quantization after the resize? This might preserve more image detail.
Similarly perhaps dithering at the colour quantization step might retain more dynamic range.
I noticed Julians via demo used dithering to a fairly decent effect is all.
Best (but most algorithmically complicated) would be to not have a quantization step at all, but compare the possible teletext renderings directly to the full-colour image. (Ideally using a distance function that understands dithering.)
Yes, indeed, this is how one would normally do image palletisation and is not that difficult but I am not convinced it is the right approach in this case. Dithering helps when you have few colours but reasonable resolution - the combination of different colours next to each other gives the appearance of more colours. But this assumes you can individually address each pixel, which is not the case in MODE 7, add to that the incredibly low resolution and you lose the benefit of dithering to fool the eye. Note that the Neurotypical demo doesn't use any dithering, any noise comes from the video source.

I will investigate generating directly from the original image, and error propagation for dithering, but right now I believe a pseudo-stylised approach is best for Teletext, hence the pre-quantisation and blue colour ramp for greys etc. The "distance" between colours is also interesting in a quantised image anyway, a typical geometric approach tells us little as every colour is at the extents of the colour cube.

Anyway, I should be able to post an update tomorrow with some improved error calcs to tidy up the images a bit and have chance to play around with some of the alternative options, including Tricky's 6x idea.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

joachim
Posts: 134
Joined: Wed Jun 21, 2006 1:20 am
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by joachim » Sat Sep 24, 2016 1:21 am

You probably already realize this but even without changing the loss function, you can find a marginally better image (lower total error) by trying graphic chars other than the one that seems to be the best fit! I guess the advantage is that they result in a different hold char, and surprisingly that sometimes pays off.

The runtime is increased significantly, but not disastrously (a constant factor, not exponential thanks to your memoization).

I tried this on your cat pic (since you uploaded the source for that one): the differences are small but the shadow on the side of the cat's face (your left, cat's right) is slightly better greyed (cyaned). My guess is that having a better hold char (probably all-full or all-empty) is allowing it to squeeze in another palette switch:
cat.png
I'd like to try it on other image styles to see whether it makes enough difference to be worth the runtime.
Attachments
0001-try-other-chars.patch.txt
(2.01 KiB) Downloaded 40 times

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Sat Sep 24, 2016 7:34 am

joachim wrote:You probably already realize this but even without changing the loss function, you can find a marginally better image (lower total error) by trying graphic chars other than the one that seems to be the best fit! I guess the advantage is that they result in a different hold char, and surprisingly that sometimes pays off.

The runtime is increased significantly, but not disastrously (a constant factor, not exponential thanks to your memoization).

I tried this on your cat pic (since you uploaded the source for that one): the differences are small but the shadow on the side of the cat's face (your left, cat's right) is slightly better greyed (cyaned). My guess is that having a better hold char (probably all-full or all-empty) is allowing it to squeeze in another palette switch:

I'd like to try it on other image styles to see whether it makes enough difference to be worth the runtime.
Nice! Thank you for the patch. This was on my list to try next (I've been experimenting with the error function in what little spare time I've had this week) so great that you've made the changes already and had chance to test it a bit. Well done for finding the branch, although I'm slightly embarrassed by the current state of the code but never mind. :)

Yes, I suspected the same - that having a seemingly "non-optimal" graphic character for the current cell may well result in a lower overall error for the whole line due to its use as the hold graphics character later on. These are marginal gains but worth having for sure, I think we'll reach the limit after Tricky's 6x offset suggestion.

You can find the source images for the other pictures in the Enhanced Mode 1 image thread, although I can't find the link right now.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Sat Sep 24, 2016 8:30 am

Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Sun Sep 25, 2016 2:38 pm

OK, so I'm getting to the point of diminishing returns here so thought I'd post the latest executable. Source is now in its own repo on GitHub also: https://github.com/kieranhj/image2mode7

Changes:
  • - Some general tidy up of the graphics character selection to help make more sensible choices
    - No longer quantises the image by default but uses error from original (try -quant flag if image has lots of greys)
    - Uses geometric distance between colours as default error metric (try -lookup with -quant for experimental lookup table error)
    - Added experimental support for separated graphics (use -sep to enable this and -fore to adjust the relative contribution of foreground colour vs background colour when calculating error for separated character cells)
    - Added the patch from Joachim to exhaustively search for all characters when considering error but disabled by default as takes quite a while and only provides marginal gains (use -tryall command line option)
    - Added -noscale option if you already have a correctly sized image (will probably crash if you give it something too large / small)
There are still some improvements that could be made to the separated graphics support but this would involve oversampling the image (this is what Julian did in his original version of the algorithm.) I'll maybe get to this at some point.
parrot_in_sep.png
parrot_3_sep.png
baboon_mode7.png
this-is-mode-7.png
Attachments
image2mode7_v2.zip
General image to mode 7 (Teletext) conversion tool
(379.6 KiB) Downloaded 36 times
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Sun Sep 25, 2016 3:16 pm

Oh, and I realised I can't think of a way to do dithering properly as this normally relies on propagating the error from pixel-to-pixel but we don't strictly know which pixels will be which colour until we've searched all available combinations. Bit of a chicken & egg that one.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

joachim
Posts: 134
Joined: Wed Jun 21, 2006 1:20 am
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by joachim » Mon Sep 26, 2016 1:04 am

kieranhj wrote:Oh, and I realised I can't think of a way to do dithering properly as this normally relies on propagating the error from pixel-to-pixel but we don't strictly know which pixels will be which colour until we've searched all available combinations. Bit of a chicken & egg that one.
Well now, I expected this to be a little nontrivial … and it's a little more nontrivial than I expected, but I have some proof-of-concept code that's just barely good enough to argue against "can't be done" (maybe not good enough to argue against "can't be done *properly*" …).

So here is some code with two MAJOR limitations:
  • Although it was intended to be based on Floyd-Steinberg, it currently only dithers horizontally, not vertically. Adding code to propagate error from the row above should be straightforward, EXCEPT when you have to propagate from the pixel at above right, which can be in a character you haven't thought about yet. In principle that's solvable by adding a compensating term when you finally get around to computing that character, but this is getting complicated. (Note, to get rid of the ugly vertical stripes in the attached example image you don't need to solve this problem: a simpler vertical dither that never looks above-right would be enough.)
  • The memoization cache doesn't know about error propagation. This means the error terms used are simply wrong sometimes. This is definitely solvable by including the propagation error in the cache key, but the resulting code might be very slow because memoization is less effective. I'm thinking a good compromise here would be to cut the error propagation down to 1 or 2 bits in each channel.
parrot.dither.png
Attachments
0001-first-attempt-at-dithering.patch.txt
(24.15 KiB) Downloaded 34 times

User avatar
PitfallJones
Posts: 432
Joined: Fri Feb 22, 2008 3:44 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by PitfallJones » Mon Sep 26, 2016 6:06 pm

Great Converter! The Baboon is particularly good I think.

Could you post the source image (for the Baboon) and the Mode7 encodings for the pictures - I could load them straight into the video mem on a real BBC
and check them out.

I always resorted to using monochrome dither to make mode7 pictures before but your method is a revelation!

-PJ

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Mon Sep 26, 2016 9:11 pm

Of course, attached. The test images are all available (along with source) on GitHub: https://github.com/kieranhj/image2mode7 ... aster/test

Here's the Baboon at edit.tf.
Attachments
baboon.zip
(623.5 KiB) Downloaded 23 times
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

joachim
Posts: 134
Joined: Wed Jun 21, 2006 1:20 am
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by joachim » Tue Sep 27, 2016 1:09 am

Okay, having learnt from yesterday's dithering attempt, I set myself the significantly more modest task of only dithering within a character cell, and came up with a far simpler patch that doesn't have any of the problems of last time.

I'm not quite sure whether I like the results, but they are most definitely dithered.
dithered_parrot.png
dithered_cat.png
dithered_bbc.png
edit.tf:
parrot cat bbc
Attachments
0001-simple-dither-within-character-cell.patch.txt
(5.19 KiB) Downloaded 28 times

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Tue Sep 27, 2016 8:38 am

joachim wrote:Okay, having learnt from yesterday's dithering attempt, I set myself the significantly more modest task of only dithering within a character cell, and came up with a far simpler patch that doesn't have any of the problems of last time.

I'm not quite sure whether I like the results, but they are most definitely dithered.
Good work Joachim! I quite like the effect on the Red Parrot picture.

I haven't had chance to check out your patch yet, as a bit busy at work, but have been thinking about this. It should be possible to propagate the error from one character cell to the next in a row by extending the state. I ideally the minimum error we'd want would be 2-bits (1x sign-bit and 1x error-bit) per channel per pixel propagating from the right-hand edge = 2x 3x 3 = 18-bits. Unfortunately there's no way we can extend the state by 18-bits as we simply don't have enough time / memory to accommodate. A less expensive option might be to propagate the ~average~ error along the right-hand edge and distribute this across the first column of the next character cell. Again we wouldn't have many bits to play with but 2-bits error x 3-channels = 6-bits could work. Not sure what the results would look like but might be worth the experiment.

It should be easier to propagate error vertically from one character row to the next. Once a character row is selected, and the final graphics characters / control codes are being written to the MODE 7 frame buffer, we know what the final pixels on screen are going to be. At this point we can calculate the error in the bottom row of pixels in each cell and then just propagate this into next row of pixels in the source image by just updating the pixel data directly. This would then get picked up as the next character row is processed. Does that make sense?
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

joachim
Posts: 134
Joined: Wed Jun 21, 2006 1:20 am
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by joachim » Tue Sep 27, 2016 4:47 pm

Yes, agree with everything you've said although I would be prepared to try cutting that 2 bits per channel down to (log 3)/(log 2) bits — possible error values are {-1, 0, +1} — or even 1 bit — possible error values are {-½, +½}. The other thing I'd really want to try in making horizontal propagation work is improving the search algorithm, since otherwise it's going to spend a lot of time solving the same problem over and over again with minor changes to the hold character and the propagated error, which will almost never have any effect beyond the next character or two. A*-search might be a place to start, but it would need to be able to make good lower-bound estimates of the error in the rest of the line and even then it may not be enough.

The within-character-cell dither patch should be easy to extend to propagate vertically between rows: it was written with exactly that in mind although not actually implemented due to me being lazy and also wanting to write a clear and concise patch unlike the first monstrosity. It propagates error downward within a cell and currently the error falls off the bottom of the cell and gets lost, whereas the horizontal propagation is implemented differently: the two horizontally-adjacent pixels in a cell are just picked simultaneously, trying to make their errors average out.

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Tue Sep 27, 2016 7:05 pm

Hey Joachim,

Totally happy for you to run with this - I've spent way longer on it already than I intended to (original motivation was my MODE 7 video player that I still haven't tidied up and released.) I put you patch on a branch in my GitHub repo but why don't you take a fork? Happy to accept PR's back and review changes. The code is rough as heck so well done for getting this far. :)
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

puppeh
Posts: 15
Joined: Tue Sep 27, 2016 9:48 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by puppeh » Wed Sep 28, 2016 9:27 am

Hi!

Some nice results in here! I'm really happy you guys have found my old converter and have hacked some use out of it! You might be interested to see the original blog posting I made about it *mumble* years ago -- http://puppygalore.livejournal.com/19711.html. No technical detail, but some early image output.

Jules/pup

User avatar
PitfallJones
Posts: 432
Joined: Fri Feb 22, 2008 3:44 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by PitfallJones » Wed Sep 28, 2016 10:01 am

Great fun!

I made a small gallery program - press space to move to the next picture.

You can compare the more colors versions to the standard ones

PJ
Attachments
gallery.zip
(21.09 KiB) Downloaded 34 times

puppeh
Posts: 15
Joined: Tue Sep 27, 2016 9:48 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by puppeh » Wed Sep 28, 2016 10:08 am

One idea with error diffusion dithering that might improve results a bit, although it has no basis in theory I don't think, is to just diffuse *some* of the error (like, 25%) instead of all of it. IIRC a version of my conversion code did that with OK results.

User avatar
simonm
Posts: 185
Joined: Mon May 09, 2016 2:40 pm
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by simonm » Wed Sep 28, 2016 11:56 am

Cool stuff guys. I personally think the dithering adds a little extra definition overall.
Would an ordered dither be better for something like this where the pixels are so large? Plus it might be better for video sequences, since ordered dither may create fewer deltas between frames.
Jules's idea of % dither sounds interesting, similar to the BBC image converter tool, sometimes just a subtle bit of dithering works well.

User avatar
kieranhj
Posts: 640
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by kieranhj » Wed Sep 28, 2016 12:56 pm

puppeh wrote:Hi!

Some nice results in here! I'm really happy you guys have found my old converter and have hacked some use out of it! You might be interested to see the original blog posting I made about it *mumble* years ago -- http://puppygalore.livejournal.com/19711.html. No technical detail, but some early image output.

Jules/pup
Nice to see you back on here Jules! You should pop over to the VGM thread - we're currently arguing about what you did with the Sonic Enters a Dancehall tune. ;)
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

joachim
Posts: 134
Joined: Wed Jun 21, 2006 1:20 am
Contact:

Re: Image2Mode7 - general image to teletext converter

Post by joachim » Wed Sep 28, 2016 7:11 pm

simonm wrote:Cool stuff guys. I personally think the dithering adds a little extra definition overall.
Would an ordered dither be better for something like this where the pixels are so large? Plus it might be better for video sequences, since ordered dither may create fewer deltas between frames.
Jules's idea of % dither sounds interesting, similar to the BBC image converter tool, sometimes just a subtle bit of dithering works well.
I dismissed ordered dither because it's not so obvious how it can adapt to the changing palette constraints: an error propagation method will happily create a colour in one place by dithering red with blue, and create the same colour in another place by dithering black with magenta, just because it started with a different palette state.

But perhaps that's not the only or most important consideration. Ordered dither would also have the advantage of not blowing up the search space, like we were discussing upthread, to store error propagation information.

Post Reply