Jump to content


Photo

Png Dll


  • Please log in to reply
40 replies to this topic

#1 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 19 September 2008 - 04:41 AM

Well, sorry for bumpinmg but this is useful for GM6.x users floating around :lol:
FINALLY IT'S HERE
PNG+Alpha in GM6.x


I think that this is GOOD place for some well.. an Introduction..

--> http://64digits.com/...etersvp/PNG.zip <--

This DLL is for GM6.x users like you that love PNGs. It loads and saves PNG files with alpha channels.

Functions
(the script headers are posted here)


png_init
//DON'T CALL THIS DIRECTLY!! it is used for other scripts to call it!!!

png2sprite

//loads a PNG file including alpha channel and returns the sprite
// example: sprite_index= png2sprite('file.png',[0,0])
// other example: global.mysprite = png2sprite('file.png', xorig,yorig);
// argument0: sprite to load
// DO NOT FORGET TO SPRITE_DELETE IT!!! (a=sprite_index; sprite_delete(a); sprite_index= something)

sprite2png
//saves a sprite as a 32bit PNG file
//
// argument0: sprite to save
// argument1: subimage
// argument2: where to save

surface2png

//saves a surface as a 32bit PNG file with its alpha channel!
//
// argument0: surface to save
// argument1: where to save

compose_png
// creates a 32-bit PNG file with alpha translucency from two BMP files
// alpha.bmp and RGB.bmp MUST exist. E.g. you first create the alpha.bmp
// and the RGB.BMP and then you must call this script
//
// example:
// do something...
// save it in a "RGB.BMP" (example: screen_save('rgb.bmp') or surface_save(...) or other saving function);
// do other thing.... grayscale only is recommended
// save it as "ALPHA.BMP"
// call this script: compose_png("File.png");
//
// argument0: file to create
//

decompose_png
// Loads a PNG file into two BMPs - alpha.bmp and RGB.BMP
// RGB.bmp is a RGB data, alpha.bmp is a grayscale alpha channel.
// You can then use these two files, for example, to load a sprite into the GM
// gm have a function - sprite_set_alpha_from_sprite - and it takes the alpha file into
// the account. decompose_png is useful if you want to export alpha channel for example, from a png
// or just the RGB data. Note that decompose_png do NOT actually converts PNG to BMP!
//
// example: decompose_png("file.png")
//
// Then you can use alpha.bmp and rgb.bmp as you want! NOTE that these two files are NOT kept forever!
// you must use them immediately after call to decompose_png
// argument0: file to decompose
//





Edited by petersvp, 19 September 2008 - 10:02 PM.

  • 0

#2 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 19 September 2008 - 06:04 AM

WOW, this is a truely incredible dll. I might use it someday, when I find a use for it... anyways, nice Job petersvp.

Edited by Caniac, 19 September 2008 - 06:08 AM.

  • 0

#3 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 19 September 2008 - 09:19 PM

GM7 can load PNGs by itself, but can't save them ^_^
  • 0

#4 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 19 September 2008 - 09:40 PM

cool. didn't know that... well, a dll is probably faster anyways.
  • 0

#5 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 20 September 2008 - 02:48 AM

The pros of this DLL is that ALLOWS GM6 to load pngs. It is not useful at all in GM7 unless you want to SAVE .png files - from surfaces with its alpha channel, this DLL allows it.

And don't forget, PNGs are very well for graphics!
  • 0

#6 mrsmes

mrsmes

    GMC Member

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

Posted 20 September 2008 - 03:52 AM

sounds, swee-ee-eet, 2 me... although a extension option would be prefered for gm7, users.
  • 0

Assuming I helped you out in a questions and answers topic won't you return the favour by helping me with one my coding problems, or recommend some one who can chat to me over pms about helping and how to overcome my obstacles, after all lets just say I did help you or them or many people with similar problems, in that topic.

Here i have a topic for those of you struggling with type writer text and mugshots in your games especially if it is a rpg see the link below for more info

http://gmc.yoyogames...howtopic=619103

almost no code needed, only uses two events.

click here for the l8est version of feed the alien pizza, it has some major polished up features.


#7 newbie013

newbie013

    GMC Member

  • GMC Member
  • 96 posts
  • Version:GM8

Posted 20 September 2008 - 10:14 AM

can you add support for animated png files, that would be cool.
  • 0

#8 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 20 September 2008 - 11:20 AM

An animated PNG would be an APNG and would just complicate things, this is a great DLL and it's about time it was made for GM6.
  • 0

#9 Sindarin

Sindarin

    Indie Game Developer

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

Posted 20 September 2008 - 01:18 PM

Does this have a horizontal png strip load feature just like GM7 has? If not, can you add it please?

This looks much faster than GM7's sprite_replace_alpha and seems it uses so less memory!

Edited by Sindarin, 20 September 2008 - 01:23 PM.

  • 0
GM 8.1 / GM:HTML5 User

#10 Nixa

Nixa

    GMC Member

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

Posted 21 September 2008 - 07:57 PM

This is GREAT!!! 10000/10 :blink: Gonna use it!
  • 0

Any questions related to GM? PM me ;)

Sudoku Puzzles [Download]


#11 fire_soul453

fire_soul453

    aarons video games

  • GMC Member
  • 542 posts

Posted 21 September 2008 - 10:05 PM

This is great! That was the main reason I was going to use gm7 but now I can stick with gm6!

Can we use this commercially? (or what is the license)

Edited by fire_soul453, 21 September 2008 - 10:07 PM.

  • 0
Game maker Top sites
I'm sick of paypal. From now on I'm not buying indie games unless I can use something else...

#12 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 22 September 2008 - 12:03 AM

@fire_soul453: Yes, you can. PNG will be ALWAYS and will REMAIN open-source forever! I will release this DLL's source in the future. Well, some donation or credit will be good idea :D

@Sindarin: In my DLL or provided scripts there is NOT such function for loading horizontal-stripped PNG.

But there IS a way to do this:

do a script, pngstrip2sprite(FILE, NUMBER_OF_IMAGES_IN_THE_STRIP)

var RGB, ALPHA;
// First: we must decompose the alpha channel from the .png:
decompose_png(FILE); //the PNG with a strip
//now we get the RGB.BMP and ALPHA.BMP in the working_directory, so lets:
RGB = sprite_add('rgb.bmp', NUMBER_OF_IMAGES_IN_THE_STRIP, ..... blahblah ....
ALPHA = sprite_add('alpha.bmp', NUMBER_OF_IMAGES_IN_THE_STRIP, ..... blahblah ....
//now we loaded these BMPs into the GM's resources. Let's now merge the alpha:
sprite_set_alpha_from_sprite(RGB,ALPHA);
//now, RGB is out loaded PNG strip frames :) but let's destroy this unneed alpha mask:
sprite_delete(ALPHA);
//done, lets return the sprite:
return RGB;
AND DON'T FORGET TO COMPLETE THE SCRIPT!
It isn't very hard. decompose_png is very good function, internal :)

==========================================

Some explanation:

decompose_png is used to strip the alpha mask in bmp format that GM's sprite_set_alpha_from_sprite understands well.
compose_png do just the opposite! If you draw and create two BMP files, one is the mask, compose_png will merge them into a PNG 32-bit file.
If you don't want to use surfaces, you can still save a png file with first saving to 2 BMPs :)



@mrsmes:

I Don't use GM7. I don't know how to make GM7 Extensions. If you can help, make one and send it to me... ask me in pm where to send, and I will post it.

Edited by petersvp, 22 September 2008 - 12:13 AM.

  • 0

#13 LoopStan

LoopStan

    North-See Developer

  • GMC Member
  • 1398 posts

Posted 22 September 2008 - 12:26 AM

I am confused on alpha channels. Where do i find them? I created a box with a completly transparent center in Paint.net, but when i try this, it doesnt use alpha or Transparency, help?
  • 0

Posted Image


#14 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 22 September 2008 - 12:41 AM

I don't use paint.net. All you must do is to save a PNG file with alpha channel. Then, my DLL will load it properly.
In every graphic program, saving and creating alpha images is different. I am not required to know all these apps. :D
Try google.
  • 0

#15 LoopStan

LoopStan

    North-See Developer

  • GMC Member
  • 1398 posts

Posted 22 September 2008 - 12:45 AM

K, i tried google, NOTHING! And how do i find the alpha? i dont quite get how this works. Could you explain?(explain how to find the alpha, or how you get it, ect.)
This is confusing to a noob in alpha.
  • 0

Posted Image


#16 Shining_Saber

Shining_Saber

    Top Gundam

  • New Member
  • 610 posts

Posted 22 September 2008 - 12:48 AM

K, i tried google, NOTHING! And how do i find the alpha? i dont quite get how this works. Could you explain?(explain how to find the alpha, or how you get it, ect.)
This is confusing to a noob in alpha.

Alpha in PNGs is the transparent "color".
  • 0
Posted Image
Clemson University Pre-Veterinary Science Major!

#17 LoopStan

LoopStan

    North-See Developer

  • GMC Member
  • 1398 posts

Posted 22 September 2008 - 01:04 AM

K, i tried google, NOTHING! And how do i find the alpha? i dont quite get how this works. Could you explain?(explain how to find the alpha, or how you get it, ect.)
This is confusing to a noob in alpha.

Alpha in PNGs is the transparent "color".


Do you have a code example? The examples that came with the thing dont tell me anything good.
is it like- sprite_index=png2sprite("Game Border.PNG",ALPHA COLOR!);?

and is the alpha color a color name or a hex???
  • 0

Posted Image


#18 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 22 September 2008 - 01:24 AM

@LoopStan, the ALPHA is EMBEDDED INSIDE the .PNG file! It is not visible/invisible! Download the DLL and see examples - what EXACTLY is the PNG alpha. It gives translucency percent for EVERY pixel in the .PNG image and is stored inside the png file. See the examples coming with the DLL.

Such PNGs you can create with GIMP, Photoshop, Flash, Illustrator... and every program that supports alpha masks.

For more information, search Google for alpha masks
  • 0

#19 LoopStan

LoopStan

    North-See Developer

  • GMC Member
  • 1398 posts

Posted 22 September 2008 - 01:52 AM

Crud, im still confuesd, BUT, thanks for trying to help, and im sure this dll kicks butt!~
  • 0

Posted Image


#20 Sindarin

Sindarin

    Indie Game Developer

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

Posted 22 September 2008 - 10:22 AM

After some tests with some larger PNG sprites, I noticed this dll in fact uses a little more memory than the internal GM7 functions, also GM7 has built in recognition for horizontal strips (although your code did work but is more work). So I think I'll go with GM7's sprite_replace_alpha(). Good work for GM6 users though, I recommend making an example with a horizontal png strip as many users will need animated PNG sprites.

Edited by Sindarin, 22 September 2008 - 10:24 AM.

  • 0
GM 8.1 / GM:HTML5 User

#21 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 24 September 2008 - 08:28 AM

I will add the strip example when I have enough time to work.
I know about the GM7's strip and alpha functions, but I still know many friends that use GM6, and even GM5, but this DLL isn't compatible with GM5 and will never be.
  • 0

#22 halo shg

halo shg

    Programmer

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

Posted 06 October 2008 - 12:19 AM

Thank you SO much! Now I can finish my competition entry! Thanks again,petersvp!
  • 0

Dev: MacBook Pro Retina Display 15" w/ Win7 (Parallels) running GM Studio: Master and GM8 (GMS: ANDROID JAVA EXTENSIONS ARE HERE!)
Devices: Samsung Galaxy Note II / Samsung Galaxy S III / iPhone 4S / iPad 2 / iPod Touch 5th gen



Politics' is made up of two words, 'poli,' which is Greek for 'many,' and 'tics,' which are blood-sucking insects.


-Gore Vidal


#23 digitalwar

digitalwar

    GMC Member

  • New Member
  • 321 posts

Posted 06 October 2008 - 08:43 AM

This is a great DLL !
Any chance you can add a function that saves a text (with transparency and antialiasing) to a png ?
Something like :
save_text("Hello","Arial",14,1,1,1,"c:\asd.png")
first 1 = is bold
second 1 = is italic
third 1 = is underlined
Would you be able to do this ?
Thanx
  • 0
... ... ...

#24 nodata10101

nodata10101

    GMC Member

  • GMC Member
  • 196 posts

Posted 10 October 2008 - 02:17 AM

I was under the impression that png alpha transparencies were already supported in GM as long as you load the file externally, or an I wrong?
  • 0

#25 FantiX

FantiX

    GMC Member

  • GMC Member
  • 175 posts

Posted 13 October 2008 - 05:12 PM

Exactly what i need!!

My gm7 stopped working :) but i prefer gm6 anyway.
  • 0

#26 johnie102

johnie102

    GMC Member

  • New Member
  • 1608 posts

Posted 18 October 2008 - 12:11 PM

sprite2png also saves the alpha channel of the sprite right?
  • 0
Have I helped you? Thank me by playing my game


note that these graphics aren't in game... yet!

GENERATION 22: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

#27 [SJB]Dude7

[SJB]Dude7

    GMC Member

  • New Member
  • 289 posts

Posted 24 October 2008 - 05:24 AM

Nice DLL, peter. We talked about this AWHILE ago I think over Skype, if you remember.
  • 0

#28 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 25 October 2008 - 11:14 PM

@digitalwar: Draw your text inside a draw_clear_alpha -ed surface. Then just save your surface as PNG. It is easy :)

@johnie102:
sprite2png actually draws a sprite into draw_clear_alpha'd surface, then creates two files: the surface's alpha mask and the surface's RGB data. Then it just calls compose_png which compiles the png file.
So, sprite2png WILL save your sprite's alpha properly.
NOTE: There is a bug in latest nVIDIA drivers, with the surfaces. If your pngs are wrong, set your Video accelerator settings to "Performance" or "Let 3D Application decide" if using nvidia 177.x or 175.x drivers. There aren't problems with ATI.

@[SJB]Dude7:
My 5kyP3 username is same as my forum username, just find me. :GM110:
  • 0

#29 digitalwar

digitalwar

    GMC Member

  • New Member
  • 321 posts

Posted 26 October 2008 - 12:01 AM

Hi petersvp,
Unfortunatly that's not the result I need. It will make the text without any antialiasing.

I need it antialiased, and with a good quality, that's why I asked if you can do it, becouse I can't :)

Thanx
  • 0
... ... ...

#30 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 06 December 2008 - 01:04 AM

@digitalwar
The text antialiasing DEPENDS of user's Font settings, right?
Or you MUST use forced-antialiased fonts like Calibri and Candara. They comes with office2007. Or set your Windows to use Cleartype or Standart smoothing. Interpolate pixels should be set in Game options.
then:
Create empty surface, do with it:
draw_clear_alpha(0,0)
then draw your text in it and save it - It should work then.
  • 0

#31 Glen

Glen

    GMC Member

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

Posted 12 January 2009 - 11:04 PM

I'd like to make a request that you host on a different site and make some mirrors. 64digits.com has been down for awhile....
  • 0
Avic Pro (Work in Progress):
Portable media manager. Just pop in your usb drive and use Avic Pro to organize and present all of your media content in categories. On top of that, it makes handling portable games, software, and other utilities a breeze. It allows you to launch just about any of your media content quickly and efficiently from your system tray. No more long paths to finding content.
Savage Defence| Text FX | Ragdoll Axe Engine | Professionalism | Online Games | Game Progression | 3D Game Development | Online Anti-Hack Strategies

#32 Away_from_the_sun

Away_from_the_sun

    GMC Member

  • New Member
  • 40 posts

Posted 27 January 2009 - 01:28 PM

Yea could you fix up the link please?
  • 0
New Computer! Core2 Quad CPU Q8200 @ 2.33GHz. 2.34GHz, 3.00 GB of RAM XP SP3.
If I report you, it's to clean the community, nothing personal.
GM user since '04 GM5.1A now using GM6.1
39dll user since '07

#33 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 09 February 2009 - 08:14 AM

The link is working for me now. I am little busy with the PhysTris game right now but there will be DLL update soon.
I will also update all my other projects.

Edited by petersvp, 09 February 2009 - 08:16 AM.

  • 0

#34 Hockeyflyers

Hockeyflyers

    Hockeyplayer Games

  • New Member
  • 1108 posts
  • Version:Unknown

Posted 19 April 2009 - 05:23 AM

Could this possibly be used to save as other formats... like say a .gif? If you save a .png then use something like image magick to convert it, could that create a single transparent .gif image?

Also (not related to this dll), are .bmps a higher quality than .jpg? I know .jpg is for pictures, but if you converted a .bmp to a .jpg would you lose quality?
  • 0

#35 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 03 July 2009 - 12:08 AM

[offtopic] JPEG do lose quality [/offtopic]

[ontopic] No, this is ONLY intended for PNGs with alpha channelp for Game Maker 6 users. In 7 there is some kind of PNG support, Game Maker 8 will load and respect PNG, so, the DLL is useless there. this is for GM6 users only.
  • 0

#36 MitchGraham

MitchGraham

    GMC Member

  • Banned Users
  • 524 posts

Posted 03 July 2009 - 06:45 AM

I dunno if you noticed, but I made good use of this dll. I don't respect shameless advertising, so pm me if you'd like a link to my creation. (You ARE credited.)

I'm just pointing out that this dll is definitely not useless at all. It's very useful, in fact.

#37 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 18 July 2009 - 11:59 PM

Thanks for using my DLL :] I really won't update to GM8 as the betas are SLOW as turtles comparing to GM7, So i will continue supporting this PNG DLL project.
  • 0

#38 krakerstaker

krakerstaker

    I R WIZ: teh 1337!!!"

  • New Member
  • 183 posts

Posted 22 July 2009 - 06:30 PM

I have been looking forever for for somthing like this. NOW I CAN FINALLY SAVE MY SURFACES! WHOOT!!

Thanx a bunch man, You have credit on my project now.

EDIT: LOL i spoke to soon. This dll would be great if the links werent dead :) very sad. Another thing that is dissapointing is you don't have background2png. WHY NOT?! Oh well i will try it out when i actually get the darn thing

Edited by krakerstaker, 22 July 2009 - 06:43 PM.

  • 0

#39 Razon

Razon

    GMC Member

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

Posted 24 July 2009 - 07:33 AM

Uploaded a copy of it to mediafire.
http://www.mediafire.com/?5znvdlnmzza

Edited by RazonEX, 24 July 2009 - 07:34 AM.

  • 0

#40 krakerstaker

krakerstaker

    I R WIZ: teh 1337!!!"

  • New Member
  • 183 posts

Posted 24 July 2009 - 08:01 AM

SWEET ^_^ Thanx Dood.

Props to OP also. This dll is insane. Well maybe not insane but i definetly love it already.

Thanx again
  • 0

#41 petersvp

petersvp

    GMC Member

  • GMC Member
  • 129 posts

Posted 11 January 2010 - 03:03 AM

The bad news... The DLL support is now closed. DLL remains "AS IS" - for use with the old Game Maker 6.x. It still work and is usable in new versions, 7 and 8, but it is unneeded unless you decide that you want to SAVE .png files :D
  • 0