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

imageformats : PBM and XPM #9

Open
Zardoz89 opened this issue Feb 15, 2016 · 11 comments
Open

imageformats : PBM and XPM #9

Zardoz89 opened this issue Feb 15, 2016 · 11 comments

Comments

@Zardoz89
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link

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
Copy link
Owner

rikkimax commented Jun 5, 2016

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
Copy link

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
Copy link
Owner

rikkimax commented Jun 5, 2016

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
Copy link

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
Copy link
Owner

rikkimax commented Jun 6, 2016

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.

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