17 typedef unsigned char Uchar;
18 typedef unsigned int Uint;
44 m_out <<
"tools::wps::~wps :"
45 <<
" bad gsave/grestore balance : " <<
m_gsave
54 wps& operator=(
const wps&){
return *
this;}
59 bool open_file(
const std::string& a_name,
bool a_anonymous =
false){
62 m_file = ::fopen(a_name.c_str(),
"wb");
73 PrintFLN(
"%%%%Creator: tools::wps.");
79 PrintFLN(
"%%%%DocumentFonts: Courier-Bold");
80 PrintFLN(
"%%%%DocumentPaperSizes: a4");
170 in_buffer(
"%.2f %.2f translate ",a_x,a_y);
202 Uchar red,green,blue,b;
205 in_buffer(
"%d %d scale ", a_width, a_height );
208 in_buffer (
"/picstr %d string def ",a_width);
209 in_buffer (
"%d %d %d ",a_width,a_height,8);
210 in_buffer (
"[ %d 0 0 -%d 0 %d ] ",a_width,a_height,a_height);
211 in_buffer (
"{ currentfile picstr readhexstring pop } " );
213 for ( row = 0; row < a_height; row++ ) {
214 for ( col = 0; col < a_width; col++) {
215 status = a_proc(a_tag,col,row,dr,dg,db)?status:
false;
217 Uchar grey = (Uchar) ( 255.0F * fgrey);
221 int nbhex = a_width * a_height * 2;
222 PrintFLN (
"%%%% nbhex digit :%d ",nbhex);
223 PrintFLN (
"%%%% nbhex/record_length :%d ",
225 PrintFLN (
"%%%% nbhex%%record_length :%d ",
228 }
else if(a_nbit==
rgb_2) {
229 int nbyte2 = (a_width * 3)/4;
232 Uint col_max = (nbyte2 * 4)/3;
235 in_buffer (
"/rgbstr %d string def ",nbyte2);
236 in_buffer (
"%d %d %d ",col_max,a_height,2);
237 in_buffer (
"[ %d 0 0 -%d 0 %d ] ",col_max,a_height,a_height);
238 in_buffer (
"{ currentfile rgbstr readhexstring pop } " );
241 for ( row = 0; row < a_height; row++ ) {
242 for ( col = 0; col < col_max; col+=4) {
243 status = a_proc(a_tag,col,row,dr,dg,db)?status:
false;
244 red = (Uchar) ( 3.0F * dr);
245 green = (Uchar) ( 3.0F * dg);
246 blue = (Uchar) ( 3.0F * db);
251 status = a_proc(a_tag,col+1,row,dr,dg,db)?status:
false;
252 red = (Uchar) ( 3.0F * dr);
253 green = (Uchar) ( 3.0F * dg);
254 blue = (Uchar) ( 3.0F * db);
261 status = a_proc(a_tag,col+2,row,dr,dg,db)?status:
false;
262 red = (Uchar) ( 3.0F * dr);
263 green = (Uchar) ( 3.0F * dg);
264 blue = (Uchar) ( 3.0F * db);
270 status = a_proc(a_tag,col+3,row,dr,dg,db)?status:
false;
271 red = (Uchar) ( 3.0F * dr);
272 green = (Uchar) ( 3.0F * dg);
273 blue = (Uchar) ( 3.0F * db);
281 }
else if(a_nbit==
rgb_4) {
282 int nbyte4 = (a_width * 3)/2;
285 Uint col_max = (nbyte4 * 2)/3;
288 in_buffer (
"/rgbstr %d string def ",nbyte4);
289 in_buffer (
"%d %d %d ",col_max,a_height,4);
290 in_buffer (
"[ %d 0 0 -%d 0 %d ] ",col_max,a_height,a_height);
291 in_buffer (
"{ currentfile rgbstr readhexstring pop } " );
294 for ( row = 0; row < a_height; row++ ) {
295 for ( col = 0; col < col_max; col+=2) {
296 status = a_proc(a_tag,col,row,dr,dg,db)?status:
false;
297 red = (Uchar) ( 15.0F * dr);
298 green = (Uchar) ( 15.0F * dg);
300 blue = (Uchar) ( 15.0F * db);
302 status = a_proc(a_tag,col+1,row,dr,dg,db)?status:
false;
303 red = (Uchar) ( 15.0F * dr);
305 green = (Uchar) ( 15.0F * dg);
306 blue = (Uchar) ( 15.0F * db);
311 }
else if(a_nbit==
rgb_8) {
312 int nbyte8 = a_width * 3;
314 in_buffer (
"/rgbstr %d string def ",nbyte8);
315 in_buffer (
"%d %d %d ",a_width,a_height,8);
316 in_buffer (
"[ %d 0 0 -%d 0 %d ] ",a_width,a_height,a_height);
317 in_buffer (
"{ currentfile rgbstr readhexstring pop } " );
320 for ( row = 0; row < a_height; row++ ) {
321 for ( col = 0; col < a_width; col++) {
322 status = a_proc(a_tag,col,row,dr,dg,db)?status:
false;
323 red = (Uchar) ( 255.0F * dr);
325 green = (Uchar) ( 255.0F * dg);
327 blue = (Uchar) ( 255.0F * db);
332 m_out <<
"PS_IMAGE :"
333 <<
" unknown rgb nbit " << a_nbit
337 m_out <<
"PS_IMAGE :"
338 <<
" problem to retrieve some pixel rgb."
353 string = ::ctime(&d);
359 return (0.30f * a_red + 0.59f * a_green + 0.11f * a_blue);
364 va_start(
args,a_format);
368 m_out <<
"tools::wps::in_buffer : overflow." << std::endl;
374 m_out <<
"tools::wps::in_buffer : overflow." << std::endl;
382 m_out <<
"tools::wps::in_buffer : fprintf failed." << std::endl;
388 ::strcpy((
char*)pointer,
m_string.c_str());
395 va_start(
args,a_format);
399 m_out <<
"tools::wps::PrintFLN : overflow." << std::endl;
407 m_out <<
"tools::wps::PrintFLN : fprintf failed." << std::endl;
412 m_out <<
"tools::wps::PrintFLN : fprintf failed." << std::endl;
419 Uchar h = a_byte / 16;
420 Uchar l = a_byte % 16;