For those who want to see their raw data in R, you can read your image like this :
fid <- file("raw-01099.dng","rb")
junk <- readBin(fid, integer(), n=5080 , size=1, endian='little')
raw <- readBin(fid, integer(), n=2592*1944 , size=2, signed=FALSE,endian='little')
close(fid)
raw <- array(raw, dim=c(2592,1944))/64
#Look at the whole image
image(raw, col=grey(1:128 / 128))
#Single color images
image(raw[seq(1,1944,by=4),], col=grey(1:128 / 128))
# histogram for each channel
hist(raw[seq(1,2592, by = 4),], breaks=256, col='green', xlim=c(0,64))
hist(raw[seq(2,2592, by = 4),], breaks=256, col='red', xlim=c(0,64))
hist(raw[seq(3,2592, by = 4),], breaks=256, col='blue', xlim=c(0,64))
hist(raw[seq(4,2592, by = 4),], breaks=256, col='dark green', xlim=c(0,64))
Now my question, Is this OK ?
pixel[col+0] = buffer[j++] << 8;
pixel[col+1] = buffer[j++] << 8;
pixel[col+2] = buffer[j++] << 8;
pixel[col+3] = buffer[j++] << 8;
split = buffer[j++]; // low-order packed bits from previous 4 pixels
pixel[col+0] += (split & 0b11000000); // unpack them bits, add to 16-bit values, left-justified
pixel[col+1] += (split & 0b00110000)<<2;
pixel[col+2] += (split & 0b00001100)<<4;
pixel[col+3] += (split & 0b00000011)<<6;
Ain't this overwriting the top bits and adding giving sometimes values close to the 1023 limit ?
#include<stdio.h>
int main(int argc, char **argv)
{
unsigned char a = 0xff, b=0xff;
unsigned short x = 0x00;
x=a;
x+=((short)b & 0b11000000)<<2;
printf("%04x\n",x);
x=a;
x+=((short)b & 0b00110000)<<4;
printf("%04x\n",x);
x=a;
x+=((short)b & 0b00001100)<<6;
printf("%04x\n",x);
x=a;
x+=((short)b & 0b00000011)<<8;
printf("%04x\n",x);
return 0;
}
Maybe I'm just too tired and need to sleep...