📄 raw2tiff.cpp
字号:
//
// raw2tiff..cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <stdarg.h>
#include "TiffFile.h"
#include "TiffTag.h"
#define PAUSE() \
{ \
putchar(getchar()); \
}
void print_error(TIFFStatus error)
{
printf("TIFF error %d occurred: %s\n", error, GetTiffErrorMsg(error));
}
int main(int argc, char* argv[])
{
CTiffFile *file;
CTiffPage *page;
CTiffTag *tag;
TIFFStatus ret;
CTagInfo tag_info;
file = new CTiffFile(TIFF_INTEL_BYTE_ORDER);
//
// First argument is name of output TIFF file
//
if ((ret = file->Create(argv[1])) != TIFF_OK) {
print_error(ret);
exit(1);
}
for (int i = 2; i < argc; i++) {
//
// Create a page for the file
//
page = file->AddPage();
//
// Read the image data and add an image strip
//
CTiffStrip *strip = new CTiffStrip();
//
// argv[i] is name of input image data file
//
char filename[80];
sprintf(filename, "%s.raw", argv[i]);
#ifdef WIN32
int image_fd = open(filename, _O_BINARY | _O_RDONLY);
#else
int image_fd = open(filename, O_RDONLY);
#endif
int bytes_read;
UInt8 strip_buffer[4096];
//
// Read image date 4k at a time, and add to the strip
//
bytes_read = read(image_fd, strip_buffer, 4096);
while (bytes_read > 0) {
strip->AddDataToStrip(strip_buffer, bytes_read);
bytes_read = read(image_fd, strip_buffer, 4096);
}
close(image_fd);
//
// Add the strip to the page
//
page->AddStrip(strip);
//
// Create the IFD by adding the desired tags
//
sprintf(filename, "%s.tags", argv[i]);
#ifdef WIN32
int tags_fd = open(filename, _O_BINARY | _O_RDONLY);
#else
int tags_fd = open(filename, O_RDONLY);
#endif
bytes_read = read(tags_fd, &tag_info, sizeof(tag_info));
while (bytes_read > 0) {
tag = page->AddTag(tag_info.m_tag, tag_info.m_type, tag_info.m_count);
UInt8 *tag_buffer = new UInt8[tag->GetTagCount() * tag->GetSizeofTagType()];
bytes_read = read(tags_fd, tag_buffer, tag->GetTagCount() * tag->GetSizeofTagType());
tag->SetTagValue(tag_buffer, tag->GetTagCount() * tag->GetSizeofTagType());
delete [] tag_buffer;
bytes_read = read(tags_fd, &tag_info, sizeof(tag_info));
tag->Print();
}
printf("-------\n");
//
// All image data is now in one strip, so change tag
//
tag = page->FindTagByNumber(TAG_ImageLength);
if (tag->GetTagType() == TAGTYPE_USHORT ||
tag->GetTagType() == TAGTYPE_SSHORT) {
UInt16 length;
tag->GetTagValue((void *) &length, sizeof(length));
tag = page->FindTagByNumber(TAG_RowsPerStrip);
if (tag->GetTagType() == TAGTYPE_USHORT ||
tag->GetTagType() == TAGTYPE_SSHORT) {
UInt16 rows_per_strip = (UInt16) length;
tag->SetTagValue((void *) &rows_per_strip, sizeof(rows_per_strip));
} else if (tag->GetTagType() == TAGTYPE_ULONG ||
tag->GetTagType() == TAGTYPE_SLONG) {
UInt32 rows_per_strip = (UInt32) length;
tag->GetTagValue((void *) &rows_per_strip, sizeof(rows_per_strip));
}
} else if (tag->GetTagType() == TAGTYPE_ULONG ||
tag->GetTagType() == TAGTYPE_SLONG) {
UInt32 length;
tag->GetTagValue((void *) &length, sizeof(length));
tag = page->FindTagByNumber(TAG_RowsPerStrip);
if (tag->GetTagType() == TAGTYPE_USHORT ||
tag->GetTagType() == TAGTYPE_SSHORT) {
UInt16 rows_per_strip = (UInt16) length;
tag->SetTagValue((void *) &rows_per_strip, sizeof(rows_per_strip));
} else if (tag->GetTagType() == TAGTYPE_ULONG ||
tag->GetTagType() == TAGTYPE_SLONG) {
UInt32 rows_per_strip = (UInt32) length;
tag->GetTagValue((void *) &rows_per_strip, sizeof(rows_per_strip));
}
}
}
if ((ret = file->Close()) != TIFF_OK)
print_error(ret);
delete file;
//
// Pause before terminating
//
printf("All tests passed\n");
PAUSE();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -