| | 387 | |
| | 388 | /* |
| | 389 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| | 390 | % % |
| | 391 | % % |
| | 392 | % % |
| | 393 | % W r i t e C A L S I m a g e % |
| | 394 | % % |
| | 395 | % % |
| | 396 | % % |
| | 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| | 398 | % |
| | 399 | % WriteCALSImage() writes an image to a file in CALS type I image format. |
| | 400 | % |
| | 401 | % The format of the WriteCALSImage method is: |
| | 402 | % |
| | 403 | % MagickBooleanType WriteCALSImage(const ImageInfo *image_info, |
| | 404 | % Image *image) |
| | 405 | % |
| | 406 | % A description of each parameter follows. |
| | 407 | % |
| | 408 | % o image_info: the image info. |
| | 409 | % |
| | 410 | % o image: The image. |
| | 411 | % |
| | 412 | */ |
| | 413 | |
| | 414 | static MagickBooleanType WriteCALSRecord(Image *image,const char *data) |
| | 415 | { |
| | 416 | char |
| | 417 | pad[128]; |
| | 418 | |
| | 419 | ssize_t |
| | 420 | count; |
| | 421 | |
| | 422 | register const char |
| | 423 | *p; |
| | 424 | |
| | 425 | register long |
| | 426 | i; |
| | 427 | |
| | 428 | i=0; |
| | 429 | if (data != (const char *) NULL) |
| | 430 | { |
| | 431 | p=data; |
| | 432 | for (i=0; (i < 128) && (p[i] != '\0'); i++); |
| | 433 | count=WriteBlob(image,(size_t) i,(unsigned char *) data); |
| | 434 | } |
| | 435 | if (i < 128) |
| | 436 | { |
| | 437 | /* |
| | 438 | Pad CALS record. |
| | 439 | */ |
| | 440 | i=128-i; |
| | 441 | (void) ResetMagickMemory(pad,' ',(size_t) i); |
| | 442 | count=WriteBlob(image,(size_t) i,(unsigned char *) pad); |
| | 443 | } |
| | 444 | return(count); |
| | 445 | } |
| | 446 | |
| | 447 | static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, |
| | 448 | Image *image) |
| | 449 | { |
| | 450 | char |
| | 451 | buffer[129]; |
| | 452 | |
| | 453 | MagickBooleanType |
| | 454 | status; |
| | 455 | |
| | 456 | register long |
| | 457 | i; |
| | 458 | |
| | 459 | ssize_t |
| | 460 | count; |
| | 461 | |
| | 462 | unsigned long |
| | 463 | density, |
| | 464 | orient_x, |
| | 465 | orient_y; |
| | 466 | |
| | 467 | /* |
| | 468 | Open output image file. |
| | 469 | */ |
| | 470 | assert(image_info != (const ImageInfo *) NULL); |
| | 471 | assert(image_info->signature == MagickSignature); |
| | 472 | assert(image != (Image *) NULL); |
| | 473 | assert(image->signature == MagickSignature); |
| | 474 | if (image->debug != MagickFalse) |
| | 475 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| | 476 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
| | 477 | if (status == MagickFalse) |
| | 478 | return(status); |
| | 479 | /* |
| | 480 | Create standard CALS header. |
| | 481 | */ |
| | 482 | count=WriteCALSRecord(image,"srcdocid: NONE"); |
| | 483 | count=WriteCALSRecord(image,"dstdocid: NONE"); |
| | 484 | count=WriteCALSRecord(image,"txtfilid: NONE"); |
| | 485 | count=WriteCALSRecord(image,"figid: NONE"); |
| | 486 | count=WriteCALSRecord(image,"srcgph: NONE"); |
| | 487 | count=WriteCALSRecord(image,"docls: NONE"); |
| | 488 | count=WriteCALSRecord(image,"rtype: 1"); |
| | 489 | switch (image->orientation) |
| | 490 | { |
| | 491 | case TopRightOrientation: |
| | 492 | { |
| | 493 | orient_x=180; |
| | 494 | orient_y=270; |
| | 495 | break; |
| | 496 | } |
| | 497 | case BottomRightOrientation: |
| | 498 | { |
| | 499 | orient_x=180; |
| | 500 | orient_y=90; |
| | 501 | break; |
| | 502 | } |
| | 503 | case BottomLeftOrientation: |
| | 504 | orient_x=0; |
| | 505 | orient_y=90; |
| | 506 | break; |
| | 507 | case LeftTopOrientation: |
| | 508 | { |
| | 509 | orient_x=270; |
| | 510 | orient_y=0; |
| | 511 | break; |
| | 512 | } |
| | 513 | case RightTopOrientation: |
| | 514 | { |
| | 515 | orient_x=270; |
| | 516 | orient_y=180; |
| | 517 | break; |
| | 518 | } |
| | 519 | case RightBottomOrientation: |
| | 520 | { |
| | 521 | orient_x=90; |
| | 522 | orient_y=180; |
| | 523 | break; |
| | 524 | } |
| | 525 | case LeftBottomOrientation: |
| | 526 | { |
| | 527 | orient_x=90; |
| | 528 | orient_y=0; |
| | 529 | break; |
| | 530 | } |
| | 531 | default: |
| | 532 | { |
| | 533 | orient_x=0; |
| | 534 | orient_y=270; |
| | 535 | } |
| | 536 | } |
| | 537 | (void) FormatMagickString(buffer,MaxTextExtent,"rorient: %03ld,%03ld", |
| | 538 | orient_x,orient_y); |
| | 539 | count=WriteCALSRecord(image,buffer); |
| | 540 | (void) FormatMagickString(buffer,MaxTextExtent,"rpelcnt: %06lu,%06lu", |
| | 541 | image->columns,image->rows); |
| | 542 | count=WriteCALSRecord(image,buffer); |
| | 543 | density=200; |
| | 544 | if (image_info->density != (char *) NULL) |
| | 545 | { |
| | 546 | GeometryInfo |
| | 547 | geometry_info; |
| | 548 | |
| | 549 | (void) ParseGeometry(image_info->density,&geometry_info); |
| | 550 | density=(unsigned long) (geometry_info.rho+0.5); |
| | 551 | } |
| | 552 | (void) FormatMagickString(buffer,MaxTextExtent,"rdensty: %04lu",density); |
| | 553 | count=WriteCALSRecord(image,buffer); |
| | 554 | count=WriteCALSRecord(image,"notes: NONE"); |
| | 555 | (void) ResetMagickMemory(buffer,' ',128); |
| | 556 | for (i=0; i < 5; i++) |
| | 557 | (void) WriteBlob(image,128,(unsigned char *) buffer); |
| | 558 | status=Huffman2DEncodeImage(image_info,image,image); |
| | 559 | (void) CloseBlob(image); |
| | 560 | return(status); |
| | 561 | } |