atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
image.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'image.c'
24*
25* Contains:
26*
27
28 - The functions to render an image from the OpenGL window
29
30*
31* List of functions:
32
33 void render_image (glwin * view, video_options * iopts);
34
35 G_MODULE_EXPORT void run_render_image (GtkNativeDialog * info, gint response_id, gpointer data);
36 G_MODULE_EXPORT void run_render_image (GtkDialog * info, gint response_id, gpointer data);
37
38*/
39
40#include "global.h"
41#include "interface.h"
42#include "project.h"
43#include "glwindow.h"
44#include "glview.h"
45#include "movie.h"
46
47#include <libavformat/avformat.h>
48
49#ifndef GTKGLAREA
50extern GdkWindow * xwin;
51extern GLXContext glcontext;
52extern Pixmap pixmap;
53extern GLXPixmap glpixmap;
54#endif
55extern GdkPixbuf * pixbuf;
56
57char * image_name[IMAGE_FORMATS] = {"PNG",
58 "JPG/JPEG",
59 "TIFF",
60 "Bitmap"};
61
62char * image_list[IMAGE_FORMATS] = {"png",
63 "jpeg",
64 "tiff",
65 "bmp"};
66
67extern void fill_image (VideoStream * vs, int width, int height, glwin * view);
68extern void init_frame_buffer (int x, int y);
69extern void close_frame_buffer ();
70
71#ifdef GTK4
81G_MODULE_EXPORT void run_render_image (GtkNativeDialog * info, gint response_id, gpointer data)
82{
83 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
84#else
94G_MODULE_EXPORT void run_render_image (GtkDialog * info, gint response_id, gpointer data)
95{
96 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
97#endif
98 if (response_id == GTK_RESPONSE_ACCEPT)
99 {
100 video_options * iopts = (video_options *)data;
101 gchar * videofile = file_chooser_get_file_name (chooser);
102#ifdef GTK4
104#else
105 destroy_this_dialog (info);
106#endif
107 init_frame_buffer (iopts -> video_res[0], iopts -> video_res[1]);
108 project * this_proj = get_project_by_id (iopts -> proj);
109 glwin * view = this_proj -> modelgl;
110 init_opengl ();
111 int i, x, y, q;
112 for (i=0; i<NGLOBAL_SHADERS; i++)
113 {
114 if (in_md_shaders (this_proj, i)) view -> n_shaders[i][step] = -1;
115 }
117 in_movie_encoding = TRUE;
118 if (iopts -> oglquality != 0)
119 {
120 q = view -> anim -> last -> img -> quality;
121 view -> anim -> last -> img -> quality = iopts -> oglquality;
122 }
123 for (i=0; i<2; i++) tmp_pixels[i] = view -> pixels[i];
124 x = view -> pixels[0];
125 y = view -> pixels[1] - 100;
126 view -> pixels[0] = iopts -> video_res[0];
127 view -> pixels[1] = iopts -> video_res[1];
128 fill_image (NULL, iopts -> video_res[0], iopts -> video_res[1], view);
129 GError * error = NULL;
130 gboolean res = gdk_pixbuf_savev (pixbuf, videofile, image_list[iopts -> codec], NULL, NULL, & error);
131 if (! res)
132 {
133 show_warning ("An error occurred when exporting an image\nyou might want to try again\nsorry for the trouble", view -> win);
134 }
136 in_movie_encoding = FALSE;
137 if (iopts -> oglquality != 0) view -> anim -> last -> img -> quality = q;
138 for (i=0; i<NGLOBAL_SHADERS; i++)
139 {
140 if (in_md_shaders (this_proj, i)) view -> n_shaders[i][step] = -1;
141 }
143 reshape (view, x, y, TRUE);
144 update (view);
145 }
146 else
147 {
148#ifdef GTK4
150#else
151 destroy_this_dialog (info);
152#endif
153 }
154}
155
164void render_image (glwin * view, video_options * iopts)
165{
166 GtkFileFilter * filter;
167 gchar * str;
168#ifdef GTK4
169 GtkFileChooserNative * info;
170#else
171 GtkWidget * info;
172#endif
173 info = create_file_chooser ("Render Image",
174 GTK_WINDOW(view -> win),
175 GTK_FILE_CHOOSER_ACTION_SAVE,
176 "Save");
177 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
178#ifdef GTK3
179 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
180#endif
182 str = g_strdup_printf ("%s.%s", prepare_for_title(get_project_by_id(view -> proj) -> name), image_list[iopts -> codec]);
183 gtk_file_chooser_set_current_name (chooser, str);
184 g_free (str);
185 filter = gtk_file_filter_new ();
186 str = g_strdup_printf ("%s file (*.%s)", image_name[iopts -> codec], image_list[iopts -> codec]);
187 gtk_file_filter_set_name (GTK_FILE_FILTER(filter), str);
188 g_free (str);
189 str = g_strdup_printf ("*.%s", image_list[iopts -> codec]);
190 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter), str);
191 g_free (str);
192 gtk_file_chooser_add_filter (chooser, filter);
193#ifdef GTK4
194 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_render_image), iopts);
195#else
196 run_this_gtk_dialog (info, G_CALLBACK(run_render_image), iopts);
197#endif
198}
GtkFileFilter * filter[NCFORMATS+1]
Definition callbacks.c:1405
gboolean in_movie_encoding
Definition global.c:180
int tmp_pixels[2]
Definition global.c:173
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
void recreate_all_shaders(glwin *view)
re-initialize all OpenGL shaders
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2188
project * proj
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2136
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
gboolean in_md_shaders(project *this_proj, int id)
is this shader MD dependent ?
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
Definition gtk-misc.c:2223
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2084
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
void reshape(glwin *view, int width, int height, gboolean use_ratio)
reshape (resize) the OpenGL window
Definition glview.c:516
void init_opengl()
initialize OpenGL rendering parameters
Definition glview.c:1390
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
int step
Definition ogl_draw.c:70
#define NGLOBAL_SHADERS
Definition glwin.h:69
Function declarations for the creation of the OpenGL window.
GLXContext glcontext
GdkWindow * xwin
void close_frame_buffer()
close the frame buffer
Definition movie.c:1206
void init_frame_buffer(int x, int y)
init a frame buffer
Definition movie.c:1178
Pixmap pixmap
GdkPixbuf * pixbuf
Definition movie.c:122
G_MODULE_EXPORT void run_render_image(GtkDialog *info, gint response_id, gpointer data)
render an image from the OpenGL window - running the dialog
Definition image.c:94
void render_image(glwin *view, video_options *iopts)
render an image from the OpenGL window - prepare the dialog
Definition image.c:164
GLXPixmap glpixmap
void fill_image(VideoStream *vs, int width, int height, glwin *view)
render an image from an OpenGL rendering
Definition movie.c:273
char * image_name[IMAGE_FORMATS]
Definition image.c:57
char * image_list[IMAGE_FORMATS]
Definition image.c:62
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:260
Messaging function declarations.
Data structure declarations for movie encoding Function declarations for movie encoding.
#define IMAGE_FORMATS
Definition movie.h:37
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:875
int oglquality
Definition w_encode.c:57
GtkWidget * res[2]
Definition w_encode.c:212
int codec
Definition w_encode.c:56
int video_res[2]
Definition w_encode.c:53
GtkWidget * img
Definition workspace.c:70