Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STBI Exception #5

Closed
Lecale opened this issue Nov 5, 2019 · 5 comments
Closed

STBI Exception #5

Lecale opened this issue Nov 5, 2019 · 5 comments

Comments

@Lecale
Copy link

Lecale commented Nov 5, 2019

When trying to use fllippy to minify an image I keep getting an error on

loadImage
stb_image\read.nim(91) load
Error: unhandled exception: can't fopen [STBI Exception]

How did I call?
var a = reduceImage("C:\\Nim\\NimExamples\\MyRecipes\\a.png", "C:\\Nim\\NimExamples\\MyRecipes\\b.png", 3)
against proc

proc reduceImage*(inFile: string, outFile: string, scale: cint): cint {.cdecl, exportc, dynlib.} =
  ## reduces image
  var image = loadImage(inFile)
  image = image.minify(scale)
  image.save(outFile)
  result = scale

Is it my own stupidity, or is it a real issue? I am on windows as you probably guessed.

@treeform
Copy link
Owner

treeform commented Nov 6, 2019

I usually get that error from STBI when I supply the wrong path. Are you sure you can open the file?

discard readFile("C:\\Nim\\NimExamples\\MyRecipes\\a.png") work?

Are you sure its a png file? STBI can't open some png files what are odd like monochrome ...

Does it work with png files in the test folder?

@EasiestSoft
Copy link

EasiestSoft commented Dec 11, 2019

The same exception accurred on Windows 10 (64):
Nim Compiler Version 1.0.4 [Windows: i386]
MinGW32 from Nim official site

Tested with fillCirle.png in the test folder and made sure the path was correct by:
doAssert img.fileExists

May be a link issue:

https://gitlab.com/define-private-public/stb_image-Nim/issues/8

@EasiestSoft
Copy link

EasiestSoft commented Dec 11, 2019

This issue can be solved by adding cdecl to stb_... procs:

# Internal functions
proc stbi_write_png(
  filename: cstring;
  w, h, comp: cint;
  data: pointer,
  stride_in_bytes: int
): cint
  {.importc: "stbi_write_png",cdecl.}

As jangko said on Nim forum:

depends on your C compiler configuration, most of the times you need to specify the calling convention explicitly, for example: stdcall for msvc or cdecl for gcc

in your case, try add cdecl:

proc addTwoIntegers(a, b: cint): cint {.importc,cdecl.}

@treeform
Copy link
Owner

I switched to using https://github.com/jangko/nimPNG which has no C code.
Does this work for you now?

@EasiestSoft
Copy link

The nimPNG based version of flippy works for me and now it supports Unicode file names on Windows(Using MinGW)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants