Sinclair QL

convert images to QL format


1st Mar 2001 - Convert any graphic into Sinclair QL Video RAM / _SCR file / QL internal video format.
There's a page on QL Character set translation too.

[ The program - Get the Perl code | How it works - Basic | How it works - You need to know this | Superbasic commands | Troubleshooting | Photoshop help | Summary ]
*** Sample Images *** Contact Me ***

Synopsis

I couldn't find a way of converting graphics into the internal format of the QL's video RAM, so I wrote a program to do it. Get it here, screenshots, before & afters, etc...

Current Version is 3

Improvements Still To Do...

Why Convert Graphics?

The easiest way to get graphics in & out of the QL is to dump/load the video memory area. At the moment I'm running Q-emuLator Lite on the Mac. GraphicConverter 3.8 upwards will import the QL screendumps, in either mode, but won't save the format. I have been unable to find a program that saves in QL video format.


Solution - raw2ql

A Perl script which will take a raw graphics file and generate a nice 32,768 byte file which will show up on your QL screen.

You may need to get a copy of Perl - a version is out for almost every OS. If you have Unix, you've probably already got Perl. Go to www.perl.com to get a free download. I've found installation a breeze with both ActiveState Perl and MacPerl.

How it works - Basic

The Input

The program reads in a graphics file in 24-bit colour/8-bit grey RAW format. This means that there is no header or footer to the file, just the uncompressed image data.
The RAW data format is one octet per channel per pixel: so the file goes R G B R G B R G B ... (or K K K K K K ... in greyscale files) from top left to bottom right, scanning in rows.

The Processing

The program reads in several pixels of data. The QL colour channels can only be on or off, so the program dithers the raw data so that each colour is either on or off. It then rearranges the bits into the QL video format and output the chunk of data to the output image file, and repeats until done.

How to save as a 24-bit Colour RAW graphics file

Adobe Photoshop
Convert your image to RGB colour, that's 24-bit colour, with only 3 channels (R, G, B) and no alpha. Go to Save As... and choose the format as RAW. Use no header or offset. You should end up with a fairly big file.

GraphicConverter
Get the image in 24 bit colour, Save As RAW, true colour, no pad byte, no header.

Other Apps
The process is similar for other apps, but you may need to consult the help or the manual.

How to save as 8-bit greyscale RAW

Essentially the same, but first convert the image to 'Greyscale', '8-bit grey' or whatever your program calls it, and then save as RAW. This should save an 8-bit greyscale RAW file.

Running the Programs

Basically, put the script and the RAW file in the same directory. Then you run the script and the output file is created in that directory. Of course, there are a few things you need to know...

Performance

On my machine, this is how long the various conversions take:

How it works - You need to know this!

My script uses a diffusion dither to "halftone" the QL display (if the image isn't already dithered). See the tips for dithering help if you want to do the dithering yourself.

Because raw2ql is not that interactive, the input and output filenames are fixed. ql.raw, ql8.raw and ql4.raw are all OK input filenames, but use ql.raw for preference - the program then autosenses the type of file. img_ql8 and img_ql4 are the outputs. Rerunning the script means your output file is clobbered.

Video RAM begins at 131072 decimal, running for 32768 bytes.

Scale your images

QL pixels are not square, so you need to stretch your original image a bit before conversion. THEN crop it (or proportionally scale it) to be the right size in pixels. Scaling factors given below.

RAW Data Format

24-bit colour, 8-bits/channel, or 8-bit greyscale. No header, no footer. In colour mode 1 pixel = 3 bytes, and byte order [ R G B ]. For mode 4 images the blue channel is ignored, but the perl script assumes there will still be THREE channels.

You MUST get your image to the EXACT right size before saving it as raw. raw2ql tries to check the filesize to see that it is a valid value. Also, the script terminates when it has written the exact amount of data needed to fill the QL's Video RAM. If you supply a file that is too short it will terminate early if it runs at all.

Specs and Properties

Property QL Mode 4 output QL Mode 8 output RAW Input file
Filename img_ql4 img_ql8 ql4.raw or ql8.raw
Filesize (bytes) 32,768 32,768 393,216 (mode 4), 196,608 (mode 8)
131,072 (mode 4 grey), 65,536 (mode 8 grey)
Image Width (pixels) 512 256 512 or 256
Image Height (pixels) 256 256 256
Scaling needed before conversion
Mode 4
- - 135% wide x 100%
Scaling needed before conversion
Mode 4
- - or 100% wide x 74% high
Scaling needed before conversion
Mode 8
- - 67% wide x 100% high
Scaling needed before conversion
Mode 8
- - or 100% wide x 148% high
Time taken to convert from 8-bit grey source* 10 sec 8 sec -
Time taken to convert from 24-bit colour source* 19 sec 14 sec -
Colours Supported
       
               
24-bit RGB colour
* - on my computer using MacPerl 5. Yours will probably be faster.

Superbasic - How to get at Video RAM

On my QL the commands are:
Load the image in with this SuperBasic:
10 LBYTES mdvX_img_ql8,131072

Dump the screen with:
10 SBYTES mdvX_img_ql8,131072,32768

Use appropriate device number/filenames in your situations. Ensure you are loading into screen RAM - damage may ensue if you get it wrong!

Troubleshooting

raw2ql isn't that elegant, but should work on any perl system (my version is 5 patchlevel 4). Some OS's may not like the '_' notation as used in QDOS. You may want to change the output filenames.

This was done for the good of the QL community, and I cannot accept any responsibility for anything this software does (or does not) do. Use this software at your own risk.

Photoshop help

For all images. Use the Curves. Click 'auto' to get the most dynamic range.

For all Images. Unsharp mask. If you use diffusion dithering (see later tips) set radius to about 1.2 threshold to 0-3, amount to 100% or more.

To get good diffusion dithered 8-colour images, save a copy for backup (in case you mess up) and then do a 'split channels' on the RGB image (the menu found on the Channels palette). You get 3 grey images. On each image change mode to Bitmap, keeping the same resolution and size (use diffusion dither for preference, but other kinds of dither may suit your purpose better). Then change mode back to greyscale, size ratio=1. In the Channels palette go to the little menu and do Merge Channels, to RGB colour, 3 channels etc.

To get good 4-colour images, fade a bit of the blue channel into the red and green channels. Easiest when the channels have been split into separate windows. Do the same sort of thing with diffusion dithering then.

For black & white images, start in RGB, go to greyscale, go to bitmap, and back to greyscale..

Summary of use

*** Sample Images! ***

selsyn at zoom co uk - conatct with bug fixes, additions etc. We'll have version 4 before you know it.