Skip to content

Commit

Permalink
[add] Introduce LibRaw to replace Dcraw
Browse files Browse the repository at this point in the history
WebView2 => 1.0.2365.46
Magick.NET => 13.6.0
  • Loading branch information
hbl917070 committed Mar 6, 2024
1 parent ae13133 commit 6e0cd65
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 208 deletions.
Binary file removed Tiefsee/Data/dcraw.exe
Binary file not shown.
385 changes: 233 additions & 152 deletions Tiefsee/Lib/ImgLib.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tiefsee/Lib/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4147,7 +4147,7 @@ public enum ConfigOption : int {
Serialized = 3
}

const string LibraryPath = "data/sqlite3";
const string LibraryPath = "sqlite3";

#if !USE_CSHARP_SQLITE && !USE_WP8_NATIVE_SQLITE && !USE_SQLITEPCL_RAW
[DllImport(LibraryPath, EntryPoint = "sqlite3_threadsafe", CallingConvention = CallingConvention.Cdecl)]
Expand Down
20 changes: 10 additions & 10 deletions Tiefsee/Server/WebServerController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -46,7 +46,7 @@ public WebServerController(WebServer ws) {

//webServer.RouteAddGet("/api/getImg/file/{*}", getImg);
webServer.RouteAdd("/api/img/magick", ImgMagick);
webServer.RouteAdd("/api/img/dcraw", ImgDcraw);
webServer.RouteAdd("/api/img/rawThumbnail", ImgRawThumbnail);
webServer.RouteAdd("/api/img/wpf", ImgWpf);
webServer.RouteAdd("/api/img/webIcc", ImgWebIcc);
webServer.RouteAdd("/api/img/nconvert", ImgNconvert);
Expand Down Expand Up @@ -92,12 +92,11 @@ void GetExif(RequestData d) {
/// </summary>
void ImgVipsInit(RequestData d) {

string json = "";
ImgInitInfo imgInfo = new ImgInitInfo();
string json;
ImgInitInfo imgInfo = new();

string path = d.args["path"];
string[] arType = d.args["type"].Split(','); // 使用什麼方式處理圖片
//string outputOriginalFile = d.args["outputOriginalFile"]; // 是否直接回傳原檔

path = Uri.UnescapeDataString(path);

Expand All @@ -114,7 +113,7 @@ void ImgVipsInit(RequestData d) {
string type = arType[i];

try {
imgInfo = ImgLib.GetImgInitInfo(path, type);
imgInfo = ImgLib.GetImgInitInfo(path, type, type);
}
catch { }

Expand All @@ -133,14 +132,15 @@ void ImgVipsInit(RequestData d) {
void ImgVipsResize(RequestData d) {
string path = d.args["path"];
double scale = Double.Parse(d.args["scale"]);
string type = d.args["type"];
string fileType = d.args["fileType"];
string vipsType = d.args["vipsType"];

path = Uri.UnescapeDataString(path);

bool is304 = HeadersAdd304(d, path); // 回傳檔案時加入快取的Headers
if (is304) { return; }

string imgPath = ImgLib.VipsResize(path, scale, type);
string imgPath = ImgLib.VipsResize(path, scale, fileType, vipsType);
WriteFile(d, imgPath); // 回傳檔案
}

Expand Down Expand Up @@ -230,15 +230,15 @@ void ImgWebIcc(RequestData d) {
/// <summary>
///
/// </summary>
void ImgDcraw(RequestData d) {
void ImgRawThumbnail(RequestData d) {
string path = d.args["path"];
path = Uri.UnescapeDataString(path);
if (File.Exists(path) == false) { return; }
d.context.Response.ContentType = "image/bmp";
bool is304 = HeadersAdd304(d, path); // 回傳檔案時加入快取的Headers
if (is304 == true) { return; }

using (Stream stream = ImgLib.Dcraw_PathToStream(path, true, 800)) {
using (Stream stream = ImgLib.RawThumbnail_PathToStream(path, 800, out int width, out int height)) {
WriteStream(d, stream); // 回傳檔案
}
}
Expand Down
18 changes: 9 additions & 9 deletions Tiefsee/Tiefsee.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Magick.NET-Q8-OpenMP-x64" Version="13.5.0" />
<PackageReference Include="Magick.NET-Q8-OpenMP-x64" Version="13.6.0" />
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2277.86" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2365.46" />
<PackageReference Include="NetVips.Extensions" Version="2.3.0" />
<PackageReference Include="NetVips.Native.win-x64" Version="8.14.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Sdcb.LibRaw" Version="0.21.1.6" />
<PackageReference Include="Sdcb.LibRaw.runtime.win64" Version="0.21.1" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -82,11 +84,6 @@
</ItemGroup>

<!-- 編譯時複製這些資料夾 -->
<ItemGroup>
<Content Include="Data\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="..\Www\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -107,15 +104,18 @@
<Content Remove="..\Www\tsconfig.json" />
<Content Remove="..\Www\nuget.config" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- 編譯後刪除這些資料夾 -->
<RemoveDir Directories="$(OutputPath)\runtimes\linux-musl-x64" />
<RemoveDir Directories="$(OutputPath)\runtimes\linux-x64" />
<RemoveDir Directories="$(OutputPath)\runtimes\osx" />
<RemoveDir Directories="$(OutputPath)\runtimes\unix" />
<RemoveDir Directories="$(OutputPath)\runtimes\win-arm64" />
<RemoveDir Directories="$(OutputPath)\runtimes\win-x86" />

<!-- 把 /Data/sqlite3.dll 複製到 輸出根目錄 裡面 -->
<Exec Command="copy $(ProjectDir)\Data\sqlite3.dll $(TargetDir)\" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion Tiefsee/VW/WV_System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void DeleteTemp(string path, int max) {
if (Directory.Exists(path) == false) { return; }
FileSystemInfo[] ar = new DirectoryInfo(path).GetFileSystemInfos(); // 取得資料夾內的所有檔案與資料夾
if (ar.Length <= max) { return; } // 如果檔案數量未達上限,就不做任何事情
List<FileSystemInfo> sortedFiles = ar.OrderBy(f => f.LastWriteTime).ToList();
var sortedFiles = ar.OrderBy(f => f.LastAccessTime).ToList(); // 依照最後存取時間排序
for (int i = 0; i < sortedFiles.Count - max; i++) {
try {
File.Delete(sortedFiles[i].FullName);
Expand Down
25 changes: 16 additions & 9 deletions Www/ejs/SettingWindow/SettingWindow.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,29 @@
<div class="box">
<div class="box-title" i18n="sw.other.title"> 其他 </div>

<div class="text-title" i18n="sw.other.displayDeleteConfirmationDialog"> 檔案刪除前顯示確認視窗 </div>
<div class="text-title" i18n="sw.other.rawImageThumbnail">
開啟 RAW 圖片時,顯示內嵌的預覽圖
</div>
<div class="text-content">
<label class="switch">
<input type="checkbox" id="switch-rawImageThumbnail">
<span class="slider round"></span>
</label>
</div>

<div class="text-title" i18n="sw.other.displayDeleteConfirmationDialog">
檔案刪除前顯示確認視窗
</div>
<div class="text-content">
<label class="switch">
<input type="checkbox" id="switch-fileDeletingShowCheckMsg">
<span class="slider round"></span>
</label>
</div>

<div class="text-title" i18n="sw.other.whenInsertingFile"> 偵測到檔案新增時,插入於 </div>
<div class="text-title" i18n="sw.other.whenInsertingFile">
偵測到檔案新增時,插入於
</div>
<div class="text-content">
<select class="text-input" id="select-whenInsertingFile">
<option value="auto" i18n="sw.other.auto"> 自動 </option>
Expand All @@ -317,7 +331,6 @@

</div>


<!-- 外觀 -->
<div class="page-tabsPage" id="tabsPage-appearance">

Expand Down Expand Up @@ -624,7 +637,6 @@
</div>
</div>


<!-- 滑鼠 -->
<div class="page-tabsPage" id="tabsPage-mouse">
<div class="page-title" i18n="sw.tabs.mouse"> 滑鼠 </div>
Expand Down Expand Up @@ -725,7 +737,6 @@
</div>
</div>


<!-- 圖片 -->
<div class="page-tabsPage" id="tabsPage-image">
<div class="page-title" i18n=""> 影像處理 </div>
Expand Down Expand Up @@ -913,10 +924,6 @@
<div class="page-title" i18n="sw.tabs.about"> 關於 </div>

<div class="box">
<!-- <div class="box-title">
<span i18n="sw.about.version">版本:</span>
<span> Tiefsee 4.0.0</span>
</div> -->

<div class="logobox">
<img class="logobox-img" src="./img/logo.svg">
Expand Down
13 changes: 12 additions & 1 deletion Www/lang/langData.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,18 @@ var langData = {
"en": "Other",
"ja": "その他",
},
rawImageThumbnail:{
"zh-TW": "開啟 RAW 圖片時,顯示內嵌的預覽圖",
"en": "Show embedded preview when opening RAW image",
"ja": "RAW 画像を開くときに埋め込みプレビューを表示する",
},


displayDeleteConfirmationDialog: {
"zh-TW": "檔案刪除前顯示確認視窗",
"en": "Display Delete confirmation dialog",
"ja": "削除の確認メッセージを表示する",
},

whenInsertingFile: {
"zh-TW": "偵測到檔案新增時,插入於",
"en": "When a new file is detected, insert it at",
Expand Down Expand Up @@ -2036,6 +2042,11 @@ var langData = {
"en": "Model",
"ja": "カメラのモデル",
},
"Lens Model": {
"zh-TW": "鏡頭型號",
"en": "Lens Model",
"ja": "レンズモデル",
},
"Windows XP Subject": {
"zh-TW": "主旨",
"en": "Subject",
Expand Down
33 changes: 18 additions & 15 deletions Www/ts/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Config {
"Comment", // 註解
"Make", // 相機型號
"Model", // 相機製造商
"Lens Model", // 鏡頭型號
"Windows XP Subject", // 主旨
"F-Number", // 光圈孔徑
"Exposure Time", // 曝光時間
Expand Down Expand Up @@ -366,6 +367,8 @@ class Config {

/** 其他 */
other: {
/** 開啟 RAW 圖片時,顯示內嵌的預覽圖 */
rawImageThumbnail : true,
/** 刪除前顯示詢問視窗 */
fileDeletingShowCheckMsg: true,
/** 偵測到檔案新增時,插入於。 [auto, start, end] */
Expand Down Expand Up @@ -422,7 +425,7 @@ class Config {
{ ext: "jfif", type: "vips", vipsType: "jpg" },
{ ext: "jpe", type: "vips", vipsType: "jpg" },
{ ext: "png", type: "vips", vipsType: "vips" },
{ ext: "webp", type: "vips", vipsType: "vips" },
{ ext: "webp", type: "vips", vipsType: "vips,magick" },
{ ext: "bmp", type: "vips", vipsType: "bitmap" },
{ ext: "apng", type: "web" },
{ ext: "gif", type: "web" },
Expand Down Expand Up @@ -465,20 +468,20 @@ class Config {
{ ext: "mpo", type: "vips", vipsType: "magick" }, // 相機
{ ext: "jxl", type: "vips", vipsType: "magick" }, // JPEG XL,開啟速度很慢

{ ext: "crw", type: "vips", vipsType: "dcraw" },
{ ext: "raf", type: "vips", vipsType: "dcraw" },
{ ext: "cr2", type: "vips", vipsType: "dcraw" },
{ ext: "mrw", type: "vips", vipsType: "dcraw" },
{ ext: "nef", type: "vips", vipsType: "dcraw" },
{ ext: "x3f", type: "vips", vipsType: "dcraw" },
{ ext: "pef", type: "vips", vipsType: "dcraw" },
{ ext: "orf", type: "vips", vipsType: "dcraw" },
{ ext: "rw2", type: "vips", vipsType: "dcraw" },
{ ext: "arw", type: "vips", vipsType: "dcraw" },
{ ext: "erf", type: "vips", vipsType: "dcraw" },
{ ext: "sr2", type: "vips", vipsType: "dcraw" },
{ ext: "srw", type: "vips", vipsType: "dcraw" },
{ ext: "dng", type: "vips", vipsType: "dcraw" },
{ ext: "crw", type: "vips", vipsType: "raw" },
{ ext: "raf", type: "vips", vipsType: "raw" },
{ ext: "cr2", type: "vips", vipsType: "raw" },
{ ext: "mrw", type: "vips", vipsType: "raw" },
{ ext: "nef", type: "vips", vipsType: "raw" },
{ ext: "x3f", type: "vips", vipsType: "raw" },
{ ext: "pef", type: "vips", vipsType: "raw" },
{ ext: "orf", type: "vips", vipsType: "raw" },
{ ext: "rw2", type: "vips", vipsType: "raw" },
{ ext: "arw", type: "vips", vipsType: "raw" },
{ ext: "erf", type: "vips", vipsType: "raw" },
{ ext: "sr2", type: "vips", vipsType: "raw" },
{ ext: "srw", type: "vips", vipsType: "raw" },
{ ext: "dng", type: "vips", vipsType: "raw" },

{ ext: "afphoto", type: "vips", vipsType: "extractPng" },
{ ext: "afdesign", type: "vips", vipsType: "extractPng" },
Expand Down
4 changes: 2 additions & 2 deletions Www/ts/MainWindow/MainExif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@ class MainExif {

// 處理 value 的值
if (name === "Metering Mode") {
value = M.i18n.t(`exif.value.${name}.${value}`);
valueI18n = `exif.value.${name}.${value}`;
value = M.i18n.t(`exif.value.${name}.${value}`);
}
else if (name === "Flash") {
valueI18n = `exif.value.${name}.${value}`;
value = M.i18n.t(`exif.value.${name}.${value}`);
valueI18n = `exif.value.${name}.${value}`
}
else if (name === "Length") {
value = Lib.getFileLength(Number(value));
Expand Down
22 changes: 18 additions & 4 deletions Www/ts/MainWindow/Script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,22 @@ class ScriptImg {
}
else if (configType === "vips") {

// 如果啟用了「開啟 RAW 圖片時,顯示內嵌的預覽圖」,則把 vipsType 內的 raw 替換成 rawThumbnail
let arVipsType = vipsType.split(",");
for (let i = 0; i < arVipsType.length; i++) {
if (arVipsType[i] === "raw") {
if (this.M.config.settings.other.rawImageThumbnail) {
arVipsType[i] = "rawThumbnail";
}
else {
arVipsType[i] = "rawFull";
}
}
}
vipsType = arVipsType.join(",");

let imgInitInfo = await WebAPI.Img.vipsInit(vipsType, fileInfo2);

// 如果處理失敗,且 vipsType2 = base64,則先用 canvas 處理成 base64 再上傳到暫存資料夾
if (imgInitInfo.code != "1" && configItem.vipsType2 === "base64") {
// console.log("處理失敗,改用 canvas 來處理");
Expand All @@ -386,13 +400,13 @@ class ScriptImg {
let base64 = await this.blobToBase64(blob);
if (base64 !== null) {
await WV_Image.Base64ToTempImg(path, base64 as string);
imgInitInfo = await WebAPI.Img.vipsInit(vipsType, fileInfo2);
imgInitInfo = await WebAPI.Img.vipsInit("base64", fileInfo2);
} else {
isFail = true;
}
}

imgInitInfo = await WebAPI.Img.vipsInit(vipsType, fileInfo2);
//imgInitInfo = await WebAPI.Img.vipsInit(vipsType, fileInfo2);
}

if (imgInitInfo.code == "1") {
Expand All @@ -411,7 +425,7 @@ class ScriptImg {
if (imgInitInfo.width * scale < 200 || imgInitInfo.height * scale < 200) { // 如果圖片太小就不處理
break;
}
let imgU = WebAPI.Img.vipsResize(scale, fileInfo2, fileType);
let imgU = WebAPI.Img.vipsResize(scale, fileInfo2, fileType, imgInitInfo.vipsType);
arUrl.push({ scale: scale, url: imgU })
}
}
Expand Down
10 changes: 10 additions & 0 deletions Www/ts/SettingWindow/SettingWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,16 @@ class SettingWindow {

// 其他
addLoadEvent(() => {

// 開啟 RAW 圖片時,顯示內嵌的預覽圖
var switch_rawImageThumbnail = getDom("#switch-rawImageThumbnail") as HTMLInputElement;
switch_rawImageThumbnail.checked = config.settings["other"]["rawImageThumbnail"];
switch_rawImageThumbnail.addEventListener("change", () => {
let val = switch_rawImageThumbnail.checked;
config.settings["other"]["rawImageThumbnail"] = val;
appleSettingOfMain();
});

// 檔案刪除前顯示確認視窗
var switch_fileDeletingShowCheckMsg = getDom("#switch-fileDeletingShowCheckMsg") as HTMLInputElement;
switch_fileDeletingShowCheckMsg.checked = config.settings["other"]["fileDeletingShowCheckMsg"];
Expand Down
Loading

0 comments on commit 6e0cd65

Please sign in to comment.