c - Improper Tiff image generated from RGB888 data -


i'm trying convert rgb888 image data tiff image. code generates improper image. i'm reading rgb data text file.here output image

attached improper image black region shouldn't there seems code making low rgb values zero. i'm creating tiff image without alpha channel.please me comprehend issue.

tiff *out= tiffopen("new.tif", "w");  int sampleperpixel = 3; uint32 width=320; uint32 height=240; unsigned char image[width*height*sampleperpixel]; int pixval; int count=0;   file *ptr=fopen("data.txt","r"); if (ptr!=null)     {       while(count<width*height)         {fscanf(ptr,"%d",&pixval);                     *(image+count)=(unsigned char)pixval;         count++;}     } printf("%d\n",count);  tiffsetfield(out, tifftag_imagewidth, width);  // set width of image tiffsetfield(out, tifftag_imagelength, height);    // set height of image tiffsetfield(out, tifftag_samplesperpixel, sampleperpixel);   // set number of channels per pixel tiffsetfield(out, tifftag_bitspersample, 8);    // set size of channels tiffsetfield(out, tifftag_orientation, orientation_topleft);    // set origin of image. //   other essential fields set not have understand now. tiffsetfield(out, tifftag_planarconfig, planarconfig_contig); tiffsetfield(out, tifftag_photometric, photometric_rgb);  tsize_t linebytes = sampleperpixel * width; unsigned char *buf = null;  //if (tiffscanlinesize(out)<linebytes) //  buf =(unsigned char *)_tiffmalloc(linebytes); //else     buf = (unsigned char *)_tiffmalloc(tiffscanlinesize(out));     tiffsetfield(out, tifftag_rowsperstrip, tiffdefaultstripsize(out, width*sampleperpixel));  uint32 row ; //now writing image file 1 strip @ time (row = 0; row < height; row++) {     //memcpy(buf, &image[(height-row-1)*linebytes], linebytes);    // check index here, , figure out why not using h*linebytes     memcpy(buf, &image[(row)*linebytes], linebytes);         if (tiffwritescanline(out, buf, row, 0) < 0)     break; }   tiffclose(out);  if (buf)  _tifffree(buf); 


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -