Image resizing and rotation on NS port without imagemagick

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Image resizing and rotation on NS port without imagemagick

Alan Third
It’s always kind of bugged me that I need imagemagick to do image
resizing when Cocoa and GNUstep support it natively, so I’ve finally
got round to implementing it.

It seems to work fine. Any comments are welcome.

NOTE: if you have libjpg, libpng, or whatever installed, configure
includes them and emacs will use them preferentially over the built‐in
EmacsImage stuff, so you may need to use

    --without-png --without-gif --without-jpeg

I imagine there’s a way to switch the default to not use them when
compiling --with-ns?
--
Alan Third

0001-Add-image-resizing-and-rotation-to-NS-port.patch (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Image resizing and rotation on NS port without imagemagick

Lars Ingebrigtsen
Alan Third <[hidden email]> writes:

> It’s always kind of bugged me that I need imagemagick to do image
> resizing when Cocoa and GNUstep support it natively, so I’ve finally
> got round to implementing it.

Allowing all the other image formats to support scaling and stuff would
be very nice, but this is just for the Apple port?  I think if Emacs has
(for instance) .png scaling, it should preferably be supported across
all architectures...

> +- (void)setSizeFromSpec: (Lisp_Object) spec
> +{
> +  NSSize size = [self size];
> +  Lisp_Object value;
> +  double scale = 1, aspect = size.width / size.height;
> +  double width = -1, height = -1, max_width = -1, max_height = -1;
> +
> +  value = Fplist_get (spec, QCscale);
> +  if (NUMBERP (value))
> +    scale = XFLOATINT (value) ;

[...]

> +  [self setSize:NSMakeSize(width, height)];

(Etc.)  This function seems to replicate the functionality of
compute_image_size in image.c?  Is there any reason why that couldn't
just be reused here, too?  (Perhaps the calling conventions would need
to be tweaked a bit...)

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

Reply | Threaded
Open this post in threaded view
|

Re: Image resizing and rotation on NS port without imagemagick

Alan Third
On Sun, Oct 08, 2017 at 10:53:28PM +0200, Lars Ingebrigtsen wrote:

> Alan Third <[hidden email]> writes:
>
> > It’s always kind of bugged me that I need imagemagick to do image
> > resizing when Cocoa and GNUstep support it natively, so I’ve finally
> > got round to implementing it.
>
> Allowing all the other image formats to support scaling and stuff would
> be very nice, but this is just for the Apple port?  I think if Emacs has
> (for instance) .png scaling, it should preferably be supported across
> all architectures...

I was under the impression that imagemagick allows you to open and
scale almost any image format, so this wouldn’t be anything new.
Perhaps I misunderstood.

This should work on any platform that GNUstep runs on, though, not
just macOS. But the list of supported formats is probably very
different across platforms.

> > +- (void)setSizeFromSpec: (Lisp_Object) spec
> > +{
> > +  NSSize size = [self size];
> > +  Lisp_Object value;
> > +  double scale = 1, aspect = size.width / size.height;
> > +  double width = -1, height = -1, max_width = -1, max_height = -1;
> > +
> > +  value = Fplist_get (spec, QCscale);
> > +  if (NUMBERP (value))
> > +    scale = XFLOATINT (value) ;
>
> [...]
>
> > +  [self setSize:NSMakeSize(width, height)];
>
> (Etc.)  This function seems to replicate the functionality of
> compute_image_size in image.c?  Is there any reason why that couldn't
> just be reused here, too?  (Perhaps the calling conventions would need
> to be tweaked a bit...)

I considered just copying and pasting it, but it would have needed a
reasonable amount of modification. The NS API uses doubles for most
sizes, while compute_image_size expects ints, so I’d have to convert
to int, do the maths, and convert back to double. It seemed as easy to
rewrite it.
--
Alan Third

Reply | Threaded
Open this post in threaded view
|

Re: Image resizing and rotation on NS port without imagemagick

Charles A. Roelli
In reply to this post by Alan Third
> Date: Sun, 8 Oct 2017 21:38:22 +0100
> From: Alan Third <[hidden email]>
>
> It’s always kind of bugged me that I need imagemagick to do image
> resizing when Cocoa and GNUstep support it natively, so I’ve finally
> got round to implementing it.
>
> It seems to work fine. Any comments are welcome.
>
> NOTE: if you have libjpg, libpng, or whatever installed, configure
> includes them and emacs will use them preferentially over the built‐in
> EmacsImage stuff, so you may need to use
>
>     --without-png --without-gif --without-jpeg
>
> I imagine there’s a way to switch the default to not use them when
> compiling --with-ns?
> --
> Alan Third>

Neat.  Thanks for working on this; it works well on macOS 10.6 too.
Do you know if we could get it to work with librsvg, so that
zooming/rotation could be done on SVGs as well?

Reply | Threaded
Open this post in threaded view
|

Re: Image resizing and rotation on NS port without imagemagick

Alan Third
On Wed, Oct 11, 2017 at 08:27:58PM +0200, Charles A. Roelli wrote:
> Neat.  Thanks for working on this; it works well on macOS 10.6 too.

Thanks for testing.

> Do you know if we could get it to work with librsvg, so that
> zooming/rotation could be done on SVGs as well?

This uses the built‐in image support in Cocoa/GNUstep, and they don’t
support SVG at all afaict. So I think librsvg is in the same boat as
libpng, libjpeg, etc. While it probably can be done it will have to be
specific to librsvg, or some generic system would have to do it and
we’re back to imagemagick.

--
Alan Third