Show
Ignore:
Timestamp:
09/18/09 19:10:44 (6 months ago)
Author:
cristy
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ImageMagick/trunk/coders/cals.c

    r1 r143  
    5252#include "magick/exception.h" 
    5353#include "magick/exception-private.h" 
     54#include "magick/geometry.h" 
    5455#include "magick/image.h" 
    5556#include "magick/image-private.h" 
     
    6667 
    6768/* 
     69 Forward declarations. 
     70*/ 
     71static MagickBooleanType 
     72  WriteCALSImage(const ImageInfo *,Image *); 
     73 
     74/* 
    6875%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    6976%                                                                             % 
     
    94101  if (length < 128) 
    95102    return(MagickFalse); 
    96   if (LocaleNCompare((char *) magick,"version: MIL-STD-1840",21) == 0) 
     103  if (LocaleNCompare((const char *) magick,"version: MIL-STD-1840",21) == 0) 
    97104    return(MagickTrue); 
    98   if (LocaleNCompare((char *) magick,"srcdocid:",9) == 0) 
     105  if (LocaleNCompare((const char *) magick,"srcdocid:",9) == 0) 
    99106    return(MagickTrue); 
    100   if (LocaleNCompare((char *) magick,"rorient:",8) == 0) 
     107  if (LocaleNCompare((const char *) magick,"rorient:",8) == 0) 
    101108    return(MagickTrue); 
    102109  return(MagickFalse); 
     
    115122% 
    116123%  ReadCALSImage() reads an Automated Interchange of Technical Information, 
    117 %  MIL-STD-1840A image file and returns it.  It allocates the memory necessary 
     124%  MIL-STD-1840A image file and returns it.  It allocates the memorient_y necessary 
    118125%  for the new Image structure and returns a pointer to the new image. 
    119126% 
     
    331338%  method to read and/or write the format, whether the format supports the 
    332339%  saving of more than one frame to the same file or blob, whether the format 
    333 %  supports native in-memory I/O, and a brief description of the format. 
     340%  supports native in-memorient_y I/O, and a brief description of the format. 
    334341% 
    335342%  The format of the RegisterCALSImage method is: 
     
    345352  entry=SetMagickInfo("CALS"); 
    346353  entry->decoder=(DecodeImageHandler *) ReadCALSImage; 
     354  entry->encoder=(EncodeImageHandler *) WriteCALSImage; 
    347355  entry->adjoin=MagickFalse; 
    348356  entry->magick=(IsImageFormatHandler *) IsCALS; 
     
    377385  (void) UnregisterMagickInfo("CALS"); 
    378386} 
     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 
     414static 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 
     447static 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}