diff semiconginev2/resources.nim @ 1242:e8b3dc80e48e

add: PNG loading and tests for it
author sam <sam@basx.dev>
date Mon, 22 Jul 2024 15:53:32 +0700
parents 176383220123
children
line wrap: on
line diff
--- a/semiconginev2/resources.nim	Mon Jul 22 12:51:50 2024 +0700
+++ b/semiconginev2/resources.nim	Mon Jul 22 15:53:32 2024 +0700
@@ -141,27 +141,25 @@
 proc LoadResource*(path: string, package = DEFAULT_PACKAGE): Stream =
   loadResource_intern(path, package = package)
 
-#[
-proc LoadImage*[T](path: string, package = DEFAULT_PACKAGE): Image[RGBAPixel] =
-  if path.splitFile().ext.toLowerAscii == ".bmp":
-    loadResource_intern(path, package = package).ReadBMP()
-  elif path.splitFile().ext.toLowerAscii == ".png":
-    loadResource_intern(path, package = package).ReadPNG()
-  else:
-    raise newException(Exception, "Unsupported image file type: " & path)
-
 proc LoadJson*(path: string, package = DEFAULT_PACKAGE): JsonNode =
   path.loadResource_intern(package = package).readAll().parseJson()
 
 proc LoadConfig*(path: string, package = DEFAULT_PACKAGE): Config =
   path.loadResource_intern(package = package).loadConfig(filename = path)
 
+# PNG-images
+
+{.compile: currentSourcePath.parentDir() & "/contrib/lodepng.c".}
+proc lodepng_decode_memory(out_data: ptr cstring, w: ptr cuint, h: ptr cuint, in_data: cstring, insize: csize_t, colorType: cint, bitdepth: cuint): cuint {.importc.}
+
+proc lodepng_encode_memory(out_data: ptr cstring, outsize: ptr csize_t, image: cstring, w: cuint, h: cuint, colorType: cint, bitdepth: cuint): cuint {.importc.}
+
+#[
 proc LoadMeshes*(path: string, defaultMaterial: MaterialType, package = DEFAULT_PACKAGE): seq[MeshTree] =
   loadResource_intern(path, package = package).ReadglTF(defaultMaterial)
 
 proc LoadFirstMesh*(path: string, defaultMaterial: MaterialType, package = DEFAULT_PACKAGE): Mesh =
   loadResource_intern(path, package = package).ReadglTF(defaultMaterial)[0].toSeq[0]
-
 ]#
 
 proc Packages*(): seq[string] =