This solution works PERFECTLY as documented

// Grab a standard TIF hdr // Update the ushort XY res values, X@[16] and Y@[22] // Slam it on top of a UINT16 RAW and call it a TIF!!! // What could POSSIBLY be easier??? // // gcc -Ofast -ffast-math -m64 -march=sandybridge -msse4.2 -mavx -fun +roll-loops -fopenmp -flto -lm c:/bin/merge.hdr.raw.c -o c:/bin/merge +.hdr.raw.exe #include "bpbfct.c" void main(int argc, char *argv[]) { FILE *hi, *ri, *to; // File pointers for 2 ins and 1 outs struct stat statbuf; // STAT function buffer char hdrfn[255] = { 0 }; char rawfn[255] = { 0 }; char tiffn[] = "hdr.raw.merge.tif"; int hsize=1376, rsize, bread, brote, tsize; // Header and RAW sizes uint16_t *hdra; // HDR data array uint16_t *rawa; // RAW data array strcpy(hdrfn, argv[1]); strcpy(rawfn, argv[2]); hdra=(uint16_t *)malloc(hsize); hi=fopen(hdrfn, "rb"); bread=fread((void *)hdra, 1, hsize, hi); printf("Read %d Bytes from %s\n", bread, hdrfn); fclose(hi); stat(rawfn, &statbuf); // Stat the file to get its size rsize=statbuf.st_size; // File size in bytes for .raw (RGB?) file rawa=(uint16_t *)malloc(rsize); ri=fopen(rawfn, "rb"); bread=fread((void *)rawa, 1, rsize, ri); printf("Read %.6lf MBytes from %s\n", bread*1E-6, rawfn); fclose(ri); // HERE's the HARD PART!!! printf("Xres @ Hdr[16]=%hu, Yres @ [22] = %hu\n", hdra[16], hdra[2 +2]); hdra[16]=(uint16_t) 7360; <<<< Is this POSSIBLE in PERL?????? hdra[22]=(uint16_t) 4912; // Did it float?? printf("FIXED?? Xres @ Raw[16]=%hu, Yres [22] = %hu\n", hdra[16], hdra[22]); to=fopen(tiffn, "wb"); // TIF output file brote = fwrite((void *)(hdra), 1, hsize, to); brote += fwrite((void *)(rawa), 1, rsize, to); fflush(to); fflush(to); fclose(to); stat(tiffn, &statbuf); // Stat the file to get its size tsize=statbuf.st_size; // File size in bytes for .raw (RGB?) file printf("Wrote %.6lf MBytes to TIF %s, Size: T-R-H=%d\n", tsize*1E-6, tiffn, brote - rsize - hsize); free(hdra); free(rawa); } // End Main().
I:\exp\6s-254623> merge.hdr.raw.exe gray.1376b.3689x2462.hdr 6s-2015 +.1031-254550.7360x4912.blue.cv.t.raw Read 1376 Bytes from gray.1376b.3689x2462.hdr Read 72.304640 MBytes from 6s-2015.1031-254550.7360x4912.blue.cv.t.raw Xres @ Hdr[16]=3689, Yres @ [22] = 2462 FIXED?? Xres @ Raw[16]=7360, Yres [22] = 4912 Wrote 72.306016 MBytes to TIF hdr.raw.merge.tif, Size: T-R-H=0 I:\exp\6s-254623>identify hdr.raw.merge.tif hdr.raw.merge.tif TIFF 7360x4912 7360x4912+0+0 16-bit Grayscale Gray 7 +2.31MB ... <p> Note the original and overwritten values. </p> <code> Xres @ Hdr[16]=3689, Yres @ [22] = 2462 FIXED?? Xres @ Raw[16]=7360, Yres [22] = 4912 <<< WORKS!!!

It's Alive!

</code>

In reply to Re^3: Write 2 uint16_t numbers to file in Perl by BrianP
in thread Write 2 uint16_t numbers to file in Perl by BrianP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.