Forum: Poser - OFFICIAL


Subject: .NET RSR library

Syrus_BD opened this issue on Nov 17, 2012 · 12 posts


lmckenzie posted Wed, 21 November 2012 at 5:20 AM

After messing with this some more, I got something that to work a bit better - a different .pct header and finding out more about the .rsr files I have. I was able to convert about 500 .rsr files OK. The caveat is that most only show up in my image viewer if I turn off or delete the alpha channel, then they're fine. I don't remember having this issue before but then I was converting to .png. Since I can't get GraphicsMagick running, I'm just saving and viewing the .pct files. I don't really need the alpha transparency for my archive database thumbnails anyway but hopefully I can figure it out in any case.

Most .rsr files (mine anyway) have a LF (hex 0A) at byte 303 (i.e. 'Normal'). Some have the LF a few bytes past 303 (i.e. 'Moved LF'). Some have what looks like some sort of embedded color profile in the header starting at byte 301. These have a block that includes text like "sRGB IEC1966-2.1" and "Hewlett-Packard" (i.e. Profile). Some, possibly all with a color profile were of Japanese origin. 

Note: a lot of my .rsr files were converted from .pngs with P3DO for P4, but I think at least some originals were in the batch I tested.

The image X & Y sizes 91 (hex 5B) appears in at least two places, including in the 8 bytes following the LF in Normal and Moved LF files. The sizes in some files were not 91 in this section for some reason and caused errors in my image viewer To work around this, I added the proper 8 bytes to the end of my stock header file.

My quick and very ugly process is:
A. read the stock header into a byte array
B. read 303 bytes from the .rsr file into a byte array
--
If byte 301 is 161 (hex A1), it has a color profile (don't know if this is always true)
read the remainder of the file into a byte array then jump to writing the .pct
or
If byte 303 is LF, read 8 more bytes to account for the longer stock header (i.e. move the file pointer).
read the remainder of the file into a byte array.
or
If 303 is not LF read bytes until LF is found or bail after (arbitrary) 100 bytes.
If found, read 8 more bytes to account for the longer stock header. (i.e. move the file pointer).
read the remainder of the file into a byte array then jump to writing the .pct
--
Write out the .pct file consisting of the stock header array followed by the remainder array

The logic & structure sucks, and there are a couple of kludges in the code not listed but it 'evolved' as I found things and it appears to mostly work so I'll "refactor" it later. I can send you a copy if you promise not to laugh, but I'm sure you can come up with something better.

"Democracy is a pathetic belief in the collective wisdom of individual ignorance." - H. L. Mencken