Created
May 4, 2018 20:50
-
-
Save fernandoc1/8533276e2d171f7e5eddc19c9bdecd6d to your computer and use it in GitHub Desktop.
This code is to convert raw data buffer acquired from Flir camera to a TIFF image, using libtiff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <tiffio.h> | |
int main(int argc, char** argv) | |
{ | |
if(argc < 2) | |
{ | |
std::cout << argv[0] << " <INPUT_FILE>" << std::endl; | |
return 1; | |
} | |
std::string filepath(argv[1]); | |
FILE* file = fopen(filepath.c_str(), "rb"); | |
fseek(file, 0, SEEK_END); | |
long fsize = ftell(file); | |
fseek(file, 0, SEEK_SET); | |
uint8_t* buffer = (uint8_t*)malloc(fsize); | |
fread(buffer, fsize, 1, file); | |
fclose(file); | |
int imgWidth = 640; | |
int imgHeight = 512; | |
std::string outputFile = filepath + std::string(".tiff"); | |
TIFF* tiff = TIFFOpen(outputFile.c_str(), "w"); | |
TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, imgWidth); | |
TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, imgHeight); | |
TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 1); | |
TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 16); | |
for(int i = 0; i < imgHeight; i++) | |
{ | |
TIFFWriteScanline(tiff, &buffer[i*imgWidth*2], i); | |
} | |
TIFFClose(tiff); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment