Create minimal TIFF from uint16_t RGB in C (GCC) and ImageMagick?
Posted: 2015-10-18T19:18:51-07:00
Exec Summary:
From inside a C program with uint16_t arrays for R,G and B, (or a single, interlaced, "uint48_t" array), what is the most direct IM way to write a usable tif/png/??? to disk with PURE, RAW DATA and a minimal header?
Gory Details:
DCraw creates a TIF file which essentially behaves like a normal TIF, but has only a 1376 byte TIF fig leaf on top of raw, 48 bit/pixel, uint16_t data. I am trying to create a tif/png/??? file with enough header to hold the XY resolution and be read like a jpg by Photoshop (no .RAW interrogation).
You can use (Identify xyz.tif) to get the XY resolution of DCRaw.TIFF. Since the XRes * YRes * 6B/pix + 1376 == file_size, you can just jettison the top header with an fseek and have access to the pure data in C. Best of both worlds!
In PerlMagick, this is a fairly direct implement to crate a tif from 48bit RAW data (without shelling out to convert.exe)
I:\br3\ac-254020>bb.pl
Running C:\bin\bb.pl Sun Oct 18 20:03:06 2015
FN2XY -> XRes=7360, YRes=4912 -> 7360x4912
ac-254020.wb.gray.mlv.7360x4912.tif created, size=216.953480MB -> tif_hdr=39560
Elapsed time = 608.035 ms
############################################################################
I write to .raw files with the XY res embedded in the filename so I don't have to remember it (brain buffer < 8 bytes <:o). Photoshop handles the .raw file extension, type in xres, yres, 3 channels, 16 bit and PC format (not Mac!) and a few more dialog about color space, .. and voila, I am only one, save-as interrogation from having a usable file.
From inside a C program with uint16_t arrays for R,G and B, (or a single, interlaced, "uint48_t" array), what is the most direct IM way to write a usable tif/png/??? to disk with PURE, RAW DATA and a minimal header (like DCraw)?
------------------------------------------------------------------------------------
Searching for (create tif) finds zero results. The only google hit for (c imagemagick c api write rgb tif 16bit rgb sample program -convert) is "Writing images from raw data?" from 2002
search.php?keywords=create++tif+&fid[0]=6
Search found 0 matches: create tif
From inside a C program with uint16_t arrays for R,G and B, (or a single, interlaced, "uint48_t" array), what is the most direct IM way to write a usable tif/png/??? to disk with PURE, RAW DATA and a minimal header?
Gory Details:
DCraw creates a TIF file which essentially behaves like a normal TIF, but has only a 1376 byte TIF fig leaf on top of raw, 48 bit/pixel, uint16_t data. I am trying to create a tif/png/??? file with enough header to hold the XY resolution and be read like a jpg by Photoshop (no .RAW interrogation).
You can use (Identify xyz.tif) to get the XY resolution of DCRaw.TIFF. Since the XRes * YRes * 6B/pix + 1376 == file_size, you can just jettison the top header with an fseek and have access to the pure data in C. Best of both worlds!
In PerlMagick, this is a fairly direct implement to crate a tif from 48bit RAW data (without shelling out to convert.exe)
Code: Select all
sub raw_to_tif() {
$raw='raw/ac-254020.wb.gray.mlv.7360x4912.raw';
($tif=$raw) =~ s/^.*\/(.*)\.raw$/$1.tif/; # Create "$BASE.tif
($xres, $yres)=&fname_to_xyres($raw); # Get XRESxYRES f/fname
$tsize=$xres . "x$yres"; # 7360x4912
print("FN2XY -> XRes=$xres, YRes=$yres -> $tsize\n");
my $im = Image::Magick->new(size=>"$tsize", type=>'TrueColor', depth=>16);
$err=$im->Read(filename=>"RGB:$raw"); warn $err if $err;
$err=$im->Write(filename=>"TIFF:$tif"); warn $err if $err;
$tsize= -s $tif;
$hsize= $tsize - (6 * $xres * $yres); # Header=fileSize - uint48Size
printf("$tif created, size=%.6fMB -> tif_hdr=$hsize\n", $tsize/1E6);
undef $im; # Nuke after last use
}
Running C:\bin\bb.pl Sun Oct 18 20:03:06 2015
FN2XY -> XRes=7360, YRes=4912 -> 7360x4912
ac-254020.wb.gray.mlv.7360x4912.tif created, size=216.953480MB -> tif_hdr=39560
Elapsed time = 608.035 ms
############################################################################
I write to .raw files with the XY res embedded in the filename so I don't have to remember it (brain buffer < 8 bytes <:o). Photoshop handles the .raw file extension, type in xres, yres, 3 channels, 16 bit and PC format (not Mac!) and a few more dialog about color space, .. and voila, I am only one, save-as interrogation from having a usable file.
From inside a C program with uint16_t arrays for R,G and B, (or a single, interlaced, "uint48_t" array), what is the most direct IM way to write a usable tif/png/??? to disk with PURE, RAW DATA and a minimal header (like DCraw)?
------------------------------------------------------------------------------------
Searching for (create tif) finds zero results. The only google hit for (c imagemagick c api write rgb tif 16bit rgb sample program -convert) is "Writing images from raw data?" from 2002
search.php?keywords=create++tif+&fid[0]=6
Search found 0 matches: create tif