X3F SIGMA Raw format documentation project

Official X3F File Format Specification is not complete. Because main image format is not specified ( and camera calibration settings).

Here you can download official x3f raw specification in PDF format. To fully understand documentation below, you should read and understand the official documentation.

Prologue

SIGMA has encrypted data that is required to process RAW image. Only two digital camera manufacturers use encryption, SIGMA and NIKON ( later ). SIGMA protects all data, NIKON only white balance settings. The only thing that I can imagine about encryption usage in SIGMA RAW files is marketing.

Camera/shot calibration info

Encrypted Data Subsection Type is marked as CAMF and point to this structure:

struct CAMF_DATA
{		
	DWORD m_dwordSectionIdentifier; // Section identifier Should be "SECc"
	DWORD m_dwordSectionFormatVersion;
	DWORD m_dwordTypeOfInfoData;
	DWORD m_dwordReserved;
	DWORD m_dwordInfoType; // Should be "FCEb"
	DWORD m_dwordInfoTypeVersion;
	DWORD m_dwordCryptKey;
}

All information below this structure is encrypted with key m_dwordCryptKey. Actually this not a strong encryption and used only as obfuscator. This is a stream cipher based on LCG ( l_dwordCryptLCG ) and S-Box ( l_dwordCryptSbox ). To decrypt this data you may use this code:

	// mp_byteSectionData pointer to the section data after m_dwordCryptKey
	// m_dwordSectionDataSize size of the section
	// LCG obfuscation + s'box
	for ( DWORD l_dwordCnt = 0; l_dwordCnt < m_dwordSectionDataSize; l_dwordCnt++ )
	{
		l_dwordCryptLCG = (( l_dwordCryptLCG * 1597 ) + 51749 ) % 244944;
		l_dwordCryptSbox = DWORD( l_dwordCryptLCG * INT64( 301593171 ) >> 24 );
		mp_byteSectionData[ l_dwordCnt ] ^= (((( l_dwordCryptLCG << 8 ) - l_dwordCryptSbox ) >> 1 ) + l_dwordCryptSbox ) >> 17;
	}

SIGMA DP1 Update

SIGMA Corp. has changed the CAMF_DATA structure. Now, it looks like the data is compressed( due to internal debug strings ). "h.m_iCamfileType == FOVB_CAMFILE_CAMB_HUFFMAN_M4". RAW Image format has been changed too, new image index is 30. It's not specified by SIGMA Corp. and I have no ideas why.

... next parts is coming soon

RAW Image section

The section with RAW image ( IMAG ) have type 6 ( m_dwordDataFormat ).

struct IMAGE_DATA
{
	DWORD m_dwordSectionIdentifier; // Section identifier Should be "SECi" . 0x69434553
	DWORD m_dwordImageFormatVersion; // Image format version Should be 2.0 for now.
	DWORD m_dwordTypeOfImageData; // Type of image data 2 = processed for preview (others RESERVED)
	DWORD m_dwordDataFormat; // Data format 
	// 3 = uncompressed 24-bit 8/8/8 RGB - preview
	// 6 = Huffman-encoded DPCM 16/16/16 RGB - RAW
	// 11 = Huffman-encoded DPCM 8/8/8 RGB - preview
	// 18 = JPEG-compressed 8/8/8 RGB
	// 30 = Unknown RAW image compression in Sigma DP1 camera
	DWORD m_dwordImageColumns; // Image columns Image width / row size in pixels
	DWORD m_dwordImageRows; // Image rows Image height in pixels
	DWORD m_dwordRowSize; // Row size in bytes Will always be a multiple of 4 (32-bit aligned).
	// A value of zero here means that rows are variable-length (as in Huffman data).
}

The section data starts with 1024 * WORD table of pixel values, next 1024 * DWORD bytes is a huffman table and it's followed by the encrypted data.

Unpacking function is the same as for big preview, except the pixel value, it takes not from index in the huffman table but from the table of pixel values.

... next parts is coming soon

Investigation is based on: Dcraw source by Dave Coffin, X3F files format and with help of Ilya O. Levin ( crypto analysis )

  Contact usCopyright 1999 - 2006 (c) CEZEO software. All rights reserved.