diff options
| author | Joakim Verona | 2010-06-14 15:57:48 +0200 |
|---|---|---|
| committer | Joakim Verona | 2010-06-14 15:57:48 +0200 |
| commit | 4917006be4c461d6dfedc205ababadd5e15d5279 (patch) | |
| tree | 954bfcb30fc38796f17b6ab7053025b5970f4c6b /src | |
| parent | c05c21ed109720d66c834a0c5b21ea29416683a6 (diff) | |
| download | emacs-4917006be4c461d6dfedc205ababadd5e15d5279.tar.gz emacs-4917006be4c461d6dfedc205ababadd5e15d5279.zip | |
mostly cosmetic, moving { instances, changing indentation accordingly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/image.c | 494 |
1 files changed, 248 insertions, 246 deletions
diff --git a/src/image.c b/src/image.c index 1ed2fc84af3..9de83fa05e2 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -7569,16 +7569,9 @@ gif_load (struct frame *f, struct image *img) | |||
| 7569 | 7569 | ||
| 7570 | /*********************************************************************** | 7570 | /*********************************************************************** |
| 7571 | imagemagick | 7571 | imagemagick |
| 7572 | ***********************************************************************/ | 7572 | ***********************************************************************/ |
| 7573 | #if defined (HAVE_IMAGEMAGICK) | 7573 | #if defined (HAVE_IMAGEMAGICK) |
| 7574 | Lisp_Object Vimagemagick_render_type; | 7574 | Lisp_Object Vimagemagick_render_type; |
| 7575 | /* Function prototypes. */ | ||
| 7576 | |||
| 7577 | static int imagemagick_image_p (Lisp_Object object); | ||
| 7578 | static int imagemagick_load (struct frame *f, struct image *img); | ||
| 7579 | |||
| 7580 | static int imagemagick_load_image (struct frame *, struct image *, | ||
| 7581 | unsigned char *, unsigned int, unsigned char *); | ||
| 7582 | 7575 | ||
| 7583 | /* The symbol `imagemagick' identifying images of this type. */ | 7576 | /* The symbol `imagemagick' identifying images of this type. */ |
| 7584 | 7577 | ||
| @@ -7588,65 +7581,46 @@ Lisp_Object Vimagemagick_render_type; | |||
| 7588 | /* Indices of image specification fields in imagemagick_format, below. */ | 7581 | /* Indices of image specification fields in imagemagick_format, below. */ |
| 7589 | 7582 | ||
| 7590 | enum imagemagick_keyword_index | 7583 | enum imagemagick_keyword_index |
| 7591 | { | 7584 | { |
| 7592 | IMAGEMAGICK_TYPE, | 7585 | IMAGEMAGICK_TYPE, |
| 7593 | IMAGEMAGICK_DATA, | 7586 | IMAGEMAGICK_DATA, |
| 7594 | IMAGEMAGICK_FILE, | 7587 | IMAGEMAGICK_FILE, |
| 7595 | IMAGEMAGICK_ASCENT, | 7588 | IMAGEMAGICK_ASCENT, |
| 7596 | IMAGEMAGICK_MARGIN, | 7589 | IMAGEMAGICK_MARGIN, |
| 7597 | IMAGEMAGICK_RELIEF, | 7590 | IMAGEMAGICK_RELIEF, |
| 7598 | IMAGEMAGICK_ALGORITHM, | 7591 | IMAGEMAGICK_ALGORITHM, |
| 7599 | IMAGEMAGICK_HEURISTIC_MASK, | 7592 | IMAGEMAGICK_HEURISTIC_MASK, |
| 7600 | IMAGEMAGICK_MASK, | 7593 | IMAGEMAGICK_MASK, |
| 7601 | IMAGEMAGICK_BACKGROUND, | 7594 | IMAGEMAGICK_BACKGROUND, |
| 7602 | IMAGEMAGICK_LAST | 7595 | IMAGEMAGICK_LAST |
| 7603 | }; | 7596 | }; |
| 7604 | 7597 | ||
| 7605 | /* Vector of image_keyword structures describing the format | 7598 | /* Vector of image_keyword structures describing the format |
| 7606 | of valid user-defined image specifications. */ | 7599 | of valid user-defined image specifications. */ |
| 7607 | 7600 | ||
| 7608 | static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] = | 7601 | static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] = |
| 7609 | { | 7602 | { |
| 7610 | {":type", IMAGE_SYMBOL_VALUE, 1}, | 7603 | {":type", IMAGE_SYMBOL_VALUE, 1}, |
| 7611 | {":data", IMAGE_STRING_VALUE, 0}, | 7604 | {":data", IMAGE_STRING_VALUE, 0}, |
| 7612 | {":file", IMAGE_STRING_VALUE, 0}, | 7605 | {":file", IMAGE_STRING_VALUE, 0}, |
| 7613 | {":ascent", IMAGE_ASCENT_VALUE, 0}, | 7606 | {":ascent", IMAGE_ASCENT_VALUE, 0}, |
| 7614 | {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, | 7607 | {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, |
| 7615 | {":relief", IMAGE_INTEGER_VALUE, 0}, | 7608 | {":relief", IMAGE_INTEGER_VALUE, 0}, |
| 7616 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 7609 | {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7617 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 7610 | {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7618 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, | 7611 | {":mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, |
| 7619 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} | 7612 | {":background", IMAGE_STRING_OR_NIL_VALUE, 0} |
| 7620 | }; | 7613 | }; |
| 7621 | /* Free X resources of imagemagick image IMG which is used on frame F. */ | 7614 | /* Free X resources of imagemagick image IMG which is used on frame F. */ |
| 7622 | 7615 | ||
| 7623 | static void | 7616 | static void |
| 7624 | imagemagick_clear_image (f, img) | 7617 | imagemagick_clear_image (struct frame *f, |
| 7625 | struct frame *f; | 7618 | struct image *img) |
| 7626 | struct image *img; | ||
| 7627 | { | 7619 | { |
| 7628 | printf("clearing imagemagick image\n"); | 7620 | printf("clearing imagemagick image\n"); |
| 7629 | x_clear_image (f, img); | 7621 | x_clear_image (f, img); |
| 7630 | } | 7622 | } |
| 7631 | 7623 | ||
| 7632 | /* Structure describing the image type `imagemagick'. Its the same type of | ||
| 7633 | structure defined for all image formats, handled by Emacs image | ||
| 7634 | functions. See struct image_type in dispextern.h. */ | ||
| 7635 | |||
| 7636 | static struct image_type imagemagick_type = | ||
| 7637 | { | ||
| 7638 | /* An identifier showing that this is an image structure for the IMAGEMAGICK format. */ | ||
| 7639 | &Qimagemagick, | ||
| 7640 | /* Handle to a function that can be used to identify a IMAGEMAGICK file. */ | ||
| 7641 | imagemagick_image_p, | ||
| 7642 | /* Handle to function used to load a IMAGEMAGICK file. */ | ||
| 7643 | imagemagick_load, | ||
| 7644 | /* Handle to function to free resources for IMAGEMAGICK. */ | ||
| 7645 | imagemagick_clear_image, | ||
| 7646 | /* An internal field to link to the next image type in a list of | ||
| 7647 | image types, will be filled in when registering the format. */ | ||
| 7648 | NULL | ||
| 7649 | }; | ||
| 7650 | 7624 | ||
| 7651 | 7625 | ||
| 7652 | /* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do | 7626 | /* Return non-zero if OBJECT is a valid IMAGEMAGICK image specification. Do |
| @@ -7654,8 +7628,7 @@ static struct image_type imagemagick_type = | |||
| 7654 | identify the IMAGEMAGICK format. */ | 7628 | identify the IMAGEMAGICK format. */ |
| 7655 | 7629 | ||
| 7656 | static int | 7630 | static int |
| 7657 | imagemagick_image_p (object) | 7631 | imagemagick_image_p (Lisp_Object object) |
| 7658 | Lisp_Object object; | ||
| 7659 | { | 7632 | { |
| 7660 | struct image_keyword fmt[IMAGEMAGICK_LAST]; | 7633 | struct image_keyword fmt[IMAGEMAGICK_LAST]; |
| 7661 | bcopy (imagemagick_format, fmt, sizeof fmt); | 7634 | bcopy (imagemagick_format, fmt, sizeof fmt); |
| @@ -7672,61 +7645,6 @@ imagemagick_image_p (object) | |||
| 7672 | #define DrawRectangle DrawRectangleGif | 7645 | #define DrawRectangle DrawRectangleGif |
| 7673 | #include <wand/MagickWand.h> | 7646 | #include <wand/MagickWand.h> |
| 7674 | 7647 | ||
| 7675 | /* Load IMAGEMAGICK image IMG for use on frame F. Value is non-zero if | ||
| 7676 | successful. this function will go into the imagemagick_type structure, and | ||
| 7677 | the prototype thus needs to be compatible with that structure. */ | ||
| 7678 | |||
| 7679 | static int | ||
| 7680 | imagemagick_load (f, img) | ||
| 7681 | struct frame *f; | ||
| 7682 | struct image *img; | ||
| 7683 | { | ||
| 7684 | int success_p = 0; | ||
| 7685 | Lisp_Object file_name; | ||
| 7686 | |||
| 7687 | /* If IMG->spec specifies a file name, create a non-file spec from it. */ | ||
| 7688 | file_name = image_spec_value (img->spec, QCfile, NULL); | ||
| 7689 | if (STRINGP (file_name)) | ||
| 7690 | { | ||
| 7691 | Lisp_Object file; | ||
| 7692 | unsigned char *contents; | ||
| 7693 | int size; | ||
| 7694 | struct gcpro gcpro1; | ||
| 7695 | |||
| 7696 | file = x_find_image_file (file_name); | ||
| 7697 | GCPRO1 (file); | ||
| 7698 | if (!STRINGP (file)) | ||
| 7699 | { | ||
| 7700 | image_error ("Cannot find image file `%s'", file_name, Qnil); | ||
| 7701 | UNGCPRO; | ||
| 7702 | return 0; | ||
| 7703 | } | ||
| 7704 | |||
| 7705 | /* Read the entire file into memory. */ | ||
| 7706 | /* contents = slurp_file (SDATA (file), &size); */ | ||
| 7707 | /* if (contents == NULL) */ | ||
| 7708 | /* { */ | ||
| 7709 | /* image_error ("Error loading IMAGEMAGICK image `%s'", img->spec, Qnil); */ | ||
| 7710 | /* UNGCPRO; */ | ||
| 7711 | /* return 0; */ | ||
| 7712 | /* } */ | ||
| 7713 | /* If the file was slurped into memory properly, parse it. */ | ||
| 7714 | success_p = imagemagick_load_image (f, img, 0, 0, SDATA(file_name)); | ||
| 7715 | UNGCPRO; | ||
| 7716 | } | ||
| 7717 | /* Else its not a file, its a lisp object. Load the image from a | ||
| 7718 | lisp object rather than a file. */ | ||
| 7719 | else | ||
| 7720 | { | ||
| 7721 | Lisp_Object data; | ||
| 7722 | |||
| 7723 | data = image_spec_value (img->spec, QCdata, NULL); | ||
| 7724 | success_p = imagemagick_load_image (f, img, SDATA (data), SBYTES (data),NULL); | ||
| 7725 | } | ||
| 7726 | |||
| 7727 | return success_p; | ||
| 7728 | } | ||
| 7729 | |||
| 7730 | /* imagemagick_load_image is a helper function for imagemagick_load, which does the | 7648 | /* imagemagick_load_image is a helper function for imagemagick_load, which does the |
| 7731 | actual loading given contents and size, apart from frame and image | 7649 | actual loading given contents and size, apart from frame and image |
| 7732 | structures, passed from imagemagick_load. | 7650 | structures, passed from imagemagick_load. |
| @@ -7737,17 +7655,11 @@ imagemagick_load (f, img) | |||
| 7737 | */ | 7655 | */ |
| 7738 | 7656 | ||
| 7739 | static int | 7657 | static int |
| 7740 | imagemagick_load_image (f, img, contents, size, filename) | 7658 | imagemagick_load_image (struct frame *f, /* Pointer to emacs frame structure. */ |
| 7741 | /* Pointer to emacs frame structure. */ | 7659 | struct image *img, /* Pointer to emacs image structure. */ |
| 7742 | struct frame *f; | 7660 | unsigned char *contents,/* String containing the IMAGEMAGICK data to be parsed. */ |
| 7743 | /* Pointer to emacs image structure. */ | 7661 | unsigned int size, /* Size of data in bytes. */ |
| 7744 | struct image *img; | 7662 | unsigned char *filename)/* Filename, either pass filename or contents/size. */ |
| 7745 | /* String containing the IMAGEMAGICK data to be parsed. */ | ||
| 7746 | unsigned char *contents; | ||
| 7747 | /* Size of data in bytes. */ | ||
| 7748 | unsigned int size; | ||
| 7749 | /* Filename, either pass filename or contents/size. */ | ||
| 7750 | unsigned char *filename; | ||
| 7751 | { | 7663 | { |
| 7752 | long unsigned int width; | 7664 | long unsigned int width; |
| 7753 | long unsigned int height; | 7665 | long unsigned int height; |
| @@ -7765,23 +7677,30 @@ imagemagick_load_image (f, img, contents, size, filename) | |||
| 7765 | PixelIterator *iterator; | 7677 | PixelIterator *iterator; |
| 7766 | PixelWand **pixels; | 7678 | PixelWand **pixels; |
| 7767 | MagickPixelPacket pixel; | 7679 | MagickPixelPacket pixel; |
| 7680 | Lisp_Object image; | ||
| 7681 | Lisp_Object value; | ||
| 7682 | Lisp_Object crop, geometry; | ||
| 7683 | long ino; | ||
| 7684 | int desired_width, desired_height; | ||
| 7685 | double rotation; | ||
| 7686 | int imagemagick_rendermethod; | ||
| 7687 | int pixelwidth; | ||
| 7768 | 7688 | ||
| 7769 | 7689 | ||
| 7770 | /* image_wand will contain the image. */ | 7690 | /* image_wand will contain the image. */ |
| 7771 | image_wand = NewMagickWand(); | 7691 | image_wand = NewMagickWand(); |
| 7772 | 7692 | ||
| 7773 | /* Parse the contents argument and initialize image_wand. */ | 7693 | /* Parse the contents argument and initialize image_wand. */ |
| 7774 | if(filename!=NULL) | 7694 | if(filename != NULL) |
| 7775 | status=MagickReadImage(image_wand, filename); | 7695 | status = MagickReadImage(image_wand, filename); |
| 7776 | else | 7696 | else |
| 7777 | status=MagickReadImageBlob(image_wand, contents, size); | 7697 | status = MagickReadImageBlob(image_wand, contents, size); |
| 7778 | image_error ("im read failed", Qnil, Qnil); | 7698 | image_error ("im read failed", Qnil, Qnil); |
| 7779 | if (status == MagickFalse) goto imagemagick_error; | 7699 | if (status == MagickFalse) goto imagemagick_error; |
| 7780 | 7700 | ||
| 7781 | /* Handle image index for image types who can contain more than one image. | 7701 | /* Handle image index for image types who can contain more than one image. |
| 7782 | Interface :index is same as for GIF. */ | 7702 | Interface :index is same as for GIF. */ |
| 7783 | Lisp_Object image; | 7703 | |
| 7784 | long ino; | ||
| 7785 | image = image_spec_value (img->spec, QCindex, NULL); | 7704 | image = image_spec_value (img->spec, QCindex, NULL); |
| 7786 | ino = INTEGERP (image) ? XFASTINT (image) : 0; | 7705 | ino = INTEGERP (image) ? XFASTINT (image) : 0; |
| 7787 | 7706 | ||
| @@ -7800,7 +7719,7 @@ imagemagick_load_image (f, img, contents, size, filename) | |||
| 7800 | img->data.lisp_val = Fcons (Qcount, | 7719 | img->data.lisp_val = Fcons (Qcount, |
| 7801 | Fcons (make_number (MagickGetNumberImages(image_wand)), | 7720 | Fcons (make_number (MagickGetNumberImages(image_wand)), |
| 7802 | img->data.lisp_val)); | 7721 | img->data.lisp_val)); |
| 7803 | if(ino==0) | 7722 | if(ino == 0) |
| 7804 | MagickSetFirstIterator(image_wand); | 7723 | MagickSetFirstIterator(image_wand); |
| 7805 | else | 7724 | else |
| 7806 | MagickSetIteratorIndex(image_wand, ino); | 7725 | MagickSetIteratorIndex(image_wand, ino); |
| @@ -7809,65 +7728,65 @@ imagemagick_load_image (f, img, contents, size, filename) | |||
| 7809 | If width and/or height is set in the display spec | 7728 | If width and/or height is set in the display spec |
| 7810 | assume we want to scale to those. */ | 7729 | assume we want to scale to those. */ |
| 7811 | 7730 | ||
| 7812 | int desired_width, desired_height; | ||
| 7813 | Lisp_Object value; | ||
| 7814 | value = image_spec_value (img->spec, QCwidth, NULL); | 7731 | value = image_spec_value (img->spec, QCwidth, NULL); |
| 7815 | desired_width = (INTEGERP (value) ? XFASTINT (value) : -1); | 7732 | desired_width = (INTEGERP (value) ? XFASTINT (value) : -1); |
| 7816 | value = image_spec_value (img->spec, QCheight, NULL); | 7733 | value = image_spec_value (img->spec, QCheight, NULL); |
| 7817 | desired_height = (INTEGERP (value) ? XFASTINT (value) : -1); | 7734 | desired_height = (INTEGERP (value) ? XFASTINT (value) : -1); |
| 7818 | if(desired_width != -1 && desired_height != -1){ | 7735 | if(desired_width != -1 && desired_height != -1) |
| 7819 | printf("MagickScaleImage %d %d\n",desired_width, desired_height); | 7736 | { |
| 7820 | status=MagickScaleImage(image_wand, desired_width, desired_height); | 7737 | printf("MagickScaleImage %d %d\n", desired_width, desired_height); |
| 7821 | if (status == MagickFalse) { | 7738 | status = MagickScaleImage(image_wand, desired_width, desired_height); |
| 7822 | image_error ("Imagemagick scale failed", Qnil, Qnil); | 7739 | if (status == MagickFalse) { |
| 7823 | goto imagemagick_error; | 7740 | image_error ("Imagemagick scale failed", Qnil, Qnil); |
| 7741 | goto imagemagick_error; | ||
| 7742 | } | ||
| 7824 | } | 7743 | } |
| 7825 | |||
| 7826 | } | ||
| 7827 | 7744 | ||
| 7828 | /* Also support :geometry and :crop which are imagemagick specific descriptors. */ | 7745 | /* Also support :geometry and :crop which are imagemagick specific descriptors. */ |
| 7829 | 7746 | ||
| 7830 | Lisp_Object crop, geometry; | ||
| 7831 | crop = image_spec_value (img->spec, QCcrop, NULL); | 7747 | crop = image_spec_value (img->spec, QCcrop, NULL); |
| 7832 | geometry = image_spec_value (img->spec, QCgeometry, NULL); | 7748 | geometry = image_spec_value (img->spec, QCgeometry, NULL); |
| 7833 | if (STRINGP (crop) && STRINGP (geometry)){ | 7749 | if (STRINGP (crop) && STRINGP (geometry)) |
| 7834 | printf("MagickTransformImage %s %s\n",SDATA(crop), SDATA(geometry)); | 7750 | { |
| 7835 | image_wand = MagickTransformImage (image_wand, SDATA (crop), SDATA (geometry)); | 7751 | printf("MagickTransformImage %s %s\n", SDATA(crop), SDATA(geometry)); |
| 7836 | /* TODO differ between image_wand and transform_wand. */ | 7752 | image_wand = MagickTransformImage (image_wand, SDATA (crop), SDATA (geometry)); |
| 7837 | } | 7753 | /* TODO differ between image_wand and transform_wand. */ |
| 7754 | } | ||
| 7838 | 7755 | ||
| 7839 | /* Furthermore :rotation. we need background color and angle for rotation. */ | 7756 | /* Furthermore :rotation. we need background color and angle for rotation. */ |
| 7840 | /* | 7757 | /* |
| 7841 | TODO background handling for rotation | 7758 | TODO background handling for rotation |
| 7842 | specified_bg = image_spec_value (img->spec, QCbackground, NULL); | 7759 | specified_bg = image_spec_value (img->spec, QCbackground, NULL); |
| 7843 | if (!STRINGP (specified_bg) | 7760 | if (!STRINGP (specified_bg) |
| 7844 | */ | 7761 | */ |
| 7845 | double rotation; | 7762 | value = image_spec_value (img->spec, QCrotation, NULL); |
| 7846 | value = image_spec_value (img->spec, QCrotation, NULL); | 7763 | if (FLOATP (value)) |
| 7847 | if (FLOATP (value)){ | 7764 | { |
| 7848 | PixelWand* background = NewPixelWand(); | 7765 | PixelWand* background = NewPixelWand(); |
| 7849 | PixelSetColor (background, "#ffffff");/*TODO remove hardcode*/ | 7766 | PixelSetColor (background, "#ffffff");/*TODO remove hardcode*/ |
| 7850 | 7767 | ||
| 7851 | rotation = extract_float (value); | 7768 | rotation = extract_float (value); |
| 7852 | printf ("MagickRotateImage %f\n",rotation); | 7769 | printf ("MagickRotateImage %f\n", rotation); |
| 7853 | 7770 | ||
| 7854 | status=MagickRotateImage (image_wand, background,rotation); | 7771 | status = MagickRotateImage (image_wand, background, rotation); |
| 7855 | DestroyPixelWand (background); | 7772 | DestroyPixelWand (background); |
| 7856 | if (status == MagickFalse) { | 7773 | if (status == MagickFalse) |
| 7857 | image_error ("Imagemagick image rotate failed", Qnil, Qnil); | 7774 | { |
| 7858 | goto imagemagick_error; | 7775 | image_error ("Imagemagick image rotate failed", Qnil, Qnil); |
| 7859 | } | 7776 | goto imagemagick_error; |
| 7777 | } | ||
| 7860 | } | 7778 | } |
| 7861 | 7779 | ||
| 7862 | /* Finaly we are done manipulating the image, | 7780 | /* Finaly we are done manipulating the image, |
| 7863 | figure out resulting width, height, and then transfer ownerwship to Emacs. | 7781 | figure out resulting width, height, and then transfer ownerwship to Emacs. |
| 7864 | */ | 7782 | */ |
| 7865 | height=MagickGetImageHeight (image_wand); | 7783 | height = MagickGetImageHeight (image_wand); |
| 7866 | width=MagickGetImageWidth (image_wand); | 7784 | width = MagickGetImageWidth (image_wand); |
| 7867 | if (status == MagickFalse) { | 7785 | if (status == MagickFalse) |
| 7786 | { | ||
| 7868 | image_error ("Imagemagick image get size failed", Qnil, Qnil); | 7787 | image_error ("Imagemagick image get size failed", Qnil, Qnil); |
| 7869 | goto imagemagick_error; | 7788 | goto imagemagick_error; |
| 7870 | } | 7789 | } |
| 7871 | 7790 | ||
| 7872 | if (! check_image_size (f, width, height)) | 7791 | if (! check_image_size (f, width, height)) |
| 7873 | { | 7792 | { |
| @@ -7880,91 +7799,95 @@ imagemagick_load_image (f, img, contents, size, filename) | |||
| 7880 | 7799 | ||
| 7881 | 7800 | ||
| 7882 | init_color_table (); | 7801 | init_color_table (); |
| 7883 | int imagemagick_rendermethod=(INTEGERP (Vimagemagick_render_type) ? XFASTINT (Vimagemagick_render_type) : 0); | 7802 | imagemagick_rendermethod = (INTEGERP (Vimagemagick_render_type) ? XFASTINT (Vimagemagick_render_type) : 0); |
| 7884 | if (imagemagick_rendermethod==0){ | 7803 | if (imagemagick_rendermethod == 0) |
| 7885 | /* Try to create a x pixmap to hold the imagemagick pixmap. */ | 7804 | { |
| 7886 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)){ | 7805 | /* Try to create a x pixmap to hold the imagemagick pixmap. */ |
| 7887 | image_error("Imagemagick X bitmap allocation failure",Qnil,Qnil); | 7806 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) |
| 7888 | goto imagemagick_error; | 7807 | { |
| 7889 | } | 7808 | image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); |
| 7809 | goto imagemagick_error; | ||
| 7810 | } | ||
| 7890 | 7811 | ||
| 7891 | /* Copy imagegmagick image to x with primitive yet robust pixel | 7812 | /* Copy imagegmagick image to x with primitive yet robust pixel |
| 7892 | pusher loop. This has been tested a lot with many different | 7813 | pusher loop. This has been tested a lot with many different |
| 7893 | images, it doesnt work too well with image archive formats though! | 7814 | images, it doesnt work too well with image archive formats though! |
| 7894 | 7815 | ||
| 7895 | Also seems slow. | 7816 | Also seems slow. |
| 7896 | */ | 7817 | */ |
| 7897 | 7818 | ||
| 7898 | /* Copy pixels from the imagemagick image structure to the x image map. */ | 7819 | /* Copy pixels from the imagemagick image structure to the x image map. */ |
| 7899 | iterator = NewPixelIterator (image_wand); | 7820 | iterator = NewPixelIterator (image_wand); |
| 7900 | if ((iterator == (PixelIterator *) NULL)) { | 7821 | if ((iterator == (PixelIterator *) NULL)) |
| 7822 | { | ||
| 7901 | image_error ("Imagemagick pixel iterator creation failed", Qnil, Qnil); | 7823 | image_error ("Imagemagick pixel iterator creation failed", Qnil, Qnil); |
| 7902 | goto imagemagick_error; | 7824 | goto imagemagick_error; |
| 7825 | } | ||
| 7826 | |||
| 7827 | for (y = 0; y < (long) MagickGetImageHeight(image_wand); y++) | ||
| 7828 | { | ||
| 7829 | pixels = PixelGetNextIteratorRow (iterator, &width); | ||
| 7830 | if ((pixels == (PixelWand **) NULL)) | ||
| 7831 | break; | ||
| 7832 | for (x = 0; x < (long) width; x++) | ||
| 7833 | { | ||
| 7834 | PixelGetMagickColor (pixels[x], &pixel); | ||
| 7835 | XPutPixel (ximg, x, y, lookup_rgb_color (f, pixel.red, pixel.green, pixel.blue)); | ||
| 7836 | } | ||
| 7837 | } | ||
| 7838 | DestroyPixelIterator (iterator); | ||
| 7903 | } | 7839 | } |
| 7904 | 7840 | ||
| 7905 | for (y=0; y < (long) MagickGetImageHeight(image_wand); y++) | 7841 | if (imagemagick_rendermethod == 1) |
| 7906 | { | 7842 | { |
| 7907 | pixels = PixelGetNextIteratorRow (iterator, &width); | 7843 | /* Try if magicexportimage is any faster than pixelpushing. */ |
| 7908 | if ((pixels == (PixelWand **) NULL)) | 7844 | /* printf("ximg: bitmap_unit:%d format:%d byte_order:%d depth:%d bits_per_pixel:%d\n", */ |
| 7909 | break; | 7845 | /* ximg->bitmap_unit,ximg->format,ximg->byte_order,ximg->depth,ximg->bits_per_pixel); */ |
| 7910 | for (x=0; x < (long) width; x++) | 7846 | int imagedepth = 24;/*MagickGetImageDepth(image_wand);*/ |
| 7911 | { | 7847 | char* exportdepth = imagedepth <= 8 ? "I" : "BGRP";/*"RGBP";*/ |
| 7912 | PixelGetMagickColor (pixels[x], &pixel); | 7848 | /* Try to create a x pixmap to hold the imagemagick pixmap. */ |
| 7913 | XPutPixel (ximg, x, y, lookup_rgb_color (f, pixel.red, pixel.green, pixel.blue)); | 7849 | printf("imagedepth:%d exportdepth:%s\n", imagedepth, exportdepth); |
| 7914 | } | 7850 | if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, &ximg, &img->pixmap)){ |
| 7851 | image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); | ||
| 7852 | goto imagemagick_error; | ||
| 7915 | } | 7853 | } |
| 7916 | DestroyPixelIterator (iterator); | ||
| 7917 | } | ||
| 7918 | |||
| 7919 | if (imagemagick_rendermethod==1){ | ||
| 7920 | /* Try if magicexportimage is any faster than pixelpushing. */ | ||
| 7921 | /* printf("ximg: bitmap_unit:%d format:%d byte_order:%d depth:%d bits_per_pixel:%d\n", */ | ||
| 7922 | /* ximg->bitmap_unit,ximg->format,ximg->byte_order,ximg->depth,ximg->bits_per_pixel); */ | ||
| 7923 | int imagedepth=24;/*MagickGetImageDepth(image_wand);*/ | ||
| 7924 | char* exportdepth= imagedepth <= 8 ? "I" : "BGRP";/*"RGBP";*/ | ||
| 7925 | /* Try to create a x pixmap to hold the imagemagick pixmap. */ | ||
| 7926 | printf("imagedepth:%d exportdepth:%s\n", imagedepth, exportdepth); | ||
| 7927 | if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, &ximg, &img->pixmap)){ | ||
| 7928 | image_error("Imagemagick X bitmap allocation failure",Qnil,Qnil); | ||
| 7929 | goto imagemagick_error; | ||
| 7930 | } | ||
| 7931 | 7854 | ||
| 7932 | 7855 | ||
| 7933 | /* Oddly, the below code doesnt seem to work:*/ | 7856 | /* Oddly, the below code doesnt seem to work:*/ |
| 7934 | int pixelwidth; | 7857 | /* switch(ximg->bitmap_unit){ */ |
| 7935 | /* switch(ximg->bitmap_unit){ */ | 7858 | /* case 8: */ |
| 7936 | /* case 8: */ | 7859 | /* pixelwidth=CharPixel; */ |
| 7937 | /* pixelwidth=CharPixel; */ | 7860 | /* break; */ |
| 7938 | /* break; */ | 7861 | /* case 16: */ |
| 7939 | /* case 16: */ | 7862 | /* pixelwidth=ShortPixel; */ |
| 7940 | /* pixelwidth=ShortPixel; */ | 7863 | /* break; */ |
| 7941 | /* break; */ | 7864 | /* case 32: */ |
| 7942 | /* case 32: */ | 7865 | /* pixelwidth=LongPixel; */ |
| 7943 | /* pixelwidth=LongPixel; */ | 7866 | /* break; */ |
| 7944 | /* break; */ | 7867 | /* } */ |
| 7945 | /* } */ | 7868 | /* |
| 7946 | /* | 7869 | Here im just guessing the format of the bitmap. |
| 7947 | Here im just guessing the format of the bitmap. | 7870 | happens to work fine for: |
| 7948 | happens to work fine for: | 7871 | - bw djvu images |
| 7949 | - bw djvu images | 7872 | on rgb display. |
| 7950 | on rgb display. | 7873 | seems about 3 times as fast as pixel pushing(not carefully measured) |
| 7951 | seems about 3 times as fast as pixel pushing(not carefully measured) | 7874 | with color djvu, the bitplanes are mapped to wrong color(seems fixed). |
| 7952 | with color djvu, the bitplanes are mapped to wrong color(seems fixed). | 7875 | |
| 7953 | 7876 | */ | |
| 7954 | */ | 7877 | pixelwidth = CharPixel;/*??? TODO figure out*/ |
| 7955 | pixelwidth=CharPixel;/*??? TODO figure out*/ | ||
| 7956 | #ifdef HAVE_MAGICKEXPORTIMAGEPIXELS | 7878 | #ifdef HAVE_MAGICKEXPORTIMAGEPIXELS |
| 7957 | MagickExportImagePixels(image_wand, | 7879 | MagickExportImagePixels(image_wand, |
| 7958 | 0,0, | 7880 | 0, 0, |
| 7959 | width,height, | 7881 | width, height, |
| 7960 | exportdepth, | 7882 | exportdepth, |
| 7961 | pixelwidth, | 7883 | pixelwidth, |
| 7962 | /*&(img->pixmap));*/ | 7884 | /*&(img->pixmap));*/ |
| 7963 | ximg->data); | 7885 | ximg->data); |
| 7964 | #else | 7886 | #else |
| 7965 | image_error("You dont have MagickExportImagePixels, upgrade ImageMagick if you want to try it!",Qnil,Qnil); | 7887 | image_error("You dont have MagickExportImagePixels, upgrade ImageMagick if you want to try it!", |
| 7888 | Qnil, Qnil); | ||
| 7966 | #endif | 7889 | #endif |
| 7967 | } | 7890 | } |
| 7968 | 7891 | ||
| 7969 | 7892 | ||
| 7970 | #ifdef COLOR_TABLE_SUPPORT | 7893 | #ifdef COLOR_TABLE_SUPPORT |
| @@ -8000,10 +7923,87 @@ imagemagick_load_image (f, img, contents, size, filename) | |||
| 8000 | return 0; | 7923 | return 0; |
| 8001 | } | 7924 | } |
| 8002 | 7925 | ||
| 8003 | DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0,0,0, | 7926 | |
| 7927 | /* Load IMAGEMAGICK image IMG for use on frame F. Value is non-zero if | ||
| 7928 | successful. this function will go into the imagemagick_type structure, and | ||
| 7929 | the prototype thus needs to be compatible with that structure. */ | ||
| 7930 | |||
| 7931 | static int | ||
| 7932 | imagemagick_load (struct frame *f, | ||
| 7933 | struct image *img) | ||
| 7934 | { | ||
| 7935 | int success_p = 0; | ||
| 7936 | Lisp_Object file_name; | ||
| 7937 | |||
| 7938 | /* If IMG->spec specifies a file name, create a non-file spec from it. */ | ||
| 7939 | file_name = image_spec_value (img->spec, QCfile, NULL); | ||
| 7940 | if (STRINGP (file_name)) | ||
| 7941 | { | ||
| 7942 | Lisp_Object file; | ||
| 7943 | unsigned char *contents; | ||
| 7944 | int size; | ||
| 7945 | struct gcpro gcpro1; | ||
| 7946 | |||
| 7947 | file = x_find_image_file (file_name); | ||
| 7948 | GCPRO1 (file); | ||
| 7949 | if (!STRINGP (file)) | ||
| 7950 | { | ||
| 7951 | image_error ("Cannot find image file `%s'", file_name, Qnil); | ||
| 7952 | UNGCPRO; | ||
| 7953 | return 0; | ||
| 7954 | } | ||
| 7955 | |||
| 7956 | /* Read the entire file into memory. */ | ||
| 7957 | /* contents = slurp_file (SDATA (file), &size); */ | ||
| 7958 | /* if (contents == NULL) */ | ||
| 7959 | /* { */ | ||
| 7960 | /* image_error ("Error loading IMAGEMAGICK image `%s'", img->spec, Qnil); */ | ||
| 7961 | /* UNGCPRO; */ | ||
| 7962 | /* return 0; */ | ||
| 7963 | /* } */ | ||
| 7964 | /* If the file was slurped into memory properly, parse it. */ | ||
| 7965 | success_p = imagemagick_load_image (f, img, 0, 0, SDATA(file_name)); | ||
| 7966 | UNGCPRO; | ||
| 7967 | } | ||
| 7968 | /* Else its not a file, its a lisp object. Load the image from a | ||
| 7969 | lisp object rather than a file. */ | ||
| 7970 | else | ||
| 7971 | { | ||
| 7972 | Lisp_Object data; | ||
| 7973 | |||
| 7974 | data = image_spec_value (img->spec, QCdata, NULL); | ||
| 7975 | success_p = imagemagick_load_image (f, img, SDATA (data), SBYTES (data), NULL); | ||
| 7976 | } | ||
| 7977 | |||
| 7978 | return success_p; | ||
| 7979 | } | ||
| 7980 | |||
| 7981 | /* Structure describing the image type `imagemagick'. Its the same type of | ||
| 7982 | structure defined for all image formats, handled by Emacs image | ||
| 7983 | functions. See struct image_type in dispextern.h. */ | ||
| 7984 | |||
| 7985 | static struct image_type imagemagick_type = | ||
| 7986 | { | ||
| 7987 | /* An identifier showing that this is an image structure for the IMAGEMAGICK format. */ | ||
| 7988 | &Qimagemagick, | ||
| 7989 | /* Handle to a function that can be used to identify a IMAGEMAGICK file. */ | ||
| 7990 | imagemagick_image_p, | ||
| 7991 | /* Handle to function used to load a IMAGEMAGICK file. */ | ||
| 7992 | imagemagick_load, | ||
| 7993 | /* Handle to function to free resources for IMAGEMAGICK. */ | ||
| 7994 | imagemagick_clear_image, | ||
| 7995 | /* An internal field to link to the next image type in a list of | ||
| 7996 | image types, will be filled in when registering the format. */ | ||
| 7997 | NULL | ||
| 7998 | }; | ||
| 7999 | |||
| 8000 | |||
| 8001 | |||
| 8002 | |||
| 8003 | DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0, 0, 0, | ||
| 8004 | doc: /* Return image file types supported by ImageMagick. | 8004 | doc: /* Return image file types supported by ImageMagick. |
| 8005 | Since ImageMagick recognizes a lot of file-types that clash with Emacs, | 8005 | Since ImageMagick recognizes a lot of file-types that clash with Emacs, |
| 8006 | such as .c, we want to be able to alter the list at the lisp level. */) | 8006 | such as .c, we want to be able to alter the list at the lisp level. */) |
| 8007 | () | 8007 | () |
| 8008 | { | 8008 | { |
| 8009 | Lisp_Object typelist = Qnil; | 8009 | Lisp_Object typelist = Qnil; |
| @@ -8012,11 +8012,12 @@ DEFUN ("imagemagick-types", Fimagemagick_types, Simagemagick_types, 0,0,0, | |||
| 8012 | char** imtypes = GetMagickList ("*", &numf, &ex); | 8012 | char** imtypes = GetMagickList ("*", &numf, &ex); |
| 8013 | int i; | 8013 | int i; |
| 8014 | Lisp_Object Qimagemagicktype; | 8014 | Lisp_Object Qimagemagicktype; |
| 8015 | for (i = 0; i < numf; i++) { | 8015 | for (i = 0; i < numf; i++) |
| 8016 | Qimagemagicktype = intern (*( imtypes + i)); | 8016 | { |
| 8017 | typelist = Fcons (Qimagemagicktype, typelist); | 8017 | Qimagemagicktype = intern (imtypes[i]); |
| 8018 | } | 8018 | typelist = Fcons (Qimagemagicktype, typelist); |
| 8019 | return typelist; | 8019 | } |
| 8020 | return typelist; | ||
| 8020 | } | 8021 | } |
| 8021 | 8022 | ||
| 8022 | #endif /* defined (HAVE_IMAGEMAGICK) */ | 8023 | #endif /* defined (HAVE_IMAGEMAGICK) */ |
| @@ -9036,13 +9037,14 @@ a large number of images, the actual eviction time may be shorter. | |||
| 9036 | The value can also be nil, meaning the cache is never cleared. | 9037 | The value can also be nil, meaning the cache is never cleared. |
| 9037 | The function `clear-image-cache' disregards this variable. */); | 9038 | The function `clear-image-cache' disregards this variable. */); |
| 9038 | Vimage_cache_eviction_delay = make_number (300); | 9039 | Vimage_cache_eviction_delay = make_number (300); |
| 9039 | } | ||
| 9040 | |||
| 9041 | #ifdef HAVE_IMAGEMAGICK | 9040 | #ifdef HAVE_IMAGEMAGICK |
| 9042 | DEFVAR_LISP ("imagemagick-render-type", &Vimagemagick_render_type, | 9041 | DEFVAR_LISP ("imagemagick-render-type", &Vimagemagick_render_type, |
| 9043 | doc: /* */); | 9042 | doc: /* Choose between ImageMagick render methods. */); |
| 9044 | #endif | 9043 | #endif |
| 9045 | 9044 | ||
| 9045 | } | ||
| 9046 | |||
| 9047 | |||
| 9046 | void | 9048 | void |
| 9047 | init_image () | 9049 | init_image () |
| 9048 | { | 9050 | { |