From 5c4ed374fa9ef3b7a5b07486f71da41b1fa07e36 Mon Sep 17 00:00:00 2001 From: JARK006 Date: Tue, 27 Aug 2024 01:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84AI=E7=94=9F=E5=9B=BEprompt?= =?UTF-8?q?=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jarkViewer/include/exifParse.h | 87 ++++++++++++++++++++++++++------- jarkViewer/jarkViewer.aps | Bin 20570728 -> 20570728 bytes jarkViewer/jarkViewer.rc | Bin 7760 -> 7760 bytes 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/jarkViewer/include/exifParse.h b/jarkViewer/include/exifParse.h index 7b20f0c..0c8a2e5 100644 --- a/jarkViewer/include/exifParse.h +++ b/jarkViewer/include/exifParse.h @@ -203,7 +203,7 @@ class ExifParse{ auto secondSpaceIdx = tagValue.find_last_of(' '); if (firstSpaceIdx != string::npos && secondSpaceIdx != string::npos && firstSpaceIdx < secondSpaceIdx) { auto n1 = handleMathDiv(tagValue.substr(0, firstSpaceIdx)); - auto n2 = handleMathDiv(tagValue.substr(firstSpaceIdx + 1, secondSpaceIdx-firstSpaceIdx-1)); + auto n2 = handleMathDiv(tagValue.substr(firstSpaceIdx + 1, secondSpaceIdx - firstSpaceIdx - 1)); auto n3 = handleMathDiv(tagValue.substr(secondSpaceIdx + 1)); tagValue = std::format("{}°{}' {}'' ({})", n1, n2, n3, tagValue); } @@ -218,14 +218,27 @@ class ExifParse{ tagValue = std::format("{}:{}:{} ({})", n1, n2, n3, tagValue); } } + else if (tagName == "Exif.Photo.UserComment") { // 可能包含AI生图prompt信息 + auto a = tag.value().clone(); + vector buf(a->size()); + a->copy(buf.data(), Exiv2::ByteOrder::bigEndian); + if (!memcmp(buf.data(), "UNICODE\0", 8)) { + wstring str((wchar_t*)(buf.data() + 8), (buf.size() - 8) / 2); + tagValue = Utils::wstringToUtf8(str); + } + } else if (2 < tagValue.length() && tagValue.length() < 100) { auto res = handleMathDiv(tagValue); if (!res.empty()) tagValue = std::format("{} ({})", res, tagValue); } - auto tmp = "\n" + translatedTagName + ": " + (tagValue.length() < 100 ? tagValue : - tagValue.substr(0, 100) + std::format(" ...] length:{}", tagValue.length())); + string tmp; + if (tagName == "Exif.Photo.UserComment") + tmp = "\n" + translatedTagName + ": " + tagValue; + else + tmp = "\n" + translatedTagName + ": " + (tagValue.length() < 100 ? tagValue : + tagValue.substr(0, 100) + std::format(" ...] length:{}", tagValue.length())); if (toEnd)ossEnd << tmp; else oss << tmp; @@ -261,26 +274,65 @@ class ExifParse{ } static string AI_Prompt(const std::wstring& path, const uint8_t* buf) { - int length = (buf[0x21] << 24) + (buf[0x22] << 16) + (buf[0x23] << 8) + buf[0x24]; - if (length > 16 * 1024) { - return ""; + if (!strncmp((const char*)buf + 0x25, "tEXtparameters", 14)) { + int length = (buf[0x21] << 24) + (buf[0x22] << 16) + (buf[0x23] << 8) + buf[0x24]; + if (length > 16 * 1024) { + return ""; + } + + string prompt((const char*)buf + 0x29, length); // format: Windows-1252 ISO/IEC 8859-1(Latin-1) + + prompt = Utils::wstringToUtf8(Utils::latin1ToWstring(prompt)); + + auto idx = prompt.find("parameters"); + if (idx != string::npos) { + prompt.replace(idx, 11, "正提示词: "); + } + + idx = prompt.find("Negative prompt"); + if (idx != string::npos) { + prompt.replace(idx, 15, "反提示词"); + } + + return "\nAI生图提示词 Prompt:\n" + prompt; } + else if (!strncmp((const char*)buf + 0x25, "iTXtparameters", 14)) { + int length = (buf[0x21] << 24) + (buf[0x22] << 16) + (buf[0x23] << 8) + buf[0x24]; + if (length > 16 * 1024) { + return ""; + } + + string prompt((const char*)buf + 0x38, length - 15); // format: Windows-1252 ISO/IEC 8859-1(Latin-1) + + prompt = Utils::wstringToUtf8(Utils::latin1ToWstring(prompt)); - string prompt((const char*)buf + 0x29, length); // format: Windows-1252 ISO/IEC 8859-1(Latin-1) + auto idx = prompt.find("parameters"); + if (idx != string::npos) { + prompt.replace(idx, 11, "正提示词: "); + } - prompt = Utils::wstringToUtf8(Utils::latin1ToWstring(prompt)); + idx = prompt.find("Negative prompt"); + if (idx != string::npos) { + prompt.replace(idx, 15, "反提示词"); + } - auto idx = prompt.find("parameters"); - if (idx != string::npos) { - prompt.replace(idx, 11, "正提示词: "); + return "\nAI生图提示词 Prompt:\n" + prompt; } + else if (!strncmp((const char*)buf + 0x25, "tEXtprompt", 10)) { - idx = prompt.find("Negative prompt"); - if (idx != string::npos) { - prompt.replace(idx, 15, "反提示词"); + int length = (buf[0x21] << 24) + (buf[0x22] << 16) + (buf[0x23] << 8) + buf[0x24]; + if (length > 16 * 1024) { + return ""; + } + + string prompt((const char*)buf + 0x29 + 7, length - 7); // format: Windows-1252 ISO/IEC 8859-1(Latin-1) + + prompt = Utils::wstringToUtf8(Utils::latin1ToWstring(prompt)); + + return "\nAI生图提示词 Prompt:\n" + prompt; } - return "\nAI生图提示词 Prompt:\n" + prompt; + return ""; } static std::string getExif(const std::wstring& path, const uint8_t* buf, int fileSize) { @@ -292,10 +344,7 @@ class ExifParse{ auto& xmpData = image->xmpData(); auto& iptcData = image->iptcData(); - string prompt; - if (!strncmp((const char*)buf + 0x25, "tEXtparameters", 14)) { - prompt = AI_Prompt(path, buf); - } + string prompt = AI_Prompt(path, buf); return exifDataToString(path, exifData) + xmpDataToString(path, xmpData) + iptcDataToString(path, iptcData) + prompt; } diff --git a/jarkViewer/jarkViewer.aps b/jarkViewer/jarkViewer.aps index 50e3471b12f8446add87bb5cc3792cf6d16fffb0..1b2b46f248367b7ce625b879a8a68bc4accf06e2 100644 GIT binary patch delta 731 zcmWm01yB_L6a`VQVgM?9Q4p}PP(e_{Z+CZhcXzk0{S>>qyIT~yySo+az;4}{GqW*A zqFrPD8H$KYJY0xR0uqu4SKM$XF-b^@2c9@ch8M|6fj2&+#1}vONkwYXkd}0$Cj$Xw zBomp*LRJFFMs{)#L@+rCA(UL?CX76UlNTrX$WH+ZQi#G7p(w>DP6JlYEp~Z)S)i*s80hL(ul@1p()L1P77Mniq^EDE$wJe2RhP;&UB$G z-RMpadeV#D^r0{P=+6KKGKj$pVJO2G&In*6qZrK?#xjoa7!#OC1e2J|6s9tb>C9jz zvzW~s<}#1@EMOsvSj-ZZvW(@dU?rTyx=9Tc+DH$@{ad>AeN7O;xk|P$~V6AgP;83H-E;+B#SGHCv%a-mnD!T zlqHh6%G_k`vc$3^vZOK(nWxMlOD6M@C6}d;dCPocDP_JgKbgNQl`OR^jV!G!oh-d9 zgDgOnQI<)TS(ZhXRTe1ACd)3%Aq$cP%W}#>WTCQLvfQ#TSsq!qEUzM+n&;u_9!GKh f=N`4(!zqUp8nx5YsRI8dBG%zlRIDSPdR_Pn3aL1U delta 731 zcmWm019TPu7)If}ZDCur{abbowQ9AN{!nJ#pt z8{O$aPa^0=Z~D-ee)MMm0~y3%hA@<23q#cl3zmwVjj0S|e^ zW1jGoXTvYfIISuR^lvL~r+YD*WF>#yXsej&+17;{0C