Jump to content


Photo

Nview Extension Dll For Loading More Image Formats


  • Please log in to reply
16 replies to this topic

#1 localmotion34

localmotion34

    GMC Member

  • New Member
  • 33 posts

Posted 19 October 2006 - 04:40 PM

This DLL is an interface to NView LIB, and allows the programmer to access the loading functions of NView.

NView DLL itself is compressed and loaded into memory when these functions are called, making it very, very fast to access. However, Nview ITSELF can be slow to load some images, but will always return a messagebox if something goes wrong.

4 functions are included, 2 directly compatible with GM6 as of this moment, and 2 that return a windows hbitmap handle in case GM later supports returns to OS pointers to handles.

Functions:

NViewOpenImage(Filename STRING, Outputfile STRING)

this will load a JPG, JIF, GIF, BMP, DIB, RLE, TGA and PCX image and spit it out to a BMP, JPEG, or PNG.

Filename = "filename|imagetype|quality"

"C:\test.pcx|bitmap|0"

you can load an image, specify what type of image you want back (i.e. bitmap, JPEG or PNG), and JPEG allows you to set the quality level.

outputfile= the name of the file you want the loaded image to be saved to.

"C:\test.jpg"

NViewOpenDlg(Outputfile STRING)

this calls the Win openfile Dialog with the filter set to all image types NView supports, and then saves it to the output file you want for later use. output file takes the same format as "Filename" above to denote what type and quality you want back.

outputfile="C:\test.png|PNG|0"



Functions for later possible use:

NViewLoad(Filename.s)

filename= "C:\test.pcx"

this procedure returns a hbitmap for:

hbitmap=NViewLoad(filename)

sendmessage(ImageHwnd, #STM_setimage, #image_Bitmap, hbitmap)

NViewLoadDlg()

calls the OS open file dialog, and returns a hbitmap of the file, or 0 if failure.

hbitmap=NViewLoadDlg(filename)
sendmessage(ImageHwnd, #STM_setimage, #image_Bitmap, hbitmap)

The included EXE i provide shows what this DLL can do. Extract all files to a directory, and load any given file. it will also take the "sun.pcx" file, load it, and save it to a JPEG.

LINK:
Edited: bug fixed with loading PCX and TGA Images
http://www.penguinby...w_Extension.zip

Edited by localmotion34, 19 October 2006 - 06:24 PM.

  • 0

#2 tsa05

tsa05

    GMC Member

  • GMC Member
  • 1063 posts
  • Version:GM:Studio

Posted 19 October 2006 - 05:20 PM

Oh wow. This sounds alarmingly impressive... It appears that you've answered the mountain of requests for an image conversion dll! Allow me to test it out, but I already like it.
  • 0

#3 localmotion34

localmotion34

    GMC Member

  • New Member
  • 33 posts

Posted 19 October 2006 - 05:37 PM

There is a bug somehow in loading, and then re-loading PCX and TGA images.

im not sure if it it my code, or NView itself.

but BMP, JPEG, GIF DIB and the rest all load 100% fine

i will keep testing, and then try and include more image encoders.

i guess if there is a "mountain" of requests for image conversion, i am quite familiar with FreeImageDLL, which can import like 50 formats, and export around 15.

Since the GIF patent is 100% expired, we can now encode to GIF.

Freeimage is a cakewalk once you know what you are doing. but i figured id start with the easier NView DLL. this took me 30 min to put together.

back to work on the PCX/TGA bug...
  • 0

#4 tsa05

tsa05

    GMC Member

  • GMC Member
  • 1063 posts
  • Version:GM:Studio

Posted 19 October 2006 - 06:58 PM

I'm having a bit of trouble making this work within GameMaker (I've noticed the issue you mentioned in the exe as well). Now, I haven't done a whole lot of this sort of thing, making scripts for another person's dll, so maybe I'm doing it wrong, but my GM game closes as soon as I call either of the external functions, without saving the new image file... I'm providing my example file so that other GM gurus can take a look and possibly spot any errors.
NView_example.gm6
Get the dll itself from localmotion34's post.

Anyone?
  • 0

#5 localmotion34

localmotion34

    GMC Member

  • New Member
  • 33 posts

Posted 19 October 2006 - 07:44 PM

GRRRR.

My fault.

the procedure returns a STRING of "true" or "false"

i think you have TY_real as the return type. change it to TY_string and test it out.

im not registered, so i cant tell for sure. but the new DLL i posted is working flat out with my EXE.

Im not a huge fan of NView, but it is ALOT smaller than FreeimageDLL. 283KB vs 1.6 megs.

If people dont care that Freeimage is so big, i can write a plugin DLL to interface with it. the plugin should only be about 30-40Kb.

Freeimage rocks, i can tell you that.

Edited by localmotion34, 19 October 2006 - 07:46 PM.

  • 0

#6 gmjab

gmjab

    GMC Member

  • New Member
  • 784 posts

Posted 19 October 2006 - 09:14 PM

Download That.... And This. Wow I can't get enough of your dll's.
  • 0

#7 Smarttart62

Smarttart62

    designFUSION™

  • New Member
  • 2619 posts

Posted 19 October 2006 - 10:39 PM

@tsa05
Haven't you even tried GMagik? Yes it's not really a DLL but a way to call a small program that has EVERY feature you could ever want, include OCR.
-Steve
  • 0

#8 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 19 October 2006 - 10:47 PM

This is a very small alternative to gmmagick. So it only adds 200kb instead of 1mb, but it doesn't have as many features.

I would use this when I only need to convert images but gmmagick when I need to change images :P

Thank you, very useful!
  • 0

#9 gmjab

gmjab

    GMC Member

  • New Member
  • 784 posts

Posted 19 October 2006 - 11:11 PM

It seems there is a bug somewhere, because when I use the example tsa05 made, the game example crashes and it doesn't convert. Is post No #5the fix to this problem ?

Edited by gmjab, 19 October 2006 - 11:12 PM.

  • 0

#10 tsa05

tsa05

    GMC Member

  • GMC Member
  • 1063 posts
  • Version:GM:Studio

Posted 19 October 2006 - 11:33 PM

@gmjab: Not sure yet... localmotion34 was right on about incorrect return types (it no longer crashes), but I'm still not sure that it's working... I'll edit in a bit.

Edit:
It's weird, it seems like the result just isn't making it to my HDD. Maybe I'm calling it wrong?
NViewOpenImage(working_directory+"\sample_image.bmp|jpg|80",working_directory+"\sample_image.jpg");
working_directory is the string holding the directory from which the program was run.
NViewOpenImage() just looks like this:
external_call(global.openImage,argument0,argument1
);
where global.openImage was set in the init function (stdcall).

Any ideas?

Edit Again: Having seen the post below, I'll wait :P

Edited by tsa05, 19 October 2006 - 11:45 PM.

  • 0

#11 localmotion34

localmotion34

    GMC Member

  • New Member
  • 33 posts

Posted 19 October 2006 - 11:35 PM

It seems there is a bug somewhere, because when I use the example tsa05 made, the game example crashes and it doesn't convert. Is post No #5the fix to this problem ?

<{POST_SNAPBACK}>



NO there is no fix. the problem is Nview dLL itself.

newer PCX, TGA, and especially JPEG files have slightly different headers than they used to. NView is a bit older, and JPEGS from newer digital cameras support "tags" much like MP3s now do, telling you what camera they came from, what date it was taken, even what GPS coordinates you took it at if the camera supports it.

i compiled EVERYTHING here, and debugged it in OllyDBG. When the trace enters the module of Nview when trying to load PCX, TGA or newer JPEG, an exception sometimes gets thrown to the stack. NView does not know how to handle this, and continues right on. making matters more complicated, in order to get this to work with GM, i had to load Nview into memory from a wrapper DLL, so it is residing in a space allocated to the hinstance of my DLL. The 2 DLL cant communicate stack exceptions. so when i drawn the supposedly loaded NView image onto a compatible HDC, all you can get is black.

i am going to forget this DLL. it has seen its day. having an unhandled stack exception floating around can eventually crash GM. i thought it would be simple.

Freeimage is the way to go. i have already successfully loaded and saved BMP, JPEG, GIF, ICO, TIF, TGA, PNG, DIB, and have performed nearly every combination of load from---save to format. It is so much faster then NView and GMmagik. the only slow operation is encoding to GIF, but that is with any DLL.

so those of you who wanted a DLL to convert images, you will get one. Batch loading will be supported ect.

i just have to make sure that Freeimage tolerates being executed from memory, otherwise we will have to use it straight up with both DLL statically linked.
  • 0

#12 localmotion34

localmotion34

    GMC Member

  • New Member
  • 33 posts

Posted 20 October 2006 - 02:37 AM

This is going to the the solution to the NView problem. I am now going to use Freeimage DLL wrapped in a wrapper DLL, and compressed with ASprotect SKE to minimize the size, and increase the loading speed.

This example i am posting here illustrates Freeimage DLL wrapped in an EXE file, that can load around 10 formats so far.

adding formats is as simple as adding more extensions to the openfile dialog filter.

this EXe needs to be examined on various systems to see if Freeimage will tolerate being executed from memory.

if you can, extract the EXe and the images to the same directory, and test it out.

if it works, please post your machine specs, and the same if it doesnt work.

it works on my WinXP AMD64 dual core 3GIGs RAM, ATI 256 X800, as well as Win64 and Vista Beta2.

once i know it REALLY works, then i will wrap Freeimage in a DLL can try and create a GM6 file. i dont want to have the same thing happen as with NView. however, i have used freeimage to make a batch conversion program where i can convert 400 images at a time, so this shouldnt be a problem.

some of the DLL procedures right now would work with GM6 calling convention, and my EXE calls them in the SAME manner.

im having a good time troubleshooting and making this work, so dont hesitate to ask for something youd like to see.


http://www.penguinby...1/FreeImage.zip
  • 0

#13 Sindarin

Sindarin

    Indie Game Developer

  • New Member
  • 1644 posts
  • Version:GM:HTML5

Posted 20 October 2006 - 07:48 AM

Is it wrapping pb functions or another free dll?
Sounds interesting.
  • 0
GM 8.1 / GM:HTML5 User

#14 localmotion34

localmotion34

    GMC Member

  • New Member
  • 33 posts

Posted 20 October 2006 - 10:37 AM

it is wrapping FreeImage functions, and NOT PureBasic functions. I dont use a single PureBasic Image encoder/decoder in this example.

we are not allowed to simply wrap PB functions in a DLL.

thats not what i am doing. i am adding FreeimageDLL to the end of my EXE, and then at runtime, loading it into memory, and getting the procedure addresses of the functions to load, save, and convert images.

this EXE is mostly WinAPI anyway, with very few actual PureBasic functions. Freeimage uses its own kind of special bitmap, which must be converted to a hbitmap to load it into a static control.

Edited by localmotion34, 20 October 2006 - 10:37 AM.

  • 0

#15 tsa05

tsa05

    GMC Member

  • GMC Member
  • 1063 posts
  • Version:GM:Studio

Posted 20 October 2006 - 02:49 PM

Looks neat... I'm not completely sure what each of the buttons is supposed to do, but 3 of them seem to work, and one of them seems to have no effect. Load bmp displays one of the bmp images in the window. Use dll Dlg asks me to choose an image, then creates test.jpg of that image. That's certainly nice to see, and it appears to work for all of the formats supplied. Load Bmp --> jpeg doesn't look like it's doing anything... No jpg is created, regardless of whether I've clicked load bmp prior or not. The final button, Quick Dlg Load, loads whatever image I select into the widow (I assume that's what is supposed to happen). No jpg or anything is created, though I don't suspect that one should be...

I like what I see up to this point!

Oh, sys info:
HP Workstation, Windows XP Pro v2002 SP2, Dual 3 GHz Pentium 4, 1.00 GB RAM
  • 0

#16 Alju5

Alju5

    GMC Member

  • New Member
  • 11 posts

Posted 01 August 2008 - 10:58 AM

Hello!

How can I make the game which use backgrounds and sounds from the computer directory. I want to create a game with the files: Then loading is faster and exe fail is smaller. :) Please help with a example code. ::lmao:: Thanks! :)

Edited by Alju5, 01 August 2008 - 11:00 AM.

  • 0

#17 xxskxx

xxskxx

    GMC Member

  • New Member
  • 47 posts

Posted 30 September 2008 - 07:16 PM

sry but i can´t download it...
when i open the ZIp folder then theres an error message :lol:
  • 0