📄 raw2profiles.cpp
字号:
//
// raw2profiles.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <stdarg.h>
#include "TiffProfileS.h"
#define PAUSE() \
{ \
putchar(getchar()); \
}
void myprint(int channel, char *log_string, va_list args)
{
vprintf(log_string, args);
}
void print_error(TIFFStatus error)
{
printf("TIFF error %d occurred: %s\n", error, GetTiffErrorMsg(error));
}
int main(int argc, char* argv[])
{
CTiffProfileS *tiff;
TIFFStatus ret;
CTiffLog log;
log.SetChannel(0);
log.SetCallback(myprint);
//
// Open the Profile S file
//
tiff = new CTiffProfileS();
TiffOptions options;
options.m_x_resolution = X_200;
options.m_y_resolution = Y_200;
options.m_t4_options = MH_EOLS_NOT_ALIGNED;
//
// First argument is name of output TIFF file
//
if ((ret = tiff->Create(argv[1]))!= TIFF_OK) {
print_error(ret);
exit(1);
}
tiff->BindLogObject(&log);
//
// FOR each file on the command line
//
for (int i = 2; i < argc; i++) {
//
// Add a new page
//
ret = tiff->AddPage(&options);
if (ret != TIFF_OK) {
print_error(ret);
exit(-1);
}
//
// 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;
unsigned char buffer[4096];
//
// Read image date 4k at a time, and add to the Tiff file
//
bytes_read = read(image_fd, buffer, 4096);
while (bytes_read > 0) {
tiff->AddImageData(i-1, buffer, bytes_read);
bytes_read = read(image_fd, buffer, 4096);
}
close(image_fd);
//
// Update the (default) IFD by setting the tags
//
sprintf(filename, "%s.tags", argv[2]);
#ifdef WIN32
int tags_fd = open(filename, _O_BINARY | _O_RDONLY);
#else
int tags_fd = open(filename, O_RDONLY);
#endif
CTagInfo tag_info;
bytes_read = read(tags_fd, &tag_info, sizeof(tag_info));
while (bytes_read > 0) {
tag_info.m_value = new UInt8[tag_info.m_sz_value];
bytes_read = read(tags_fd, tag_info.m_value, tag_info.m_sz_value);
if (bytes_read != (signed) tag_info.m_sz_value) {
// TODO: Something bad happened...
}
ret = tiff->SetTag(i-1, &tag_info);
if (ret != TIFF_OK) {
print_error(ret);
}
delete [] tag_info.m_value;
bytes_read = read(tags_fd, &tag_info, sizeof(tag_info));
}
close(tags_fd);
}
if ((ret = tiff->Close()) != TIFF_OK)
print_error(ret);
delete tiff;
//
// Pause before terminating
//
printf("All tests passed\n");
PAUSE();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -