Converting Images to mode8 _scr files

Anything QL Software or Programming Related.
Post Reply
User avatar
XorA
Site Admin
Posts: 1629
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Converting Images to mode8 _scr files

Post by XorA »

So suffering from too much caffeine and because i could not find a simple util to do this I got my bash mojo on.

Code: Select all

#! /bin/bash

INFILE="$1"
OUTFILE="$2"

CONVERTED=`magick "$INFILE" -dither FloydSteinburg -resize 256x256\!  -remap ql-palette.png txt:`

if [ -f "$OUTFILE" ]; then
    rm "$OUTFILE"
fi

y=-1
s=0
hashstring="#"

IFS=$'\n'
for line in $CONVERTED
do
    if [ $y -lt 0 ]; then
        y=$[$y+1]
        continue
    fi

    rest=${line#*$hashstring}
    position=$(( ${#line} - ${#rest} - ${#searchstring} ))

    pixel=${line:$[position]:6}

    if [ $s -eq 0 ]; then
        byte1=0
        byte2=0
    fi

    if [ $[0x$pixel & 0xFF00] -ne 0 ]; then
        byte1=$[($byte1 << 2) | 0x02]
    else
        byte1=$[$byte1 << 2]
    fi

    if [ $[0x$pixel & 0xFF0000] -ne 0 ]; then
        byte2=$[($byte2 << 1) | 0x01]
    else
        byte2=$[$byte2 << 1]
    fi

    if [ $[0x$pixel & 0xFF] -ne 0 ]; then
        byte2=$[($byte2 << 1) | 0x01]
    else
        byte2=$[$byte2 << 1]
    fi

    s=$[$s+1]
    if [ $s -eq 4 ]; then
        byte1out=$(printf "%x" $byte1)
        byte2out=$(printf "%x" $byte2)

        printf "\x$byte1out" >> "$OUTFILE"
        printf "\x$byte2out" >> "$OUTFILE"

        s=0
    fi

done
It will blindly convert any image no matter the size, BUT if you want the aspect ratio to be correct on BBQL then you want to start with an image of 1024x768 or same aspect ratio.

Have a happy christmas!
image2mode8scr.zip
(973 Bytes) Downloaded 64 times


User avatar
XorA
Site Admin
Posts: 1629
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Converting Images to mode8 _scr files

Post by XorA »

And having proved the process here is a C version (its just a teensy bit faster)

https://github.com/xXorAa/ql-picture

AFAIK it needs ImageMagick v7+, I think there is an incompatible API change between v6 and v7 and v7 is the default in brew!


Derek_Stewart
Font of All Knowledge
Posts: 4684
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Converting Images to mode8 _scr files

Post by Derek_Stewart »

HI,

I downloaded the source code from GIT hub, found that my installed version of cmake and ImageMagick required updating. So I downloaded the source code to cmake and ImageMagick, compiled and install onto my system.

The "ql-picture" code compiled with no errors and converted the supplied PNG file to Mode 8 SCR files, which loaded into Fileinfo2 Picture Viewer on SMSQ/E v3.38

Nice code...


Regards,

Derek
User avatar
XorA
Site Admin
Posts: 1629
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Converting Images to mode8 _scr files

Post by XorA »

Derek_Stewart wrote:HI,

I downloaded the source code from GIT hub, found that my installed version of cmake and ImageMagick required updating. So I downloaded the source code to cmake and ImageMagick, compiled and install onto my system.

The "ql-picture" code compiled with no errors and converted the supplied PNG file to Mode 8 SCR files, which loaded into Fileinfo2 Picture Viewer on SMSQ/E v3.38

Nice code...
Can I ask what distro you use? I thought I had set cmake to the one in Ubuntu 20.04!

Nice to hear it works, I need to clean the code a bit and put some error handling!


Derek_Stewart
Font of All Knowledge
Posts: 4684
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Converting Images to mode8 _scr files

Post by Derek_Stewart »

Hi

I am using Linux Mint 19.3, which based on Ubuntu 18.04, but I tried upgrade to Mint 20.04, but 6 months ago there was a few apps tgat needed special attension. I have manually updated many applications, so the system probably cnlose to Mint 20.

I think the offical Mint 20 may be more stable now, so I may look into upgrading the system in the comming weeks.


Regards,

Derek
User avatar
XorA
Site Admin
Posts: 1629
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Converting Images to mode8 _scr files

Post by XorA »

It should now work with IM6 and IM7


Post Reply