Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port init-image-library to rust #1536

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 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;

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

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

/// Value is non-nil if SPEC is a valid image specification.
#[cfg(feature = "glyph-debug")]
Expand All @@ -13,4 +15,15 @@ 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
19 changes: 3 additions & 16 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,11 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
/* List of supported image types. Use define_image_type to add new
types. Use lookup_image_type to find a type for a given symbol. */

static struct image_type *image_types;
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