rikkimax / alphaPhobos

Assume License: Boost
11 stars 1 forks source link

imageformats : PBM and XPM #9

Open Zardoz89 opened 8 years ago

Zardoz89 commented 8 years ago

Haver you planed to support PBM and XPM formats ? They are very trivial, and are very useful for embed small image resources on code.

rikkimax commented 8 years ago

I've just had a look at XPM and PBM formats, I wouldn't mind PBM and family, but XPM not really. Right now PNG is the only one implemented as a reference implementation, but I think I could do PBM some time soon.

Zardoz89 commented 8 years ago

PBM it's very trivial to implement. I wrote a PBM reader on C++ some time ago to generate a bitmap font from it.

rikkimax commented 8 years ago

Yeah, that's what I thought as well. Unfortunately to do XPM properly it looks like you need a c lexer. Which I do have, but I know will never go into Phobos.

Zardoz89 commented 8 years ago

XPM have different versions .

The original version , really need a more complex parsing. It was design to be used with a #include "image.xpm" from C.

XPM2 not have these C stuff . If you check XPM2, It's similar to PBM :

! XPM2
48 4 2 1
a c #FFFFFF
b c #000000
abaabaababaaabaabababaabaabaababaabaaababaabaaab
abaabaababaaabaabababaabaabaababaabaaababaabaaab
abaabaababaaabaabababaabaabaababaabaaababaabaaab
abaabaababaaabaabababaabaabaababaabaaababaabaaab

XPM3 isn't hard to parse, as the only C stuff is at the begin/end of the file :

/* XPM */
static char * XFACE[] = {
/* <Values> */
/* <width/cols> <height/rows> <colors> <char on pixel>*/
"48 4 2 1",
/* <Colors> */
"a c #ffffff",
"b c #000000",
/* <Pixels> */
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
"abaabaababaaabaabababaabaabaababaabaaababaabaaab",
"abaabaababaaabaabababaabaabaababaabaaababaabaaab"
};

If you remove the opening/end, is a list of strings and uses // & /* */ as comments.

rikkimax commented 8 years ago

I'm happy with XPM2 just not the others. For now I'm happy with XPM having the status "to be implemented by community", just like JPEG.

At the current time, I won't be implementing another file format any where close to PNG's complexity, ones enough for now.

I'll see what I can do in the next few hours about PBM support.

docandrew commented 8 years ago

I've started on the XPM work - trying to mirror the PNG interface as much as possible. Plan is to start with XPM2 and then do a version of XPM1/3 that doesn't use the full C lexer if I can pull it off.

rikkimax commented 8 years ago

Don't worry too much about what I have with PNG. Get something working e.g. using GC and all. Then let's worry about getting it good quality.

docandrew commented 8 years ago

OK that's encouraging - I've been trying to make sense of the allocator work and interfaces, it's a lot to take in!

rikkimax commented 8 years ago

Lets just say my first go of png reader/writer was quite a bit different. https://github.com/Devisualization/image/tree/master/source/png/devisualization/image/png

docandrew commented 8 years ago

Making good progress. Initially I'll have a "D-ized" XPM1 and XPM3 that basically take raw D strings to make it easy for people to embed the XPM in their D code.

Reading external .xpm with the valid C syntax will be a little more work but will definitely not require a full C lexer.

I think the format is used rarely, and not really intended for high-performance image manipulation, so a lot of optimization is probably unnecessary.

One question for you rikkimax: is there an image or bitmap class you'd prefer me to use for the export/internal representation? I poked around the repository source and had a hard time finding something with an obvious API that I should use.

rikkimax commented 8 years ago

They are provided by std.experimental.graphic.image.storage. They all satisfy isImage and the default for PNG is horizontal.

Hard code it for now to be e.g. horizontal. I have a solution for that in PNG that'll work fine here as well.