Changeset 634 for libcaca/trunk
- Timestamp:
- Mar 16, 2006, 7:09:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/export_ps.c
-
Property
svn:keywords
set to
Id
r620 r634 11 11 12 12 /** \file export.c 13 * \version \$Id : export_irc.c 384 2006-03-13 18:07:35Z sam$13 * \version \$Id$ 14 14 * \author Sam Hocevar <sam@zoy.org> 15 15 * \author Jean-Yves Lamoureux <jylam@lnxscene.org> … … 31 31 32 32 static char const *ps_header = 33 "%%! \n" 34 "%%%% libcaca PDF export \n" 35 "%%%%LanguageLevel: 2 \n" 36 "%%%%Pages: 1 \n" 37 "%%%%DocumentData: Clean7Bit \n" 38 "/csquare { \n" 39 " newpath \n" 40 " 0 0 moveto \n" 41 " 0 1 rlineto \n" 42 " 1 0 rlineto \n" 43 " 0 -1 rlineto \n" 44 " closepath \n" 45 " setrgbcolor \n" 46 " fill \n" 47 "} def \n" 48 "/S { \n" 49 " Show \n" 50 "} bind def \n" 51 "/Courier-Bold findfont \n" 52 "8 scalefont \n" 33 //"%!PS-Adobe-2.0\n" 34 "%!\n" 35 "%% libcaca PDF export\n" 36 "%%LanguageLevel: 2\n" 37 "%%Pages: 1\n" 38 "%%DocumentData: Clean7Bit\n" 39 "/csquare {\n" 40 " newpath\n" 41 " 0 0 moveto\n" 42 " 0 1 rlineto\n" 43 " 1 0 rlineto\n" 44 " 0 -1 rlineto\n" 45 " closepath\n" 46 " setrgbcolor\n" 47 " fill\n" 48 "} def\n" 49 "/S {\n" 50 " Show\n" 51 "} bind def\n" 52 "/Courier-Bold findfont\n" 53 "8 scalefont\n" 53 54 "setfont\n" 54 "gsave 55 "6 10 scale 55 "gsave\n" 56 "6 10 scale\n"; 56 57 57 58 /** \brief Generate Postscript representation of current image. … … 62 63 void _cucul_get_ps(cucul_t *qq, struct cucul_buffer *ex) 63 64 { 65 static char const * const palette[] = 66 { 67 "0.0 0.0 0.0", "0.0 0.0 0.5", "0.0 0.5 0.0", "0.0 0.5 0.5", 68 "0.5 0.0 0.0", "0.5 0.0 0.5", "0.5 0.5 0.0", "0.5 0.5 0.5", 69 70 "0.2 0.2 0.2", "0.2 0.2 1.0", "0.2 1.0 0.2", "0.2 1.0 1.0", 71 "1.0 0.2 0.2", "1.0 0.2 1.0", "1.0 1.0 0.2", "1.0 1.0 1.0", 72 }; 73 64 74 char *cur; 65 int x, y; 66 67 static float const paletteR[] = 68 { 69 0, 0, 0, 0, 70 0.5, 0.5, 0.5, 0.5, 71 0.5, 0.5, 0.5, 0.5, 72 1.0, 1.0, 1.0, 1.0, 73 }; 74 static float const paletteG[] = 75 { 76 0, 0, 0.5, 0.5, 77 0, 0, 0.5, 0.5, 78 0, 0, 1.0, 1.0, 79 0, 0, 1.0, 1.0, 80 }; 81 static float const paletteB[] = 82 { 83 0, 0.5, 0, 0.5, 84 0, 0.5, 0, 0.5, 85 0, 1.0, 0.5, 1.0, 86 0, 1.0, 0, 1.0, 87 }; 88 75 unsigned int x, y; 89 76 90 77 /* 200 is arbitrary but should be ok */ … … 98 85 99 86 /* Background, drawn using csquare macro defined in header */ 100 for(y=(int)(qq->height-1);y>=0; y--) { 87 for(y = qq->height; y--; ) 88 { 101 89 uint8_t *lineattr = qq->attr + y * qq->width; 102 90 103 for(x = 0; x < (int)qq->width; x++) { 104 float bgR = paletteR[lineattr[x] >> 4]; 105 float bgG = paletteG[lineattr[x] >> 4]; 106 float bgB = paletteB[lineattr[x] >> 4]; 91 for(x = 0; x < qq->width; x++) 92 { 93 cur += sprintf(cur, "1 0 translate\n %s csquare\n", 94 palette[*lineattr++ >> 4]); 95 } 107 96 108 109 cur += sprintf(cur, "1 0 translate \n %f %f %f csquare\n", bgR, bgG, bgB); 110 } 111 112 /* Return to beginning of the line, and jump to the next one */ 113 cur += sprintf(cur, "%d 1 translate \n", -qq->width); 114 115 97 /* Return to beginning of the line, and jump to the next one */ 98 cur += sprintf(cur, "-%d 1 translate\n", qq->width); 116 99 } 117 100 118 cur += sprintf(cur, "grestore\n"); // Restore normal transformation matrix 119 for(y=(int)(qq->height-1);y>=0; y--) { 120 uint8_t *lineattr = qq->attr + y * qq->width; 101 cur += sprintf(cur, "grestore\n"); /* Restore transformation matrix */ 102 103 for(y = qq->height; y--; ) 104 { 105 uint8_t *lineattr = qq->attr + y * qq->width; 121 106 uint32_t *linechar = qq->chars + y * qq->width; 122 107 123 for(x = 0; x < (int)qq->width; x++) { 124 uint32_t cR = linechar[x]; 125 float fgR = paletteR[lineattr[x] & 0x0f]; 126 float fgG = paletteG[lineattr[x] & 0x0f]; 127 float fgB = paletteB[lineattr[x] & 0x0f]; 128 129 cur += sprintf(cur, "newpath\n%d %d moveto\n", (x+1)*6, (y)*10); 130 cur += sprintf(cur, "%f %f %f setrgbcolor\n", fgR, fgG, fgB); 131 cur += sprintf(cur, "(%c) show\n", cR); 132 133 } 108 for(x = 0; x < qq->width; x++) 109 { 110 cur += sprintf(cur, "newpath\n"); 111 cur += sprintf(cur, "%d %d moveto\n", (x + 1) * 6, y * 10); 112 cur += sprintf(cur, "%s setrgbcolor\n", 113 palette[*lineattr++ & 0x0f]); 114 cur += sprintf(cur, "(%c) show\n", *linechar++ & 0x7f); 115 } 134 116 } 135 117 136 137 cur += sprintf(cur, "showpage"); 118 cur += sprintf(cur, "showpage\n"); 138 119 139 120 /* Crop to really used size */ 140 121 ex->size = strlen(ex->buffer) + 1; 141 122 ex->buffer = realloc(ex->buffer, ex->size); 142 143 123 } 144 124 -
Property
svn:keywords
set to
Note: See TracChangeset
for help on using the changeset viewer.