Graphics Programming with Perl 1st Edition Martien Verbruggen instant download
Graphics Programming with Perl 1st Edition Martien Verbruggen instant download
https://ebookultra.com/download/graphics-programming-with-
perl-1st-edition-martien-verbruggen/
https://ebookultra.com/download/programming-the-network-with-perl-1st-
edition-paul-barry/
https://ebookultra.com/download/modern-perl-programming-1st-edition-
michael-saltzman/
https://ebookultra.com/download/advanced-perl-programming-second-
edition-simon-cozens/
https://ebookultra.com/download/advanced-3d-game-programming-with-
directx-10-0-wordware-game-and-graphics-library-1st-edition-peter-
walsh/
Penetration Testing with Perl 1st Edition Berdeaux
https://ebookultra.com/download/penetration-testing-with-perl-1st-
edition-berdeaux/
https://ebookultra.com/download/perl-hacks-tips-and-tools-for-
programming-debugging-and-surviving-1st-edition-chromatic/
XML Processing with Perl Python and PHP 1st Edition Martin
C. Brown
https://ebookultra.com/download/xml-processing-with-perl-python-and-
php-1st-edition-martin-c-brown/
https://ebookultra.com/download/mobile-3d-graphics-with-opengl-es-
and-m3g-1st-edition-kari-pulli/
https://ebookultra.com/download/computer-graphics-with-open-gl-fourth-
edition-pearson-new-international-edition-baker/
Graphics Programming with Perl 1st Edition Martien
Verbruggen Digital Instant Download
Author(s): Martien Verbruggen
ISBN(s): 9781930110021, 1930110022
Edition: 1st
File Details: PDF, 2.55 MB
Year: 2002
Language: english
Graphics Programming with Perl
Graphics
Programming
with Perl
MARTIEN VERBRUGGEN
MANNING
Greenwich
(74° w. long.)
For online information and ordering of this and other Manning books,
go to www.manning.com. The publisher offers discounts on this book
when ordered in quantity. For more information, please contact:
Special Sales Department
Manning Publications Co.
209 Bruce Park Avenue Fax: (203) 661-9018
Greenwich, CT 06830 email: [email protected]
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial
caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have the
books we publish printed on acid-free paper, and we exert our best efforts to that end.
ISBN 1-930110-02-2
Part 1 Foundations 1
1 Overview of graphics 3
1.1 Perl and graphics 4
1.2 The bits and pieces in graphics programming 5
1.3 Color spaces and palettes 7
RGB 7 ✦ CMY and CMYK 8 ✦ HSV and HLS 9
YUV, YIQ and YCbCr 12 ✦ Grayscale 12
Color distance 13 ✦ Reducing the number of
colors in an image 13
1.4 Summary 14
vii
3 Overview of tools and modules 27
3.1 CPAN 28
3.2 The tools 29
The Chart::* modules 29 ✦ Gnuplot 29
GD 29 ✦ GD::Graph, GIFgraph and Chart::PNGgraph 30
GD::Text 30 ✦ The Gimp 30 ✦ Image::Magick 30
Image::Size 31 ✦ Inline 31 ✦ OpenGL 32
PGPLOT 32 ✦ RenderMan 33 ✦ Term::Gnuplot 33
3.3 A note on module versions 34
3.4 Summary 34
viii CONTENTS
6 Graphics and the Web 90
6.1 The Common Gateway Interface 91
HTTP and CGI 91
6.2 Suitable image formats 92
Web safe color palettes 92
6.3 CGI and dynamically generated graphics 94
6.4 Forms and encapsulated graphics 96
6.5 Image collections and thumbnailing 100
Thumbnails with Image::Magick 101
Thumbnails with GD 102 ✦ Contact sheets with
Image::Magick’s ✦ visual directory 103
Contact sheets with Image::Magick::Montage 104
An example application: A web photo album 105
Designing the data 107
6.6 Summary 121
7 Animations for the Web 122
7.1 Animation file formats 123
GIF 123 ✦ MNG 124
Macromedia Flash 124 ✦ SVG 125
7.2 GIF animations 125
7.3 Perl and animations 126
7.4 Repeatedly applying a filter 127
Example: making objects appear 127
Example: Zooming in on an object 129
7.5 Animated text 131
7.6 Animated charts 132
7.7 Animations with the Gimp 134
7.8 Summary 137
CONTEN TS ix
9 Three-dimensional graphics 153
9.1 OpenGL 154
OpenGL library functions in Perl 155
Capturing your OpenGL output 157
Example: a planetary system 160
OpenGL summary 164
9.2 RenderMan 164
How to use the module and the BMRT 165
The RenderMan language binding for Perl 166
Example: A rotating cube of cubes 167
9.3 Summary 172
x CONTENTS
12.3 Convolution 215
Convolution with Image::Magick 217
Using Image::Magick's Convolve() method 224
Convolution with PDL 226
12.4 Alpha channels and transparency 229
Transparency and the GD module 229
Transparency and Image::Magick 230
How to view partially transparent images 233
12.5 Fast manipulation of image pixels 233
Using Inline::C 234
12.6 Summary 238
CONTEN TS xi
preface
Welcome to Graphics Programming with Perl. When Manning Publications contacted
me to assess my interest in writing a book about graphics programming for the Perl
language, I was a bit skeptical at first. I didn’t think there would be enough coherent
material to write such a book, and I wasn’t entirely certain there would be much room
for one.
However, after doing some research I noticed that, in fact, there was a gap in the
published material. The only book I could find that combined graphics programming
and Perl was too general, and was largely a collection of recipes on how to use tools,
many of which had no relation to Perl [1]. There were not enough references that
described and explained how to achieve concrete graphics tasks in Perl.
So I accepted the challenge and started working, with the goal of providing a book
that would sum up the ways to work with graphics from within Perl, and to offer suf-
ficient background information to improve the understanding of graphics program-
ming and graphics in general. This work seeks to provide a programmer with enough
fundamental knowledge and pointers to achieve the most common graphics program-
ming tasks. I hope those goals have been realized.
xiii
graphics programming.1 For that you are encouraged to read the documentation that
comes with the modules, which in most cases is satisfactory. This book is also not
intended to be an exhaustive introduction to graphics in general, or a detailed expla-
nation of graphics algorithms, although where appropriate, some graphics theory and
algorithm description will be touched on.
The reader is expected to have a basic knowledge of Perl. The programs and code
fragments will be explained in terms of what they do and how they operate, and only
occasionally in terms of what the Perl statements mean. The documentation that
comes with Perl and the Camel [2] does a much better job of accurately describing
Perl, and other books [3],[4] provide a useful introduction to programming with Perl.
Where necessary, general programming techniques and their implementation in Perl
will be explained when this is pertinent to graphics programming (as in chapter 10,
“Writing your own graphics modules”).
There are many tasks you can accomplish with graphics, and there is a plethora of
questions you might ask when confronted with a graphics programming job. When
thinking about how this book should be arranged, several highly structured possibil-
ities for organizing the content sprang to mind. However, trying to fit various bits and
pieces into this organization turned out to be not that simple. Many tasks in graphics
programming defy neat categorization.
For that reason you might find that, even though the book is divided into chapters,
some of the sections in those chapters might also apply to other chapters. The book is
structured such that it may be read from beginning to end, but it is also arranged to facil-
itate access to specific information relevant to the actual tasks in which you are engaged.
1
There is one exception to this: the Image::Magick module is used extensively in the book, but lacks well
developed documentation of its own, so a reference is included in appendix A.
xiv PREFACE
web work, and many other bits and pieces. If you want to know how to use the graph-
ics modules available for Perl to write your programs, read this book. If you want to
know for which graphics programming tasks Perl is suited, and for which ones it is
less so, read this book. If you want some minimal introduction to graphics theory—
just enough to get you to work—read this book. If you are looking for a reference
for Image::Magick you will find this book useful. If you need to know how to gen-
erally combine graphics and HTML in your CGI applications, read this book. If you
find yourself repeatedly doing the same graphics tasks in an interactive program, read
this book.
On the other hand, if you are seeking a book that teaches you to build graphical
user interfaces, this isn’t it: there is no PerlTk discussion in this book. The programs
presented all use a command-line interface, if they accept input at all.
If you want to learn about graphics theory and computer graphics algorithms, you
will find some rudimentary introductions in this book, but a more elaborate discussion
of these issues is available elsewhere.
CODING PRACTICES
The code in this book has been written to be as portable as possible between the dif-
ferent operating systems on which Perl runs. You might find a slight bias toward
Unix2 operating systems, since that is what I work on most of the time. Pathnames
are always separated by a slash (/), which works on Unix and Microsoft-based operat-
ing systems, but not, for example, on older operating systems for the Macintosh. If
you are on a system that doesn’t support the slash as a directory separator, you might
need to do some work before the example code will run for you. Really portable code
of course uses File::Spec, but, for the sake of clarity I decided not to do that.
When writing code to create graphical output, which is often binary data, it is
imperative to remember the use of binmode() on the file handles that are used to
read and write image files. Failing to do this commonly leads to the creation of bugs
that are difficult to track on platforms in which there is a distinction between text and
binary files. On platforms where there is no such distinction, using binmode() has
no effect; however, that is no excuse to leave it out. Portable code always calls bin-
mode() on a file handle that is to be used for binary data. Apart from portability
issues, using binmode(), even when you know it has no effect, is a good way to doc-
ument that the data stream is of a binary nature.
Coding standards are always up for debate, and mine are not always consistent with
the guidelines from the perlstyle documentation, although they come very close.
I’ll highlight some points that regularly crop up as a subject of disagreement, and some
that I find important.
2
... and BSD and Linux and others. When I refer to Unix, I mean all Unix-like operating systems, not
just the ones licensed by X/Open.
CODING PRACTICES xv
Random documents with unrelated
content Scribd suggests to you:
you want to fire, or you deaden the boat’s way. Take care also to let
the sheet be under the barrel of the gun, in order that your line of
aim may be clear of every thing. In this pursuit, when the more wind
sometimes the more sport, never go with less than three good
hands; and be careful in squally weather not to make too fast the
mainsheet, as nine-tenths of the misfortunes that we hear of, have
occurred from this very circumstance.—Hawker.
The Old English Setter. (Canis Index, variety α.)—This breed was
originally produced between the Spanish pointer and the large water
spaniel, and was famous on account of his steadiness and exquisite
sense of smelling; the hair over the whole body was much more
curled than that of the present breed, which has been considerably
lightened by the additional cross of the springer; he was also much
more steady than the improved variety, but then he had not the
same speed to recommend him. Fine dogs of this kind were also
produced by a cross with the stag and blood hounds. They united
great strength, considerable swiftness, and were used for the chace
in some few instances.
The English Setter (Canis Index, variety β), is a breed produced
between the Spanish pointer, the English water spaniel and springer,
which, by careful cultivation, has attained a high degree of
perfection as a sporting dog. He has an elegant figure, and a very
pleasing diversity of colour; added to this, his skin is covered with
beautifully curled hair, very villous on the lower margin of the tail;
being altogether an extremely handsome dog, and quite unrivalled
by any of the canine species.
The setter has all the excellent qualities of the pointer, with a greater
degree of speed and natural vivacity of temper; he, however, is not
so easily broken in as the pointer, and requires a certain degree of
training every year, to make him continue staunch. There are,
however, various instances of setters being self-taught, as the
following example will show:—The black and tan small setter bitch
which I have (says Mr. Torry), was originally out of the Duke of
Bedford’s breed, and both she and her mother inherit the utmost
natural sagacity as sporting dogs. At ten months old, and before she
had got a lesson in breaking, or had seen game killed, she was
taken to the moors for the first time, and on finding a bird, was
perfectly steady at her point, backed, and did not run the game. The
gentleman who was with me wounded a bird, and it fell at a
considerable distance. The pup, unknown to us, had kept her eye
upon it, and, to our astonishment, after we had loaded, and again
ordered our dogs to range, she went direct to the spot where the
bird fell, found and fetched it to my friend’s feet. This happened in
August, 1825.
The setter ranges with great speed, and is a very hardy dog. Many
prefer him to the pointer, and if water is plentiful, he is certainly
more useful, for his feet are much better defended against the sharp
cutting of the heath than those of the pointer, as he has a great deal
of hair growing between the toes and round the ball of the foot, of
which the latter is almost destitute. Besides, he unquestionably
ranges much faster, and can endure much more fatigue. He can also
serve in thick coverts, where a pointer will not enter; and, on this
account, is useful in woodcock shooting, where springers or cockers
are not kept.
Formerly the setter was used for the purpose of taking partridges
with a draw-net, and was generally taught to squat down when the
game was within a proper distance—hence the name setter. They
are now, however, trained to point in the same manner as the
spaniel. It is said that Robert Dudley, Duke of Northumberland, was
the first person who broke a setter to the net.
There is not a country in Europe that can boast of finer setters than
Ireland; they are there called English spaniels, and differ widely from
the setters of England and Scotland. They are not esteemed in
Ireland unless their colour be either a deep chestnut and white, or
all red; a black and white setter, or any colour but red, or red and
white, would not be looked upon or reputed well bred, allowing
them to be ever so good. It matters not whether they are all red, or
red and white; but those esteemed most have a black nose, and a
black roof to their mouth,—as most sportsmen conceive the black
nose to be finer and superior to any other. Sir William Barker, Mr.
Oliver of Castle Oliver, Mr. Macarthy of Spring House, and many
other gentlemen in Ireland, have the most beautiful and steady of
this kind. A circumstance occurred, with respect to the steadiness
and discipline of some of this breed, which the compiler was an eye-
witness to:—Colonel Macdonald being on a visit at Mr. Oliver’s,
during the grousing season, and going out one day, took out with
him five brace of setters; on getting to the mountains, one of the
dogs found some birds, all the rest backed in at once, upon which
Colonel Macdonald called to the last dog to take the lead, and in that
manner he drew the dogs alternately, until the last became first, and
fixed the birds, which had run nearly a mile. These dogs in general
fetch a long price; Mr. Macarthy got two hundred guineas for a brace
of them, and a gentleman in the north of Ireland was known once to
have given, for a dog and bitch of this sort, to his tenant, the
renewal of a lease of a farm for nine hundred and ninety-nine years,
which if this lease had expired, would have cleared to the landlord
above two hundred and fifty pounds a year. The compiler himself
sold a brace of setters, in the year 1801, for two hundred guineas,
to a Captain Baggot.—Brown—Thornhill.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com