www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - bmp/png libs?

reply "Nick Sabalausky" <a a.a> writes:
Can anyone suggest good up-to-date D libs or bindings for loading/saving bmp 
and png files? 
May 13 2009
next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving bmp 
 and png files? 

BMP - who in their right mind still uses this? PNG - Lodepng is one http://www.dsource.org/projects/scrapple/wiki/LodePngLibrary but it depends on what you want to be able to do with PNGs. I'm not aware of any full-featured (beyond encoding/decoding of the actual image) PNG library yet. I'm sure there are also a handful of general image format libraries out there, but can't seem to find them at the moment. Maybe someone else can help.... Stewart.
May 14 2009
next sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Stewart Gordon wrote:
 BMP - who in their right mind still uses this?

Yeah, zero-overhead; who needs that?
May 14 2009
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Robert,

 Stewart Gordon wrote:
 
 BMP - who in their right mind still uses this?
 


if you want zero overhead use PPM in binary mode: 32bit color and about ~16 bytes of non image data that can be output by printf.
May 14 2009
parent Robert Fraser <fraserofthenight gmail.com> writes:
BCS wrote:
 Reply to Robert,
 
 Stewart Gordon wrote:

 BMP - who in their right mind still uses this?


if you want zero overhead use PPM in binary mode: 32bit color and about ~16 bytes of non image data that can be output by printf.

Yeah, but who's heard of that?
May 14 2009
prev sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Robert Fraser wrote:
 Stewart Gordon wrote:
 BMP - who in their right mind still uses this?

Yeah, zero-overhead; who needs that?

I've never seen BMP loading or saving code that didn't have to resort to the Windows API. Even then, the code was horrible. TGA is a good format for when you just need to put pixels to disk. A single fixed-sized header out the front and then just dump the pixels. Think of it as the non-ass version of BMP that also supports 32-bit colour. -- Daniel
May 14 2009
prev sibling parent reply Rainer Deyke <rainerd eldwood.com> writes:
Stewart Gordon wrote:
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for
 loading/saving bmp and png files? 

BMP - who in their right mind still uses this?

BMP is the most popular uncompressed image format. Uncompressed file format + lzma compression leads to smaller file size than png + lzma compression. -- Rainer Deyke - rainerd eldwood.com
May 14 2009
parent reply "Nick Sabalausky" <a a.a> writes:
"Rainer Deyke" <rainerd eldwood.com> wrote in message 
news:guij2k$6sd$2 digitalmars.com...
 Stewart Gordon wrote:
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for
 loading/saving bmp and png files?

BMP - who in their right mind still uses this?

BMP is the most popular uncompressed image format.

Yea, this is pretty much the key. Even if nothing else, it's at least useful *because* it's popular. In other words, the same reason why any audio app realisticlly needs to support MP3 even though MP3 is probably the single worst lossy audio codec out there (an assertion which, by the way, I would love to be proven wrong about, just you know, so I don't pop a vein every time I think about "average joe" and music players...).
May 14 2009
parent reply Rainer Deyke <rainerd eldwood.com> writes:
Nick Sabalausky wrote:
 Yea, this is pretty much the key.  Even if nothing else, it's at least 
 useful *because* it's popular. In other words, the same reason why any audio 
 app realisticlly needs to support MP3 even though MP3 is probably the single 
 worst lossy audio codec out there (an assertion which, by the way, I would 
 love to be proven wrong about, just you know, so I don't pop a vein every 
 time I think about "average joe" and music players...). 

mp3 is the worst lossy lossy audio compression codec precisely because it is so popular that it managed to kill off all of its competitors except those that have a strong advantage over mp3. You don't hear about au files or mp2 files anymore. -- Rainer Deyke - rainerd eldwood.com
May 14 2009
parent reply "Nick Sabalausky" <a a.a> writes:
"Rainer Deyke" <rainerd eldwood.com> wrote in message 
news:guimbr$dem$1 digitalmars.com...
 Nick Sabalausky wrote:
 Yea, this is pretty much the key.  Even if nothing else, it's at least
 useful *because* it's popular. In other words, the same reason why any 
 audio
 app realisticlly needs to support MP3 even though MP3 is probably the 
 single
 worst lossy audio codec out there (an assertion which, by the way, I 
 would
 love to be proven wrong about, just you know, so I don't pop a vein every
 time I think about "average joe" and music players...).

mp3 is the worst lossy lossy audio compression codec precisely because it is so popular that it managed to kill off all of its competitors except those that have a strong advantage over mp3. You don't hear about au files or mp2 files anymore.

Good point. au was lossy?
May 14 2009
parent Rainer Deyke <rainerd eldwood.com> writes:
Nick Sabalausky wrote:
 au was lossy? 

Yes, to the extend that it was compressed at all. Each 16 bit sample was independently reduced to 8 bits using a logarithmic scale. -- Rainer Deyke - rainerd eldwood.com
May 14 2009
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wed, May 13, 2009 at 11:35:03PM -0400, Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving bmp 
 and png files? 
 

I wrote a very minimal BMP class in D2 a while back. I didn't finish it so IIRC it only supports 24 and maybe 8 bit bitmaps, but it worked for what I needed it for - Paint can read and write those formats too. Looking at the code, oh foo, it saves but doesn't load. I have C code that can load 8 and 24 bit though. Probably not super useful, but it is simple, so maybe it will help. Here's a link. Includes both the D and C files. Look at the bottom of each file for an example main(). Other than that, there are no docs, but the function names should be fairly self-explanatory. http://arsdnet.net/bmpstuff.zip I didn't put a copyright notice in the files, but I release them into the public domain, so do whatever you want with it. With the weekend coming up, I'll hopefully have the time to go back and finish / improve / document that code and I'll update the zip and post another message to the group then if anyone is interested. Let me know if it is at all useful. -- Adam D. Ruppe http://arsdnet.net
May 14 2009
parent "Nick Sabalausky" <a a.a> writes:
"Adam D. Ruppe" <destructionator gmail.com> wrote in message 
news:mailman.70.1242352289.13405.digitalmars-d puremagic.com...
 On Wed, May 13, 2009 at 11:35:03PM -0400, Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving 
 bmp
 and png files?

I wrote a very minimal BMP class in D2 a while back. I didn't finish it so IIRC it only supports 24 and maybe 8 bit bitmaps, but it worked for what I needed it for - Paint can read and write those formats too. Looking at the code, oh foo, it saves but doesn't load. I have C code that can load 8 and 24 bit though. Probably not super useful, but it is simple, so maybe it will help. Here's a link. Includes both the D and C files. Look at the bottom of each file for an example main(). Other than that, there are no docs, but the function names should be fairly self-explanatory. http://arsdnet.net/bmpstuff.zip I didn't put a copyright notice in the files, but I release them into the public domain, so do whatever you want with it. With the weekend coming up, I'll hopefully have the time to go back and finish / improve / document that code and I'll update the zip and post another message to the group then if anyone is interested. Let me know if it is at all useful.

Thanks, I'll take a look. Although now that you mention it, I also have some old C code somewhere that handles BMP (at least loading anyway, and PCX too, in fact (remember that?) ). But I have a suspicion that reading/understanding/adapting yours, even if it's not cleaned up, will probably be easier than digging out and porting my old stuff :) Also, thanks for eveyone else's advice.
May 14 2009
prev sibling next sibling parent reply div0 <div0 users.sourceforge.net> writes:
Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving bmp 
 and png files? 
 
 

http://www.ssTk.co.uk/png.php Import is for d2, but changing it for d1 would be trivial. -- My enormous talent is exceeded only by my outrageous laziness.
May 14 2009
parent reply "Nick Sabalausky" <a a.a> writes:
"div0" <div0 users.sourceforge.net> wrote in message 
news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving 
 bmp
 and png files?

http://www.ssTk.co.uk/png.php Import is for d2, but changing it for d1 would be trivial.

Ah, cool.
 -- 
 My enormous talent is exceeded only by my outrageous laziness.

Heh, I'm gonna have to steal that line, but slightly changed (disclaimer: this is not intended as an insult to you (only an insult to me ;) )): "My enormous talent is exceeded only by my sheer arrogance." (Again, that's not intended as a jab at you, I just think that line would be hilarious :) )
May 14 2009
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Nick Sabalausky wrote:
 "div0" <div0 users.sourceforge.net> wrote in message 
 news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving 
 bmp
 and png files?

Import is for d2, but changing it for d1 would be trivial.

Ah, cool.
 -- 
 My enormous talent is exceeded only by my outrageous laziness.

Heh, I'm gonna have to steal that line, but slightly changed (disclaimer: this is not intended as an insult to you (only an insult to me ;) )): "My enormous talent is exceeded only by my sheer arrogance." (Again, that's not intended as a jab at you, I just think that line would be hilarious :) )

My enormous talent is exceeded only by my skill at creating one-liners. Andrei (succumbing to infinite recursion)
May 14 2009
parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Andrei Alexandrescu wrote:
 Nick Sabalausky wrote:
 "div0" <div0 users.sourceforge.net> wrote in message
 news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for
 loading/saving bmp
 and png files?

Import is for d2, but changing it for d1 would be trivial.

Ah, cool.
 -- 
 My enormous talent is exceeded only by my outrageous laziness.

Heh, I'm gonna have to steal that line, but slightly changed (disclaimer: this is not intended as an insult to you (only an insult to me ;) )): "My enormous talent is exceeded only by my sheer arrogance." (Again, that's not intended as a jab at you, I just think that line would be hilarious :) )

My enormous talent is exceeded only by my skill at creating one-liners. Andrei (succumbing to infinite recursion)

Wouldn't that be "My enormous talent is exceeded only by my enormous talent."? -- Daniel
May 14 2009
parent reply Georg Wrede <georg.wrede iki.fi> writes:
Daniel Keep wrote:
 
 Andrei Alexandrescu wrote:
 Nick Sabalausky wrote:
 "div0" <div0 users.sourceforge.net> wrote in message
 news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for
 loading/saving bmp
 and png files?

Import is for d2, but changing it for d1 would be trivial.

 -- 
 My enormous talent is exceeded only by my outrageous laziness.

(disclaimer: this is not intended as an insult to you (only an insult to me ;) )): "My enormous talent is exceeded only by my sheer arrogance." (Again, that's not intended as a jab at you, I just think that line would be hilarious :) )

Andrei (succumbing to infinite recursion)

Wouldn't that be "My enormous talent is exceeded only by my enormous talent."?

My enormous sarcasm is exceeded only by my enormous talent.
May 16 2009
parent div0 <div0 users.sourceforge.net> writes:
Georg Wrede wrote:
 Daniel Keep wrote:
 Andrei Alexandrescu wrote:
 Nick Sabalausky wrote:
 "div0" <div0 users.sourceforge.net> wrote in message
 news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for
 loading/saving bmp
 and png files?

Import is for d2, but changing it for d1 would be trivial.

 -- 
 My enormous talent is exceeded only by my outrageous laziness.

(disclaimer: this is not intended as an insult to you (only an insult to me ;) )): "My enormous talent is exceeded only by my sheer arrogance." (Again, that's not intended as a jab at you, I just think that line would be hilarious :) )

Andrei (succumbing to infinite recursion)

Wouldn't that be "My enormous talent is exceeded only by my enormous talent."?

My enormous sarcasm is exceeded only by my enormous talent.

There should be some web comic that expresses the sinking feeling you get went you come to suspect that your usenet sig will be the most important contribution you make to the world. :P -- My enormous talent is exceeded only by my outrageous laziness.
May 16 2009
prev sibling next sibling parent div0 <div0 users.sourceforge.net> writes:
Nick Sabalausky wrote:
 "div0" <div0 users.sourceforge.net> wrote in message 
 news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving 
 bmp
 and png files?

Import is for d2, but changing it for d1 would be trivial.

Ah, cool.
 -- 
 My enormous talent is exceeded only by my outrageous laziness.

Heh, I'm gonna have to steal that line, but slightly changed (disclaimer: this is not intended as an insult to you (only an insult to me ;) )): "My enormous talent is exceeded only by my sheer arrogance." (Again, that's not intended as a jab at you, I just think that line would be hilarious :) )

:) share and enjoy. -- My enormous talent is exceeded only by my outrageous laziness.
May 14 2009
prev sibling parent div0 <div0 users.sourceforge.net> writes:
Nick Sabalausky wrote:
 "div0" <div0 users.sourceforge.net> wrote in message 
 news:guirpq$m70$1 digitalmars.com...
 Nick Sabalausky wrote:
 Can anyone suggest good up-to-date D libs or bindings for loading/saving 
 bmp
 and png files?

Import is for d2, but changing it for d1 would be trivial.

Ah, cool.

Thinking about it, if you do modify it for d1, send me the changed version and I'll merge it with a version block. Got a version of jpeg6b & freeType as well. I'll upload them later once ftp access stops being a pig. -- My enormous talent is exceeded only by my outrageous laziness.
May 14 2009
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
Well, I've been doing some more work on it today. The biggest new function
is BMP.display(), which pops up a window displaying the bmp on the screen.

I also cleaned up the code a little, put in a preliminary load from file
function, and added some ddocs.

Download here:

http://arsdnet.net/bmpstuff.zip

DDoc here:

http://arsdnet.net/bmp.html

See also the bottom of bmp.d for some examples (also see the commented code in
that main function).

A short example program:

----

import bmp;

void main() {
	auto i = new BMP("picture.bmp"); // note this MUST be a 24 bit bmp
	i.display(); // show it on screen!
	i.setPixel(10, 10, Color(255,255,255)); // add a white pixel at 10,10
	i.save("hacked.bmp"); // save it back to a file
}

-------

Writing to a file is useful, but showing it right there is really cool.

The display function I've written is still somewhat buggy and is very slow on
X11, but works reasonably well on Windows. (I really need to brush up on my
xlib.)

But what I imagine this being useful for is whipping up quick graphs and such.
Saving to a bmp is fun, but this seems useful too.



I also had to read the PNG spec yesterday for work, and am starting on adding
basic png read/write support too. I already have the chunks read into D
structs for easy processing (not in that zip), but haven't coded the
compression, so it can't actually work with the image data.

I probably won't get around to finishing this until at least next weekend.

Off topic:
I also have some D + C code for playing and doing light work with .wav
and .mid files too. As I have the time, I'll see about posting that somewhere
too. These basic file formats are nice things to have.

-- 
Adam D. Ruppe
http://arsdnet.net
May 16 2009