0
RGB888 이미지 데이터를 TIFF 이미지로 변환하려고합니다. 그러나 코드는 부적절한 이미지를 생성합니다. 내가 텍스트 file.Here에서 RGB 데이터를 읽고 있어요 출력 이미지RGB888 데이터에서 생성 된 부적절한 Tiff 이미지
검은 색 지역이 안가 그 코드가 제로로 낮은 RGB 값을 만드는 것 같다에게 있습니다. 알파 채널을 사용하지 않고 티파니 이미지를 만듭니다. 문제를 이해하도록 도와주세요.
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 the width of the image
TIFFSetField(out, TIFFTAG_IMAGELENGTH, height); // set the height of the image
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel); // set number of channels per pixel
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); // set the size of the channels
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the origin of the image.
// Some other essential fields to set that you do not have to understand for 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 to the file one strip at a time
for (row = 0; row < height; row++)
{
//memcpy(buf, &image[(height-row-1)*linebytes], linebytes); // check the index here, and 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);
한 번에 한 단계 씩 진행해야합니다. 먼저 텍스트 파일에서 데이터를 읽는 대신 harcoded 값으로 모든 스캔 라인을 채우려 고 시도하면 어떻게됩니까? (예 : 완전히 빨간색 티파니 생성) – Jem
TIFFTAG_ROWSPERSTRIP이 잘못되었습니다. HEIGHT 또는 HEIGHT의 분수 분할로 설정해야합니다. 나머지는 괜찮아 보인다. 실제 파일을 게시하면 어디에서 잘못되었는지 자세히 알 수 있습니다. – BitBank
@BitBank 전체 코드이므로 파일에 대해 자세히 설명해주십시오. 이 외에도 데이터 파일 만 있습니다. 감사합니다 – vid09