| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2007.04.11 13:26 "Re: DC to tiff", by Joris Van Dammesirkukskall@yahoo.no wrote:
> Anybody know how to print a DC to a tiff file? I can't seem to make
> it work..
>
>...
>
> for(UINT32 row = 0; row < height; row++ ){
> // initialize the scan line to zero
> memset(pdst,0,(size_t)(width * 3));
> // moving the data from the dib to a row structure that
> // can be used by the tiff library
> for(UINT32 col = 0; col < (UINT32)width; col++){
> src_index=(width-row-1)*width*bytecount+col*bytecount;
> dst_index = col*3;
> pdst[dst_index++]=psrc[src_index+2];
> pdst[dst_index++]=psrc[src_index+1];
> pdst[dst_index]=psrc[src_index];
> }
There may be other problems with your code, I've not looked at it too
carefully, but the src_index calculation is very suspicious. 'row' loops
from 0 to height-1, so any calculation of width-row is nonsense, is, like,
three cows minus two horses (but maybe with a lot more progress in the field
of genetic manipulation before the latter will start making sense in the end
;-)). You probably mean height-row-1, as you're reading from bottom-up dibs.
But even then, the calculation isn't correct, as DIB scanlines are padded to
multiple of 32bits. And even then, the placement of that calculation inside
that inner RGB channel swapping loop is far from ideal...
How about replacing the above code snippet with...
UINT8* src_pos;
UINT8* dst_pos;
for(UINT32 row = 0; row < height; row++ ){
// initialize the scan line to zero
memset(pdst,0,(size_t)(width * 3));
// moving the data from the dib to a row structure that
// can be used by the tiff library
src_pos=(UINT8*)psrc+(((height-row-1)*width*3+3)&(~3));
dst_pos=(UINT8*)pdst;
for(UINT32 col = 0; col < (UINT32)width; col++){
dst_pos[0]=src_pos[2];
dst_pos[1]=src_pos[1];
dst_pos[2]=src_pos[0];
src_pos+=3;
dst_pos+=3;
}
That will work if the DIB is 24bits per pixel, as seems to be the case. If
you want more flexible code that works for other DIB bitdepths, the best is
to adapt the above snippet for other DIB bitdepths, and select outside of
the inner RGB channel swapping loop.
Best regards,
Joris Van Damme
info@awaresystems.be
http://www.awaresystems.be/
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html
|
|||||||