Fun With APNG & LC

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Fun With APNG & LC

Post by Thierry » Thu Feb 11, 2021 2:30 pm

capellan wrote:
Wed Feb 10, 2021 1:43 am
In fact, I posted this stack long, long time ago, and back then discovered that
hashing some kind of data produces wrong results.

Using the crc32b produced by the built-in Livecode function "compress"
is more reliable.
Hi Al,

Thanks a lot for this information!

Out of curiosity, I did play for a couple of hours last sunday on istech problem...

For this purpose, I did rewrite a bit the crc32 stack you are talking about.
The main modification was to drop the hexValues field and replace it with an array, all set up in the script.
This permits to have the crc32 code in a script only stack (or to copy/paste in your own stack script)
Second one was about speed optimization: gain ~10%.


Finally, I made a test:
- parse 3 different animated png files
- for each apng chunk found, extract the data part and the corresponding crc
- process the data to calculate a new crc, and compare it with the original one.


unElephantCaTrumpEnormément.jpg


So, processing around 500 Kbytes of binary datas,
did find 172 chunks and all the 172 checksums calculation were fine!

I consider this test quite encouraging, but it is certainly not a complete valid test.
All that said, if you remember some details about the crc32 calculation failures,
I would appreciate to know more before sharing this update.

Thanks again

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: Fun With APNG & LC

Post by capellan » Thu Feb 11, 2021 9:09 pm

Hi Thierry,

It was so long ago, that I do not remember but surely was
related to crc 32 byte alignment.

Testing again, I found this simple error
calculating the crc32 of this text:

Code: Select all

 !"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~ 
 ¡¢£¤¥¦§¨©ª«¬ ®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëì
This text produces this crc 32 error: C62E7
Correct answer is: 000C62E7
or E7620C00 as written by the internal gzip's crc32

There are 3 missing zeros.

The solution is using format:

Code: Select all

function Crc32Str str
   
   put 4294967295 into crc
   
   repeat for each char tChar in str
      put Crc32Add(crc,chartonum(tChar)) into crc
   end repeat
   
   put bitwiseXor(crc, 4294967295) into tHex3
   put format("%08s",baseConvert(tHex3,10,16)) into fld 3
end Crc32Str
Al

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Fun With APNG & LC

Post by Thierry » Fri Feb 12, 2021 10:10 am

capellan wrote:
Thu Feb 11, 2021 9:09 pm

This text produces this crc 32 error: C62E7
Correct answer is: 000C62E7 (3 missing zeros)

The solution is using format:

Code: Select all

function Crc32Str str
   .....
   put format("%08s", baseConvert(tHex3,10,16)) into fld 3
end Crc32Str
Thanks Al, and good catch !

Back to this thread which is about coding/decoding APNG files,
I did add to the CRC-32 stack another function called crc32.
This function returns the binary value of the calculated crc.

I've done that, so it's easy to update/store the crc in any binary file.
That's certainly why I couldn't witness this bug during my tests.

Kind regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

istech
Posts: 194
Joined: Thu Sep 19, 2013 10:08 am

Re: Fun With APNG & LC

Post by istech » Fri Feb 12, 2021 12:16 pm

Thierry wrote:
Thu Feb 11, 2021 2:30 pm
capellan wrote:
Wed Feb 10, 2021 1:43 am
In fact, I posted this stack long, long time ago, and back then discovered that
hashing some kind of data produces wrong results.

Using the crc32b produced by the built-in Livecode function "compress"
is more reliable.
Hi Al,

Thanks a lot for this information!

Out of curiosity, I did play for a couple of hours last sunday on istech problem...

For this purpose, I did rewrite a bit the crc32 stack you are talking about.
The main modification was to drop the hexValues field and replace it with an array, all set up in the script.
This permits to have the crc32 code in a script only stack (or to copy/paste in your own stack script)
Second one was about speed optimization: gain ~10%.


Finally, I made a test:
- parse 3 different animated png files
- for each apng chunk found, extract the data part and the corresponding crc
- process the data to calculate a new crc, and compare it with the original one.



unElephantCaTrumpEnormément.jpg



So, processing around 500 Kbytes of binary datas,
did find 172 chunks and all the 172 checksums calculation were fine!

I consider this test quite encouraging, but it is certainly not a complete valid test.
All that said, if you remember some details about the crc32 calculation failures,
I would appreciate to know more before sharing this update.

Thanks again

Thierry
Thanks one and all very cool stuff here. I'll update you on where I am and maybe we can help each other to put a stack together. I have posted a stack but Thierry you seem to be further along than myself. The crc32 stack I found took a long time to calculate the crc for large apng files so I put the hex into the memory rather than from a field(See in my stack). It got a little improvement but not much.

So far I can load and play very few apng with this stack as the png chunks are not being decoded correctly. The fdat chunks need a PNG decoder to properly read the chunk data, palette etc. So far this stack only works with single IDAT chunks. So need/am building a function to decode all the PNG chunks correctly.(Unless someone already has one/or knows a better way to decode the png data.

Please take this stack as a "VERY ROUGH EXPERIMENTAL SCRIPT". Please add, change, experiment. Would be so cool to get this to work well.

DISCLAIMER:- PLEASE DON'T EXPECT COMMERICAL CODE. STRICKLY EXPERIMENTAL CODE FOR SHARING AND TEST USE. AS ALWAYS USE AT YOUR OWN RISK.

https://www.dropbox.com/s/i5kj9hd5n55e8 ... l.zip?dl=0

Image
Last edited by istech on Fri Feb 12, 2021 2:57 pm, edited 4 times in total.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Fun With APNG & LC

Post by Thierry » Fri Feb 12, 2021 12:56 pm

istech wrote: The crc32 stack I found took a long time to calculate the crc for large apng files
so I put the hex into the memory rather than from a field(See in my stack).
It got a little improvement but not much.
Hi istech,

if you look at my crc32 tests few posts before, you'll see all this took 20 seconds.
Well, this is way to long for a responsive png animation in LC.
What I have done then, is first translate the apng file to a specific apng_lc datas,
this can be then read almost instantaneously, and the working animations have the
same speed as the apng animations in the browser for instance.
Today, I can decode the elephant animation in 14 seconds.
The result is a smooth animation in LC, respecting timings.

Looking back at your first post, the php script is ways faster than the one in LC
as the crc32 function is implemented inside php (built-in function).

And BTW, this php script is a naive implementation;
will works only with some apngs.

So far I can load and play very few apng with this stack
as the png chunks are not being decoded correctly.
The chunks need a PNG decoder to properly read the chunk data, pallet etc.
So far this stack only works with single IDAT chunks.
So need/am building a function to decode all the PNG chunks correctly.(Unless someone already has one)

Please take this stack as a "VERY ROUGH EXPERIMENTAL SCRIPT".
Please add, change, experiment.
Would be so cool to get this to work well.
Great!
As I don't have much free time to work on this topic, I'll try next sunday
to check your stack and see what could be mixed with mine....
But from what I've seen so far, the *big* problem within LC is to decode differential frames.
( I can send you one of this apng file if you like)
Here, you need to compute your current frame with the previous one ( kind of copy over...)
That will be another long process in LC :(

Last, I won't share my current code as it is;
need to do some cleaning and refactoring before :)

Good luck and see you soon,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

istech
Posts: 194
Joined: Thu Sep 19, 2013 10:08 am

Re: Fun With APNG & LC

Post by istech » Fri Feb 12, 2021 1:16 pm

No worriers, thanks for your time Thierry and don't be shy I'm certainly not putting out commercial code here.(Hence the disclaimer above) I'm more interested in getting my elephant to work. :D

I'm out of time also. But if I find a spare couple hours will looking further into it. Stay safe and look to hear from you soon.
Last edited by istech on Fri Feb 12, 2021 6:57 pm, edited 1 time in total.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Fun With APNG & LC

Post by Thierry » Fri Feb 12, 2021 1:27 pm

istech wrote: No worriers, thanks for your time Thierry
and don't be shy I'm certainly not putting out commercial code here.
You're welcome :)

I'm not shy but only cautious due to my limited free time.
I'm more interested in getting my elephant to work. :D
Ok, I'll do my best to send your jumping elephant
to you on sunday :)
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Fun With APNG & LC

Post by thatkeith » Sat Feb 13, 2021 10:00 pm

I have a sound use case for creating APNGs, so it's NOT just a waste of time. One of my main 360 panorama tour builder tools uses APNGs for animated hotspot elements within a 360 scene. Currently people use After Effects or DaVinci Resolve to create these, which is insane overkill. I've wondered about driving a command line tool from a LC stack to assemble frames into an APNG animation.
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Fun With APNG & LC

Post by sphere » Wed Feb 24, 2021 11:20 am

istech wrote:
Fri Jan 29, 2021 9:14 pm

Betamax was always the better format but VHS won in the end because of adoption.
Not at all, the best was VCR aka Video2000 made by Philips, 2 sides payable, perfect still image. Stripe-less fast forward with image. Hi-Fi stereo.
VHS won the race because Video2000 refused to bring out some kind of adult movies on their system.

Sorry had to chime in to correct what was really the best video system back then.

Post Reply

Return to “Talking LiveCode”