Skip to content

Commit

Permalink
Port init-image-library to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
benreyn committed Aug 13, 2019
1 parent f4ecc23 commit 7291918
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
16 changes: 14 additions & 2 deletions rust_src/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Functions for image support on window system.

#[cfg(feature = "glyph-debug")]
use remacs_macros::lisp_fn;

#[cfg(feature = "glyph-debug")]
use crate::{lisp::LispObject, remacs_sys::valid_image_p};
use crate::remacs_sys::valid_image_p;

use crate::lisp::LispObject;
use crate::remacs_sys::lookup_image_type;

/// Value is non-nil if SPEC is a valid image specification.
#[cfg(feature = "glyph-debug")]
Expand All @@ -13,4 +15,14 @@ pub fn imagep(spec: LispObject) -> bool {
unsafe { valid_image_p(spec) }
}

/// Initialize image library implementing image type TYPE.
/// Return non-nil if TYPE is a supported image type.
/// If image libraries are loaded dynamically (currently only the case on
/// MS-Windows), load the library for TYPE if it is not yet loaded, using
/// the library file(s) specified by `dynamic-library-alist'.
#[lisp_fn]
pub fn init_image_library(r#type: LispObject) -> bool {
unsafe { !lookup_image_type(r#type).is_null() }
}

include!(concat!(env!("OUT_DIR"), "/image_exports.rs"));
1 change: 1 addition & 0 deletions src/dispextern.h
Original file line number Diff line number Diff line change
Expand Up @@ -3339,6 +3339,7 @@ extern Lisp_Object x_find_image_file (Lisp_Object);

void x_kill_gs_process (Pixmap, struct frame *);
struct image_cache *make_image_cache (void);
struct image_type *lookup_image_type (Lisp_Object);
void free_image_cache (struct frame *);
void clear_image_caches (Lisp_Object);
void mark_image_cache (struct image_cache *);
Expand Down
17 changes: 2 additions & 15 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ static struct image_type *image_types;

/* Forward function prototypes. */

static struct image_type *lookup_image_type (Lisp_Object);
struct image_type *lookup_image_type (Lisp_Object);
static void x_laplace (struct frame *, struct image *);
static void x_emboss (struct frame *, struct image *);
static void x_build_heuristic_mask (struct frame *, struct image *,
Expand Down Expand Up @@ -9687,22 +9687,10 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0,
Initialization
***********************************************************************/

DEFUN ("init-image-library", Finit_image_library, Sinit_image_library, 1, 1, 0,
doc: /* Initialize image library implementing image type TYPE.
Return non-nil if TYPE is a supported image type.
If image libraries are loaded dynamically (currently only the case on
MS-Windows), load the library for TYPE if it is not yet loaded, using
the library file(s) specified by `dynamic-library-alist'. */)
(Lisp_Object type)
{
return lookup_image_type (type) ? Qt : Qnil;
}

/* Look up image type TYPE, and return a pointer to its image_type
structure. Return 0 if TYPE is not a known image type. */

static struct image_type *
struct image_type *
lookup_image_type (Lisp_Object type)
{
/* Types pbm and xbm are built-in and always available. */
Expand Down Expand Up @@ -9914,7 +9902,6 @@ non-numeric, there is no explicit limit on the size of images. */);
#endif /* HAVE_NTGUI */
#endif /* HAVE_RSVG */

defsubr (&Sinit_image_library);
#ifdef HAVE_IMAGEMAGICK
defsubr (&Simagemagick_types);
#endif
Expand Down
12 changes: 12 additions & 0 deletions test/rust_src/src/image-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;;; image-tests.el --- Tests for image.rs

;;; Code:

(require 'ert)

(ert-deftest image-test--init-image-library ()
(should (eq (init-image-library 'jpeg) t)))

(provide 'image-tests)

;; image-tests.el ends here

0 comments on commit 7291918

Please sign in to comment.