convert tiff to raw
i try to change my code into opengl code. but it have error.. so sad..
who can help me???
please save me..
sir.
what problem went i put my code into lesson34 it not display the terrain.
my code is about read tiff image then convert it to raw image.
that is my code.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <string.h>
#define ROW 1000
#define COLUMN 1000
short unsigned int rawData[ROW][COLUMN];
struct HEADER
{
short int ByteOrder;
short int version;
long int OffsetOfFirstIFD;
short int noOfDE;
};
struct DE
{
short int tag;
short int type;
long int length;
long int value;
};
struct IMAGE
{
long int width;
long int length;
long int dataBegin;
long int dataSize;
};
void readTiff (LPSTR& , HEADER& , DE* , IMAGE&);
void main()
{
LPSTR fileTiff;
IMAGE img;
HEADER head;
DE de;
fileTiff.open ("1983-2.tif", ios::in | ios::binary);
if (!fileTiff)
{
cout<<" \n\tFile cannot be read... "<<endl;
}
readTiff(fileTiff, head, &de, img);
fileTiff.close();
getch();
}
void readTiff(LPSTR& fileTiff, HEADER& head, DE *de , IMAGE& img)
{
int i;
ofstream raw;
raw.open("1983-2.raw", ios::out|ios::binary);
if(!raw)
{
cout<<"Failed!!";
}
fileTiff.read((char*) &head.ByteOrder,2);
fileTiff.read((char*) &head.version,2);
fileTiff.read((char*) &head.OffsetOfFirstIFD,4);
fileTiff.read((char*) &head.noOfDE,2);
short int noOfDE = head.noOfDE;
de = new DE[noOfDE];
for(i = 0; i < noOfDE; i++)
{
fileTiff.read((char*) &de.tag,2);
fileTiff.read((char*) &de.type,2);
fileTiff.read((char*) &de.length,4);
fileTiff.read((char*) &de.value,4);
if(de.tag == 256) //ImageWidth
{
img.width = de.value;
cout<<img.width;
}
if(de.tag == 257) //ImageLength
img.length = de.value
if(de.tag == 273) //StripOffsets
img.dataBegin = de.value;
if(de.tag == 279) //StripByteCounts
img.dataSize = de.value;
i++;
}
fileTiff.seekg(img.dataBegin,ios::beg);
for(i = 0; i<img.length; i++)
{
for(int j = 0; j<img.width; j++)
{
fileTiff.read((char*) &rawData[j],1);
raw.setf(ios::hex);
raw.write((char*) &rawData[j],sizeof rawData[j]);
}
}
raw.close();
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement