Sunday, August 17, 2014

Revisiting Cinepak

While working on an as-of-yet-unnamed engine last year, I realized I needed to dither some videos. My only hope was that it wouldn't be as painful as DrMcCoy had it several years ago (and I'm pretty sure the "beauty" part was sarcastic). Looking at how the game dithers the graphics, I figured out that it relied on Video for Windows to handle dithering. VFW promptly handles it by making the codec handle it.

For this game, that codec was Cinepak. The Cinepak decoder has been in ScummVM since 2009 (I wrote it in late 2007 or so, so it's really even older). I refused to use some other dithering algorithm that would have been different and given different results. If I was going to implement this, I was going to do it to match the original 100%. That meant it was time to figure out what it does.

Basically, the algorithm is based on pre-dithered tables that are for a given hardcoded palette. For custom palettes, it finds the nearest (using a simple distance equation) color in it and maps from the Cinepak palette index to the custom one. It then uses the pre-dithered tables to generate 4x4 blocks based on the contents of the codebook which is then mapped to the custom palette.

I pushed the code for the curious.

QuickTime also does something similar (but with a different dithering algorithm in Cinepak, of course), which I'll be working on for Myst.

Here's the result, using one of the Cinepak samples from the MPlayer samples archive (in this case, the Lara Croft one):

Normal decode to 24bpp
Dither to 8bpp

The result looks pretty decent. I was mostly glad it wasn't a ridiculous amount of extra code.

2 comments:

Anthony817 said...

Hello! Long time no see! Did you ever finish the port of Myst? I wanted to play it on Dreamcast, but I think I have 5 years of posts to read through to see if you did it.

Thanks for still using your blog.

You can reach me here if you feel like responding.

http://dreamcast-talk.com/forum/viewtopic.php?t=2637

Please respond so us Sega fans can know if we can stop waiting on it or if you ever felt like stopping the project. I actually mentioned it in this thread just now.

http://dreamcast-talk.com/forum/viewtopic.php?t=2637

I know it has been a long time, but I haven't kept up with it. Please let me know if you haven't worked on it so I can know not to keep waiting. Either way just knowing is better than hoping forever. XD

Thanks.

Anthony817 said...

http://dreamcast-talk.com/forum/viewtopic.php?f=53&t=7350&p=81306#p81306

Sorry the latest post was actually here.