Difference between revisions of "Programs"
(→Python) |
(CairoSVG workaround documentation) |
||
(16 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{langs|en=Programs|ru=Программирование}} | {{langs|en=Programs|ru=Программирование}} | ||
− | |||
− | + | = Printing = | |
+ | My most significant contributions to free software are patches to Ghostscript. Ghostscript is a software suite built around a PostScript interpreter. It is a central part of the Common Unix Printing System (CUPS). Every GNU/Linux system that can print has Ghostscript installed. Ghostscript is also used for file format conversion. Although my patches are only a small part of the Ghostscript code base, and Ghostscript is just one of the thousands of programs that comprise GNU/Linux, out of all my programs, these are the ones that benefit the most people. | ||
− | == | + | The [https://bugs.ghostscript.com/attachment.cgi?id=14053&action=diff patch] for bug [https://bugs.ghostscript.com/show_bug.cgi?id=690595 690595] improves the efficiency of the spooling subsystem. When the document mixes black-and-white and color pages, all pages were sent to the spooler as uncompressed true color bitmaps. This patch recognizes images with few colors and reduces their color depth, if possible. |
+ | The [https://bugs.ghostscript.com/attachment.cgi?id=13996&action=diff patch] for bug [https://bugs.ghostscript.com/show_bug.cgi?id=689451 689451] addresses a special case of arc rendering, when the arc is so big that it overflows the fixed point numbers used in the graphic library. The patch allows the arc to be replaced with a polyline of no more than 9 segments, thus preserving its visual appearance. This line can be further clipped by the graphic library. Although this case may seem artificial, it does occur in practice when an artist draws an arc through 3 points and the points are almost collinear. | ||
+ | |||
+ | The [https://bugs.ghostscript.com/attachment.cgi?id=13268&action=diff patch] for bug [https://bugs.ghostscript.com/show_bug.cgi?id=696302 696302] | ||
+ | makes a simple user interface improvement: The GL version of the muPDF viewer can now be controlled using the arrow keys. | ||
+ | |||
+ | The [https://bugs.ghostscript.com/attachment.cgi?id=13268&action=diff patch] for bug [https://bugs.ghostscript.com/show_bug.cgi?id=696520 696520] | ||
+ | fixes a case of bit rot. The old contributed drivers were not updated when the call pattern changed. | ||
+ | |||
+ | Ghostscript is a living program and its maintenance work continues. | ||
+ | |||
+ | = Research = | ||
+ | |||
+ | I've also been working on a few research projects. | ||
+ | |||
+ | == Strongly Regular Graph Search == | ||
+ | |||
+ | I've been searching for a strongly regular graph. I'd started with a [http://www.mathmoth.org/programs/conway99/one-edge.c simple edge-by-edge search], added client-[http://www.mathmoth.org/programs/conway99/server.c server] functionality to allow for distributed computing, and then [http://www.mathmoth.org/programs/conway99/srg2opb.c delegated] the job to dedicated pseudo-SAT solvers. | ||
+ | |||
+ | == Search for Halftone == | ||
+ | |||
+ | I'm searching for an improved set of kernels for error diffusion. To do this, one must be able to gauge the quality of a halftone. One way to do this is to check the power spectrum of a flat, dithered gray square. I wrote [http://www.mathmoth.org/programs/stoh/pnm-to-fft.c a program] which uses a FFT library to take the power spectrum of a PPM image of this kind. However, some dithers may have obvious artifacts caused by starting with no error on every cell at the top row, especially for gray levels that are very sparse (either very dark or very light). Thus, to give such dithers a fair advantage, I first dither a rectangle, then use [http://www.mathmoth.org/programs/stoh/pnm-select.c a program] to cut off the top to make a square. A good dither's artifacts should thus be removed. I've actually written [http://www.mathmoth.org/programs/stoh/search-halftone.c one unified program] to do all this all at once. | ||
+ | |||
+ | = Fun = | ||
+ | |||
+ | Of course, one can't work all the time. Here are some programs made just for fun, and to relax. | ||
== Sudoku solver == | == Sudoku solver == | ||
− | My teacher | + | My first program; back then, my teacher considered solving Sudoku puzzles as advanced math. Not being advanced at math yet, I outsourced this job to a computer. [http://www.mathmoth.org/programs/sudoku/desud.c The program] uses an efficient representation of a Sudoku puzzle and a simple backtracking algorithm. |
+ | == PDP-11 Games == | ||
+ | |||
+ | Before the era of widespread game consoles, people found ways to entertain themselves. The few who had computers made a few simple yet captivating text-based games. Now that retro gaming is becoming widespread, there is an excellent opportunity to bring these games back. Since almost nobody has a PDP-11 available nowadays, I have ported the best to Python and ncurses. They run on Linux and Mac OS, and under Windows with cygwin. They do not work on stock Windows because it does not have ncurses. The games are hosted [https://savannah.nongnu.org/projects/pdp11games/ on Savannah], but I have download links below as well. | ||
+ | |||
+ | === Super Pacman === | ||
+ | |||
+ | A pacman game. You dodge ghosts, eat dots, and eat ghosts if you have a power pellet. It has a scoreboard and ramping difficulty, and was the most popular of the games and the one I did first. | ||
+ | The code is somewhat object oriented; the main loop polls all the objects in the game and has them do the appropriate actions. Download it [http://www.mathmoth.org/programs/pdp11games/sp21 here]. | ||
+ | |||
+ | === Xonix === | ||
+ | A came about staking out bits of area while dodging ghosts. Claim enough area to move onto the next level. It uses a recursive flood fill algorithm to find what area you claimed. Thus, it requires a larger stack than Python allocates by default. Download it [http://www.mathmoth.org/programs/pdp11games/xonix here]. | ||
+ | |||
+ | === Mars War === | ||
+ | A simpler game. Fend off martians and protect your own troops. It presents an initial dialog to set the difficulty mode,adjusting the number of martians, their amount of movement and your launcher's defense capabilities. The code is quite object-oriented, with every sprite being an object. A good implementation would use a priority queue, but merely polling all the objects turned out to be sufficient. | ||
+ | The original was probably written in a high-level language, because there are numerous variations. I've implemented an unified variant, taking the best parts of all I could find. Download it [http://www.mathmoth.org/programs/pdp11games/marswar here]. | ||
+ | |||
+ | == Display Hacks == | ||
+ | |||
+ | Making display hacks, programs to make pretty pictures, is fun; I've made a few. There's a classic display hack, [http://www.mathmoth.org/programs/displayhacks/munch munching squares], which fills the screen with an animated plot of X XOR Y using truecolor SGR codes, a [http://www.mathmoth.org/programs/displayhacks/pastelmunching more colorful version], which does the same thing but manipulates hue instead of brightness, thus filling the screen with shifting color, a [http://www.mathmoth.org/programs/displayhacks/lolcat re-implementation] of [https://github.com/busyloop/lolcat lolcat] (which applies a rainbow effect to standard input) that is aware of line wrapping and uses truecolor, and a [http://www.mathmoth.org/programs/displayhacks/pseudorender general-purpose multi-mode feature-creeped pseudo-graphic image renderer], which uses an improved halftone based on my own set of kernels. | ||
+ | |||
+ | == Historic Font == | ||
+ | |||
+ | [http://www.mathmoth.org/programs/DigiPlot/DigiPlot This font] has been adapted from character paths designed by Igor Melichev's team for a Digigraph pen plotter circa 1987. The main goal of this program is preservation of computer history but you are free to use it for any purpose according to GNU GPL. Feel free to contact me if you intend to use this file and need any changes. | ||
== 1966 Snoopy Calendar == | == 1966 Snoopy Calendar == | ||
− | [http://www-users.cs.york.ac.uk/susan/joke/quiche.htm Everybody knows] that | + | [http://www-users.cs.york.ac.uk/susan/joke/quiche.htm Everybody knows] that a real programmer |
− | + | ||
doesn't use [http://www.lysator.liu.se/c/bwk-on-pascal.html Pascal], | doesn't use [http://www.lysator.liu.se/c/bwk-on-pascal.html Pascal], | ||
+ | can write a [http://jerz.setonhill.edu/if/crowther/advf4.77-03-31 5-page loop] without being confused, | ||
and has a 1966 Snoopy Calendar on the wall. | and has a 1966 Snoopy Calendar on the wall. | ||
− | The works | + | The works of real programmers are still with us to cherish and imitate. But where's the calendar? |
− | + | This [http://www.mathmoth.org/programs/snoopy/snoopy.pl.txt CGI script] recreates the famous calendar from the mainframe era, | |
− | This [ | + | |
which is also valid for the given year. Print the calendar and keep it on the wall. | which is also valid for the given year. Print the calendar and keep it on the wall. | ||
− | It will be useful again in the coming years. | + | It will be useful again and again in the coming years. |
+ | <htmlet>snoopy</htmlet> | ||
+ | |||
+ | == Python one-liners== | ||
+ | Python is a powerful and expressive language, but many people object to its choice to denote program structure by indentation. Yet there's an elegant solution to this dilemma. [[One-line Python programs | A one-line Python program]] can solve any problem. | ||
− | + | = Hacks = | |
+ | == CairoSVG == | ||
+ | Matplotlib's SVGs are too complex for LibreOffice to import, as they rely on CSS style objects. This is a known bug, and it is in the bug tracker as [https://bugs.documentfoundation.org/show_bug.cgi?id=94765 Bug 94765]. So far, nothing has been done about it; thus, a workaround needs to be employed. Of course, you can go through the SVG by hand and move the styles, but this is slow and prone to errors. Most SVG optimizers also assume that your SVG viewer is intelligent and can handle advanced features, instead opting to golf down the file syntactically. | ||
− | + | This is where CairoSVG comes in. It is a tool which takes an SVG and renders it into a PDF, PostScript program, PNG, or another SVG. Notably, when converting from SVG to SVG, the resulting SVG renders almost always identically, but is structured as a single, flat group of styled paths, which even the simplest SVG viewer should be able to make sense of. This includes LibreOffice's renderer. | |
− | + |
Latest revision as of 01:28, 2 November 2017
English Russian
Contents
Printing
My most significant contributions to free software are patches to Ghostscript. Ghostscript is a software suite built around a PostScript interpreter. It is a central part of the Common Unix Printing System (CUPS). Every GNU/Linux system that can print has Ghostscript installed. Ghostscript is also used for file format conversion. Although my patches are only a small part of the Ghostscript code base, and Ghostscript is just one of the thousands of programs that comprise GNU/Linux, out of all my programs, these are the ones that benefit the most people.
The patch for bug 690595 improves the efficiency of the spooling subsystem. When the document mixes black-and-white and color pages, all pages were sent to the spooler as uncompressed true color bitmaps. This patch recognizes images with few colors and reduces their color depth, if possible.
The patch for bug 689451 addresses a special case of arc rendering, when the arc is so big that it overflows the fixed point numbers used in the graphic library. The patch allows the arc to be replaced with a polyline of no more than 9 segments, thus preserving its visual appearance. This line can be further clipped by the graphic library. Although this case may seem artificial, it does occur in practice when an artist draws an arc through 3 points and the points are almost collinear.
The patch for bug 696302 makes a simple user interface improvement: The GL version of the muPDF viewer can now be controlled using the arrow keys.
The patch for bug 696520 fixes a case of bit rot. The old contributed drivers were not updated when the call pattern changed.
Ghostscript is a living program and its maintenance work continues.
Research
I've also been working on a few research projects.
Strongly Regular Graph Search
I've been searching for a strongly regular graph. I'd started with a simple edge-by-edge search, added client-server functionality to allow for distributed computing, and then delegated the job to dedicated pseudo-SAT solvers.
Search for Halftone
I'm searching for an improved set of kernels for error diffusion. To do this, one must be able to gauge the quality of a halftone. One way to do this is to check the power spectrum of a flat, dithered gray square. I wrote a program which uses a FFT library to take the power spectrum of a PPM image of this kind. However, some dithers may have obvious artifacts caused by starting with no error on every cell at the top row, especially for gray levels that are very sparse (either very dark or very light). Thus, to give such dithers a fair advantage, I first dither a rectangle, then use a program to cut off the top to make a square. A good dither's artifacts should thus be removed. I've actually written one unified program to do all this all at once.
Fun
Of course, one can't work all the time. Here are some programs made just for fun, and to relax.
Sudoku solver
My first program; back then, my teacher considered solving Sudoku puzzles as advanced math. Not being advanced at math yet, I outsourced this job to a computer. The program uses an efficient representation of a Sudoku puzzle and a simple backtracking algorithm.
PDP-11 Games
Before the era of widespread game consoles, people found ways to entertain themselves. The few who had computers made a few simple yet captivating text-based games. Now that retro gaming is becoming widespread, there is an excellent opportunity to bring these games back. Since almost nobody has a PDP-11 available nowadays, I have ported the best to Python and ncurses. They run on Linux and Mac OS, and under Windows with cygwin. They do not work on stock Windows because it does not have ncurses. The games are hosted on Savannah, but I have download links below as well.
Super Pacman
A pacman game. You dodge ghosts, eat dots, and eat ghosts if you have a power pellet. It has a scoreboard and ramping difficulty, and was the most popular of the games and the one I did first. The code is somewhat object oriented; the main loop polls all the objects in the game and has them do the appropriate actions. Download it here.
Xonix
A came about staking out bits of area while dodging ghosts. Claim enough area to move onto the next level. It uses a recursive flood fill algorithm to find what area you claimed. Thus, it requires a larger stack than Python allocates by default. Download it here.
Mars War
A simpler game. Fend off martians and protect your own troops. It presents an initial dialog to set the difficulty mode,adjusting the number of martians, their amount of movement and your launcher's defense capabilities. The code is quite object-oriented, with every sprite being an object. A good implementation would use a priority queue, but merely polling all the objects turned out to be sufficient. The original was probably written in a high-level language, because there are numerous variations. I've implemented an unified variant, taking the best parts of all I could find. Download it here.
Display Hacks
Making display hacks, programs to make pretty pictures, is fun; I've made a few. There's a classic display hack, munching squares, which fills the screen with an animated plot of X XOR Y using truecolor SGR codes, a more colorful version, which does the same thing but manipulates hue instead of brightness, thus filling the screen with shifting color, a re-implementation of lolcat (which applies a rainbow effect to standard input) that is aware of line wrapping and uses truecolor, and a general-purpose multi-mode feature-creeped pseudo-graphic image renderer, which uses an improved halftone based on my own set of kernels.
Historic Font
This font has been adapted from character paths designed by Igor Melichev's team for a Digigraph pen plotter circa 1987. The main goal of this program is preservation of computer history but you are free to use it for any purpose according to GNU GPL. Feel free to contact me if you intend to use this file and need any changes.
1966 Snoopy Calendar
Everybody knows that a real programmer doesn't use Pascal, can write a 5-page loop without being confused, and has a 1966 Snoopy Calendar on the wall. The works of real programmers are still with us to cherish and imitate. But where's the calendar? This CGI script recreates the famous calendar from the mainframe era, which is also valid for the given year. Print the calendar and keep it on the wall. It will be useful again and again in the coming years.
Python one-liners
Python is a powerful and expressive language, but many people object to its choice to denote program structure by indentation. Yet there's an elegant solution to this dilemma. A one-line Python program can solve any problem.
Hacks
CairoSVG
Matplotlib's SVGs are too complex for LibreOffice to import, as they rely on CSS style objects. This is a known bug, and it is in the bug tracker as Bug 94765. So far, nothing has been done about it; thus, a workaround needs to be employed. Of course, you can go through the SVG by hand and move the styles, but this is slow and prone to errors. Most SVG optimizers also assume that your SVG viewer is intelligent and can handle advanced features, instead opting to golf down the file syntactically.
This is where CairoSVG comes in. It is a tool which takes an SVG and renders it into a PDF, PostScript program, PNG, or another SVG. Notably, when converting from SVG to SVG, the resulting SVG renders almost always identically, but is structured as a single, flat group of styled paths, which even the simplest SVG viewer should be able to make sense of. This includes LibreOffice's renderer.