40 #include <sys/types.h>
45 #if defined(GL2PS_HAVE_ZLIB)
49 #if defined(GL2PS_HAVE_LIBPNG)
62 #define GL2PS_EPSILON 5.0e-3F
63 #define GL2PS_ZSCALE 1000.0F
64 #define GL2PS_ZOFFSET 5.0e-2F
65 #define GL2PS_ZOFFSET_LARGE 20.0F
66 #define GL2PS_ZERO(arg) (fabs(arg) < 1.e-20)
70 #define GL2PS_NO_TYPE -1
74 #define GL2PS_QUADRANGLE 4
75 #define GL2PS_TRIANGLE 5
76 #define GL2PS_PIXMAP 6
77 #define GL2PS_IMAGEMAP 7
78 #define GL2PS_IMAGEMAP_WRITTEN 8
79 #define GL2PS_IMAGEMAP_VISIBLE 9
80 #define GL2PS_SPECIAL 10
84 #define GL2PS_COINCIDENT 1
85 #define GL2PS_IN_FRONT_OF 2
86 #define GL2PS_IN_BACK_OF 3
87 #define GL2PS_SPANNING 4
91 #define GL2PS_POINT_COINCIDENT 0
92 #define GL2PS_POINT_INFRONT 1
93 #define GL2PS_POINT_BACK 2
97 #define GL2PS_BEGIN_OFFSET_TOKEN 1
98 #define GL2PS_END_OFFSET_TOKEN 2
99 #define GL2PS_BEGIN_BOUNDARY_TOKEN 3
100 #define GL2PS_END_BOUNDARY_TOKEN 4
101 #define GL2PS_BEGIN_STIPPLE_TOKEN 5
102 #define GL2PS_END_STIPPLE_TOKEN 6
103 #define GL2PS_POINT_SIZE_TOKEN 7
104 #define GL2PS_LINE_WIDTH_TOKEN 8
105 #define GL2PS_BEGIN_BLEND_TOKEN 9
106 #define GL2PS_END_BLEND_TOKEN 10
107 #define GL2PS_SRC_BLEND_TOKEN 11
108 #define GL2PS_DST_BLEND_TOKEN 12
109 #define GL2PS_IMAGEMAP_TOKEN 13
110 #define GL2PS_DRAW_PIXELS_TOKEN 14
111 #define GL2PS_TEXT_TOKEN 15
195 #if defined(GL2PS_HAVE_ZLIB)
196 Bytef *dest, *src, *start;
197 uLongf destLen, srcLen;
211 GLint format,
sort, options, colorsize, colormode, buffersize;
214 GLfloat *feedback, offset[2], lastlinewidth;
215 GLint viewport[4], blendfunc[2], lastfactor;
250 void (*printHeader)(void);
251 void (*printFooter)(void);
252 void (*beginViewport)(GLint viewport[4]);
253 GLint (*endViewport)(void);
254 void (*printPrimitive)(
void *data);
255 void (*printFinalPrimitive)(void);
275 static void gl2psMsg(GLint level,
const char *fmt, ...)
281 case GL2PS_INFO : fprintf(stderr,
"GL2PS info: ");
break;
282 case GL2PS_WARNING : fprintf(stderr,
"GL2PS warning: ");
break;
283 case GL2PS_ERROR : fprintf(stderr,
"GL2PS error: ");
break;
286 vfprintf(stderr, fmt, args);
288 fprintf(stderr,
"\n");
297 if(!size)
return NULL;
309 if(!size)
return NULL;
310 ptr = realloc(orig, size);
328 int size =
sizeof(
unsigned long);
329 for(i = 1; i <= bytes; ++i){
330 fputc(0xff & (data >> (size - i) * 8), gl2ps->
stream);
337 #if defined(GL2PS_HAVE_ZLIB)
339 static void gl2psSetupCompress(
void)
349 static void gl2psFreeCompress(
void)
362 static int gl2psAllocCompress(
unsigned int srcsize)
378 static void *gl2psReallocCompress(
unsigned int srcsize)
383 if(srcsize < gl2ps->compress->srcLen)
397 static int gl2psWriteBigEndianCompress(
unsigned long data,
int bytes)
400 int size =
sizeof(
unsigned long);
401 for(i = 1; i <= bytes; ++i){
402 *gl2ps->
compress->src = (Bytef)(0xff & (data >> (size-i) * 8));
408 static int gl2psDeflate(
void)
423 #if defined(GL2PS_HAVE_ZLIB)
424 static char buf[1024];
426 GLboolean freebuf = GL_FALSE;
427 unsigned int oldsize = 0;
428 #if !defined(GL2PS_HAVE_NO_VSNPRINTF)
431 size_t bufsize =
sizeof(buf);
435 #if defined(GL2PS_HAVE_NO_VSNPRINTF)
436 ret = vsprintf(buf, fmt, args);
438 ret = vsnprintf(bufptr, bufsize, fmt, args);
441 #if !defined(GL2PS_HAVE_NO_VSNPRINTF)
442 while(ret >= (bufsize - 1) || ret < 0){
445 if(freebuf == GL_TRUE)
gl2psFree(bufptr);
449 ret = vsnprintf(bufptr, bufsize, fmt, args);
454 gl2ps->
compress->start = (Bytef*)gl2psReallocCompress(oldsize + ret);
455 memcpy(gl2ps->
compress->start + oldsize, bufptr, ret);
456 if(freebuf == GL_TRUE)
gl2psFree(bufptr);
462 ret = vfprintf(gl2ps->
stream, fmt, args);
464 #if defined(GL2PS_HAVE_ZLIB)
472 #if defined(GL2PS_HAVE_ZLIB)
473 char tmp[10] = {
'\x1f',
'\x8b',
481 gl2psSetupCompress();
483 fwrite(tmp, 10, 1, gl2ps->
stream);
490 #if defined(GL2PS_HAVE_ZLIB)
496 if(Z_OK != gl2psDeflate()){
502 if(gl2ps->
compress->dest[1] & (1<<5)){
510 for(n = 0; n < 4; ++n){
511 tmp[n] = (char)(crc & 0xff);
515 for(n = 4; n < 8; ++n){
516 tmp[n] = (char)(len & 0xff);
519 fwrite(tmp, 8, 1, gl2ps->
stream);
555 if(incr <= 0) incr = 1;
587 memcpy(&list->
array[(list->
n - 1) * list->
size], data, list->
size);
603 if((idx < 0) || (idx >= list->
n)){
611 int (*fcmp)(
const void *a,
const void *b))
615 qsort(list->
array, list->
n, list->
size, fcmp);
636 #if defined(GL2PS_HAVE_LIBPNG)
638 static void gl2psListRead(
GL2PSlist *list,
int index,
void *data)
640 if((index < 0) || (index >= list->
n))
645 static void gl2psEncodeBase64Block(
unsigned char in[3],
unsigned char out[4],
int len)
647 static const char cb64[] =
648 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
650 out[0] = cb64[ in[0] >> 2 ];
651 out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
652 out[2] = (len > 1) ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] :
'=';
653 out[3] = (len > 2) ? cb64[ in[2] & 0x3f ] :
'=';
656 static void gl2psListEncodeBase64(
GL2PSlist *list)
658 unsigned char *buffer, in[3], out[4];
659 int i, n, index, len;
661 n = list->
n * list->
size;
662 buffer = (
unsigned char*)
gl2psMalloc(n *
sizeof(
unsigned char));
663 memcpy(buffer, list->
array, n *
sizeof(
unsigned char));
669 for(i = 0; i < 3; i++) {
671 in[i] = buffer[index];
680 gl2psEncodeBase64Block(in, out, len);
681 for(i = 0; i < 4; i++)
705 for(i = 1; i < prim->
numverts; i++){
718 if(n < 2)
return GL_TRUE;
720 for(i = 1; i < n; i++){
721 if(fabs(rgba[0][0] - rgba[i][0]) > threshold[0] ||
722 fabs(rgba[0][1] - rgba[i][1]) > threshold[1] ||
723 fabs(rgba[0][2] - rgba[i][2]) > threshold[2])
733 for(i = 0; i < 3; ++i){
739 GLfloat *red, GLfloat *green, GLfloat *blue)
742 GLsizei width = im->
width;
743 GLsizei height = im->
height;
744 GLfloat *pixels = im->
pixels;
750 pimag = pixels + 4 * (width * (height - 1 - y) + x);
754 pimag = pixels + 3 * (width * (height - 1 - y) + x);
757 *red = *pimag; pimag++;
758 *green = *pimag; pimag++;
759 *blue = *pimag; pimag++;
761 return (im->
format == GL_RGBA) ? *pimag : 1.0F;
780 size = image->
height * image->
width * 4 *
sizeof(GLfloat);
784 size = image->
height * image->
width * 3 *
sizeof(GLfloat);
802 #if defined(GL2PS_HAVE_LIBPNG)
804 #if !defined(png_jmpbuf)
805 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
808 static void gl2psUserWritePNG(png_structp png_ptr, png_bytep data, png_size_t length)
812 for(i = 0; i < length; i++)
816 static void gl2psUserFlushPNG(png_structp png_ptr)
825 unsigned char *row_data;
829 if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
832 if(!(info_ptr = png_create_info_struct(png_ptr))){
833 png_destroy_write_struct(&png_ptr, NULL);
837 if(setjmp(png_jmpbuf(png_ptr))) {
838 png_destroy_write_struct(&png_ptr, &info_ptr);
842 png_set_write_fn(png_ptr, (
void *)png, gl2psUserWritePNG, gl2psUserFlushPNG);
843 png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
844 png_set_IHDR(png_ptr, info_ptr, pixmap->
width, pixmap->
height, 8,
845 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
846 PNG_FILTER_TYPE_BASE);
847 png_write_info(png_ptr, info_ptr);
849 row_data = (
unsigned char*)
gl2psMalloc(3 * pixmap->
width *
sizeof(
unsigned char));
850 for(row = 0; row < pixmap->
height; row++){
851 for(col = 0; col < pixmap->
width; col++){
853 row_data[3*col] = (
unsigned char)(255. * dr);
854 row_data[3*col+1] = (
unsigned char)(255. * dg);
855 row_data[3*col+2] = (
unsigned char)(255. * db);
857 png_write_row(png_ptr, (png_bytep)row_data);
861 png_write_end(png_ptr, info_ptr);
862 png_destroy_write_struct(&png_ptr, &info_ptr);
869 static GLint
gl2psAddText(GLint type,
const char *str,
const char *fontname,
870 GLshort fontsize, GLint alignment, GLfloat angle,
881 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
884 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
887 prim->
type = (GLshort)type;
900 memcpy(prim->
verts[0].
rgba, color, 4 *
sizeof(
float));
902 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->
verts[0].
rgba);
922 strcpy(text->
str, t->
str);
948 if( (sfactor == GL_SRC_ALPHA && dfactor == GL_ONE_MINUS_SRC_ALPHA) ||
949 (sfactor == GL_ONE && dfactor == GL_ZERO) )
1012 GLboolean assignprops)
1017 if(GL_TRUE == assignprops)
1025 for(i = 0; i < 3; i++)
1086 return (plane[0] * point[0] +
1087 plane[1] * point[1] +
1088 plane[2] * point[2] +
1094 return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
1099 c[0] = a[1]*b[2] - a[2]*b[1];
1100 c[1] = a[2]*b[0] - a[0]*b[2];
1101 c[2] = a[0]*b[1] - a[1]*b[0];
1106 return (GLfloat)sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
1130 GL2PSxyz v = {0.0F, 0.0F, 0.0F}, w = {0.0F, 0.0F, 0.0F};
1143 plane[0] = plane[1] = 0.0F;
1152 - plane[2] * prim->
verts[0].
xyz[2];
1160 plane[0] = plane[1] = 0.0F;
1172 - plane[2] * prim->
verts[0].
xyz[2];
1180 plane[0] = plane[1] = 0.0F;
1186 plane[0] = plane[1] = plane[3] = 0.0F;
1198 v[0] = b->
xyz[0] - a->
xyz[0];
1199 v[1] = b->
xyz[1] - a->
xyz[1];
1200 v[2] = b->
xyz[2] - a->
xyz[2];
1207 c->
xyz[0] = a->
xyz[0] + v[0] * sect;
1208 c->
xyz[1] = a->
xyz[1] + v[1] * sect;
1209 c->
xyz[2] = a->
xyz[2] + v[2] * sect;
1211 c->
rgba[0] = (1 - sect) * a->
rgba[0] + sect * b->
rgba[0];
1212 c->
rgba[1] = (1 - sect) * a->
rgba[1] + sect * b->
rgba[1];
1213 c->
rgba[2] = (1 - sect) * a->
rgba[2] + sect * b->
rgba[2];
1214 c->
rgba[3] = (1 - sect) * a->
rgba[3] + sect * b->
rgba[3];
1219 GLshort *index0, GLshort *index1)
1250 for(i = 0; i < numverts; i++){
1256 plane, &child->
verts[i]);
1262 GLshort i, GLshort j)
1266 for(k = 0; k < *nb; k++){
1267 if((index0[k] == i && index1[k] == j) ||
1268 (index1[k] == i && index0[k] == j))
return;
1277 return (i < num - 1) ? i + 1 : 0;
1286 for(i = 0; i < prim->
numverts; i++){
1294 for(i = 0; i < prim->
numverts; i++){
1314 GLshort i, j, in = 0, out = 0, in0[5], in1[5], out0[5], out1[5];
1320 for(i = 0; i < prim->
numverts; i++){
1331 for(i = 0; i < prim->
numverts; i++){
1377 (*t1)->numverts = (*t2)->numverts = 3;
1378 (*t1)->culled = (*t2)->culled = quad->
culled;
1379 (*t1)->offset = (*t2)->offset = quad->
offset;
1380 (*t1)->pattern = (*t2)->pattern = quad->
pattern;
1381 (*t1)->factor = (*t2)->factor = quad->
factor;
1382 (*t1)->width = (*t2)->width = quad->
width;
1385 (*t1)->verts[0] = quad->
verts[0];
1386 (*t1)->verts[1] = quad->
verts[1];
1387 (*t1)->verts[2] = quad->
verts[2];
1388 (*t1)->boundary = ((quad->
boundary & 1) ? 1 : 0) | ((quad->
boundary & 2) ? 2 : 0);
1389 (*t2)->verts[0] = quad->
verts[0];
1390 (*t2)->verts[1] = quad->
verts[2];
1391 (*t2)->verts[2] = quad->
verts[3];
1392 (*t2)->boundary = ((quad->
boundary & 4) ? 2 : 0) | ((quad->
boundary & 8) ? 4 : 0);
1398 GLfloat dq = 0.0F, dw = 0.0F, diff;
1409 for(i = 0; i < w->numverts; i++){
1432 return (q->
type < w->
type ? 1 : -1);
1437 GLint i, j, count, best = 1000000, idx = 0;
1454 for(i = 0; i < maxp; i++){
1463 if(count > best)
break;
1469 if(!count)
return idx;
1483 while(list != NULL){
1527 if((*tree)->primitives){
1539 if(f1 > f2)
return GL_TRUE;
1540 else return GL_FALSE;
1545 if(f1 < f2)
return GL_TRUE;
1546 else return GL_FALSE;
1613 GLboolean (*compare)(GLfloat f1, GLfloat f2),
1614 void (*action)(
void *data),
int inverse)
1622 if(GL_TRUE == compare(result, epsilon)){
1632 else if(GL_TRUE == compare(-epsilon, result)){
1651 GLfloat minZ, maxZ, rangeZ, scaleZ;
1652 GLfloat factor, units, area, dZ, dZdX, dZdY, maxdZ;
1660 minZ = maxZ = prim->
verts[0].
xyz[2];
1661 for(i = 1; i < prim->
numverts; i++){
1667 for(j = 0; j < prim->
numverts; j++){
1672 rangeZ = (maxZ - minZ);
1678 if(scaleZ > 100000.F) scaleZ = 100000.F;
1683 for(j = 0; j < prim->
numverts; j++){
1698 factor = gl2ps->
offset[0];
1699 units = gl2ps->
offset[1];
1716 maxdZ = (GLfloat)sqrt(dZdX * dZdX + dZdY * dZdY);
1721 dZ = factor * maxdZ + units;
1739 plane[0] = b[1] - a[1];
1740 plane[1] = a[0] - b[0];
1741 n = (GLfloat)sqrt(plane[0]*plane[0] + plane[1]*plane[1]);
1746 plane[3] = -plane[0]*a[0]-plane[1]*a[1];
1785 if((*tree == NULL) && (prim->
numverts > 2)){
1791 for(i = 0; i < prim->
numverts-1; i++){
1809 for(i = 2+offset; i < prim->
numverts; i++){
1816 for(i = 1+offset; i < prim->
numverts-1; i++){
1817 if(cur->front == NULL){
1822 cur->front->plane)){
1828 if(cur->front == NULL){
1833 cur->front->plane)){
1834 cur->front->front = NULL;
1835 cur->front->back = NULL;
1843 for(i = 0; i < 4; i++){
1847 for(i = 1+offset; i < prim->
numverts-1; i++){
1848 if(cur->front == NULL){
1853 cur->front->plane)){
1859 if(cur->front == NULL){
1864 cur->front->plane)){
1865 cur->front->front = NULL;
1866 cur->front->back = NULL;
1887 for(i = 1; i < prim->
numverts; i++){
1924 for(i = 0; i < numverts; i++){
1925 child->
verts[i] = vertx[i];
1940 GLint cur = -1, prev = -1, i, v1 = 0, v2 = 0,
flag = 1, prev0 = -1;
1943 GL2PSvertex *front_list = NULL, *back_list = NULL;
1946 GLshort front_count = 0, back_count = 0;
1948 for(i = 0; i <= prim->
numverts; i++){
1962 if(((prev == -1) || (prev == cur) || (prev == 0) || (cur == 0)) &&
1963 (i < prim->numverts)){
1968 front_list[front_count-1] = prim->
verts[v1];
1974 back_list[back_count-1] = prim->
verts[v1];
1980 front_list[front_count-1] = prim->
verts[v1];
1984 back_list[back_count-1] = prim->
verts[v1];
1988 else if((prev != cur) && (cur != 0) && (prev != 0)){
1997 plane, &front_list[front_count-1]);
2001 back_list[back_count-1] = front_list[front_count-1];
2041 if((*tree)->front != NULL){
2052 if((*tree)->back != NULL){
2058 if((*tree)->front != NULL){
2094 c[0] = c[1] = c[2] = 0.0F;
2095 for(i = 0; i < prim->
numverts; i++){
2102 for(i = 0; i < prim->
numverts; i++){
2103 if(prim->
boundary & (GLint)pow(2., i)){
2116 v[0] = c[0] - prim->
verts[i].
xyz[0];
2117 v[1] = c[1] - prim->
verts[i].
xyz[1];
2178 GLushort pattern, GLint factor,
2179 GLfloat width,
char boundary)
2189 prim->
offset = (char)offset;
2192 prim->
width = width;
2210 i = (GLint)(p[3] + 0.5);
2229 GLushort pattern = 0;
2231 GLint i, sizeoffloat, count, v, vtot, offset = 0, factor = 0, auxindex = 0;
2232 GLfloat lwidth = 1.0F, psize = 1.0F;
2239 boundary = gl2ps->
boundary = GL_FALSE;
2243 if(GL_TRUE == boundary) gl2ps->
boundary = GL_TRUE;
2245 switch((GLint)*current){
2246 case GL_POINT_TOKEN :
2253 pattern, factor, psize, 0);
2255 case GL_LINE_TOKEN :
2256 case GL_LINE_RESET_TOKEN :
2266 pattern, factor, lwidth, 0);
2268 case GL_POLYGON_TOKEN :
2269 count = (GLint)current[1];
2273 while(count > 0 && used > 0){
2281 if(GL_TRUE == boundary){
2282 if(!count && vtot == 2) flag = 1|2|4;
2283 else if(!count) flag = 2|4;
2284 else if(vtot == 2) flag = 1|2;
2290 pattern, factor, 1, flag);
2291 vertices[1] = vertices[2];
2297 case GL_BITMAP_TOKEN :
2298 case GL_DRAW_PIXEL_TOKEN :
2299 case GL_COPY_PIXEL_TOKEN :
2306 case GL_PASS_THROUGH_TOKEN :
2307 switch((GLint)current[1]){
2318 pattern = (GLushort)current[1];
2321 factor = (GLint)current[1];
2326 gl2ps->
blendfunc[0] = (GLint)current[1];
2331 gl2ps->
blendfunc[1] = (GLint)current[1];
2341 lwidth = current[1];
2370 current += 2; used -= 2;
2372 current += i; used -= i;
2375 current += 2; used -= 2;
2379 for(i = 1; i < 4; i++){
2380 for(v = 0; v < 3; v++){
2391 sizeoffloat =
sizeof(GLfloat);
2392 v = 2 * sizeoffloat;
2399 for(i = 0; i < vtot; i += sizeoffloat){
2400 current += 2; used -= 2;
2402 memcpy(&(((
char*)(node->
image->
pixels))[i + v]), &(current[2]), sizeoffloat);
2404 memcpy(&(((
char*)(node->
image->
pixels))[i + v]), &(current[2]), vtot - i);
2440 unsigned char h = byte / 16;
2441 unsigned char l = byte % 16;
2447 GLuint nbhex, nbyte, nrgb, nbits;
2448 GLuint row, col, ibyte, icase;
2449 GLfloat dr = 0., dg = 0., db = 0., fgrey;
2450 unsigned char red = 0, green = 0, blue = 0, b, grey;
2451 GLuint width = (GLuint)im->
width;
2452 GLuint height = (GLuint)im->
height;
2459 if((width <= 0) || (height <= 0))
return;
2468 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2469 gl2psPrintf(
"{ currentfile picstr readhexstring pop }\n");
2471 for(row = 0; row < height; row++){
2472 for(col = 0; col < width; col++){
2474 fgrey = (0.30F * dr + 0.59F * dg + 0.11F * db);
2475 grey = (
unsigned char)(255. * fgrey);
2480 nbhex = width * height * 2;
2485 nbits = nrgb * nbit;
2487 if((nbyte * 8) != nbits) nbyte++;
2490 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2491 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2494 for(row = 0; row < height; row++){
2498 for(ibyte = 0; ibyte < nbyte; ibyte++){
2507 red = (
unsigned char)(3. * dr);
2508 green = (
unsigned char)(3. * dg);
2509 blue = (
unsigned char)(3. * db);
2520 red = (
unsigned char)(3. * dr);
2521 green = (
unsigned char)(3. * dg);
2522 blue = (
unsigned char)(3. * db);
2528 else if(icase == 2) {
2538 red = (
unsigned char)(3. * dr);
2539 green = (
unsigned char)(3. * dg);
2540 blue = (
unsigned char)(3. * db);
2547 else if(icase == 3) {
2556 red = (
unsigned char)(3. * dr);
2557 green = (
unsigned char)(3. * dg);
2558 blue = (
unsigned char)(3. * db);
2572 nbits = nrgb * nbit;
2574 if((nbyte * 8) != nbits) nbyte++;
2577 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2578 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2581 for(row = 0; row < height; row++){
2584 for(ibyte = 0; ibyte < nbyte; ibyte++){
2593 red = (
unsigned char)(15. * dr);
2594 green = (
unsigned char)(15. * dg);
2598 else if(icase == 2) {
2599 blue = (
unsigned char)(15. * db);
2607 red = (
unsigned char)(15. * dr);
2611 else if(icase == 3) {
2612 green = (
unsigned char)(15. * dg);
2613 blue = (
unsigned char)(15. * db);
2625 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ]\n", width, height, height);
2626 gl2psPrintf(
"{ currentfile rgbstr readhexstring pop }\n");
2629 for(row = 0; row < height; row++){
2630 for(col = 0; col < width; col++){
2632 red = (
unsigned char)(255. * dr);
2634 green = (
unsigned char)(255. * dg);
2636 blue = (
unsigned char)(255. * db);
2647 GLsizei width, GLsizei height,
2648 const unsigned char *imagemap){
2651 if((width <= 0) || (height <= 0))
return;
2653 size = height + height * (width - 1) / 8;
2657 gl2psPrintf(
"%d %d scale\n%d %d\ntrue\n", width, height,width, height);
2658 gl2psPrintf(
"[ %d 0 0 -%d 0 %d ] {<", width, height);
2659 for(i = 0; i < size; i++){
2685 "%%%%Creator: GL2PS %d.%d.%d%s, %s\n"
2687 "%%%%CreationDate: %s"
2688 "%%%%LanguageLevel: 3\n"
2689 "%%%%DocumentData: Clean7Bit\n"
2697 "%%%%DocumentMedia: Default %d %d 0 () ()\n",
2706 "%%%%EndComments\n",
2730 "/gl2psdict 64 dict def gl2psdict begin\n"
2731 "0 setlinecap 0 setlinejoin\n"
2732 "/tryPS3shading %s def %% set to false to force subdivision\n"
2733 "/rThreshold %g def %% red component subdivision threshold\n"
2734 "/gThreshold %g def %% green component subdivision threshold\n"
2735 "/bThreshold %g def %% blue component subdivision threshold\n",
2740 "/C { setrgbcolor } BD\n"
2741 "/G { 0.082 mul exch 0.6094 mul add exch 0.3086 mul add neg 1.0 add setgray } BD\n"
2742 "/W { setlinewidth } BD\n");
2744 gl2psPrintf(
"/FC { findfont exch /SH exch def SH scalefont setfont } BD\n"
2745 "/SW { dup stringwidth pop } BD\n"
2746 "/S { FC moveto show } BD\n"
2747 "/SBC{ FC moveto SW -2 div 0 rmoveto show } BD\n"
2748 "/SBR{ FC moveto SW neg 0 rmoveto show } BD\n"
2749 "/SCL{ FC moveto 0 SH -2 div rmoveto show } BD\n"
2750 "/SCC{ FC moveto SW -2 div SH -2 div rmoveto show } BD\n"
2751 "/SCR{ FC moveto SW neg SH -2 div rmoveto show } BD\n"
2752 "/STL{ FC moveto 0 SH neg rmoveto show } BD\n"
2753 "/STC{ FC moveto SW -2 div SH neg rmoveto show } BD\n"
2754 "/STR{ FC moveto SW neg SH neg rmoveto show } BD\n");
2759 "/SR { gsave FCT moveto rotate show grestore } BD\n"
2760 "/SBCR{ gsave FCT moveto rotate SW -2 div 0 rmoveto show grestore } BD\n"
2761 "/SBRR{ gsave FCT moveto rotate SW neg 0 rmoveto show grestore } BD\n"
2762 "/SCLR{ gsave FCT moveto rotate 0 SH -2 div rmoveto show grestore} BD\n");
2763 gl2psPrintf(
"/SCCR{ gsave FCT moveto rotate SW -2 div SH -2 div rmoveto show grestore} BD\n"
2764 "/SCRR{ gsave FCT moveto rotate SW neg SH -2 div rmoveto show grestore} BD\n"
2765 "/STLR{ gsave FCT moveto rotate 0 SH neg rmoveto show grestore } BD\n"
2766 "/STCR{ gsave FCT moveto rotate SW -2 div SH neg rmoveto show grestore } BD\n"
2767 "/STRR{ gsave FCT moveto rotate SW neg SH neg rmoveto show grestore } BD\n");
2769 gl2psPrintf(
"/P { newpath 0.0 360.0 arc closepath fill } BD\n"
2770 "/LS { newpath moveto } BD\n"
2771 "/L { lineto } BD\n"
2772 "/LE { lineto stroke } BD\n"
2773 "/T { newpath moveto lineto lineto closepath fill } BD\n");
2779 " /b1 exch def /g1 exch def /r1 exch def /y1 exch def /x1 exch def\n"
2780 " /b2 exch def /g2 exch def /r2 exch def /y2 exch def /x2 exch def\n"
2781 " /b3 exch def /g3 exch def /r3 exch def /y3 exch def /x3 exch def\n"
2782 " gsave << /ShadingType 4 /ColorSpace [/DeviceRGB]\n"
2783 " /DataSource [ 0 x1 y1 r1 g1 b1 0 x2 y2 r2 g2 b2 0 x3 y3 r3 g3 b3 ] >>\n"
2784 " shfill grestore } BD\n");
2790 "/Tm { 3 -1 roll 8 -1 roll 13 -1 roll add add 3 div\n"
2792 " 3 -1 roll 7 -1 roll 11 -1 roll add add 3 div\n"
2794 " 3 -1 roll 6 -1 roll 9 -1 roll add add 3 div"
2804 " 4 index 15 index add 0.5 mul\n"
2805 " 4 index 15 index add 0.5 mul\n"
2806 " 4 index 15 index add 0.5 mul\n"
2807 " 4 index 15 index add 0.5 mul\n"
2808 " 4 index 15 index add 0.5 mul\n"
2809 " 5 copy 5 copy 25 15 roll\n");
2814 " 9 index 30 index add 0.5 mul\n"
2815 " 9 index 30 index add 0.5 mul\n"
2816 " 9 index 30 index add 0.5 mul\n"
2817 " 9 index 30 index add 0.5 mul\n"
2818 " 5 copy 5 copy 35 5 roll 25 5 roll 15 5 roll\n");
2823 " 4 index 10 index add 0.5 mul\n"
2824 " 4 index 10 index add 0.5 mul\n"
2825 " 4 index 10 index add 0.5 mul\n"
2826 " 4 index 10 index add 0.5 mul\n"
2827 " 5 copy 5 copy 40 5 roll 25 5 roll 15 5 roll 25 5 roll\n");
2831 gl2psPrintf(
" STnoshfill STnoshfill STnoshfill STnoshfill } BD\n");
2838 " 2 index 8 index sub abs rThreshold gt\n"
2840 " { 1 index 7 index sub abs gThreshold gt\n"
2842 " { dup 6 index sub abs bThreshold gt\n"
2844 " { 2 index 13 index sub abs rThreshold gt\n"
2846 " { 1 index 12 index sub abs gThreshold gt\n"
2848 " { dup 11 index sub abs bThreshold gt\n"
2850 " { 7 index 13 index sub abs rThreshold gt\n");
2852 " { 6 index 12 index sub abs gThreshold gt\n"
2854 " { 5 index 11 index sub abs bThreshold gt\n"
2869 " { /ST { STshfill } BD }\n"
2870 " { /ST { STnoshfill } BD }\n"
2872 "{ /ST { STnoshfill } BD }\n"
2878 "/DeviceRGB setcolorspace\n"
2882 "%%%%BeginPageSetup\n");
2896 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
2909 gl2psPrintf(
"%g %g %g C\n", rgba[0], rgba[1], rgba[2]);
2923 for(i = 0; i < 3; i++)
2925 for(i = 0; i < 4; i++)
2931 int *nb,
int array[10])
2934 int on[8] = {0, 0, 0, 0, 0, 0, 0, 0};
2935 int off[8] = {0, 0, 0, 0, 0, 0, 0, 0};
2939 for(n = 15; n >= 0; n--){
2940 tmp[n] = (char)(pattern & 0x01);
2945 for(i = 0; i < 8; i++){
2946 while(n < 16 && !tmp[n]){ off[i]++; n++; }
2947 while(n < 16 && tmp[n]){ on[i]++; n++; }
2948 if(n >= 15){ i++;
break; }
2957 for(n = i - 1; n >= 0; n--){
2958 array[(*nb)++] = factor * on[n];
2959 array[(*nb)++] = factor * off[n];
2960 if(*nb == 10)
break;
2966 int len = 0, i, n, array[10];
2974 if(!pattern || !factor){
2981 for(i = 0; i < n; i++){
3038 newline ?
"LS" :
"L");
3044 gl2psPrintf(
"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ST\n",
3147 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
3149 glRenderMode(GL_FEEDBACK);
3153 gl2ps->
header = GL_FALSE;
3161 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
3164 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
3171 "newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3173 rgba[0], rgba[1], rgba[2],
3174 x, y, x+w, y, x+w, y+h, x, y+h);
3177 gl2psPrintf(
"newpath %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
3179 x, y, x+w, y, x+w, y+h, x, y+h);
3219 "Encapsulated Postscript"
3235 for(i = (
int)strlen(gl2ps->
filename) - 1; i >= 0; i--){
3242 if(i <= 0) strcpy(name, gl2ps->
filename);
3245 strcpy(name,
"untitled");
3252 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
3254 "%% CreationDate: %s",
3260 "\\setlength{\\unitlength}{1pt}\n"
3261 "\\begin{picture}(0,0)\n"
3262 "\\includegraphics{%s}\n"
3263 "\\end{picture}%%\n"
3264 "%s\\begin{picture}(%d,%d)(0,0)\n",
3277 fprintf(gl2ps->
stream,
"\\fontsize{%d}{0}\n\\selectfont",
3279 fprintf(gl2ps->
stream,
"\\put(%g,%g)",
3283 fprintf(gl2ps->
stream,
"{\\makebox(0,0)");
3286 fprintf(gl2ps->
stream,
"{");
3289 fprintf(gl2ps->
stream,
"[l]{");
3292 fprintf(gl2ps->
stream,
"[r]{");
3295 fprintf(gl2ps->
stream,
"[b]{");
3298 fprintf(gl2ps->
stream,
"[br]{");
3301 fprintf(gl2ps->
stream,
"[t]{");
3304 fprintf(gl2ps->
stream,
"[tl]{");
3307 fprintf(gl2ps->
stream,
"[tr]{");
3311 fprintf(gl2ps->
stream,
"[bl]{");
3314 fprintf(gl2ps->
stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
3318 fprintf(gl2ps->
stream,
"}");
3319 fprintf(gl2ps->
stream,
"}}\n");
3334 fprintf(gl2ps->
stream,
"\\end{picture}%s\n",
3341 glRenderMode(GL_FEEDBACK);
3345 gl2ps->
header = GL_FALSE;
3379 #if defined(GL2PS_HAVE_ZLIB)
3381 return fprintf(gl2ps->
stream,
"/Filter [/FlateDecode]\n");
3392 for(i = 0; i < 3; ++i){
3395 else if(rgba[i] < 1e-4 || rgba[i] > 1e6)
3408 for(i = 0; i < 3; ++i){
3411 else if(rgba[i] < 1e-4 || rgba[i] > 1e6)
3424 else if(lw < 1e-4 || lw > 1e6)
3432 GLfloat rad, crad, srad;
3434 if(text->
angle == 0.0F){
3444 rad = (GLfloat)(3.141593F * text->
angle / 180.0F);
3445 srad = (GLfloat)sin(rad);
3446 crad = (GLfloat)cos(rad);
3450 "%f %f %f %f %f %f Tm\n"
3453 cnt, text->
fontsize, crad, srad, -srad, crad, x, y, text->
str);
3466 "%d 0 0 %d %f %f cm\n"
3469 (
int)image->
width, (
int)image->
height, x, y, cnt);
3502 GL2PSrgba lastrgba = {-1.0F, -1.0F, -1.0F, -1.0F};
3503 GLushort lastpattern = 0;
3504 GLint lastfactor = 0;
3505 GLfloat lastwidth = 1;
3507 int lastTriangleWasNotSimpleWithSameColor = 0;
3533 if(lasttype != p->
type || lastwidth != p->
width ||
3546 lastwidth = p->
width;
3552 if(lasttype != p->
type || lastwidth != p->
width ||
3562 lastwidth = p->
width;
3569 lastTriangleWasNotSimpleWithSameColor =
3573 lastTriangleWasNotSimpleWithSameColor){
3676 for(j = 0; j <= lastel; ++j){
3698 for(j = 1; j <= lastel; ++j){
3707 prev->verts[1].xyz[0], prev->verts[1].xyz[1]);
3733 for(j = 0; j <= lastel; ++j){
3753 for(j = 0; j <= lastel; ++j){
3776 for(j = 0; j <= lastel; ++j){
3818 for(j = 0; j <= lastel; ++j){
3825 for(j = 0; j <= lastel; ++j){
3833 for(j = 0; j <= lastel; ++j){
3851 offs += fprintf(gl2ps->
stream,
3860 offs += fprintf(gl2ps->
stream,
">>\n");
3872 offs += fprintf(gl2ps->
stream,
3882 offs += fprintf(gl2ps->
stream,
">>\n");
3895 offs += fprintf(gl2ps->
stream,
3918 offs += fprintf(gl2ps->
stream,
">>\n");
3930 offs += fprintf(gl2ps->
stream,
"/Font\n<<\n");
3939 offs += fprintf(gl2ps->
stream,
">>\n");
3970 newtime = gmtime(&now);
3972 offs = fprintf(gl2ps->
stream,
3976 "/Creator (GL2PS %d.%d.%d%s, %s)\n"
3983 offs += fprintf(gl2ps->
stream,
3989 offs += fprintf(gl2ps->
stream,
3990 "/CreationDate (D:%d%02d%02d%02d%02d%02d)\n"
3993 newtime->tm_year+1900,
4006 return fprintf(gl2ps->
stream,
4017 return fprintf(gl2ps->
stream,
4033 offs += fprintf(gl2ps->
stream,
4036 "/Length 5 0 R\n" );
4038 offs += fprintf(gl2ps->
stream,
4072 #if defined(GL2PS_HAVE_ZLIB)
4074 gl2psSetupCompress();
4078 offs += fprintf(gl2ps->
stream,
"%%PDF-1.4\n");
4114 #if defined(GL2PS_HAVE_ZLIB)
4116 if(Z_OK != gl2psDeflate())
4123 gl2psFreeCompress();
4127 offs += fprintf(gl2ps->
stream,
4137 return fprintf(gl2ps->
stream,
4151 offs = fprintf(gl2ps->
stream,
4156 "/MediaBox [%d %d %d %d]\n",
4161 offs += fprintf(gl2ps->
stream,
"/Rotate -90\n");
4163 offs += fprintf(gl2ps->
stream,
4167 "/ProcSet [/PDF /Text /ImageB /ImageC] %%/ImageI\n");
4191 offs += fprintf(gl2ps->
stream,
4202 return fprintf(gl2ps->
stream,
4205 "/Type /ExtGState\n"
4221 int (*action)(
unsigned long data,
int size),
4222 GLfloat dx, GLfloat dy,
4223 GLfloat xmin, GLfloat ymin)
4232 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4234 offs += (*action)(edgeflag, 1);
4240 offs += (*action)(0, 4);
4241 offs += (*action)(0, 4);
4244 diff = (vertex->
xyz[0] - xmin) / dx;
4249 imap = (
unsigned long)(diff * dmax);
4250 offs += (*action)(imap, 4);
4252 diff = (vertex->
xyz[1] - ymin) / dy;
4257 imap = (
unsigned long)(diff * dmax);
4258 offs += (*action)(imap, 4);
4267 int (*action)(
unsigned long data,
int size))
4274 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4276 imap = (
unsigned long)((vertex->
rgba[0]) * dmax);
4277 offs += (*action)(imap, 1);
4279 imap = (
unsigned long)((vertex->
rgba[1]) * dmax);
4280 offs += (*action)(imap, 1);
4282 imap = (
unsigned long)((vertex->
rgba[2]) * dmax);
4283 offs += (*action)(imap, 1);
4291 int (*action)(
unsigned long data,
int size),
4299 if(
sizeof(
unsigned long) == 8) dmax = dmax - 2048.;
4301 if(sigbyte != 8 && sigbyte != 16)
4306 imap = (
unsigned long)((vertex->
rgba[3]) * dmax);
4308 offs += (*action)(imap, sigbyte);
4316 GLfloat dx, GLfloat dy,
4317 GLfloat xmin, GLfloat ymin,
4318 int (*action)(
unsigned long data,
int size),
4324 if(gray && gray != 8 && gray != 16)
4327 for(i = 0; i < 3; ++i){
4329 dx, dy, xmin, ymin);
4343 GLfloat *ymin, GLfloat *ymax,
4353 for(i = 0; i < cnt; ++i){
4354 for(j = 0; j < 3; ++j){
4355 if(*xmin > triangles[i].vertex[j].xyz[0])
4357 if(*xmax < triangles[i].vertex[j].xyz[0])
4359 if(*ymin > triangles[i].vertex[j].xyz[1])
4361 if(*ymax < triangles[i].vertex[j].xyz[1])
4375 int i, offs = 0, vertexbytes, done = 0;
4376 GLfloat xmin, xmax, ymin, ymax;
4380 vertexbytes = 1+4+4+1+1+1;
4383 vertexbytes = 1+4+4+1;
4386 vertexbytes = 1+4+4+2;
4390 vertexbytes = 1+4+4+1;
4396 offs += fprintf(gl2ps->
stream,
4401 "/BitsPerCoordinate 32 "
4402 "/BitsPerComponent %d "
4404 "/Decode [%f %f %f %f 0 1 %s] ",
4406 (gray) ?
"/DeviceGray" :
"/DeviceRGB",
4408 xmin, xmax, ymin, ymax,
4409 (gray) ?
"" :
"0 1 0 1");
4411 #if defined(GL2PS_HAVE_ZLIB)
4413 gl2psAllocCompress(vertexbytes * size * 3);
4415 for(i = 0; i < size; ++i)
4417 xmax-xmin, ymax-ymin, xmin, ymin,
4418 gl2psWriteBigEndianCompress, gray);
4420 if(Z_OK == gl2psDeflate() && 23 + gl2ps->
compress->destLen < gl2ps->
compress->srcLen){
4422 offs += fprintf(gl2ps->
stream,
4432 gl2psFreeCompress();
4439 offs += fprintf(gl2ps->
stream,
4443 vertexbytes * 3 * size);
4444 for(i = 0; i < size; ++i)
4446 xmax-xmin, ymax-ymin, xmin, ymin,
4450 offs += fprintf(gl2ps->
stream,
4463 offs += fprintf(gl2ps->
stream,
4468 "/BBox [ %d %d %d %d ]\n"
4469 "/Group \n<<\n/S /Transparency /CS /DeviceRGB\n"
4476 ? (
int)strlen(
"/TrSh sh\n") + (
int)log10((
double)childobj)+1
4477 : (
int)strlen(
"/TrSh0 sh\n");
4479 offs += fprintf(gl2ps->
stream,
4484 offs += fprintf(gl2ps->
stream,
4487 offs += fprintf(gl2ps->
stream,
4502 offs += fprintf(gl2ps->
stream,
4507 offs += fprintf(gl2ps->
stream,
4508 "/SMask << /S /Alpha /G %d 0 R >> ",
4511 offs += fprintf(gl2ps->
stream,
4523 offs += fprintf(gl2ps->
stream,
4536 int (*action)(
unsigned long data,
int size),
4542 if(im->
format != GL_RGBA && gray)
4545 if(gray && gray != 8 && gray != 16)
4550 shift = (
sizeof(
unsigned long) - 1) * 8;
4552 for(y = 0; y < im->
height; ++y){
4553 for(x = 0; x < im->
width; ++x){
4555 if(im->
format == GL_RGBA && gray){
4556 (*action)((
unsigned long)(a * 255) << shift, gray);
4559 (*action)((
unsigned long)(r * 255) << shift, 1);
4560 (*action)((
unsigned long)(g * 255) << shift, 1);
4561 (*action)((
unsigned long)(b * 255) << shift, 1);
4576 int offs = 0, done = 0, sigbytes = 3;
4578 if(gray && gray !=8 && gray != 16)
4582 sigbytes = gray / 8;
4584 offs += fprintf(gl2ps->
stream,
4592 "/BitsPerComponent 8\n",
4595 (gray) ?
"/DeviceGray" :
"/DeviceRGB" );
4596 if(GL_RGBA == im->
format && gray == 0){
4597 offs += fprintf(gl2ps->
stream,
4602 #if defined(GL2PS_HAVE_ZLIB)
4604 gl2psAllocCompress((
int)(im->
width * im->
height * sigbytes));
4608 if(Z_OK == gl2psDeflate() && 23 + gl2ps->
compress->destLen < gl2ps->
compress->srcLen){
4610 offs += fprintf(gl2ps->
stream,
4619 gl2psFreeCompress();
4626 offs += fprintf(gl2ps->
stream,
4634 offs += fprintf(gl2ps->
stream,
4645 offs += fprintf(gl2ps->
stream,
4652 "/Encoding /MacRomanEncoding\n"
4666 int offs = entryoffs;
4686 for(j = 0; j < size; ++j){
4791 #if defined(GL2PS_HAVE_ZLIB)
4793 gl2psFreeCompress();
4807 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
4809 glRenderMode(GL_FEEDBACK);
4813 gl2ps->
header = GL_FALSE;
4820 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
4823 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
4868 "Portable Document Format"
4882 for(i = 0; i < n; i++){
4883 xyz[i][0] = verts[i].
xyz[0];
4886 for(j = 0; j < 4; j++)
4887 rgba[i][j] = verts[i].rgba[j];
4893 int r = (
int)(255. * rgba[0]);
4894 int g = (
int)(255. * rgba[1]);
4895 int b = (
int)(255. * rgba[2]);
4896 int rc = (r < 0) ? 0 : (r > 255) ? 255 : r;
4897 int gc = (g < 0) ? 0 : (g > 255) ? 255 : g;
4898 int bc = (b < 0) ? 0 : (b > 255) ? 255 : b;
4899 sprintf(str,
"#%2.2x%2.2x%2.2x", rc, gc, bc);
4904 int x, y, width, height;
4926 gl2psPrintf(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
4927 gl2psPrintf(
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n");
4928 gl2psPrintf(
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
4929 " width=\"%dpx\" height=\"%dpx\" viewBox=\"%d %d %d %d\">\n",
4930 width, height, x, y, width, height);
4944 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col,
4952 gl2psPrintf(
"<g shape-rendering=\"crispEdges\">\n");
4969 if(rgba[0][3] < 1.0F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
4970 gl2psPrintf(
"points=\"%g,%g %g,%g %g,%g\"/>\n", xyz[0][0], xyz[0][1],
4971 xyz[1][0], xyz[1][1], xyz[2][0], xyz[2][1]);
4975 for(i = 0; i < 3; i++){
4976 xyz2[0][i] = xyz[0][i];
4977 xyz2[1][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
4978 xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
4980 for(i = 0; i < 4; i++){
4981 rgba2[0][i] = rgba[0][i];
4982 rgba2[1][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
4983 rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
4986 for(i = 0; i < 3; i++){
4987 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
4988 xyz2[1][i] = xyz[1][i];
4989 xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
4991 for(i = 0; i < 4; i++){
4992 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
4993 rgba2[1][i] = rgba[1][i];
4994 rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
4997 for(i = 0; i < 3; i++){
4998 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
4999 xyz2[1][i] = xyz[2][i];
5000 xyz2[2][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5002 for(i = 0; i < 4; i++){
5003 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5004 rgba2[1][i] = rgba[2][i];
5005 rgba2[2][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5008 for(i = 0; i < 3; i++){
5009 xyz2[0][i] = 0.5F * (xyz[0][i] + xyz[1][i]);
5010 xyz2[1][i] = 0.5F * (xyz[1][i] + xyz[2][i]);
5011 xyz2[2][i] = 0.5F * (xyz[0][i] + xyz[2][i]);
5013 for(i = 0; i < 4; i++){
5014 rgba2[0][i] = 0.5F * (rgba[0][i] + rgba[1][i]);
5015 rgba2[1][i] = 0.5F * (rgba[1][i] + rgba[2][i]);
5016 rgba2[2][i] = 0.5F * (rgba[0][i] + rgba[2][i]);
5024 int i, n, array[10];
5026 if(!pattern || !factor)
return;
5030 for(i = 0; i < n; i++){
5043 for(i = 0; i < 3; i++)
5045 for(i = 0; i < 4; i++)
5052 #if defined(GL2PS_HAVE_LIBPNG)
5064 sizeof(
unsigned char));
5065 gl2psConvertPixmapToPNG(pixmap, png);
5066 gl2psListEncodeBase64(png);
5067 gl2psPrintf(
"<image x=\"%g\" y=\"%g\" width=\"%d\" height=\"%d\"\n",
5069 gl2psPrintf(
"xlink:href=\"data:image/png;base64,");
5071 gl2psListRead(png, i, &c);
5077 (void) x; (void) y; (void) pixmap;
5079 "order to embed images in SVG streams");
5106 if(rgba[0][3] < 1.0F)
gl2psPrintf(
"fill-opacity=\"%g\" ", rgba[0][3]);
5108 xyz[0][0], xyz[0][1], 0.5 * prim->
width);
5133 gl2psPrintf(
"<polyline fill=\"none\" stroke=\"%s\" stroke-width=\"%g\" ",
5135 if(rgba[0][3] < 1.0F)
gl2psPrintf(
"stroke-opacity=\"%g\" ", rgba[0][3]);
5137 gl2psPrintf(
"points=\"%g,%g ", xyz[0][0], xyz[0][1]);
5154 gl2psPrintf(
"<text fill=\"%s\" x=\"%g\" y=\"%g\" font-size=\"%d\" ",
5161 gl2psPrintf(
"text-anchor=\"middle\" baseline-shift=\"%d\" ",
5165 gl2psPrintf(
"text-anchor=\"start\" baseline-shift=\"%d\" ",
5169 gl2psPrintf(
"text-anchor=\"end\" baseline-shift=\"%d\" ",
5173 gl2psPrintf(
"text-anchor=\"middle\" baseline-shift=\"0\" ");
5176 gl2psPrintf(
"text-anchor=\"end\" baseline-shift=\"0\" ");
5179 gl2psPrintf(
"text-anchor=\"middle\" baseline-shift=\"%d\" ",
5183 gl2psPrintf(
"text-anchor=\"start\" baseline-shift=\"%d\" ",
5187 gl2psPrintf(
"text-anchor=\"end\" baseline-shift=\"%d\" ",
5192 gl2psPrintf(
"text-anchor=\"start\" baseline-shift=\"0\" ");
5198 gl2psPrintf(
"font-family=\"Times\" font-weight=\"bold\">");
5200 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\">");
5202 gl2psPrintf(
"font-family=\"Times\" font-style=\"italic\" font-weight=\"bold\">");
5204 gl2psPrintf(
"font-family=\"Helvetica\" font-weight=\"bold\">");
5206 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\">");
5208 gl2psPrintf(
"font-family=\"Helvetica\" font-style=\"oblique\" font-weight=\"bold\">");
5210 gl2psPrintf(
"font-family=\"Courier\" font-weight=\"bold\">");
5212 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\">");
5214 gl2psPrintf(
"font-family=\"Courier\" font-style=\"oblique\" font-weight=\"bold\">");
5243 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5245 glRenderMode(GL_FEEDBACK);
5249 gl2ps->
header = GL_FALSE;
5254 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5257 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5264 gl2psPrintf(
"<polygon fill=\"%s\" points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n", col,
5267 x + w, gl2ps->
viewport[3] - (y + h),
5271 gl2psPrintf(
"<clipPath id=\"cp%d%d%d%d\">\n", x, y, w, h);
5272 gl2psPrintf(
" <polygon points=\"%d,%d %d,%d %d,%d %d,%d\"/>\n",
5275 x + w, gl2ps->
viewport[3] - (y + h),
5278 gl2psPrintf(
"<g clip-path=\"url(#cp%d%d%d%d)\">\n", x, y, w, h);
5306 "Scalable Vector Graphics"
5319 fprintf(gl2ps->
stream,
"\\color[rgb]{%f,%f,%f}\n", rgba[0], rgba[1], rgba[2]);
5331 "%% Creator: GL2PS %d.%d.%d%s, %s\n"
5333 "%% CreationDate: %s",
5338 fprintf(gl2ps->
stream,
"\\begin{pgfpicture}\n");
5342 "\\pgfpathrectanglecorners{"
5343 "\\pgfpoint{%dpt}{%dpt}}{\\pgfpoint{%dpt}{%dpt}}\n"
5344 "\\pgfusepath{fill}\n",
5352 int i, n, array[10];
5360 if(!pattern || !factor){
5362 fprintf(gl2ps->
stream,
"\\pgfsetdash{}{0pt}\n");
5366 fprintf(gl2ps->
stream,
"\\pgfsetdash{");
5367 for(i = 0; i < n; i++) fprintf(gl2ps->
stream,
"{%dpt}", array[i]);
5368 fprintf(gl2ps->
stream,
"}{0pt}\n");
5384 default :
return "south west";
5399 "\\pgfpathrectangle{\\pgfpoint{%fpt}{%fpt}}"
5400 "{\\pgfpoint{%fpt}{%fpt}}\n\\pgfusepath{fill}\n",
5413 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5414 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5415 "\\pgfusepath{stroke}\n",
5422 fprintf(gl2ps->
stream,
"\\pgfsetlinewidth{0.01pt}\n");
5426 "\\pgfpathmoveto{\\pgfpoint{%fpt}{%fpt}}\n"
5427 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5428 "\\pgflineto{\\pgfpoint{%fpt}{%fpt}}\n"
5430 "\\pgfusepath{fill,stroke}\n",
5436 fprintf(gl2ps->
stream,
"{\n\\pgftransformshift{\\pgfpoint{%fpt}{%fpt}}\n",
5442 fprintf(gl2ps->
stream,
"\\pgfnode{rectangle}{%s}{\\fontsize{%d}{0}\\selectfont",
5446 fprintf(gl2ps->
stream,
"\\textcolor[rgb]{%g,%g,%g}{{%s}}",
5450 fprintf(gl2ps->
stream,
"}{}{\\pgfusepath{discard}}}\n");
5465 fprintf(gl2ps->
stream,
"\\end{pgfpicture}\n");
5472 int x = viewport[0], y = viewport[1], w = viewport[2], h = viewport[3];
5474 glRenderMode(GL_FEEDBACK);
5478 gl2ps->
header = GL_FALSE;
5481 fprintf(gl2ps->
stream,
"\\begin{pgfscope}\n");
5484 glGetFloatv(GL_COLOR_CLEAR_VALUE, rgba);
5487 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5495 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5496 "{\\pgfpoint{%dpt}{%dpt}}\n"
5497 "\\pgfusepath{fill}\n",
5502 "\\pgfpathrectangle{\\pgfpoint{%dpt}{%dpt}}"
5503 "{\\pgfpoint{%dpt}{%dpt}}\n"
5504 "\\pgfusepath{clip}\n",
5512 fprintf(gl2ps->
stream,
"\\end{pgfscope}\n");
5530 "PGF Latex Graphics"
5558 for(i = 0; i < prim->
numverts; i++){
5576 used = glRenderMode(GL_RENDER);
5596 gl2ps->
header = GL_FALSE;
5604 switch(gl2ps->
sort){
5651 GLint viewport[4], GLint format, GLint sort,
5652 GLint options, GLint colormode,
5654 GLint nr, GLint ng, GLint nb, GLint buffersize,
5655 FILE *stream,
const char *filename)
5667 if(format >= 0 && format < (GLint)(
sizeof(
gl2psbackends) /
sizeof(gl2psbackends[0]))){
5708 glGetIntegerv(GL_VIEWPORT, gl2ps->
viewport);
5711 for(i = 0; i < 4; i++){
5725 gl2ps->
threshold[0] = nr ? 1.0F / (GLfloat)nr : 0.064F;
5726 gl2ps->
threshold[1] = ng ? 1.0F / (GLfloat)ng : 0.034F;
5727 gl2ps->
threshold[2] = nb ? 1.0F / (GLfloat)nb : 0.100F;
5729 gl2ps->
buffersize = buffersize > 0 ? buffersize : 2048 * 2048;
5730 for(i = 0; i < 3; i++){
5733 for(i = 0; i < 4; i++){
5750 glGetIntegerv(GL_BLEND_SRC, &gl2ps->
blendfunc[0]);
5751 glGetIntegerv(GL_BLEND_DST, &gl2ps->
blendfunc[1]);
5756 glGetFloatv(GL_COLOR_CLEAR_VALUE, gl2ps->
bgcolor);
5758 else if(gl2ps->
colormode == GL_COLOR_INDEX){
5759 if(!colorsize || !colormap){
5768 glGetIntegerv(GL_INDEX_CLEAR_VALUE, &idx);
5783 gl2ps->
title[0] =
'\0';
5787 strcpy(gl2ps->
title, title);
5812 glRenderMode(GL_FEEDBACK);
5868 GLshort fontsize, GLint alignment, GLfloat angle,
5876 GLshort fontsize, GLint alignment, GLfloat angle)
5893 GLint xorig, GLint yorig,
5894 GLenum format, GLenum type,
5899 GLfloat pos[4], zoom_x, zoom_y;
5905 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
5909 if((format != GL_RGB && format != GL_RGBA) || type != GL_FLOAT){
5911 "GL_RGB/GL_RGBA, GL_FLOAT pixels");
5915 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
5918 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
5919 glGetFloatv(GL_ZOOM_X, &zoom_x);
5920 glGetFloatv(GL_ZOOM_Y, &zoom_y);
5927 prim->
verts[0].
xyz[0] = pos[0] + xorig;
5928 prim->
verts[0].
xyz[1] = pos[1] + yorig;
5935 glGetFloatv(GL_CURRENT_RASTER_COLOR, prim->
verts[0].
rgba);
5949 size = height * width * 3;
5951 piv = (
const GLfloat*)pixels;
5952 for(i = 0; i < size; ++i, ++piv){
5959 size = height * width * 4;
5966 size = height * width * 3;
5979 const GLfloat position[3],
5980 const unsigned char *imagemap){
5982 int sizeoffloat =
sizeof(GLfloat);
5986 if((width <= 0) || (height <= 0))
return GL2PS_ERROR;
5988 size = height + height * ((width - 1) / 8);
5991 glVertex3f(position[0], position[1],position[2]);
5993 glPassThrough((GLfloat)width);
5994 glPassThrough((GLfloat)height);
5995 for(i = 0; i < size; i += sizeoffloat){
5996 const float *value = (
const float*)imagemap;
5997 glPassThrough(*value);
5998 imagemap += sizeoffloat;
6012 glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &gl2ps->
offset[0]);
6013 glGetFloatv(GL_POLYGON_OFFSET_UNITS, &gl2ps->
offset[1]);
6020 glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &tmp);
6021 glPassThrough((GLfloat)tmp);
6022 glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &tmp);
6023 glPassThrough((GLfloat)tmp);
6066 glPassThrough(value);
6076 glPassThrough(value);
6089 glPassThrough((GLfloat)sfactor);
6091 glPassThrough((GLfloat)dfactor);
6119 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0])))
6122 return "Unknown format";
6127 if(format >= 0 && format < (GLint)(
sizeof(gl2psbackends) /
sizeof(gl2psbackends[0])))
6130 return "Unknown format";