Writing an image format

classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Writing an image format

Mike McGonagle
Hello all,

I am looking for a simple way to generate and write a color image to
disk. I know that there is the GD library, the Cairo library, and
several other things that require the installation of various C level
libraries in order to use them. I don't want to have to install a
bunch of libraries that deal with reading and writing images, as all I
am looking to do is be able to generate some simple image files that I
can then view in other programs.

Thanks,

Mike

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Patrick Mc(avery
Hi Mike

What about a .xpm file?

http://en.wikipedia.org/wiki/X_PixMap

They are bitmaps from text. You could always convert it to a .png later.

-Patrick

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Wesley Smith
In reply to this post by Mike McGonagle
> I am looking for a simple way to generate and write a color image to
> disk. I know that there is the GD library, the Cairo library, and
> several other things that require the installation of various C level
> libraries in order to use them. I don't want to have to install a
> bunch of libraries that deal with reading and writing images, as all I
> am looking to do is be able to generate some simple image files that I
> can then view in other programs.

Have you tried image magick?
http://www.imagemagick.org/script/command-line-processing.php

I don't think you can get away with not having these kinds of libs.
You don't say what OS you're on.  I would give different advice for
windows, osx and linux.

wes

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Gabriel Duarte
There is some bind from ImageMagick to Lua???

On Tue, Oct 26, 2010 at 8:12 PM, Wesley Smith <[hidden email]> wrote:
> I am looking for a simple way to generate and write a color image to
> disk. I know that there is the GD library, the Cairo library, and
> several other things that require the installation of various C level
> libraries in order to use them. I don't want to have to install a
> bunch of libraries that deal with reading and writing images, as all I
> am looking to do is be able to generate some simple image files that I
> can then view in other programs.

Have you tried image magick?
http://www.imagemagick.org/script/command-line-processing.php

I don't think you can get away with not having these kinds of libs.
You don't say what OS you're on.  I would give different advice for
windows, osx and linux.

wes




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work
Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Wesley Smith
On Tue, Oct 26, 2010 at 3:14 PM, Gabriel Duarte <[hidden email]> wrote:
> There is some bind from ImageMagick to Lua???
>

No bindings, but you can use the os module to run the command line
tools.  It's really handy for batch image operations.
wes

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Gabriel Duarte
In reply to this post by Patrick Mc(avery
Or write a .ppm file, only a header and after, just the RGB values :P

On Tue, Oct 26, 2010 at 8:05 PM, Patrick Mc(avery <[hidden email]> wrote:
Hi Mike

What about a .xpm file?

http://en.wikipedia.org/wiki/X_PixMap

They are bitmaps from text. You could always convert it to a .png later.

-Patrick




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work
Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Daniel Aquino
Yea ppm is a simple option.

On Tue, Oct 26, 2010 at 6:19 PM, Gabriel Duarte <[hidden email]> wrote:
Or write a .ppm file, only a header and after, just the RGB values :P


On Tue, Oct 26, 2010 at 8:05 PM, Patrick Mc(avery <[hidden email]> wrote:
Hi Mike

What about a .xpm file?

http://en.wikipedia.org/wiki/X_PixMap

They are bitmaps from text. You could always convert it to a .png later.

-Patrick




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Gabriel Duarte
If you want, I got a code that handle a buffer and writes it into a .ppm file...

On Tue, Oct 26, 2010 at 8:20 PM, Daniel Aquino <[hidden email]> wrote:
Yea ppm is a simple option.


On Tue, Oct 26, 2010 at 6:19 PM, Gabriel Duarte <[hidden email]> wrote:
Or write a .ppm file, only a header and after, just the RGB values :P


On Tue, Oct 26, 2010 at 8:05 PM, Patrick Mc(avery <[hidden email]> wrote:
Hi Mike

What about a .xpm file?

http://en.wikipedia.org/wiki/X_PixMap

They are bitmaps from text. You could always convert it to a .png later.

-Patrick




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work
Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Daniel Aquino
here is a reader for you

-- vim:set sw=4 ts=4:
--
-- This Lua script reads texture data from a .ppm file.
--
-- Copyright (C) 2009 Pim Goossens
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, see <http://www.gnu.org/licenses/>, or write
-- to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-- Boston, MA 02110-1301 USA.

local f = io.open(..., 'rb')
if not f then
error('error while opening file ' .. (...))
end
-- Read the header
local magic = f:read()
if not magic == 'P6' then
error('not a PPM file')
end
local width, height, maxval = f:read("*n", "*n", "*n")
if not maxval == 255 then
error('expected maxval of 255')
end
-- Skip the single whitespace character following the maxval
f:read(1)
-- Now read the image data
data = f:read(width * height * 3)
if #data < width * height * 3 then
error('insufficient data')
end
f:close()

return {
width = width;
height = height;
flags = 0;
data = data;
}


On Tue, Oct 26, 2010 at 6:22 PM, Gabriel Duarte <[hidden email]> wrote:
If you want, I got a code that handle a buffer and writes it into a .ppm file...


On Tue, Oct 26, 2010 at 8:20 PM, Daniel Aquino <[hidden email]> wrote:
Yea ppm is a simple option.


On Tue, Oct 26, 2010 at 6:19 PM, Gabriel Duarte <[hidden email]> wrote:
Or write a .ppm file, only a header and after, just the RGB values :P


On Tue, Oct 26, 2010 at 8:05 PM, Patrick Mc(avery <[hidden email]> wrote:
Hi Mike

What about a .xpm file?

http://en.wikipedia.org/wiki/X_PixMap

They are bitmaps from text. You could always convert it to a .png later.

-Patrick




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work




--
Gabriel Duarte
Linux User #471185
Rio de Janeiro - RJ
http://w3.impa.br/~gabrield

Phones:
(55) (21) 9463-7760  -> Mobile
(55) (21) 2464-9302  -> Home
(55) (21) 2529-5080  -> Work

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Luiz Henrique de Figueiredo
In reply to this post by Mike McGonagle
> I am looking for a simple way to generate and write a color image to disk.

The simplest format is the Netpbm family of formats:
        http://en.wikipedia.org/wiki/Netpbm_format

Easy to generate from Lua. Here's a Lua program for generating a gray-scale
picture of the Mandelbrot set (Mandelbrot died earlier this month).
--lhf

local N=256
print("P2\n",N,N,255)
for i=1,N do
        local y=2-4*(i-1)/(N-1)
        for j=1,N do
                local x=-2+4*(j-1)/(N-1)
                local xc,yc=x,y
                local X,Y=0,0
                local p=0
                for n=1,255 do
                        X,Y = X^2-Y^2+xc, 2*X*Y+yc
                        if X^2+Y^2>4 then p=n break end
                end
                print(p)
        end
end

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Mike McGonagle
In reply to this post by Mike McGonagle
Thanks, everyone... after looking at some of the options, and looking
at the version of Photoshop that I have, I think I can write a raw
file that interleaves the RGB data in either 8 bit or 16 bit depths. I
am also looking into what Gimp on the Mac can do...

Oh, and I guess I should say that I am on Mac OS X 10.4.11.

I was trying to remember the XPM format, and had thought about the
NETPBM formats, but those are not read directly by Photoshop. At the
same time, I could just find some conversion utility. Maybe Gimp will
read those formats. I had not thought of the ImageMagick stuff, but I
probably wouldn't want to use that...

I really appreciate all the assistance that everyone suggested. I am
essentially trying to investigate some fractal data and wanted to
produce some simple grayscale and color plots. I have a Java program
that does this, but having moved to Lua in the last year, I wanted to
have everything usable from there...

Mike

On Tue, Oct 26, 2010 at 6:05 PM, Mike McGonagle <[hidden email]> wrote:

> Hello all,
>
> I am looking for a simple way to generate and write a color image to
> disk. I know that there is the GD library, the Cairo library, and
> several other things that require the installation of various C level
> libraries in order to use them. I don't want to have to install a
> bunch of libraries that deal with reading and writing images, as all I
> am looking to do is be able to generate some simple image files that I
> can then view in other programs.
>
> Thanks,
>
> Mike
>

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Luiz Henrique de Figueiredo
> Oh, and I guess I should say that I am on Mac OS X 10.4.11.

My old PB G4 came with Mac OS X 10.4 and GraphicConverter, which can
read NETPBM.

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Patrick Mc(avery
In reply to this post by Mike McGonagle
Hi Mike

Gimp will work with XPM, I just double checked before my first response.

I can't see any defects in the.xpm images vs .png images but the file
size is about 3X larger-Patrick




Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Miles Bader-2
In reply to this post by Mike McGonagle
Mike McGonagle <[hidden email]> writes:
> I was trying to remember the XPM format, and had thought about the
> NETPBM formats, but those are not read directly by Photoshop.

The TGA (aka "Targa") format is also very simple to write, basically a
small header + rows of rgb triplets (hmm, actuallly the values are
stored in B-G-R order in the file), and somewhat common.

http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/

-Miles

--
My books focus on timeless truths.  -- Donald Knuth

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

eugeny gladkih
In reply to this post by Mike McGonagle
On 27.10.2010 2:05, Mike McGonagle wrote:

> Hello all,
>
> I am looking for a simple way to generate and write a color image to
> disk. I know that there is the GD library, the Cairo library, and
> several other things that require the installation of various C level
> libraries in order to use them. I don't want to have to install a
> bunch of libraries that deal with reading and writing images, as all I
> am looking to do is be able to generate some simple image files that I
> can then view in other programs.
>

what about SVG? http://www.w3.org/Graphics/SVG/

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Philippe Lhoste
On 27/10/2010 09:46, john gladkih 599133195 wrote:
> what about SVG? http://www.w3.org/Graphics/SVG/

Not very suited for bitmap images, no?

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

steve donovan
On Wed, Oct 27, 2010 at 11:49 AM, Philippe Lhoste <[hidden email]> wrote:
> Not very suited for bitmap images, no?

But very entertaining.

Especially if you use an XML builder (like stanza or luaexpat-utils)
to generate SVG.

Then there is the rsvg program to rasterize the .svg files
(librsvg2-bin on Debian)

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Patrick Mc(avery
In reply to this post by eugeny gladkih

>
> what about SVG? http://www.w3.org/Graphics/SVG/
>
>

Mike do your fractals have to me bitmap? Inkscape has some built in
filters for creating some similar shapes in SVG and those filters might
work as template code. If this could be done in SVG it might be pretty
cool -Patrick

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Matthew Wild
In reply to this post by Luiz Henrique de Figueiredo
On 26 October 2010 23:26, Luiz Henrique de Figueiredo
<[hidden email]> wrote:
>> I am looking for a simple way to generate and write a color image to disk.
>
> The simplest format is the Netpbm family of formats:
>        http://en.wikipedia.org/wiki/Netpbm_format
>
> Easy to generate from Lua. Here's a Lua program for generating a gray-scale
> picture of the Mandelbrot set (Mandelbrot died earlier this month).

Fun. Mostly as an academic excercise I ported your code to use my
lua-xpm library[1]. I was surprised to find that it took slightly less
time to produce the output (I guess due to less i/o), but the output
file size is about half (XPM is palette-based).

And on the assumption you don't mind, I've adopted that code for a
demo in the lua-xpm repository:
http://code.matthewwild.co.uk/lua-xpm/file/fa4d448b07d3/test_mandelbrot.lua
:)

Thanks,
Matthew

[1]: http://code.matthewwild.co.uk/lua-xpm

Reply | Threaded
Open this post in threaded view
|

Re: Writing an image format

Tony Finch
In reply to this post by Daniel Aquino
On Tue, 26 Oct 2010, Daniel Aquino wrote:

> Yea ppm is a simple option.

Here's something I wrote over the weekend:
http://dotat.at/cgi/git?p=mandelbrot.git;f=mandelbrot.lua;a=blob

Works best with LuaJIT :-)

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7,
DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR
ROUGH. RAIN THEN FAIR. GOOD.

12