void test_TiffPhotoShopTag(const std::string& tiffFilePath, const std::string& binFilePath, const std::string& textFilePath)
{
TIFF* tif = TIFFOpen(tiffFilePath.c_str(), "rCm");
assert(tif);
//写文件
uint32 ps_size = 0;
void* ps_data = NULL;
if (TIFFGetField(tif, TIFFTAG_PHOTOSHOP, &ps_size, &ps_data))
{
{
std::fstream fs;
fs.open(binFilePath, std::ios_base::out | std::ios_base::binary);
assert(fs.is_open());
fs.write((char*)ps_data, ps_size);
fs.close();
}
{
std::fstream fs;
fs.open(textFilePath, std::ios_base::out | std::ios_base::binary);
assert(fs.is_open());
//转化为文本
char szBuf[1024] = { 0 };
std::string str;
str.reserve(1024 * 1024 * 5);
uint8* p = (uint8*)ps_data;
int pos = 0;
for (uint32 i = 0; i < ps_size; ++i)
{
//特殊处理
bool b = false;
if (i + 5 < ps_size)
{
if (p[i] == '8' && p[i] && p[i + 1] == 'B' && p[i + 2] == 'P' && p[i + 3] == 'S')
{
b = true;
_snprintf_s(szBuf, 1024, "\n\n[8BPS %02X%02X] ", (int)(p[i + 4]), (int)(p[i + 5]));
i += 5;
pos = i + 1;
}
if (p[i] == '8' && p[i] && p[i + 1] == 'B' && p[i + 2] == 'I' && p[i + 3] == 'M')
{
b = true;
_snprintf_s(szBuf, 1024, "\n\n[8BIM %02X%02X] ", (int)(p[i + 4]), (int)(p[i + 5]));
i += 5;
pos = i + 1;
}
}
if (b)
{
str += szBuf;
}
else
{
if ((i - pos) % 16 == 0)
str += "\n";
_snprintf_s(szBuf, 1024, "%02X ", (int)(p[i]));
str += szBuf;
}
}
fs.write(str.c_str(), str.size());
fs.close();
}
}
TIFFClose(tif);
tif = nullptr;
}
分析 Tiff的TIFFTAG_PHOTOSHOP标签的部分代码
最新推荐文章于 2023-09-17 12:13:02 发布