A final look at SIFF

October 29th, 2022

This is a resource format (as one could guess from its name) used by Beam Software for various resources in its games. The first time I had to deal with it was when some anonymous contributor contacted me with a REd decoder for videos in Lost Vikings 2. I adapted for FFmpeg (wow, it’s been fifteen years ago) and added sound support as well.

Recently I decided to revisit it (previously I tried to adapt decoder for 15-bit video but could not make it exactly right for some reason). So I looked at it, it turned out to be exactly the same algorithm but depending on whether palette is present in the frame (yes, 256-colour palette with RGB555 entries) pixel data is read either as byte palette indices or raw 16-bit values. I also looked at The Dame was Loaded game and its FCP format turned out to use exactly the same compression but with a different frame format (16-bit sizes, different audio/palette/video order and so on). And the game audio uses packed 12-bit PCM (two samples without low nibble are stored in three bytes) which is not something you often see.

And with that I’m done with game formats for a long time. Probably I should write a toy encoder or two now.

Looking at Talisman animations

October 27th, 2022

While the situation in Ukraine is stable bad so I keep looking at game formats instead of playing those games instead.

Apparently there’s a German adventure game from mid-1990s called Talisman and that’s about all I can tell about it. Yet it seems to have rather interesting animation format that’s worth talking about.

It turned out to be codebook-based compression with a codebook shared by a group of frames (typically 20-30) and actual codebook being created from a transmitted codebook data mixed with the static codebook (an interesting fact: unlike many other game formats, this one not merely allows seeking inside, there’s a special chunk preceding group of frames with the same codebook that contains an offset of the next such chunk). Tile operations are either copying 2×2 tile from another part of the frame (optionally updating one pixel in it) or reading it raw.

While it’s not the most complex format ever it turned out to be interesting enough. And with that I’ve probably exhausted the game video formats to look at. I’ll probably revisit SIFF but that’s about it.

A quick look at PDQ2

October 21st, 2022

So there’s this new service discmaster.textfiles.com for searching for files from some old disks and discs at archive.org and out of curiosity I took a look at what it offers.

While it’s physically impossible to check all hundreds of millions of files it indexes (even just videos), I took a look at one rather curious category called aviAudio. There are about six hundred files of such type found so I decided to check them to see what kind of beast that is.

Some files turned out to exactly AVI audio files—AVI files with single stream that turns out to be audio (I don’t know why but this happens). The rest of the files were AVIs with unrecognized video track (just what I was hoping for!). One set of the samples come from some game with IPMA codec, other sources mostly feature Motion Pixels video (which is horrible both to RE and to support so I’d rather not touch it), one sample was special “codec” for some russian erotic game (which means complete garbage even by russian game standards) that is really just obfuscated Indeo 5. And finally there was a single PDQ2 sample (from some Incredible Hulk game demo from 1997).

An interesting thing is that it’s a DOS game with built-in AVI demuxing and decoding of this codec. The codec turned out to be a lot like various lossless codecs (so its FOURCC probably stands for something like “pretty damn quick codec, version 2”). It splits video into 4×4 tiles and emits up to three streams stored one after another: tile opcode (copy previous tile, copy previous data with an arbitrary offset, skip tile, raw tile), variable offsets and tile pixels. Additionally frame data may be packed further with LZ77-based scheme. As I said, a rather familiar scheme for lossless video codecs and it makes me wonder whether it’s a codec developed specifically for the game(s) or it was borrowed from somewhere else.

Another bunch of interesting game codecs

October 17th, 2022

While Iran wages a proxy war with Ukraine (and I can easily believe they’re not against doing it to the last russian), I’m still trying to distract myself by looking at various video formats in games I have no intention to play.

Finding games with unknown formats gets harder and harder (or at least more tedious). So here are two games with an interesting approach to video compression.

Dark Earth packs frames as separate planes with 5-bit components and each plane is compressed using a peculiar modification of LZ77 scheme: depending on a bit set, it either codes a run or a forward reference in either the same or previous buffer. Additionally it codes it using non-bytealigned stream (run mode is coded in 13 bits and copy mode takes 25 bits).

There’s also Defcon 5 game (the one from the mid-1990s, do not confuse it with a game with the same name but from a previous decade). This one employs a different method I don’t remember seeing anywhere else: painting squares. Of course you’re used to various codecs splitting tiles in blocks and filling them (from older codecs using quadtrees to H.26x and its rip-offs). This one does it differently though: there is a fixed set of tile sizes selected for each video (I’ve seen only 32, 16, 8, 4, 2 set though) and frame data is essentially a list of commands telling at which offsets to paint a tile of this size with a given colour (those offsets may be completely arbitrary). It may be not the most efficient compression algorithm but it’s quite interesting. Also the container specifies palette as fixed and changing colours—first part is stored in the header and the second part is transmitted with each frame. Again, it’s not something extremely effective but I can’t easily remember any other format doing it that way.

I’ll probably try to do something different next time but I consider time spent on looking at these formats well-wasted.

Looking at yet another game format

October 15th, 2022

Since I have nothing better to do and I don’t feel a desire to write a lengthy rant about what’s wrong with this world (beside the fact that russia still exists of course), I keep looking at various games I can find in order to see if they have some interesting format. Last time I’ve managed to locate an elusive Indeo IVF sample, now it’s rather curious FMV format.

So there’s an unpublished PC game called Highlander: The Last of the MacLeods which is apparently some kind of 3D action game based on the animated series (one of those, the franchise seems to have a lot in it beside the one good movie). And it turns out that it has a three dozen of FMV clips in proprietary format (stored inside mov.dat but extracting them is trivial).

From technical point of view the format is rather simple but video compression is rather peculiar: each frame in coded independently by painting each 4×4 block with 1-16 pixels using a certain pattern. That’s common but this data is packed with a simple history-based method: depending on a flag a value is rather read raw or reused from a history buffer depending on two previously decoded values. And now there’s a twist—this compression is applied twice.

Overall, it was fun to look at the format even if I don’t care about the game itself and the video quality is rather poor (probably thanks to the rather low bitrate and fixed palette all those FMVs share despite half of them being digitised animation clips and half of them being recorded in-game 3D animation). Still, now I can play the files with NihAV if I ever get such desire.

Looking at true IVF

October 13th, 2022

So while russia demonstrates once again what a hysterical führer and his similarly minded generals would do, I’m trying to do something to distract myself from the thoughts about the losses Ukraine suffered in last couple of days (and previous couple hundreds of days too).

Accidentally I’ve managed to find a sample in IVF format—the original streaming format for Indeo codecs. Despite the expectations it was not a renamed AVI file which made it even more interesting. So I took Ghidra and binary specification and started implementing it.

The format by itself is rather simple and the only interesting thing is that it transmits video data in passes: first it’s just bare minimum keyframes and all other frames as drop frames, then some inter frames are sent, then more data is sent and more. Unfortunately there’s no obvious field to tell where each part starts so I simply assemble frames in memory (which is not effective but still better than the original creating temporary files for assembling fragments).

Then there was a problem with decoding them: my existing decoder expected a frame with sequential structure while in this case fragments are transmitted out of order. Normally you’d get all four bands for luma plane and then a band for each chroma planes but in this case it may be one or two bands for luma plane, then chroma plane bands, then some zero padding and then the rest of the bands for luma (if they were transmitted at all). In the reference implementation the demuxer seems to parse and re-assemble the frame while I ended up writing a slightly different decoder for this scalable mode. It seems to work fine so now NihAV support for Indeo family of formats is even more complete than ever.

P.S. The Wiki had only the entry for Duck test samples format (that has the same extension) so somebody had to correct that. Which also makes me think about things like Duck AVC, AVS being an FMV game format or Chinese non-Duck AVC rip-off, IEEE AAC and so on. This confusion deserves to be written about but don’t expect me to do that.

Model of man and social/economic systems

October 6th, 2022

Here’s some random thoughts about how some subjects should’ve been explained at school to make understanding it easier. Or maybe they were and I was unlucky.
Read the rest of this entry »

German PEGs

September 29th, 2022

Having said everything I could on the current political situation, I returned to looking at random codecs and I found one with a curious name.

The name is DPEG and it’s used in at least one random game I’ve never heard of. It turned out to be a rather simple tile-based codec with raw intra frames and inter frames that employ RLE and motion compensation.

So nothing interesting but then it struck me: wait a bit, I remember REing a codec with almost the same name, block-based RLE coding approach and also from a German company (a different one though).

And there’s this Fraunhofer society involved in MPEG Video and MPEG Audio (different branches though)…

So what’s the German fascination with naming codecs [A-Z]PEG and how many out of 22 possible codecs are really implemented?

Why it’s pointless to expect anything good from russians

September 26th, 2022

So we have two major events going in parallel in two deeply undemocratic countries: Iranians having enough of their leaders and russians fleeing mobilisation. I can’t even pretend to have any knowledge on Iran so IMO the uprising there may lead to something or may be squashed like the previous ones, yet Iranians still have my respect for doing that. As for russians, even if I’d be not from Ukraine but know their history and current events, I’d still not expect anything good from them.

Here I’ll try to give a short review on russian history, culture and society to show how artificial it is, how those parts do not connect with each other, and why the population of russia mostly remained inert.

History

russian propaganda often claims that other countries (usually those having misfortune to border it) are artificial while in reality russia is the one artificial country more than any of its neighbours. If you look at e.g. Ukraine, Kazakhstan or Baltic States, the countries are formed around the nations which had been living in the corresponding regions since ages. If you look at russia, you’ll see a lot of territory grabbed from the natives by the invaders (the same applies to the USA but there are certain differences mentioned below that make them sufficiently different).

If you look at the origin of Ukraine, you’ll see that it formed itself on the trade route “from the Varangians to the Greeks” (i.e. from Scandinavia to East Roman Empire) and spread naturally around it assimilating various Slavic tribes living nearby. russia, on the other hand, takes it origin from a remote outpost on a completely different trade route in a territory populated by Finno-Ugric tribes (fun fact: Moscow originally was just a town in the principality of Suzdal and you won’t get an answer when it actually became the capital). For a long time it was a part of the Golden Horde (another fun fact russians don’t want to know: until XVIIIth century russia paid tribute to the Crimean Khanate, the successor of the Golden Horde, as its client) until it decided to become independent.

You probably have heard the title “czar”, some of you probably know that it comes from Caesar’s name but how many of you know that it was a self-proclaimed title not supported by anybody else? For comparison, Kings of Galycia-Volyn (now Western Ukraine) got their title from Pope Innocent IV as any other European monarchs did at that time. The ruling of the first czar Ivan IV was the example that set the course for russia since then: self-proclaimed titles (and history retconning), creating puppet states recognized by nobody else, limiting personal freedoms, hiding behind nominal figurehead, oprichnina, territorial conquests (and wars to squash democracies and gain seaports) and so on. This topic deserves at least a separate book so I’ll leave it at this.

To sum up the following centuries, russia behaved like an empire with the colonies being attached to it instead of being located overseas (because they could not control overseas colonies, that’s why they sold Alaska and Californian colonies for a rather measly sum). And running the empire required a lot of trained professionals—which usually were Ukrainians and Germans (usually from Baltic States area). Fun fact: even the transition of Myscovy Kingdom to russian empire was invented and proposed by a Ukrainian. So here’s one difference from the USA already: USA has not tried to pretend that it was a successor of British Empire or that its history spawned millennia.

Culture

Modern russian language is invented mostly by Ukrainians and sustained by Germans. Yes, russian empire started to invent russian language culture in XIXth century and had to rely on non-russians for that (before that elites spoke in French and russian-speaking common folk had various dialects closer to modern Ukrainian than to modern Russian; that’s why it’s easier to understand older russian or Old Slavic language if you know Ukrainian or Belarusian). And of course they tried to strangle down Ukrainian culture (the Valuev Circular and the Ems Decree are the most notorious examples) so that talented Ukrainians would have to write in russian in order to achieve anything. So when russians criticise Ukrainian language for being not as developed as russian it’s like mocking a person that you hit in a knee that he is lame.

It was no better in Soviet times: Ukrainian culture was developed by enthusiasts and the official government cared mostly about curbing the development. For example, there was a Ukrainian grammar developed in 1920 (so-called Skrypnykivka) which was less than a decade later replaced with something closer to russian language (and with subsequent reforms to make it even closer, many of those coincident with famines). Ukrainian movies were quite often forbidden to be released or were re-dubbed in russian before release (and Ukrainian originals were lost in the archives). And stealing things from the other cultures while passing them as their own is a very russian thing.

Of course borrowing is a normal thing that enriches culture. But when you take something not belonging to you, pretend that it’s your own and try to get rid of the original creator—that’s definitely bad (and only Di$ney is allowed to do so, just read the story about Kimba the White Lion). Fun thing is that is you look at any symbol associated with russia you’ll find that it’s been stolen from elsewhere with no credit given (except for the original words of USSR anthem).

Overall, russian culture is created for the needs of uniting the empire instead of coming from the common folk and thus it’s rather artificial one that still does not connect with the people (for the reasons clear from their society structure). So whatever is presented for the export is what you call classics (“something that everybody wants to have read and nobody wants to read”) while what is popular is of a completely different type. The main source of their culture seems to be prison, so virtually everybody knows at least some of prison argot and traditions, and шансон (or блатняк) is their unique genre of music universally loved there (it’s about criminals as you can guess and quite often about them getting to prison too). Side note: while American culture is not that great either but at least it’s not ashamed about its burgers, rap and typical Hollywood action movies as they’re both consumed internally and exported worldwide.

Society

Anyway, now it’s time to talk about their society structure. As I said in the beginning, the principality of Suzdal was founded by Slavic people on Finno-Ugric lands which meant not so good treatment for the locals. The same applied to other conquered nations and no wonder that serfdom was common (and if it’s not slavery it’s pretty damn close). You had all varieties of serfs—private serfs (belonging to some landlord), state serfs (belonging to the state which was not much better) and even industry serfs (serfs that were supposed to work at some mine, fabric or plant without a right to leave it). By some estimations by 1861 three quarters of the russian empire population were serfs of some kind. After “emancipation” their state has not improved much. There was a great divide between elites (who spoke French before 1812 like in many other European countries), literate people living in cities and illiterate peasants (with legal barriers preventing them from getting higher education). Returning to the culture, no wonder that whatever citizens and rich landlords created was not sticking to the majority of the population.

Additionally there’s a theory that russians living on not very fertile lands had to create a community, but it was a kind of community where everybody had nothing (except for something you’ve managed to hide) so it could be a very dynamic community to which members belonged or not depending on the current goals. That’s why a russian may expect a help from a stranger since he’s included him into his community (while the stranger usually did not). That’s why they can claim they don’t leave their own behind while actually leaving people behind—they’ve been excluded from the community.

During Soviet times there was an attempt to build classless society of the future, so it was mostly the society of workers and peasants, a strata of engineers, scientists and teachers/librarians/whatever (who earned less than workers for more skilled work) and nomenklatura (people occupying high posts in The Party who managed everybody and everything else). Of course the ideology ruled everything so almost every unpopular decision like rising prices (there was no inflation in the USSR!) were justified by “the popular demands”. And the protests were put down in rather secretive way (Novocherkassk massacre is the best known example). So people lived in the nice state of doublethink: while they saw that not everything was good they were believing it’s just them and the rest of the country was fine. And of course state propaganda claimed in all possible ways (there’s an expression “from every [electric clothes] iron” to describe exactly how ubiquitous it was) that people were living in the best possible country with the best possible order of things and minor deficiencies are caused by enemy countries that are envious of the Soviet way of things. Of course decades of such brainwashing stuck to many people, especially poor ones.

And it’s worth noticing that there was a process of divorcing reality from the reports. Since Soviet Union had plan economy, on the one hand there was a shortage of goods demanded by the population (because they were either not put in plan or the quantity was mispredicted) and on the other hand the plants and factories had to meet the plan and go slightly over the top (you’d get punished for failing to deliver the demanded amount of goods and if you do too well the plans for the next period would be increased which might be an even worse punishment). So people started to build a parallel economy based on personal connections and bartering (e.g. you know somebody who works at shoe shop, he can reserve a nice pair of shoes for you when they’re available for something he can’t easily buy himself) with the various forms of theft and forgery required to cover up for the goods sold illegally (like diluting milk to have the required amount after your friends got couple of litres of fresh fat milk) and organisations started to lie in their reports about the amounts of goods they produced (because they were rewarded or punished based on the reports).

Plus during Andropov times there was an inflation of KGB and police numbers (my grandpa told once that back in his youth they had one policeman and he was formidable, later they had dozens policemen and they hardly got any respect), and those KGB/police personnel who had to maintain internal order were bored and started to get connections with illegal manufacturers or goods, smugglers and such leading to the famous fusion of criminals and law enforcement (especially in the 1990s). Other institutions were decaying as well, in the army soldiers were used as a free labour to build houses for the commanders and lying there was ubiquitous as well (for example, many memoirs and recollections tell how it was more important to make an impression of doing something big instead of doing something small properly; it is also said that a plane escaped USSR because anti-air defence reported plane movements after its regular schedule, i.e. always giving the same numbers instead of actually looking at the radar).

Modern times

After dissolution of the USSR in 1991, the situation was grim for many post-Soviet republics because of the destroyed economical ties (and the fact that most of the goods produced were acceptable only inside of the USSR and only for the lack of the alternative). In either case, 1990s in russia are nicknamed the cursed nineties and people don’t want to realise those were the times that made russia stronger and wealthier. But considering how the first president of russia had to protect himself and certain people around him from possible (well-grounded) legal persecution, he passed the post in semi-democratic way (i.e. there were elections but with mass media under proper control and virtually no time for the other candidates to prepare) to the selected successor, who was a former KGB agent and a member of Tambov Gang. During his rule all strategic companies were put under control of his friends, cronies or underlings. And of course since the führer missed USSR, he tried to reboot it including switching to the different economic model where everything important belongs to the state (i.e. his people acting in his and their own interests) and the rest of people live essentially in trickle-down economy where oligarchs get money from the state usually by being allowed to mine and sell natural resources or to fulfil state contracts, other companies get their share of money from serving those oligarchs, other companies get their money from doing work for them and so on. And law enforcement forces get their share for turning blind eye to it or directly participating in the illegal activity.

This of course corrupted people as they see the quickest way to get rich is to either have proper connections so you can participate in cut-and-kickback scheme or to join law enforcement (or some safety inspection) and get you money from bribes and “protection” money. Doing business in such condition is possible only if you have right connections to protect you from the people above (though people protecting you might want to take your business for themselves if it gets profitable enough). And if you’re too poor you just have to rely on the pity sustenance provided to you by the state (which paradoxically makes you love it).

So what are russians and what to do with them?

And that is how you get russians—not a real nation but rather a gathering of people (if you can call them people) who care only about themselves. Even with the current protests against “partial” mobilisation you can see that protesters in Moscow do nothing for the others and let them be detained while in e.g. Dagestan protesters fight against the police to prevent people from being arrested (similarly to the current Iranian uprising or Ukrainian Euromaidan of 2014). Similarly russians have never protested for defending their freedoms, there were several uprisings in the past but they were mostly a way to tell the czar that their living conditions are bad (or sometimes it was against a reform introducing something new).

Thanks to their imperial past they feel superior to other nations and despise them while still being afraid of any real nation—like Ukrainians or their Caucasian nations (Dagestani, Chechen and so on). This probably happens because of their disunity since they know nobody will fight for them while others may get help from their compatriots. And of course such people would be worse than professional executioners if they get a chance to get even on somebody else. The findings and testaments from places like Bucha, Yahidne or Izyum prove that. Similarly there are many accounts when russians hearing about mobilisation are outraged by the fact it affects them as they’d prefer somebody else to die instead of them, especially national minorities (“russian tank driver from Buryatia” has become a meme during the first phase of this war in 2014 already).

Probably another affect of their disunity is their volatility and unreliability. In the past centuries they’ve been trained well enough to support whatever is forced unto them by the authorities (either out of fear or in faint hope of reward) but they do it half-heartedly. That is why after the parade with photos of fallen WWII heroes (or whatever passes for them) as their current state religion demands all those photos gets thrown away to the nearest garbage heap. That is why they were putting half-swastikas onto their cars after the start of the war and that’s why they’re removing it after hearing the rumours that those wearing it would be drafted first (all while complaining “I’m a patriot so let all those prisoners and traitors fight instead”).

That is why I don’t think that accepting russian “refugees” (especially in large quantities) is a good idea neither from the strategic point of view (as those troops won’t make a large difference anyway, modern wars are fought not by large masses of unequipped people) nor for the receiving side. Thanks again to the imperial past, they hate other nations and refuse to learn local language let alone to fully integrate—Baltic states can tell a lot of stories and here in Germany it’s no better. Diaspora by itself is not a bad thing at all, but not respecting a host country while still expecting it to provide for you is. Now “good russians” (an oxymoron IMO) point at Mongolia offering Buryats a refuge and saying other countries should do the same but in this case we have a country offering a shelter to an oppressed national minority with a culture similar to its own and not somebody fleeing from the mess he helped to create (or she, if they start drafting women at large too). It’s like the saying I heard here that Austrians consider Austria to be the first victim of Hitler while Germans say it’s Germany (but guess who voted him to power).

I’m not a nice man and I believe that you should not try to save adults from their own mistakes. Of course it’s different for children but that’s exactly because they don’t know much and don’t realize what consequences their actions might have. If you’re a legal adult you don’t have such excuse and you should bear full responsibility. Giving those fleeing russians a shelter won’t stop the war, won’t eliminate the risk of a deranged dictator using nuclear weapons as the last resort and it won’t help russians to realize that what they’re doing is wrong. The opposite will probably have the same effect but would require significantly less efforts and resources. Save them for the occasion when you can finally make difference by teaching them that their ideology is bad and why. It had worked for the West Germany after all.

Why I’m not excited about RISC-V

September 20th, 2022

So while russia is trying to commit political suicide by recognizing its war officially and making it a criminal offence to evade it (or disagreeing with the official course in general), here’s a text I wanted to write for a long time but finished only recently.

In general I’m eager to look at some computer architecture and see how multimedia software can be run there (even if I’m no Måns). For a long time my primary development machine was PowerPC-based (before I could buy some decent x86_64-based laptop), I played with ARMv7 and NEON years before Raspberry Pi was created (but who remembers Beagle Board nowadays?), I had two laptops with Chinese MIPS inside (and tried optimising for Loongson 2 SIMD too), I own ARM64-based box too (and did some work on it as well). I’d like to try RISC-V hardware but the state of RISC-V gives me no excitement and here I’ll try to explain why.
Read the rest of this entry »