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

📄 tiff2raw.cpp

📁 Dialogic DM3板卡传真示例程序
💻 CPP
字号:
//
// tiff2raw.cpp : Defines the entry point for the console application.
//


#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <stdarg.h>

#include "TiffFile.h"


#define PAUSE() \
{ \
	putchar(getchar()); \
}


void print_error(TIFFStatus err)
{
	printf("TIFF error %d occurred: %s\n", err, GetTiffErrorMsg(err));
}

int main(int argc, char* argv[])
{
	CTiffFile	*file;
	CTiffPage	*page;
	CTiffTag	*tag;
	CTiffStrip  *strip;

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

	file = new CTiffFile();
	if ((ret = file->Open(argv[1])) != TIFF_OK) {
		print_error(ret);
		exit(1);
	}
//
//	FOR each page in the TIFF file:
//
	for (i = 0; i < file->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) {
			exit(-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) {
			exit(-1);
		}

//
//		Get a page from the file
//
		page = file->GetPage(i);
//
//		FOR each tag in the current IFD
//
		int num_tags = page->GetNumTags();
		for (int j = 0; j < num_tags; j++)
		{
			unsigned char buffer[256];
			int buffer_length;
//
//			Get the tag pointer by its index
//			Print out the tag information
//
			tag = page->GetTagByIndex(j);
			
//			tag->Print();
			tag->GetTagBuffer(buffer, buffer_length);
			printf("Tag %d: %d bytes.. ", tag->GetTagNumber(), buffer_length);
			for (int u = 0; u < buffer_length; u++)
				printf("%02x", buffer[u]);
			printf("\r\n");

			write(raw_tags, buffer, buffer_length);
//
//		ENDFOR
//
		}
		printf("----------\n");

		for (int k = 0; k < page->GetNumStrips(); k++) {
			UInt8 buffer[4096];
			int bytes_from_strip;
			long bytes_to_write;

			strip = page->GetStripByIndex(k);
			bytes_to_write = strip->GetStripSize();
			strip->StartDataTransfer();

			while (bytes_to_write > 0) {
				bytes_from_strip = strip->GetDataFromStrip(buffer, 4096);
				bytes_to_write -= bytes_from_strip;
				write(raw_image, buffer, bytes_from_strip);
			}
		}

		close(raw_image);
		close(raw_tags);
//
//		Print out page stats
//
//		printf("Number of tags    %d\n", page->GetNumTags());
//		printf("IFD base size     %d\n", page->GetIFDBaseSize());
//		printf("IFD extended size %d\n", page->GetIFDExtendedSize());
//
//	ENDFOR
//	Close the file and delete the file object
//
	}

	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 + -