Selaa lähdekoodia

* Optimised for speed and space, fixed a few bugs, and improved coding style

in the PS exporter (vieux porc !).
tags/v0.99.beta14
Sam Hocevar sam 19 vuotta sitten
vanhempi
commit
e48078c585
1 muutettua tiedostoa jossa 57 lisäystä ja 77 poistoa
  1. +57
    -77
      cucul/export_ps.c

+ 57
- 77
cucul/export_ps.c Näytä tiedosto

@@ -10,7 +10,7 @@
*/ */


/** \file export.c /** \file export.c
* \version \$Id: export_irc.c 384 2006-03-13 18:07:35Z sam $ * \version \$Id$
* \author Sam Hocevar <sam@zoy.org> * \author Sam Hocevar <sam@zoy.org>
* \author Jean-Yves Lamoureux <jylam@lnxscene.org> * \author Jean-Yves Lamoureux <jylam@lnxscene.org>
* \brief Export function * \brief Export function
@@ -30,29 +30,30 @@
#include "cucul_internals.h" #include "cucul_internals.h"


static char const *ps_header = static char const *ps_header =
"%%! \n" //"%!PS-Adobe-2.0\n"
"%%%% libcaca PDF export \n" "%!\n"
"%%%%LanguageLevel: 2 \n" "%% libcaca PDF export\n"
"%%%%Pages: 1 \n" "%%LanguageLevel: 2\n"
"%%%%DocumentData: Clean7Bit \n" "%%Pages: 1\n"
"/csquare { \n" "%%DocumentData: Clean7Bit\n"
" newpath \n" "/csquare {\n"
" 0 0 moveto \n" " newpath\n"
" 0 1 rlineto \n" " 0 0 moveto\n"
" 1 0 rlineto \n" " 0 1 rlineto\n"
" 0 -1 rlineto \n" " 1 0 rlineto\n"
" closepath \n" " 0 -1 rlineto\n"
" setrgbcolor \n" " closepath\n"
" fill \n" " setrgbcolor\n"
"} def \n" " fill\n"
"/S { \n" "} def\n"
" Show \n" "/S {\n"
"} bind def \n" " Show\n"
"/Courier-Bold findfont \n" "} bind def\n"
"8 scalefont \n" "/Courier-Bold findfont\n"
"8 scalefont\n"
"setfont\n" "setfont\n"
"gsave \n" "gsave\n"
"6 10 scale \n"; "6 10 scale\n";


/** \brief Generate Postscript representation of current image. /** \brief Generate Postscript representation of current image.
* *
@@ -61,31 +62,17 @@ static char const *ps_header =
*/ */
void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex) void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex)
{ {
char *cur; static char const * const palette[] =
int x, y; {

"0.0 0.0 0.0", "0.0 0.0 0.5", "0.0 0.5 0.0", "0.0 0.5 0.5",
static float const paletteR[] = "0.5 0.0 0.0", "0.5 0.0 0.5", "0.5 0.5 0.0", "0.5 0.5 0.5",
{ "0.2 0.2 0.2", "0.2 0.2 1.0", "0.2 1.0 0.2", "0.2 1.0 1.0",
0, 0, 0, 0, "1.0 0.2 0.2", "1.0 0.2 1.0", "1.0 1.0 0.2", "1.0 1.0 1.0",
0.5, 0.5, 0.5, 0.5, };
0.5, 0.5, 0.5, 0.5,
1.0, 1.0, 1.0, 1.0,
};
static float const paletteG[] =
{
0, 0, 0.5, 0.5,
0, 0, 0.5, 0.5,
0, 0, 1.0, 1.0,
0, 0, 1.0, 1.0,
};
static float const paletteB[] =
{
0, 0.5, 0, 0.5,
0, 0.5, 0, 0.5,
0, 1.0, 0.5, 1.0,
0, 1.0, 0, 1.0,
};


char *cur;
unsigned int x, y;


/* 200 is arbitrary but should be ok */ /* 200 is arbitrary but should be ok */
ex->size = strlen(ps_header) + (qq->width * qq->height * 200); ex->size = strlen(ps_header) + (qq->width * qq->height * 200);
@@ -97,48 +84,41 @@ void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex)
cur += sprintf(cur, "%s", ps_header); cur += sprintf(cur, "%s", ps_header);


/* Background, drawn using csquare macro defined in header */ /* Background, drawn using csquare macro defined in header */
for(y=(int)(qq->height-1);y>=0; y--) { for(y = qq->height; y--; )
{
uint8_t *lineattr = qq->attr + y * qq->width; uint8_t *lineattr = qq->attr + y * qq->width;


for(x = 0; x < (int)qq->width; x++) { for(x = 0; x < qq->width; x++)
float bgR = paletteR[lineattr[x] >> 4]; {
float bgG = paletteG[lineattr[x] >> 4]; cur += sprintf(cur, "1 0 translate\n %s csquare\n",
float bgB = paletteB[lineattr[x] >> 4]; palette[*lineattr++ >> 4]);

}

cur += sprintf(cur, "1 0 translate \n %f %f %f csquare\n", bgR, bgG, bgB);
}

/* Return to beginning of the line, and jump to the next one */
cur += sprintf(cur, "%d 1 translate \n", -qq->width);



/* Return to beginning of the line, and jump to the next one */
cur += sprintf(cur, "-%d 1 translate\n", qq->width);
} }


cur += sprintf(cur, "grestore\n"); // Restore normal transformation matrix cur += sprintf(cur, "grestore\n"); /* Restore transformation matrix */
for(y=(int)(qq->height-1);y>=0; y--) {
uint8_t *lineattr = qq->attr + y * qq->width;
uint32_t *linechar = qq->chars + y * qq->width;

for(x = 0; x < (int)qq->width; x++) {
uint32_t cR = linechar[x];
float fgR = paletteR[lineattr[x] & 0x0f];
float fgG = paletteG[lineattr[x] & 0x0f];
float fgB = paletteB[lineattr[x] & 0x0f];


cur += sprintf(cur, "newpath\n%d %d moveto\n", (x+1)*6, (y)*10); for(y = qq->height; y--; )
cur += sprintf(cur, "%f %f %f setrgbcolor\n", fgR, fgG, fgB); {
cur += sprintf(cur, "(%c) show\n", cR); uint8_t *lineattr = qq->attr + y * qq->width;
uint32_t *linechar = qq->chars + y * qq->width;


} for(x = 0; x < qq->width; x++)
{
cur += sprintf(cur, "newpath\n");
cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10);
cur += sprintf(cur, "%s setrgbcolor\n",
palette[*lineattr++ & 0x0f]);
cur += sprintf(cur, "(%c) show\n", *linechar++ & 0x7f);
}
} }



cur += sprintf(cur, "showpage\n");
cur += sprintf(cur, "showpage");


/* Crop to really used size */ /* Crop to really used size */
ex->size = strlen(ex->buffer) + 1; ex->size = strlen(ex->buffer) + 1;
ex->buffer = realloc(ex->buffer, ex->size); ex->buffer = realloc(ex->buffer, ex->size);

} }



||||||
x
 
000:0
Ladataan…
Peruuta
Tallenna