Jelajahi Sumber

Merge pull request #27327 from goodyttoor/grayscale_exr

Fix import grayscale EXR
Rémi Verschelde 6 tahun lalu
induk
melakukan
c9aa0c20a0
1 mengubah file dengan 23 tambahan dan 14 penghapusan
  1. 23 14
      modules/tinyexr/image_loader_tinyexr.cpp

+ 23 - 14
modules/tinyexr/image_loader_tinyexr.cpp

@@ -107,22 +107,31 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f
 		}
 		}
 	}
 	}
 
 
-	if (idxR == -1) {
-		ERR_PRINT("TinyEXR: R channel not found.");
-		// @todo { free exr_image }
-		return ERR_FILE_CORRUPT;
-	}
+	if (exr_header.num_channels == 1) {
+		// Grayscale channel only.
+		idxR = 0;
+		idxG = 0;
+		idxB = 0;
+		idxA = 0;
+	} else {
+		// Assume RGB(A)
+		if (idxR == -1) {
+			ERR_PRINT("TinyEXR: R channel not found.");
+			// @todo { free exr_image }
+			return ERR_FILE_CORRUPT;
+		}
 
 
-	if (idxG == -1) {
-		ERR_PRINT("TinyEXR: G channel not found.")
-		// @todo { free exr_image }
-		return ERR_FILE_CORRUPT;
-	}
+		if (idxG == -1) {
+			ERR_PRINT("TinyEXR: G channel not found.")
+			// @todo { free exr_image }
+			return ERR_FILE_CORRUPT;
+		}
 
 
-	if (idxB == -1) {
-		ERR_PRINT("TinyEXR: B channel not found.")
-		// @todo { free exr_image }
-		return ERR_FILE_CORRUPT;
+		if (idxB == -1) {
+			ERR_PRINT("TinyEXR: B channel not found.")
+			// @todo { free exr_image }
+			return ERR_FILE_CORRUPT;
+		}
 	}
 	}
 
 
 	// EXR image data loaded, now parse it into Godot-friendly image data
 	// EXR image data loaded, now parse it into Godot-friendly image data