Motion piQtures

Anything QL Software or Programming Related.
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Motion piQtures

Post by pjw »

tcat wrote:<>
EDIT: decompression routine added, some code corrections - WORKS!

<code>
Tom, I tested the compression code you published against the internal SMSQ/E RLE decompressor, but they dont appear to match. Does your latest code match the RLE decompressor? (It can be found at iod_con2_ptr_rle_asm in the SMSQ/E sources. Converting a compressed image to a sprite, with the correct header, would be one simple way to do the test.)

To previous suggestions of using a special extension for compressed files (_rle was my preferred one), I suggest adding at least the following header to the compressed data in the file, to ease identification, and interfacing with other components:

Code: Select all

       dc.l 'RLEx'             where x = 1, 2 or 4
       dc.l <size of uncompressed data>
       <compressed data goes here>
This could be considered a general data file format, not specifically for screen dumps. (A screen dump file format would also require Mode information, to be of any use.)


Per
dont be happy. worry
- ?
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: Motion piQtures

Post by tcat »

Hi All,

This is a first version of `RLE' with embedded machine code in Super BASIC as promised. With hope anybody may follow and test along with Cristian's animator program. Compression ratio varies depending on a level of details in the actual screens.
rle.zip
RLE de/compression _bas
(1.06 KiB) Downloaded 125 times
USAGE (file names are quoted):

Code: Select all

rlencode 'infile_scr','outfile_rle'
rldecode 'infile_rle'
Per,

Thank you for you suggestions, I will try to do deal with as a next step. Please, what are modes 1 and 2, as I know of only 4 and 8 on std QL?

Many thanks.
Tom


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Motion piQtures

Post by mk79 »

tcat wrote:I have seen here all magnificent stuff, here is my humble attempt at screen compression.
Could the `rle' size be trusted at all?
I've had a short look at your code and unfortunately I think it has three problems:
1. Data that cannot be compressed becomes twice as big
2. A 16-bit run-length counter wastes a lot of memory, too, except in extremely homogeneous areas
3. It doesn't compress/decompress certain byte sequences correctly if the data happens to match the run length counter

The SMSQ/E algorithm has none of those problems, so I suggest to check it out, it's described at https://www.kilgus.net/smsqe/display.txt.

All the best, Marcel


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: Motion piQtures

Post by tcat »

Hi Marcel,

Thank you.

Surely my code is not perfect, I just wanted to code something really simple, to be able to toy with animations here.

EDIT
Ad 1) True e.g. the sequence 1,1,2,2,3,3...16384,16384 encodes into by a 1/3 bigger file
Ad 2) True, e.g. blank screen would compress only in three words: 0,0,16384. Code is uncomplicated as all is in words and on even address. Run counts in bytes would require keeping them in a separate list, possibly.

'miao' animation goes 50% ratio
`merry' greetings goes only 16% ratio

Ad 3) I was thinking of this, then thought it impossible to happen, perhaps it can

I will try another piece of code to be of more general use as per's and your suggestions.

EDIT
These are funny, each only 6 bytes
screens.zip
(478 Bytes) Downloaded 119 times
Thank you.
Tomas


User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Motion piQtures

Post by pjw »

Tomas, it works very well :) I see we have been talking at cross purposes. I assumed you were aiming for the SMSQ/E variety when that wasnt the case. I may have a go at doing an SMSQ/E-compatible version when I get the time.


Per
dont be happy. worry
- ?
tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: Motion piQtures

Post by tcat »

Hi Per,

Xmas, Xpurposes, possibly?

I am not SMSQ/E owner and little would I know. My machine is QDOS v1.10 (JS-ROM), 2-MDs, 0-floppy, 0-HDD.

All the same, I wish to know what RLEx (=1,2,4) are, and how they differ to my code.

Many thanks
Tomas


User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Motion piQtures

Post by pjw »

tcat wrote:Hi Per,

Xmas, Xpurposes, possibly?
Probably ;)
I am not SMSQ/E owner and little would I know. My machine is QDOS v1.10 (JS-ROM), 2-MDs, 0-floppy, 0-HDD.
You could very easily be a proud SMSQ/E "owner" by downloading Marcel Kilgus'es excellent QPC2, and perhaps one of the beautiful distros currently available..
All the same, I wish to know what RLEx (=1,2,4) are, and how they differ to my code.

Many thanks
Tomas
Sorry, I forgot to reply to that one. RLE 1, 2, and 4 relate to the possible data sizes the inbuilt RLE decompressor works with. More detail may be found by following the link mk79 supplied in an earlier post here. However, the details arent quite clear to me by just reading that description, so to properly understand the workings of the format it is best to look at the source code. I hope Im doing no wrong by dropping the code here (the SMSQ/E license
applies!) I have slightly modified register usage and a few small steps, as I attached it to a S*BASIC keyword (all thats missing from this code is the initialisation code for one SB procedure):

Code: Select all

; Decompress RLE compressed data   V1.00                   ©2002 Marcel Kilgus
;
; Sandpit version - Wrapped for S*BASIC by pjw

        section code

        include dev8_keys_qlv
        include dev8_keys_err

        xdef    derle

*
* Usage: DERLE source, target
*
* De-compresses a previously RLE-compressed data chunk
* The format of the compressed data chunk is:

* dc.l 'RLEx'           with x = 1, 2, or 4
* dc.l uncompressed_size
* data
*

err_bp
         moveq #err.ipar,d0

err_exit
        rts

*
derle
         move.w sb.gtlin,a2     get some longs
         jsr (a2)
         bne.s err_exit

         subq.w #2,d3           only two wanted
         bne.s err_bp

         move.l 0(a6,a1.l),a2   -> compressed data header
         move.l 4(a6,a1.l),a4   -> buffer of at least uncompressed data size

;+++
; Decompressed RLE compressed data
;
; RLE header:   0  'RLEx' with x either '1', '2' or '4' (item size in bytes)
;               4  size of uncompressed data
;               8+ compressed data
;
; Algorithm can work on an item size of byte, word and longword (s.above)
;
; The RLE data stream always consists of one byte and some items following.
; If the leading byte is in range of 0<=x<128 then x+1 uncompressed items
; are following the byte. Otherwise the next item is to be taken 257-x
; times.
;
;       d0  r   < 0 error, > 0 size of data
;       a2 c  p start of compressed data
;       a4 cr   address of buffer with uncompressed data
;---
regs    reg     d1-d2/a0/a2

pt_derle
        movem.l regs,-(sp)
        moveq   #0,d2
        move.l  (a2)+,d1                ; ID
        cmpi.l  #'RLE1',d1
        beq.s   prle_rle
        addq.w  #2,d2
        cmpi.l  #'RLE2',d1
        beq.s   prle_rle
        addq.w  #2,d2
        cmpi.l  #'RLE4',d1
        bne.s   prle_norle

prle_rle
        move.l  a4,a0
        move.l  (a2)+,d1                ; uncompressed size
        move.l  d1,-(sp)
        move.w  pt_decomp(pc,d2.w),d2
        jsr     pt_decomp(pc,d2.w)
        move.l  (sp)+,d0                ; return size of data
prle_exit
        movem.l (sp)+,regs

prle_norle
        moveq   #0,d0
        rts

pt_decomp
        dc.w    prle_1-pt_decomp
        dc.w    prle_2-pt_decomp
        dc.w    prle_4-pt_decomp

; Uncompress byte sized data
prle1_loop
        moveq   #0,d0
        move.b  (a2)+,d0
        bmi.s   prle1_comp              ; compressed data
        sub.l   d0,d1                   ; subtract from total data size
        bcs.s   prle_rts                ; emergency exit
        subq.l  #1,d1                   ; it's x+1 actually
prle1_ucloop
        move.b  (a2)+,(a0)+             ; just copy uncompressed data
        dbf     d0,prle1_ucloop
        bra.s   prle_1
prle1_comp
        move.l  #257,d2
        sub.l   d0,d2
        sub.l   d2,d1                   ; subtract from total size
        bcs.s   prle_rts                ; emergency exit
        subq.l  #1,d2                   ; dbf loop makes it one less
        move.b  (a2)+,d0
prle1_cloop
        move.b  d0,(a0)+                ; insert item d2 times
        dbf     d2,prle1_cloop
prle_1
        tst.l   d1
        bhi.s   prle1_loop
prle_rts
        rts

; Uncompress 2 byte sized data
prle_2
        lsr.l   #1,d1                   ; size in bytes -> size in items
        bra.s   prle2_start

prle2_loop
        moveq   #0,d0
        move.b  (a2)+,d0
        bmi.s   prle2_comp              ; compressed data
        sub.l   d0,d1                   ; subtract from total data size
        bcs.s   prle_rts                ; emergency exit
        subq.l  #1,d1                   ; it's x+1 actually
prle2_ucloop
        move.w  (a2)+,(a0)+             ; just copy uncompressed data
        dbf     d0,prle2_ucloop
        bra.s   prle2_start
prle2_comp
        move.l  #257,d2
        sub.l   d0,d2
        sub.l   d2,d1                   ; subtract from total size
        bcs.s   prle_rts                ; emergency exit
        subq.l  #1,d2                   ; dbf loop makes it one less
        move.w  (a2)+,d0
prle2_cloop
        move.w  d0,(a0)+                ; insert item d2 times
        dbf     d2,prle2_cloop
prle2_start
        tst.l   d1
        bhi.s   prle2_loop
        rts

; Uncompress 4 byte sized data
prle_4
        lsr.l   #2,d1                   ; size in bytes -> size in items
        bra.s   prle4_start

prle4_loop
        moveq   #0,d0
        move.b  (a2)+,d0
        bmi.s   prle4_comp              ; compressed data
        sub.l   d0,d1                   ; subtract from total data size
        bcs     prle_rts                ; emergency exit
        subq.l  #1,d1                   ; it's x+1 actually
prle4_ucloop
        move.l  (a2)+,(a0)+             ; just copy uncompressed data
        dbf     d0,prle4_ucloop
        bra.s   prle4_start
prle4_comp
        move.l  #257,d2
        sub.l   d0,d2
        sub.l   d2,d1                   ; subtract from total size
        bcs     prle_rts                ; emergency exit
        subq.l  #1,d2                   ; dbf loop makes it one less
        move.l  (a2)+,d0
prle4_cloop
        move.l  d0,(a0)+                ; insert item d2 times
        dbf     d2,prle4_cloop
prle4_start
        tst.l   d1
        bhi.s   prle4_loop
        rts
*
        end
It seems to me that while the decompressor can be a pretty mechanical affair, the compressor could do with some intelligence to improve on the degree of compression (eg a pair of identical adjacent items in a string of < 128 different items could be ignored, saving a byte for each occurrence)


Per
dont be happy. worry
- ?
User avatar
Cristian
Aurora
Posts: 960
Joined: Mon Feb 16, 2015 1:40 pm
Location: Veneto

Re: Motion piQtures

Post by Cristian »

tcat wrote:My machine is QDOS v1.10 (JS-ROM), 2-MDs, 0-floppy, 0-HDD.
:o A real retro computing man :)


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: Motion piQtures

Post by tcat »

RLE 1, 2, and 4 relate to the possible data sizes the inbuilt RLE decompressor works with.
RLE1 - byte
RLE2 - word
RLE4 - long word

As I compress on words, my code is sort of RLE2 compliant?
Correct?

Tom


User avatar
QLvsJAGUAR
Gold Card
Posts: 455
Joined: Tue Feb 15, 2011 8:42 am
Location: Lucerne, Switzerland
Contact:

Re: Motion piQtures

Post by QLvsJAGUAR »

BSJR wrote:Apparently nobody has checked out my latest SQRview, also using David Westbury's GIF tool.Bob
Finally I did. And I must say I like it. Good work, Bob!

SQRview is now part of QL/E (added in v3.16 which was released end of February 2017)! Thanks to the work of Markus Dettwiler, SQRview is now one of the predefined picture viewers in QL/E with FileInfo2 support.

I see some room for improvement, I shall start a new thread on this.

QL forever!

Urs


QL forever!
https://www.sinclairql.net/ - Go and get THE DISTRIBUTION & QL/E!
https://www.youtube.com/QLvsJAGUAR/community - Blog
https://www.youtube.com/QLvsJAGUAR - Dedicated QL videos
Sinclair, QL, ATARI, JAGUAR, NUON, APPLE, NeXT, MiST & much more...
Videos, pictures & information
Post Reply