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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export format-stride-for-width #25

Open
kensanata opened this issue Jul 20, 2022 · 1 comment
Open

Export format-stride-for-width #25

kensanata opened this issue Jul 20, 2022 · 1 comment

Comments

@kensanata
Copy link

I'm using the following monkey patch in my program:

(in-package :cairo)

(defun format-stride-for-width (format width)
  (cairo_format_stride_for_width (lookup-enum format table-format) width))

(export 'format-stride-for-width)

The reason being is that I'm painting onto a SDL2 surface.

  (let* ((surface (get-window-surface window))
	 (x (* *dimension* *scale*))
	 (y (* 2 x))
	 (line-height x))
    (setf cairo:*context*
	  (cairo:create-context
	   (cairo:create-image-surface-for-data
	    (surface-pixels surface)
	    :argb32
	    (surface-width surface)
	    (surface-height surface)
	    (cairo:format-stride-for-width :argb32 (surface-width surface)))))
   …

The Cairo docs tell me that I need to calculate stride using cairo_format_stride_for_width, which is why I've added it. I think it would make a good addition to surface.lisp and I'd be happy to send a pull request.

@kensanata
Copy link
Author

Returning to my code, two years later, I found that it no longer worked. I have no idea why. Now I use a different hack:

    (setf cairo:*context*
	  (cairo:create-context
	   (cairo:create-image-surface-for-data
	    (surface-pixels surface)
	    :argb32;; (surface-format surface)
	    (surface-width surface)
	    (surface-height surface)
            ;; Sorry for the ugly hack… cairo_format_stride_for_width is not exported.
	    (cairo::cairo_format_stride_for_width :CAIRO_FORMAT_ARGB32 (surface-width surface)))))

It would be nice if format-stride-for-width were exported. I'm hoping that all this requires is adding it to package.lisp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant