Skip to content
Snippets Groups Projects
Commit 115cd247 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

update to 0.9.1
parent c8eb2071
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
* GL2PS, an OpenGL to PostScript Printing Library
* Copyright (C) 1999-2003 Christophe Geuzaine
*
* $Id: gl2ps.cpp,v 1.65 2003-06-02 18:26:22 geuzaine Exp $
* $Id: gl2ps.cpp,v 1.66 2003-06-12 17:39:33 geuzaine Exp $
*
* E-mail: geuz@geuz.org
* URL: http://www.geuz.org/gl2ps/
......@@ -1170,26 +1170,14 @@ GLint gl2psGetVertex(GL2PSvertex *v, GLfloat *p){
}
}
GLint gl2psParseFeedbackBuffer(void){
void gl2psParseFeedbackBuffer(GLint used){
char flag, dash = 0;
GLshort boundary;
GLint i, used, count, v, vtot, offset = 0;
GLint i, count, v, vtot, offset = 0;
GLfloat lwidth = 1., psize = 1.;
GLfloat *current;
GL2PSvertex vertices[3];
used = glRenderMode(GL_RENDER);
if(used < 0){
gl2psMsg(GL2PS_INFO, "OpenGL feedback buffer overflow");
return GL2PS_OVERFLOW;
}
if(used == 0){
/* gl2psMsg(GL2PS_INFO, "Empty feedback buffer"); */
return GL2PS_NO_FEEDBACK;
}
current = gl2ps->feedback;
boundary = gl2ps->boundary = 0;
......@@ -1284,8 +1272,6 @@ GLint gl2psParseFeedbackBuffer(void){
break;
}
}
return GL2PS_SUCCESS;
}
GLboolean gl2psSameColor(GL2PSrgba rgba1, GL2PSrgba rgba2){
......@@ -1317,7 +1303,7 @@ void gl2psWriteByte(FILE *stream, unsigned char byte){
fprintf(stream, "%x%x", h, l);
}
int gl2psGetRGB(GLfloat *pixels, GLsizei width, GLsizei height, GLuint x, GLuint y,
void gl2psGetRGB(GLfloat *pixels, GLsizei width, GLsizei height, GLuint x, GLuint y,
GLfloat *red, GLfloat *green, GLfloat *blue){
/* OpenGL image is from down to up, PS image is up to down */
GLfloat *pimag;
......@@ -1325,30 +1311,27 @@ int gl2psGetRGB(GLfloat *pixels, GLsizei width, GLsizei height, GLuint x, GLuint
*red = *pimag; pimag++;
*green = *pimag; pimag++;
*blue = *pimag; pimag++;
return 1;
}
void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLfloat *pixels,
FILE *stream){
typedef unsigned char Uchar;
int status = 1, nbhex, nbyte2, nbyte4, nbyte8;
int nbhex, nbyte2, nbyte4, nbyte8;
GLsizei row, col, col_max;
float dr, dg, db, fgrey;
Uchar red, green, blue, b, grey;
/* FIXME: this has to be generalized... */
int shade = 0;
int nbit = 4;
unsigned char red, green, blue, b, grey;
if((width <= 0) || (height <= 0)) return;
/* FIXME: define an option for these? */
int greyscale = 0; /* set to 1 to output greyscale image */
int nbits = 8; /* number of bits per color compoment (2, 4 or 8) */
/* Msg(INFO, "gl2psPrintPostScriptPixmap: x %g y %g w %d h %d", x, y, width, height); */
if((width <= 0) || (height <= 0)) return;
fprintf(stream, "gsave\n");
fprintf(stream, "%.2f %.2f translate\n", x, y);
fprintf(stream, "%d %d scale\n", width, height);
if(shade != 0){ /* grey */
if(greyscale){ /* greyscale, 8 bits per pixel */
fprintf(stream, "/picstr %d string def\n", width);
fprintf(stream, "%d %d %d\n", width, height, 8);
fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height);
......@@ -1356,10 +1339,9 @@ void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei hei
fprintf(stream, "image\n");
for(row = 0; row < height; row++){
for(col = 0; col < width; col++){
status = gl2psGetRGB(pixels, width, height,
col, row, &dr, &dg, &db) == 0 ? 0 : status;
gl2psGetRGB(pixels, width, height, col, row, &dr, &dg, &db);
fgrey = (0.30 * dr + 0.59 * dg + 0.11 * db);
grey = (Uchar)(255. * fgrey);
grey = (unsigned char)(255. * fgrey);
gl2psWriteByte(stream, grey);
}
fprintf(stream, "\n");
......@@ -1367,13 +1349,11 @@ void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei hei
nbhex = width * height * 2;
fprintf(stream, "%%%% nbhex digit :%d\n", nbhex);
}
else if(nbit == 2){
else if(nbits == 2){ /* color, 2 bits for r and g and b; rgbs following each other */
nbyte2 = (width * 3)/4;
nbyte2 /=3;
nbyte2 *=3;
col_max = (nbyte2 * 4)/3;
/* 2 bit for r and g and b */
/* rgbs following each other */
fprintf(stream, "/rgbstr %d string def\n", nbyte2);
fprintf(stream, "%d %d %d\n", col_max, height, 2);
fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", col_max, height, height);
......@@ -1382,39 +1362,33 @@ void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei hei
fprintf(stream, "colorimage\n" );
for(row = 0; row < height; row++){
for(col = 0; col < col_max; col+=4){
status = gl2psGetRGB(pixels, width, height,
col, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(3. * dr);
green = (Uchar)(3. * dg);
blue = (Uchar)(3. * db);
gl2psGetRGB(pixels, width, height, col, row, &dr, &dg, &db);
red = (unsigned char)(3. * dr);
green = (unsigned char)(3. * dg);
blue = (unsigned char)(3. * db);
b = red;
b = (b<<2)+green;
b = (b<<2)+blue;
status = gl2psGetRGB(pixels, width, height,
col+1, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(3. * dr);
green = (Uchar)(3. * dg);
blue = (Uchar)(3. * db);
gl2psGetRGB(pixels, width, height, col+1, row, &dr, &dg, &db);
red = (unsigned char)(3. * dr);
green = (unsigned char)(3. * dg);
blue = (unsigned char)(3. * db);
b = (b<<2)+red;
gl2psWriteByte(stream, b);
b = green;
b = (b<<2)+blue;
status = gl2psGetRGB(pixels, width, height,
col+2, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(3. * dr);
green = (Uchar)(3. * dg);
blue = (Uchar)(3. * db);
gl2psGetRGB(pixels, width, height, col+2, row, &dr, &dg, &db);
red = (unsigned char)(3. * dr);
green = (unsigned char)(3. * dg);
blue = (unsigned char)(3. * db);
b = (b<<2)+red;
b = (b<<2)+green;
gl2psWriteByte(stream, b);
b = blue;
status = gl2psGetRGB(pixels,width,height,
col+3, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(3. * dr);
green = (Uchar)(3. * dg);
blue = (Uchar)(3. * db);
gl2psGetRGB(pixels, width, height, col+3, row, &dr, &dg, &db);
red = (unsigned char)(3. * dr);
green = (unsigned char)(3. * dg);
blue = (unsigned char)(3. * db);
b = (b<<2)+red;
b = (b<<2)+green;
b = (b<<2)+blue;
......@@ -1423,13 +1397,11 @@ void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei hei
fprintf(stream, "\n");
}
}
else if(nbit == 4){
else if(nbits == 4){ /* color, 4 bits for r and g and b; rgbs following each other */
nbyte4 = (width * 3)/2;
nbyte4 /=3;
nbyte4 *=3;
col_max = (nbyte4 * 2)/3;
/* 4 bit for r and g and b */
/* rgbs following each other */
fprintf(stream, "/rgbstr %d string def\n", nbyte4);
fprintf(stream, "%d %d %d\n", col_max, height, 4);
fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", col_max, height, height);
......@@ -1438,27 +1410,23 @@ void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei hei
fprintf(stream, "colorimage\n");
for(row = 0; row < height; row++){
for(col = 0; col < col_max; col+=2){
status = gl2psGetRGB(pixels, width, height,
col, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(15. * dr);
green = (Uchar)(15. * dg);
gl2psGetRGB(pixels, width, height, col, row, &dr, &dg, &db);
red = (unsigned char)(15. * dr);
green = (unsigned char)(15. * dg);
fprintf(stream, "%x%x", red, green);
blue = (Uchar)(15. * db);
status = gl2psGetRGB(pixels, width, height,
col+1, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(15. * dr);
blue = (unsigned char)(15. * db);
gl2psGetRGB(pixels, width, height, col+1, row, &dr, &dg, &db);
red = (unsigned char)(15. * dr);
fprintf(stream,"%x%x",blue,red);
green = (Uchar)(15. * dg);
blue = (Uchar)(15. * db);
green = (unsigned char)(15. * dg);
blue = (unsigned char)(15. * db);
fprintf(stream, "%x%x", green, blue);
}
fprintf(stream, "\n");
}
}
else{
else{ /* color, 8 bits for r and g and b; rgbs following each other */
nbyte8 = width * 3;
/* 8 bit for r and g and b */
fprintf(stream, "/rgbstr %d string def\n", nbyte8);
fprintf(stream, "%d %d %d\n", width, height, 8);
fprintf(stream, "[ %d 0 0 -%d 0 %d ]\n", width, height, height);
......@@ -1467,22 +1435,18 @@ void gl2psPrintPostScriptPixmap(GLfloat x, GLfloat y, GLsizei width, GLsizei hei
fprintf(stream, "colorimage\n");
for(row = 0; row < height; row++){
for(col = 0; col < width; col++){
status = gl2psGetRGB(pixels, width, height,
col, row, &dr, &dg, &db) == 0 ? 0 : status;
red = (Uchar)(255. * dr);
gl2psGetRGB(pixels, width, height, col, row, &dr, &dg, &db);
red = (unsigned char)(255. * dr);
gl2psWriteByte(stream, red);
green = (Uchar)(255. * dg);
green = (unsigned char)(255. * dg);
gl2psWriteByte(stream, green);
blue = (Uchar)(255. * db);
blue = (unsigned char)(255. * db);
gl2psWriteByte(stream, blue);
}
fprintf(stream, "\n");
}
}
if(status == 0){
gl2psMsg(GL2PS_ERROR, "Problem to retrieve some pixel rgb");
}
fprintf(stream, "grestore\n");
}
......@@ -1543,7 +1507,7 @@ void gl2psPrintPostScriptHeader(void){
fprintf(gl2ps->stream,
"%%%%BeginProlog\n"
"/gl2psdict 64 dict def gl2psdict begin\n"
"1 setlinecap 1 setlinejoin\n"
"0 setlinecap 0 setlinejoin\n"
"/tryPS3shading %s def %% set to false to force subdivision\n"
"/rThreshold %g def %% red component subdivision threshold\n"
"/gThreshold %g def %% green component subdivision threshold\n"
......@@ -1917,15 +1881,26 @@ GLint gl2psPrintTeXEndViewport(void){
GLint gl2psPrintPrimitives(void){
GL2PSbsptree *root;
GL2PSxyz eye = {0., 0., 100000.};
GLint res = GL2PS_SUCCESS;
GLint used;
void (*pprim)(void *a, void *b) = 0;
used = glRenderMode(GL_RENDER);
if(used < 0){
gl2psMsg(GL2PS_INFO, "OpenGL feedback buffer overflow");
return GL2PS_OVERFLOW;
}
if(used == 0){
return GL2PS_NO_FEEDBACK; /* Empty feedback buffer */
}
if(gl2ps->format == GL2PS_PS || gl2ps->format == GL2PS_EPS){
res = gl2psParseFeedbackBuffer();
gl2psParseFeedbackBuffer(used);
}
if(res != GL2PS_SUCCESS){
return res;
if(!gl2psListNbr(gl2ps->primitives)){
return GL2PS_SUCCESS; /* Nothing to print */
}
switch(gl2ps->format){
......@@ -1974,13 +1949,12 @@ GLint gl2psPrintPrimitives(void){
break;
default :
gl2psMsg(GL2PS_ERROR, "Unknown sorting algorithm: %d", gl2ps->sort);
res = GL2PS_ERROR;
break;
return GL2PS_ERROR;
}
fflush(gl2ps->stream);
return res;
return GL2PS_SUCCESS;
}
/* The public routines */
......
......@@ -2,7 +2,7 @@
* GL2PS, an OpenGL to PostScript Printing Library
* Copyright (C) 1999-2003 Christophe Geuzaine
*
* $Id: gl2ps.h,v 1.39 2003-06-02 18:26:22 geuzaine Exp $
* $Id: gl2ps.h,v 1.40 2003-06-12 17:39:33 geuzaine Exp $
*
* E-mail: geuz@geuz.org
* URL: http://www.geuz.org/gl2ps/
......@@ -57,7 +57,7 @@
#define GL2PS_MAJOR_VERSION 0
#define GL2PS_MINOR_VERSION 9
#define GL2PS_PATCH_VERSION 0
#define GL2PS_PATCH_VERSION 1
#define GL2PS_VERSION (GL2PS_MAJOR_VERSION + \
0.01 * GL2PS_MINOR_VERSION + \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment