473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Writing PNG with pure Python

Just in case anybody has the same problem, here's my first attempt at
implementing a subset of the PNG spec in pure Python. I license it to
you under the terms of the GNU GPL.

http://trac.browsershots.org/browser...b/image/png.py

It encodes RGB images with 24 bits per pixel into PNG, using only the
modules sys, zlib and struct. These are all included in the base
distribution of Python. You don't need gd or imlib.

I have done a little testing, and my implementation processes 8 megs of
RGB input in 0.6 seconds. With Adam7 interlacing enabled, it takes 10
times longer.

I would really appreciate any feedback and suggestions for improvement.

Cheers,
Johann

Jun 9 '06 #1
17 8690
> You should really also include the alpha channel. Without that, PNG is
crippled IMHO.


I have now added simple transparency (marking one color as transparent
with a tRNS chunk). If anybody wants full alpha channel support, ask
kindly or send me a patch. I would like to avoid duplicating all the
functions, so maybe we should introduce a parameter to switch between 3
and 4 bytes per pixel.

Cheers,
Johann

Jun 9 '06 #2
On Fri, 09 Jun 2006 07:43:21 -0400, Johann C. Rocholl
<jc*******@googlemail.com> wrote:
here's my first attempt at
implementing a subset of the PNG spec in pure Python. I license it to
you under the terms of the GNU GPL.
http://trac.browsershots.org/browser...b/image/png.py


It's your code, so you get to license it.
But if you wish to solicit patches,
a more Pythonic license is IMHO more likely
to prove fruitful.

Alan Isaac
Jun 9 '06 #3
Em Sex, 2006-06-09 Ã*s 12:30 -0400, Alan Isaac escreveu:
It's your code, so you get to license it.
But if you wish to solicit patches,
a more Pythonic license is IMHO more likely
to prove fruitful.


"Pythonic license"? That's new to me. I can figure out what a
"Python-like license" is, but I'm clueless about a "Pythonic license".

--
Felipe.

Jun 9 '06 #4
> Em Sex, 2006-06-09 às 12:30 -0400, Alan Isaac escreveu:
It's your code, so you get to license it.
But if you wish to solicit patches,
a more Pythonic license is IMHO more likely
to prove fruitful.

"Felipe Almeida Lessa" <fe**********@gmail.com> wrote in message
news:ma***************************************@pyt hon.org... "Pythonic license"? That's new to me. I can figure out what a
"Python-like license" is, but I'm clueless about a "Pythonic license".

http://www.panikon.com/phurba/alteng/i.html
hth,
Alan Isaac
Jun 9 '06 #5
Alan Isaac schrieb:
It's your code, so you get to license it.
But if you wish to solicit patches,
a more Pythonic license is IMHO more likely
to prove fruitful.


What license would you suggest? After some reading at [1] and [2] and
[3], I found that the Academic Free License (version 2.1) and the
Apache License (version 2.0) are considered helpful for contributions
to the Python Software Foundation.

So far, I haven't used either of these licenses for my own code, and
after a little reading the AFL seems okay for me. I would perhaps
consider the LGPL [4] as an alternative because it is less restrictive
than the GPL.

Thoughts or links, anybody?

Cheers,
Johann

[1] http://www.python.org/moin/PythonSof...tionLicenseFaq
[2] http://www.python.org/psf/records/bo...es/2004-11-09/
[3] http://www.python.org/psf/contrib/
[4] http://www.gnu.org/licenses/lgpl.html

Jun 9 '06 #6

"Johann C. Rocholl" <jc*******@googlemail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
What license would you suggest?


I recommend that you choose the license that will best achieve
your long run goals for the code. As I understand them, and
as I understand your application and software development,
this implies something like the MIT license:
http://www.opensource.org/licenses/mit-license.php
I believe that the MIT license maximizes the likelihood that
a small scale application will receive useful patches, as long
as you actively incorporate patches.

You may reach other conclusions for many reasons ...

Cheers,
Alan Isaac
Jun 9 '06 #7
The MIT license is enticingly short and simple, thank you for the tip.

I have now decided to license my project (including the pure python PNG
library) under the Apache License 2.0 which is less restrictive than
the GPL in terms of sublicensing. The Apache License looks modern and
well-maintained to me. My project runs on Apache, so there is some
context there as well. Also, this change will simplify things if I ever
want to contribute some of the code to the Python Software Foundation.

Cheers,
Johann

Jun 10 '06 #8
> Just in case anybody has the same problem, here's my first attempt at
implementing a subset of the PNG spec in pure Python. I license it to
you under the terms of the GNU GPL.
Update: the code is now licensed under the Apache License 2.0.
http://trac.browsershots.org/browser...b/image/png.py


Update: the module has moved to its own package, with its own setup.py:

http://trac.browsershots.org/browser/trunk/pypng
http://svn.browsershots.org/trunk/pypng/

Cheers,
Johann

Jun 12 '06 #9
Johann C. Rocholl wrote:
The MIT license is enticingly short and simple, thank you for the tip.

I have now decided to license my project (including the pure python PNG
library) under the Apache License 2.0 which is less restrictive than
the GPL in terms of sublicensing.


But it is also incompatible with the GPL:

http://www.fsf.org/licensing/license...atibleLicenses

It's obviously your decision about how you license your own code, but
I'd advise you to disregard the "Pythonic license" rhetoric, whatever
that means: Python's original licence was regarded as not being enough
of a licence by some lawyers (that's what some people refer to as the
original Python licence); subsequent licences aren't recommended for
application to any other works (like various licences of the Python
code over the years); despite advocacy for permissive licences by some
parties, there exist numerous successful GPL'd and LGPL'd Python
projects (meaning that projects licensed in such a way are not lesser
members of the community). Moreover, any licensing gymnastics
undertaken by the PSF did involve various extra somersaults to remain
GPL-compatible, meaning that even people who favour permissive licences
regard "licence interoperability" positively.

If you're convinced that a permissive licence suits your code best,
please consider something whose side-effects you understand. If the
additional patent grant or licence termination clauses (which the FSF
don't regard as a bad thing, just something incompatible with the
current GPL/LGPL) are specifically what you want, then the Apache
Licence may be what you're after; otherwise, you should choose
something less baroque and better understood, perhaps from this list:

http://www.fsf.org/licensing/license...atibleLicenses

Yes, one of the best places to find out about non-FSF licences is
actually the FSF themselves, undermining various myths some people like
to put forward.

Paul

Jun 12 '06 #10
Paul Boddie wrote:
Johann C. Rocholl wrote:
The MIT license is enticingly short and simple, thank you for the tip.

I have now decided to license my project (including the pure python PNG
library) under the Apache License 2.0 which is less restrictive than
the GPL in terms of sublicensing.

But it is also incompatible with the GPL:

http://www.fsf.org/licensing/license...atibleLicenses

It's obviously your decision about how you license your own code, but
I'd advise you to disregard the "Pythonic license" rhetoric, whatever
that means: Python's original licence was regarded as not being enough
of a licence by some lawyers (that's what some people refer to as the
original Python licence); subsequent licences aren't recommended for
application to any other works (like various licences of the Python
code over the years); despite advocacy for permissive licences by some
parties, there exist numerous successful GPL'd and LGPL'd Python
projects (meaning that projects licensed in such a way are not lesser
members of the community). Moreover, any licensing gymnastics
undertaken by the PSF did involve various extra somersaults to remain
GPL-compatible, meaning that even people who favour permissive licences
regard "licence interoperability" positively.

If you're convinced that a permissive licence suits your code best,
please consider something whose side-effects you understand. If the
additional patent grant or licence termination clauses (which the FSF
don't regard as a bad thing, just something incompatible with the
current GPL/LGPL) are specifically what you want, then the Apache
Licence may be what you're after; otherwise, you should choose
something less baroque and better understood, perhaps from this list:

http://www.fsf.org/licensing/license...atibleLicenses

Yes, one of the best places to find out about non-FSF licences is
actually the FSF themselves, undermining various myths some people like
to put forward.

Also remember that it's perfectly possible to release the same code
under several different licenses. This can happen, for example, with
contributions to Python. The PSF doesn't care how you license it to
anyone else, only that you license it to the PSF under the Free Academic
Licence or v2 of the Apache License. We then re-license it to Python
users (under the Python license, naturally).

If the contributor then wants to license the same code under the GPL to
other people there's no problem with that.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 12 '06 #11
> > I have now decided to license my project (including the pure python PNG
library) under the Apache License 2.0 which is less restrictive than
the GPL in terms of sublicensing.
But it is also incompatible with the GPL:

http://www.fsf.org/licensing/license...atibleLicenses


Thank you for enlightening me. I was under the wrong impression that
the Apache License was compatible with the GPL, perhaps because it is
OSI-approved, which means a different thing as I now understand.
If you're convinced that a permissive licence suits your code best,
please consider something whose side-effects you understand. If the
additional patent grant or licence termination clauses (which the FSF
don't regard as a bad thing, just something incompatible with the
current GPL/LGPL) are specifically what you want, then the Apache
Licence may be what you're after; otherwise, you should choose
something less baroque and better understood, perhaps from this list:

http://www.fsf.org/licensing/license...atibleLicenses


I do believe that my code will be useful for more people if it's under
a permissive license, but obviously also if it's under a GPL-compatible
license. Therefore it's perhaps a good idea to change the license of my
software again.

Currently, I am considering the following options:
- LGPL
- Modified BSD License
- X11 License (aka MIT License)

I appreciate the simplicity of the BSD and MIT Licenses, except for the
names. "BSD License" can be confused with the original BSD License,
while "MIT License" according to the FSF "is misleading, since MIT has
used many licenses for software." But perhaps these drawbacks are just
mentioned on the FSF page to get more people to use the GPL or LGPL.
:-)

I don't want to start a holy war about the benefits of the GPL, but I
would like some more input about the choices of licensing. Perhaps I'll
put the larger part of my Project under the GPL and only some
standalone library parts (like the PNG encoder) under the LGPL.

If I ever want to contribute some of the code to the Python Software
Foundation, I can still license it to them under the Apache License,
right? But how about the parts of the code that others contribute to my
software while it's licensed under the LGPL?

Cheers, Johann

Jun 13 '06 #12
Johann C. Rocholl wrote:
I appreciate the simplicity of the BSD and MIT Licenses, except for the
names. "BSD License" can be confused with the original BSD License,
while "MIT License" according to the FSF "is misleading, since MIT has
used many licenses for software."

I had one lawyer tell me the MIT license was better at declaring your
non-liability than BSD. IANAL, your lawyer may vary, ....

--
--Scott David Daniels
sc***********@acm.org
Jun 13 '06 #13
"Johann C. Rocholl" <jc*******@googlemail.com> writes:
Currently, I am considering the following options:
- LGPL
- Modified BSD License
- X11 License (aka MIT License)

I appreciate the simplicity of the BSD and MIT Licenses, except for
the names. "BSD License" can be confused with the original BSD
License, while "MIT License" according to the FSF "is misleading,
since MIT has used many licenses for software." But perhaps these
drawbacks are just mentioned on the FSF page to get more people to
use the GPL or LGPL. :-)
I think these are real concerns. Discussion of these licenses usually
needs to be couched in clarifications, such as "the three-clause
BSD-style license" or "the MIT X11 license"; but these clarifications
are also often dropped, leaving ambiguity as to exactly which license
terms are being discussed.

If you want a permissive, GPL-compatible, copyright-preserving
license, the Expat license is probably the simplest.

<URL:http://www.fsf.org/licensing/licenses/#Expat>
I don't want to start a holy war about the benefits of the GPL, but
I would like some more input about the choices of licensing.
The FSF licensing webpage offers assistance via email in choosing a
license:

<URL:http://www.fsf.org/licensing/licenses/#Introduction>
If I ever want to contribute some of the code to the Python Software
Foundation, I can still license it to them under the Apache License,
right?
This would be a reason to choose something like the Expat license; it
isn't a copyleft, so others can take your code and redistribute it
under a *different* license, such as the Apache license, without
seeking extra permission from you.
But how about the parts of the code that others contribute to my
software while it's licensed under the LGPL?


You could require that all contributions be licensed by the author
under the Expat license, allowing you to take it into the whole
without needing to seek out that author in future, while still
preserving their copyright.

--
\ "I was in the grocery store. I saw a sign that said 'pet |
`\ supplies'. So I did. Then I went outside and saw a sign that |
_o__) said 'compact cars'." -- Steven Wright |
Ben Finney

Jun 13 '06 #14
How about this here construct?

#!/usr/bin/env python
# png.py - PNG encoder in pure Python
# Copyright (C) 2006 Johann C. Rocholl <jo****@browsershots.org>
#
# This file is licensed alternatively under one of the following:
# 1. GNU Lesser General Public License (LGPL), Version 2.1 or newer
# 2. GNU General Public License (GPL), Version 2 or newer
# 3. Apache License, Version 2.0 or newer
# 4. The following license (aka MIT License)
#
# --------------------- start of license -----------------------------
# Copyright (C) 2006 Johann C. Rocholl <jo****@browsershots.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ----------------------- end of license -----------------------------
#
# You may not use this file except in compliance with at least one of
# the above four licenses.

Jun 13 '06 #15
"Johann C. Rocholl" <jc*******@googlemail.com> writes:
How about this here construct?

#!/usr/bin/env python
# png.py - PNG encoder in pure Python
# Copyright (C) 2006 Johann C. Rocholl <jo****@browsershots.org>
#
# This file is licensed alternatively under one of the following:
# 1. GNU Lesser General Public License (LGPL), Version 2.1 or newer
# 2. GNU General Public License (GPL), Version 2 or newer
# 3. Apache License, Version 2.0 or newer
# 4. The following license (aka MIT License)


Pointless. Licensing it under the Expat license (what you're calling
"MIT License", but we've already discussed the ambiguities in that
term) allows all the rights granted in all the other license you name,
plus just about anything else.

Hence, there's no point listing the others if you are also happy for
people to have it under the Expat license. On the other hand, if you
want to be more restrictive than the terms of the Expat license, you
need to choose a different license.

Simplify. Please don't attempt to write yet another set of license
terms without expert legal assistance. You've already chosen the Expat
license as being acceptable; use that, and you grant all the rest
without even mentioning it.

--
\ "[On the Internet,] power and control will shift to those who |
`\ are actually contributing something useful rather than just |
_o__) having lunch." -- Douglas Adams |
Ben Finney

Jun 13 '06 #16
Ben Finney schrieb:
Simplify. Please don't attempt to write yet another set of license
terms without expert legal assistance. You've already chosen the Expat
license as being acceptable; use that, and you grant all the rest
without even mentioning it.


Sorry for my stubborn ignorance, and thank you for your patient
explanations.

I think I finally got it: I'll put the bulk of my browsershots project
under the GNU GPL again, and the independent library parts like png.py
under the Expat License.

Cheers,
Johann

Jun 14 '06 #17
"Johann C. Rocholl" <jc*******@googlemail.com> writes:
Ben Finney schrieb:
Simplify. Please don't attempt to write yet another set of license
terms without expert legal assistance. You've already chosen the
Expat license as being acceptable; use that, and you grant all the
rest without even mentioning it.
Sorry for my stubborn ignorance, and thank you for your patient
explanations.


No problems; if license proliferation can be reduced, it's worth
spending some time to do so.
I think I finally got it: I'll put the bulk of my browsershots
project under the GNU GPL again, and the independent library parts
like png.py under the Expat License.


Sounds quite workable. This has the effect that the work as a whole
can be redistributed under the GNU GPL (since the Expat license allows
this), and the library parts can be redistributed independently under
just about any license.

--
\ "As we enjoy great advantages from the inventions of others, we |
`\ should be glad to serve others by any invention of ours." -- |
_o__) Benjamin Franklin |
Ben Finney

Jun 14 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ravi | last post by:
Hi, I did some googling, and found that there doesn't seem to be a pure python MySQL communication module. There is one for perl however, Net::MySQL. I was wondering if there was a specific...
11
by: Brett C. | last post by:
For my thesis (once the bloody thing stops throwing bugs at me) I am going to need to collect stats on the frequency that atomic types in local variables are applied to various opcodes and methods....
5
by: Fuzzyman | last post by:
Python 2.4 is built with Microsoft Visiual C++ 7. This means that it uses msvcr7.dll, which *isn't* a standard part of the windows operating system. This means that if you build a windows installer...
5
by: Fernando Perez | last post by:
Hi all, by reading through the docs, the func_closure attribute of function objects is listed as writable. Yet, nowhere does it say _how_ to write to it. I am trying to do a run-time...
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
13
by: Steven Bethard | last post by:
Jean-Paul Calderone <exarkun@divmod.comwrote: Interesting. Could you give a few illustrations of this? (I didn't run into the same problem at all, so I'm curious.) Steve
3
by: Paul Moore | last post by:
I'd like to write some scripts to analyze and manipulate my music files. The files themselves are in MP3 and FLAC format (mostly MP3, but FLAC where I ripped original CDs and wanted a lossless...
12
by: betabrain.honshu | last post by:
Hi Folks, for those of you who are familiar with the micropledge.com project, here is a good opportunity to spend or earn something: http://micropledge.com/projects/pysalsa20 I know that the...
28
by: n00m | last post by:
Both codes below read the same huge(~35MB) text file. In the file 1000000 lines, the length of each line < 99 chars. Stable result: Python runs ~0.65s C : ~0.70s Any thoughts?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.