Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/coders/dps.c

Go to the documentation of this file.
00001 /* 00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00003 % % 00004 % % 00005 % % 00006 % DDDD PPPP SSSSS % 00007 % D D P P SS % 00008 % D D PPPP SSS % 00009 % D D P SS % 00010 % DDDD P SSSSS % 00011 % % 00012 % % 00013 % Read Postscript Using the Display Postscript System. % 00014 % % 00015 % Software Design % 00016 % John Cristy % 00017 % July 1992 % 00018 % % 00019 % % 00020 % Copyright 1999-2004 ImageMagick Studio LLC, a non-profit organization % 00021 % dedicated to making software imaging solutions freely available. % 00022 % % 00023 % You may not use this file except in compliance with the License. You may % 00024 % obtain a copy of the License at % 00025 % % 00026 % http://www.imagemagick.org/www/Copyright.html % 00027 % % 00028 % Unless required by applicable law or agreed to in writing, software % 00029 % distributed under the License is distributed on an "AS IS" BASIS, % 00030 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 00031 % See the License for the specific language governing permissions and % 00032 % limitations under the License. % 00033 % % 00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00035 % 00036 % 00037 */ 00038 00039 /* 00040 Include declarations. 00041 */ 00042 #include "magick/studio.h" 00043 #include "magick/blob.h" 00044 #include "magick/blob_private.h" 00045 #include "magick/client.h" 00046 #include "magick/error.h" 00047 #include "magick/error_private.h" 00048 #include "magick/image.h" 00049 #include "magick/image_private.h" 00050 #include "magick/list.h" 00051 #include "magick/magick.h" 00052 #include "magick/memory_.h" 00053 #include "magick/monitor.h" 00054 #include "magick/static.h" 00055 #include "magick/string_.h" 00056 #include "magick/utility.h" 00057 #include "magick/xwindow.h" 00058 #if defined(HasDPS) 00059 #include <DPS/dpsXclient.h> 00060 #include <DPS/dpsXpreview.h> 00061 #endif 00062 00063 #if defined(HasDPS) 00064 /* 00065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00066 % % 00067 % % 00068 % % 00069 % R e a d D P S I m a g e % 00070 % % 00071 % % 00072 % % 00073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00074 % 00075 % ReadDPSImage() reads a Adobe Postscript image file and returns it. It 00076 % allocates the memory necessary for the new Image structure and returns a 00077 % pointer to the new image. 00078 % 00079 % The format of the ReadDPSImage method is: 00080 % 00081 % Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception) 00082 % 00083 % A description of each parameter follows: 00084 % 00085 % o image_info: The image info. 00086 % 00087 % o exception: return any errors or warnings in this structure. 00088 % 00089 % 00090 */ 00091 static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception) 00092 { 00093 Display 00094 *display; 00095 00096 float 00097 pixels_per_point; 00098 00099 Image 00100 *image; 00101 00102 int 00103 sans, 00104 status; 00105 00106 long 00107 x, 00108 y; 00109 00110 Pixmap 00111 pixmap; 00112 00113 register IndexPacket 00114 *indexes; 00115 00116 register long 00117 i; 00118 00119 register PixelPacket 00120 *q; 00121 00122 register unsigned long 00123 pixel; 00124 00125 Screen 00126 *screen; 00127 00128 XColor 00129 *colors; 00130 00131 XImage 00132 *dps_image; 00133 00134 XRectangle 00135 page, 00136 bits_per_pixel; 00137 00138 XResourceInfo 00139 resource_info; 00140 00141 XrmDatabase 00142 resource_database; 00143 00144 XStandardColormap 00145 *map_info; 00146 00147 XVisualInfo 00148 *visual_info; 00149 00150 /* 00151 Open X server connection. 00152 */ 00153 assert(image_info != (const ImageInfo *) NULL); 00154 assert(image_info->signature == MagickSignature); 00155 if (image_info->debug != MagickFalse) 00156 (void) LogMagickEvent(TraceEvent,GetMagickModule(),image_info->filename); 00157 assert(exception != (ExceptionInfo *) NULL); 00158 assert(exception->signature == MagickSignature); 00159 display=XOpenDisplay(image_info->server_name); 00160 if (display == (Display *) NULL) 00161 return((Image *) NULL); 00162 /* 00163 Set our forgiving error handler. 00164 */ 00165 (void) XSetErrorHandler(XError); 00166 /* 00167 Open image file. 00168 */ 00169 image=AllocateImage(image_info); 00170 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 00171 if (status == MagickFalse) 00172 return((Image *) NULL); 00173 /* 00174 Get user defaults from X resource database. 00175 */ 00176 resource_database=XGetResourceDatabase(display,GetClientName()); 00177 XGetResourceInfo(resource_database,GetClientName(),&resource_info); 00178 /* 00179 Allocate standard colormap. 00180 */ 00181 map_info=XAllocStandardColormap(); 00182 visual_info=(XVisualInfo *) NULL; 00183 if (map_info == (XStandardColormap *) NULL) 00184 ThrowReaderException(ResourceLimitError,"UnableToCreateStandardColormap") 00185 else 00186 { 00187 /* 00188 Initialize visual info. 00189 */ 00190 (void) CloneString(&resource_info.visual_type,"default"); 00191 visual_info=XBestVisualInfo(display,map_info,&resource_info); 00192 map_info->colormap=(Colormap) NULL; 00193 } 00194 if ((map_info == (XStandardColormap *) NULL) || 00195 (visual_info == (XVisualInfo *) NULL)) 00196 { 00197 image=DestroyImage(image); 00198 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00199 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00200 return((Image *) NULL); 00201 } 00202 /* 00203 Create a pixmap the appropriate size for the image. 00204 */ 00205 screen=ScreenOfDisplay(display,visual_info->screen); 00206 pixels_per_point=XDPSPixelsPerPoint(screen); 00207 if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0)) 00208 pixels_per_point=Min(image->x_resolution,image->y_resolution)/72.0; 00209 status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen, 00210 GetBlobFileHandle(image),visual_info->depth,pixels_per_point,&pixmap, 00211 &bits_per_pixel,&page); 00212 if ((status == dps_status_failure) || (status == dps_status_no_extension)) 00213 { 00214 image=DestroyImage(image); 00215 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00216 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00217 return((Image *) NULL); 00218 } 00219 /* 00220 Rasterize the file into the pixmap. 00221 */ 00222 status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap, 00223 GetBlobFileHandle(image),bits_per_pixel.height,visual_info->depth,&page, 00224 -page.x,-page.y,pixels_per_point,MagickTrue,MagickFalse,MagickTrue,&sans); 00225 if (status != dps_status_success) 00226 { 00227 image=DestroyImage(image); 00228 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00229 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00230 return((Image *) NULL); 00231 } 00232 /* 00233 Initialize DPS X image. 00234 */ 00235 dps_image=XGetImage(display,pixmap,0,0,bits_per_pixel.width, 00236 bits_per_pixel.height,AllPlanes,ZPixmap); 00237 (void) XFreePixmap(display,pixmap); 00238 if (dps_image == (XImage *) NULL) 00239 { 00240 image=DestroyImage(image); 00241 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00242 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00243 return((Image *) NULL); 00244 } 00245 /* 00246 Get the colormap colors. 00247 */ 00248 colors=(XColor *) 00249 AcquireMagickMemory(visual_info->colormap_size*sizeof(XColor)); 00250 if (colors == (XColor *) NULL) 00251 { 00252 image=DestroyImage(image); 00253 XDestroyImage(dps_image); 00254 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00255 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00256 return((Image *) NULL); 00257 } 00258 if ((visual_info->storage_class != DirectColor) && 00259 (visual_info->storage_class != TrueColor)) 00260 for (i=0; i < visual_info->colormap_size; i++) 00261 { 00262 colors[i].pixel=i; 00263 colors[i].pad=0; 00264 } 00265 else 00266 { 00267 unsigned long 00268 blue, 00269 blue_bit, 00270 green, 00271 green_bit, 00272 red, 00273 red_bit; 00274 00275 /* 00276 DirectColor or TrueColor visual. 00277 */ 00278 red=0; 00279 green=0; 00280 blue=0; 00281 red_bit=visual_info->red_mask & (~(visual_info->red_mask)+1); 00282 green_bit=visual_info->green_mask & (~(visual_info->green_mask)+1); 00283 blue_bit=visual_info->blue_mask & (~(visual_info->blue_mask)+1); 00284 for (i=0; i < visual_info->colormap_size; i++) 00285 { 00286 colors[i].pixel=red | green | blue; 00287 colors[i].pad=0; 00288 red+=red_bit; 00289 if (red > visual_info->red_mask) 00290 red=0; 00291 green+=green_bit; 00292 if (green > visual_info->green_mask) 00293 green=0; 00294 blue+=blue_bit; 00295 if (blue > visual_info->blue_mask) 00296 blue=0; 00297 } 00298 } 00299 (void) XQueryColors(display,XDefaultColormap(display,visual_info->screen), 00300 colors,visual_info->colormap_size); 00301 /* 00302 Convert X image to MIFF format. 00303 */ 00304 if ((visual_info->storage_class != TrueColor) && 00305 (visual_info->storage_class != DirectColor)) 00306 image->storage_class=PseudoClass; 00307 image->columns=dps_image->width; 00308 image->rows=dps_image->height; 00309 if (image_info->ping != MagickFalse) 00310 { 00311 CloseBlob(image); 00312 return(GetFirstImageInList(image)); 00313 } 00314 switch (image->storage_class) 00315 { 00316 case DirectClass: 00317 default: 00318 { 00319 register unsigned long 00320 color, 00321 index; 00322 00323 unsigned long 00324 blue_mask, 00325 blue_shift, 00326 green_mask, 00327 green_shift, 00328 red_mask, 00329 red_shift; 00330 00331 /* 00332 Determine shift and mask for red, green, and blue. 00333 */ 00334 red_mask=visual_info->red_mask; 00335 red_shift=0; 00336 while ((red_mask & 0x01) == 0) 00337 { 00338 red_mask>>=1; 00339 red_shift++; 00340 } 00341 green_mask=visual_info->green_mask; 00342 green_shift=0; 00343 while ((green_mask & 0x01) == 0) 00344 { 00345 green_mask>>=1; 00346 green_shift++; 00347 } 00348 blue_mask=visual_info->blue_mask; 00349 blue_shift=0; 00350 while ((blue_mask & 0x01) == 0) 00351 { 00352 blue_mask>>=1; 00353 blue_shift++; 00354 } 00355 /* 00356 Convert X image to DirectClass packets. 00357 */ 00358 if ((visual_info->colormap_size > 0) && 00359 (visual_info->storage_class == DirectColor)) 00360 for (y=0; y < (long) image->rows; y++) 00361 { 00362 q=SetImagePixels(image,0,y,image->columns,1); 00363 if (q == (PixelPacket *) NULL) 00364 break; 00365 for (x=0; x < (long) image->columns; x++) 00366 { 00367 pixel=XGetPixel(dps_image,x,y); 00368 index=(pixel >> red_shift) & red_mask; 00369 q->red=ScaleShortToQuantum(colors[index].red); 00370 index=(pixel >> green_shift) & green_mask; 00371 q->green=ScaleShortToQuantum(colors[index].green); 00372 index=(pixel >> blue_shift) & blue_mask; 00373 q->blue=ScaleShortToQuantum(colors[index].blue); 00374 q++; 00375 } 00376 if (SyncImagePixels(image) == MagickFalse) 00377 break; 00378 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00379 (QuantumTick(y,image->rows) != MagickFalse)) 00380 { 00381 status=image->progress_monitor(LoadImageTag,y,image->rows, 00382 image->client_data); 00383 if (status == MagickFalse) 00384 break; 00385 } 00386 } 00387 else 00388 for (y=0; y < (long) image->rows; y++) 00389 { 00390 q=SetImagePixels(image,0,y,image->columns,1); 00391 if (q == (PixelPacket *) NULL) 00392 break; 00393 for (x=0; x < (long) image->columns; x++) 00394 { 00395 pixel=XGetPixel(dps_image,x,y); 00396 color=(pixel >> red_shift) & red_mask; 00397 q->red=ScaleShortToQuantum((color*65535L)/red_mask); 00398 color=(pixel >> green_shift) & green_mask; 00399 q->green=ScaleShortToQuantum((color*65535L)/green_mask); 00400 color=(pixel >> blue_shift) & blue_mask; 00401 q->blue=ScaleShortToQuantum((color*65535L)/blue_mask); 00402 q++; 00403 } 00404 if (SyncImagePixels(image) == MagickFalse) 00405 break; 00406 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00407 (QuantumTick(y,image->rows) != MagickFalse)) 00408 { 00409 status=image->progress_monitor(LoadImageTag,y,image->rows, 00410 image->client_data); 00411 if (status == MagickFalse) 00412 break; 00413 } 00414 } 00415 break; 00416 } 00417 case PseudoClass: 00418 { 00419 /* 00420 Create colormap. 00421 */ 00422 if (AllocateImageColormap(image,visual_info->colormap_size) == MagickFalse) 00423 { 00424 image=DestroyImage(image); 00425 colors=(XColor *) RelinquishMagickMemory(colors); 00426 XDestroyImage(dps_image); 00427 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00428 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00429 return((Image *) NULL); 00430 } 00431 for (i=0; i < (long) image->colors; i++) 00432 { 00433 image->colormap[colors[i].pixel].red=ScaleShortToQuantum(colors[i].red); 00434 image->colormap[colors[i].pixel].green= 00435 ScaleShortToQuantum(colors[i].green); 00436 image->colormap[colors[i].pixel].blue= 00437 ScaleShortToQuantum(colors[i].blue); 00438 } 00439 /* 00440 Convert X image to PseudoClass packets. 00441 */ 00442 for (y=0; y < (long) image->rows; y++) 00443 { 00444 q=SetImagePixels(image,0,y,image->columns,1); 00445 if (q == (PixelPacket *) NULL) 00446 break; 00447 indexes=GetIndexes(image); 00448 for (x=0; x < (long) image->columns; x++) 00449 indexes[x]=(unsigned short) XGetPixel(dps_image,x,y); 00450 if (SyncImagePixels(image) == MagickFalse) 00451 break; 00452 if ((image->progress_monitor != (MagickProgressMonitor) NULL) && 00453 (QuantumTick(y,image->rows) != MagickFalse)) 00454 { 00455 status=image->progress_monitor(LoadImageTag,y,image->rows, 00456 image->client_data); 00457 if (status == MagickFalse) 00458 break; 00459 } 00460 } 00461 break; 00462 } 00463 } 00464 colors=(XColor *) RelinquishMagickMemory(colors); 00465 XDestroyImage(dps_image); 00466 if (image->storage_class == PseudoClass) 00467 (void) SyncImage(image); 00468 /* 00469 Rasterize matte image. 00470 */ 00471 status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen, 00472 GetBlobFileHandle(image),1,pixels_per_point,&pixmap,&bits_per_pixel,&page); 00473 if ((status != dps_status_failure) && (status != dps_status_no_extension)) 00474 { 00475 status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap, 00476 GetBlobFileHandle(image),bits_per_pixel.height,1,&page,-page.x, 00477 -page.y,pixels_per_point,MagickTrue,MagickTrue,MagickTrue,&sans); 00478 if (status == dps_status_success) 00479 { 00480 XImage 00481 *matte_image; 00482 00483 /* 00484 Initialize image matte. 00485 */ 00486 matte_image=XGetImage(display,pixmap,0,0,bits_per_pixel.width, 00487 bits_per_pixel.height,AllPlanes,ZPixmap); 00488 (void) XFreePixmap(display,pixmap); 00489 if (matte_image != (XImage *) NULL) 00490 { 00491 image->storage_class=DirectClass; 00492 image->matte=MagickTrue; 00493 for (y=0; y < (long) image->rows; y++) 00494 { 00495 q=SetImagePixels(image,0,y,image->columns,1); 00496 if (q == (PixelPacket *) NULL) 00497 break; 00498 for (x=0; x < (long) image->columns; x++) 00499 { 00500 q->opacity=OpaqueOpacity; 00501 if (XGetPixel(matte_image,x,y) == 0) 00502 q->opacity=TransparentOpacity; 00503 q++; 00504 } 00505 if (SyncImagePixels(image) == MagickFalse) 00506 break; 00507 } 00508 XDestroyImage(matte_image); 00509 } 00510 } 00511 } 00512 /* 00513 Free resources. 00514 */ 00515 XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL, 00516 (XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL); 00517 CloseBlob(image); 00518 return(GetFirstImageInList(image)); 00519 } 00520 #endif 00521 00522 /* 00523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00524 % % 00525 % % 00526 % % 00527 % R e g i s t e r D P S I m a g e % 00528 % % 00529 % % 00530 % % 00531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00532 % 00533 % RegisterDPSImage() adds attributes for the Display Postscript image 00534 % format to the list of supported formats. The attributes include the image 00535 % format tag, a method to read and/or write the format, whether the format 00536 % supports the saving of more than one frame to the same file or blob, 00537 % whether the format supports native in-memory I/O, and a brief 00538 % description of the format. 00539 % 00540 % The format of the RegisterDPSImage method is: 00541 % 00542 % RegisterDPSImage(void) 00543 % 00544 */ 00545 ModuleExport void RegisterDPSImage(void) 00546 { 00547 MagickInfo 00548 *entry; 00549 00550 entry=SetMagickInfo("DPS"); 00551 #if defined(HasDPS) 00552 entry->decoder=(DecoderHandler *) ReadDPSImage; 00553 #endif 00554 entry->blob_support=MagickFalse; 00555 entry->description=AcquireString("Display Postscript Interpreter"); 00556 entry->module=AcquireString("DPS"); 00557 (void) RegisterMagickInfo(entry); 00558 } 00559 00560 /* 00561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00562 % % 00563 % % 00564 % % 00565 % U n r e g i s t e r D P S I m a g e % 00566 % % 00567 % % 00568 % % 00569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00570 % 00571 % UnregisterDPSImage() removes format registrations made by the 00572 % DPS module from the list of supported formats. 00573 % 00574 % The format of the UnregisterDPSImage method is: 00575 % 00576 % UnregisterDPSImage(void) 00577 % 00578 */ 00579 ModuleExport void UnregisterDPSImage(void) 00580 { 00581 (void) UnregisterMagickInfo("DPS"); 00582 }

Generated on Mon Oct 25 13:40:36 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC