<commit_before>(in-package :mcclim-raster-image)

;;;
;;; with-output-to ...
;;;

(defmacro with-output-to-raster-image-stream ((stream-var stream format &rest options)
					      &body body)
  (let ((cont (gensym))
	(exit-fn (gensym))
	(enter-fn (gensym)))
    `(flet ((,cont (,stream-var)
              ,@body)
	    (,exit-fn (sheet stream)
              (declare (ignorable stream))
	      (save-mirror-image-to-stream (sheet-mirror sheet) ,stream ,format))
	    (,enter-fn (sheet stream)
	      (declare (ignore sheet stream))
	      nil))
       (declare (dynamic-extent #',cont))
       (invoke-with-output-to-raster-image #',cont #',enter-fn #',exit-fn 
					   :opticl-image
					   ,format
					   ,@options))))

(defmacro with-output-to-raster-image-file ((stream-var file &rest options)
					    &body body)
  (flet ((extract-format (file)
	   (intern (string-upcase (pathname-type (pathname file))) (find-package :keyword))))
    (let ((cont (gensym))
	  (exit-fn (gensym))
	  (enter-fn (gensym)))
      `(flet ((,cont (,stream-var)
		,@body)
	      (,exit-fn (sheet stream)
		(save-mirror-image-to-file (sheet-mirror sheet) ,file (extract-format ,file)))
	      (,enter-fn (sheet stream)
		(declare (ignore sheet stream))
		nil))
	 (declare (dynamic-extent #',cont))
	 (invoke-with-output-to-raster-image #',cont #',enter-fn #',exit-fn
					     :opticl-image
					     (extract-format ,file)
					     ,@options)))))

(defmacro with-output-to-rgb-image ((stream-var image &rest options)
				       &body body)
  (let ((cont (gensym))
	(exit-fn (gensym))
	(enter-fn (gensym)))
    `(flet ((,cont (,stream-var)
              ,@body)
	    (,exit-fn (sheet stream)
              (declare (ignore stream))
	      (mcclim-render::image-mirror-image (sheet-mirror sheet)))
	    (,enter-fn (sheet stream)
	      (declare (ignore stream))
	      (when ,image
                (setf (mcclim-render::image-mirror-image sheet) ,image))))
       (declare (dynamic-extent #',cont))
       (invoke-with-output-to-raster-image #',cont #',enter-fn #',exit-fn 
					   :rgb-image
					   :rgb-image
					   ,@options))))

(defmacro with-output-to-rgb-pattern ((stream-var &rest options)
				      &body body)
  `(make-instance 'clim-internals::rgb-pattern
		  :image (with-output-to-rgb-image
			     (,stream-var nil ,@options)<commit_msg>fix call to extract-format, I think.<commit_after>(in-package :mcclim-raster-image)

;;;
;;; with-output-to ...
;;;

(defmacro with-output-to-raster-image-stream ((stream-var stream format &rest options)
					      &body body)
  (let ((cont (gensym))
	(exit-fn (gensym))
	(enter-fn (gensym)))
    `(flet ((,cont (,stream-var)
              ,@body)
	    (,exit-fn (sheet stream)
              (declare (ignorable stream))
	      (save-mirror-image-to-stream (sheet-mirror sheet) ,stream ,format))
	    (,enter-fn (sheet stream)
	      (declare (ignore sheet stream))
	      nil))
       (declare (dynamic-extent #',cont))
       (invoke-with-output-to-raster-image #',cont #',enter-fn #',exit-fn 
					   :opticl-image
					   ,format
					   ,@options))))

(defmacro with-output-to-raster-image-file ((stream-var file &rest options)
					    &body body)
  (flet ((extract-format (file)
	   (intern (string-upcase (pathname-type (pathname file))) (find-package :keyword))))
    (let ((cont (gensym))
	  (exit-fn (gensym))
	  (enter-fn (gensym)))
      `(flet ((,cont (,stream-var)
		,@body)
	      (,exit-fn (sheet stream)
                (declare (ignore stream))
		(save-mirror-image-to-file (sheet-mirror sheet) ,file ,(extract-format file)))
	      (,enter-fn (sheet stream)
		(declare (ignore sheet stream))
		nil))
	 (declare (dynamic-extent #',cont))
	 (invoke-with-output-to-raster-image #',cont #',enter-fn #',exit-fn
					     :opticl-image
					     ,(extract-format file)
					     ,@options)))))

(defmacro with-output-to-rgb-image ((stream-var image &rest options)
				       &body body)
  (let ((cont (gensym))
	(exit-fn (gensym))
	(enter-fn (gensym)))
    `(flet ((,cont (,stream-var)
              ,@body)
	    (,exit-fn (sheet stream)
              (declare (ignore stream))
	      (mcclim-render::image-mirror-image (sheet-mirror sheet)))
	    (,enter-fn (sheet stream)
	      (declare (ignore stream))
	      (when ,image
                (setf (mcclim-render::image-mirror-image sheet) ,image))))
       (declare (dynamic-extent #',cont))
       (invoke-with-output-to-raster-image #',cont #',enter-fn #',exit-fn 
					   :rgb-image
					   :rgb-image
					   ,@options))))

(defmacro with-output-to-rgb-pattern ((stream-var &rest options)
				      &body body)
  `(make-instance 'clim-internals::rgb-pattern
		  :image (with-output-to-rgb-image
			     (,stream-var nil ,@options)
{'fraction_non_alphanumeric': 0.17719112988384372, 'fraction_numerical': 0.0, 'mean_word_length': 2.590598938589841, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2124295', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1600, 'n_words': 353}