
Untitled
By: a guest on
Apr 24th, 2012 | syntax:
None | size: 1.32 KB | hits: 13 | expires: Never
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define RGB_HEADER_LENGTH 0xCC
#define RGB_BYTES_PER_PIXEL 3
#define RGB_WIDTH_OFFSET 0x34
#define RGB_HEIGHT_OFFSET 0x40
unsigned char * readRGBtiff(char * filename, int * width, int * height){
// Get handle to file
FILE *fstream= fopen(filename, "r");
// Seek to the width
fseek(fstream, RGB_WIDTH_OFFSET, SEEK_SET);
// Attempt to read width
if(!fread(width, sizeof(*width), 1, fstream))
{
printf("Error reading width...\n");
}
// Seek to height
fseek(fstream, RGB_HEIGHT_OFFSET, SEEK_SET);
// Attempt to read height
if(!fread(height, sizeof(*height), 1, fstream))
{
printf("Error reading height...\n");
}
// Seek to RGB data
fseek(fstream, RGB_HEADER_LENGTH, SEEK_SET);
int fileSize = (*width) * (*height) * RGB_BYTES_PER_PIXEL;
// Allocate space
unsigned char* buffOut = (unsigned char*)malloc(fileSize - RGB_HEADER_LENGTH + 1);
if(buffOut == NULL)
{
printf("malloc failed\n");
}
unsigned int readLen = fileSize - RGB_HEADER_LENGTH;
if(!fread(buffOut, readLen, 1, fstream))
{
printf("Error reading RGB\n");
}
return buffOut;
}
int main()
{
int width, height;
readRGBtiff("C:\\test.tif", &width, &height);
printf("w: %d, h: %d\n\n", width, height);
int k =0;
}