Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bc7b393
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.o | ||
/Makefile | ||
/Makefile.in | ||
/aclocal.m4 | ||
/autom4te.cache/ | ||
/build-aux/ | ||
/config.cache | ||
/config.h | ||
/config.h.in | ||
/config.log | ||
/config.status | ||
/configure | ||
/stamp-h1 | ||
/pixels2pgf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright (c) 2012, Michał Górny | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bin_PROGRAMS = pixels2pgf | ||
|
||
pixels2pgf_SOURCES = src/pixels2pgf.c | ||
pixels2pgf_CPPFLAGS = $(SDL_CFLAGS) | ||
pixels2pgf_LDADD = $(SDL_LIBS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AC_PREREQ([2.60]) | ||
AC_INIT([pixels2pgf], [0]) | ||
AC_CONFIG_AUX_DIR([build-aux]) | ||
AM_INIT_AUTOMAKE([1.6 foreign dist-bzip2 no-dependencies]) | ||
|
||
PKG_CHECK_MODULES([SDL], [sdl SDL_image]) | ||
|
||
AC_PROG_CC | ||
|
||
AC_CONFIG_HEADERS([config.h]) | ||
AC_CONFIG_FILES([Makefile]) | ||
AC_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* pixels2pgf -- pixel-exact image to PGF converter | ||
* (c) 2012 Michał Górny | ||
* Released under the terms of the 2-clause BSD license | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include <SDL.h> | ||
#include <SDL_image.h> | ||
|
||
void output_pgf(unsigned char* pixels, int width, int height, int pitch) | ||
{ | ||
int y, x; | ||
|
||
for (y = 0; y < height; ++y) | ||
{ | ||
for (x = 0; x < width; ++x) | ||
{ | ||
unsigned char pixel = pixels[y * pitch + x]; | ||
|
||
if (!(pixel & 0xBF)) | ||
printf("\\filldraw (%d, -%d) rectangle ++(1, -1);\n", x, y); | ||
} | ||
} | ||
} | ||
|
||
int process(SDL_Surface* input) | ||
{ | ||
SDL_PixelFormat nicepf = { | ||
NULL, | ||
8, 1, | ||
0, 2, 4, 6, | ||
6, 6, 6, 6, | ||
0x03, 0x0C, 0x30, 0xC0, | ||
0xC0, 0 | ||
}; | ||
|
||
SDL_Surface* image; | ||
|
||
if (!input) | ||
{ | ||
fprintf(stderr, "Failed to load image: %s\n", IMG_GetError()); | ||
return 1; | ||
} | ||
|
||
/* Convert to a nicer format. */ | ||
image = SDL_ConvertSurface(input, &nicepf, SDL_SWSURFACE); | ||
SDL_FreeSurface(input); | ||
|
||
if (!image) | ||
{ | ||
fprintf(stderr, "Unable to convert image: %s\n", | ||
SDL_GetError()); | ||
return 1; | ||
} | ||
|
||
output_pgf(image->pixels, image->w, image->h, image->pitch); | ||
|
||
SDL_FreeSurface(image); | ||
return 0; | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
int ret; | ||
|
||
if (argc != 2) | ||
{ | ||
fprintf(stderr, "Usage: %s <file>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
if (SDL_Init(0)) | ||
{ | ||
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); | ||
return 1; | ||
} | ||
IMG_Init(0); | ||
|
||
ret = process(IMG_Load(argv[1])); | ||
|
||
IMG_Quit(); | ||
SDL_Quit(); | ||
|
||
return ret; | ||
} |