Sony RX1 RAW file issue? An investigative report...

Started Dec 27, 2012 | Discussions thread
Iliah Borg
Forum ProPosts: 16,134
Like?
Re: Sony RX1 RAW file issue? An investigative report...
In reply to tesilab, Jan 1, 2013

The relevant piece of code to unpack ARW2 format

  1. // Process 32 pixels (16x2) per loop.
  2. { );30 - w < x ;0 =uint32 x ( for    
  3. ;)(checkPos      bits.
  4. ;)11(getBits bits.= _max int      
  5. ;)11(getBits bits.= _min int      
  6. ;)4(getBits bits.= _imax int      
  7. ;)4(getBits bits.= _imin int      
  8. ; shint      
  9. ;)++ sh; _min- _max <= sh << 0x80 && 4 < sh ;0 =sh ( for      
  10. { )++ i;16 < i ;0 = i int( for      
  11. ; pint        
  12. ; _max= p ) _imax==( if        
  13. ; _min= p ) _imin==( if else        
  14. { else        
  15. ; _min+ ) sh<< )7(getBitsbits.( =          p 
  16. )0x7ff >( if          
  17. ;0x7ff =            p 
  18. }        
  19. ;]1 <<[ curve= ]2*i+x[        dest
  20. }      
  21. // Skip to next 32 pixels  ;1 : 31 ? 1 & x =+      x 
  22. }    
  • To comment on the code,
    • Pixels with odd and even numbers within one scan line are processed separately as they belong to different colour channels.
    • The scan line is cut into blocks each containing 16 sequential pixels belonging to the same colour channel.
    • For a 16-byte block the following data is recorded:
      • 11-bit maximimum value for this block.
      • 11-bit minimum value for this block.
      • 4-bit indices of min and max pixels in the block, that allows precise coding of those values using 4 bits.
      • 14 7-bit delta values, delta relative to the min value.
    • 7-bit data is converted to 11 bits by shifting to the left (0..4 bits shift) and adding min value from the block.
  • That is:
    • If the variations within the block are small (less than 128 ADC units) the compression is lossless. Even gradients should be rendered without any visual posterisation..
    • If the block contains a sharp edge or some pixel is noisy - the coding precision is 7 bits.
  • 11-bit data ("locally 7-bit data") is shifted 1 bit to the left and rendered through decompression curve.

For the Russian version and discussion please see Alex Tutubalin's blog http://blog.lexa.ru/2012/12/29/o_sortakh_raw_u_sony.html

Reply   Reply with quote   Complain
Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark post MMy threads
Color scheme? Blue / Yellow