⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profiles2raw.cpp

📁 Dialogic DM3板卡传真示例程序
💻 CPP
字号:
//
// profiles2raw.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 print_error(TIFFStatus err)
{
	printf("TIFF error %d occurred: %s\n", err, GetTiffErrorMsg(err));
}

void myprint(int channel, char *log_string, va_list args)
{
	vprintf(log_string, args);
}


int main(int argc, char* argv[])
{
	CTiffProfileS	*tiff;
	CTagInfo *tags;
	int num_tags;

	TIFFStatus	ret;
	int		raw_image;
	int     raw_tags;
	char 	filename[80];

	CTiffLog log;

	log.SetChannel(0);
	log.SetCallback(myprint);

	tiff = new CTiffProfileS();

	tiff->BindLogObject(&log);

	if ((ret = tiff->Open(argv[1])) != TIFF_OK) {
		print_error(ret);
		PAUSE();
		return -1;
	}
		
	for (int i = 0; i < tiff->GetNumPages(); i++) {

		sprintf(filename, "%s.%d.raw", argv[2], i+1);
#ifdef WIN32
		raw_image = open(filename, _O_BINARY | _O_CREAT | _O_TRUNC | _O_RDWR);
#else
		raw_image = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
#endif
		if (raw_image == -1) {
			PAUSE();
			return -1;
		}

		sprintf(filename, "%s.%d.tags", argv[2], i+1);

#ifdef WIN32
		raw_tags = open(filename, _O_BINARY | _O_CREAT | _O_TRUNC | _O_RDWR);
#else
		raw_tags = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
#endif
		if (raw_tags == -1) {
			PAUSE();
			return -1;
		}

		ret = tiff->GetAllTags(i+1, &tags, &num_tags);

		if (ret != TIFF_OK) {
			print_error(ret);
			PAUSE();
			return -1;
		}
//
//		Write out each tag's data
//
		for (int j = 0; j < num_tags; j++)
		{
			write(raw_tags, (void *) &(tags[j]), sizeof(CTagInfo));
			write(raw_tags, tags[j].m_value, tags[j].m_sz_value);
		}
//
//		Write out each page's image data
//
		unsigned char buffer[4096];
		int num_bytes;

		ret = tiff->GetImageData(i+1, buffer, 4096, num_bytes);
		while (ret == TIFF_OK && num_bytes > 0) {
			write(raw_image, buffer, num_bytes);
			ret = tiff->GetImageData(i+1, buffer, 4096, num_bytes);
		}

		if (ret != TIFF_OK) {
			print_error(ret);
			PAUSE();
			return -1;
		}

		close(raw_image);
		close(raw_tags);
	}
//
//	Close the file and delete the file object
//
	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 + -