66#if LIBAVCODEC_VERSION_MAJOR < 56
67# define PIXEL_FORMAT PIX_FMT_YUV420P
69# define PIXEL_FORMAT AV_PIX_FMT_YUV420P
72#define AVS_FRAME_ALIGN 16
74#define RGB_TO_Y(pixels, loc) (0.29900 * pixels[loc] + 0.58700 * pixels[loc+1] + 0.11400 * pixels[loc+2])
75#define RGB_TO_U(pixels, loc)(-0.16874 * pixels[loc] - 0.33126 * pixels[loc+1] + 0.50000 * pixels[loc+2]+128.0)
76#define RGB_TO_V(pixels, loc) (0.50000 * pixels[loc] - 0.41869 * pixels[loc+1] - 0.08131 * pixels[loc+2]+128.0)
78#define AVIO_FLAG_READ 1
79#define AVIO_FLAG_WRITE 2
80#define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)
82#ifndef AV_ROUND_PASS_MINMAX
83#define AV_ROUND_PASS_MINMAX 8192
102#if LIBAVCODEC_VERSION_MAJOR > 54
140 gint
x,
y, location, location2;
141 gint inner_x, inner_y, half_location;
143 gint pixbuf_xsize, pixbuf_ysize;
146 gboolean x_odd, y_odd;
148 pixbuf_xsize = gdk_pixbuf_get_width (
pixbuf);
149 pixbuf_ysize = gdk_pixbuf_get_height (
pixbuf);
150 pixels = gdk_pixbuf_get_pixels (
pixbuf);
151 row_stride = gdk_pixbuf_get_rowstride (
pixbuf);
152 y_odd = (pixbuf_ysize & 0x1);
153 x_odd = (pixbuf_xsize & 0x1);
156 for (
y=0;
y<pixbuf_ysize-1;
y+=2)
158 for (
x=0;
x<pixbuf_xsize-1;
x+=2)
162 for (inner_y =
y; inner_y <
y+2; inner_y++)
163 for (inner_x =
x; inner_x <
x+2; inner_x++)
165 location = inner_y*row_stride+3*inner_x;
166 picture -> data[0][inner_x+inner_y*w] =
RGB_TO_Y (pixels, location);
170 half_location =
x/2 +
y*w/4;
171 picture -> data[1][half_location] = cb/4.0;
172 picture -> data[2][half_location] = cr/4.0;
176 location =
y*row_stride+3*
x;
177 location2 = (
y+1)*row_stride+3*
x;
179 picture -> data[0][
x+
y*w] =
RGB_TO_Y (pixels, location);
180 picture -> data[0][
x+1+
y*w] = 0;
181 picture -> data[0][
x+(
y+1)*w] =
RGB_TO_Y (pixels, location2);
182 picture -> data[0][
x+1+(
y+1)*w] = 0;
184 half_location =
x/2 +
y*w/4;
185 picture -> data[1][half_location] = (
RGB_TO_U(pixels, location) +
RGB_TO_U(pixels, location2)+256)/4.0;
186 picture -> data[2][half_location] = (
RGB_TO_V(pixels, location) +
RGB_TO_V(pixels, location2)+256)/4.0;
191 for (
x=0;
x<pixbuf_xsize-1;
x+=2)
193 location =
y*row_stride+3*
x;
194 location2 =
y*row_stride+3*(
x+1);
196 picture -> data[0][
x+
y*w] =
RGB_TO_Y(pixels, location);
197 picture -> data[0][
x+1+
y*w] =
RGB_TO_Y(pixels, location2);
198 picture -> data[0][
x+(
y+1)*w] = 0;
199 picture -> data[0][
x+1+(
y+1)*w] = 0;
201 half_location =
x/2 +
y*w/4;
202 picture -> data[1][half_location] = (
RGB_TO_U(pixels, location)+
RGB_TO_U(pixels, location2)+256)/4.0;
203 picture -> data[2][half_location] = (
RGB_TO_V(pixels, location)+
RGB_TO_V(pixels, location2)+256)/4.0;
207 location =
y*row_stride+3*
x;
209 picture -> data[0][
x+
y*w] =
RGB_TO_Y(pixels, location);
210 picture -> data[0][
x+1+
y*w] = 0;
211 picture -> data[0][
x+(
y+1)*w] = 0;
212 picture -> data[0][
x+1+(
y+1)*w] = 0;
214 half_location =
x/2 +
y*w/4;
215 picture -> data[1][half_location] = (
RGB_TO_U(pixels, location)+384)/4.0;
216 picture -> data[2][half_location] = (
RGB_TO_V(pixels, location)+384)/4.0;
229static void ffmpeg_encoder_set_frame_yuv_from_rgb (uint8_t * rgb,
VideoStream * vs)
231 const int in_linesize = 4 * vs -> cc -> width;
232 vs -> sws_ctx = sws_getCachedContext (vs -> sws_ctx,
233 vs -> cc -> width, vs -> cc -> height, AV_PIX_FMT_BGRA,
235 0, NULL, NULL, NULL);
236 sws_scale (vs -> sws_ctx, (
const uint8_t *
const *)&rgb,
237 & in_linesize, 0, vs -> cc -> height,
238 vs -> frame -> data, vs -> frame -> linesize);
246static GLubyte * capture_opengl_image (
unsigned int width,
unsigned int height)
249 nvals = width * height * 4;
250 GLubyte * pixels = g_malloc0(nvals *
sizeof(GLubyte));
251 GLubyte * rgb = g_malloc0(nvals *
sizeof(GLubyte));
257 glReadPixels (0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
259 for (i = 0;
i < height;
i++)
261 memcpy (rgb + 4 * width * i, pixels + 4 * width * (height - i - 1), 4 * width);
281 reshape (view, width, height, FALSE);
284 GLubyte *
image = capture_opengl_image (width, height);
288 ffmpeg_encoder_set_frame_yuv_from_rgb (
image, vs);
292 cairo_surface_t * surf = cairo_image_surface_create_for_data ((guchar *)
image, CAIRO_FORMAT_ARGB32,
293 width, height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
295 cairo_surface_destroy (surf);
310static void write_video_frame (AVFormatContext * f_context,
VideoStream * vs,
int frame_id,
glwin * view)
314 fill_image (vs, vs -> cc -> width, vs -> cc -> height, view);
317#if LIBAVCODEC_VERSION_MAJOR > 57
318 out_size = av_new_packet (& packet, 0);
322 g_warning (_(
"Error in movie encoding : video frame - error : %s"), av_err2str(out_size));
326 av_init_packet (& packet);
331 packet.dts = packet.pts = AV_NOPTS_VALUE;
335 vs -> frame -> pts = frame_id + 1;
336 out_size = avcodec_send_frame (vs -> cc, vs -> frame);
340 g_warning (_(
"Error in movie encoding : video frame - error : %s"), av_err2str (out_size));
344 if (avcodec_receive_packet (vs -> cc, & packet) < 0)
347 if (frame_id + 1 >
frame_start) g_warning (_(
"Error in movie encoding : video frame - warning : packet empty, ignoring frame= %d"), frame_id);
351 av_packet_rescale_ts (& packet, vs -> cc -> time_base, vs -> st -> time_base);
353 packet.stream_index = vs -> st -> index;
354 packet.flags |= AV_PKT_FLAG_KEY;
355 out_size = av_interleaved_write_frame (f_context, & packet);
359 g_warning (_(
"Error in movie encoding : video frame - error : %s"), av_err2str(out_size));
361 av_packet_unref(& packet);
374static AVFrame * alloc_video_frame (AVCodecContext * cc)
377 frame = av_frame_alloc ();
382 frame -> format = cc -> pix_fmt;
383 frame -> width = cc -> width;
384 frame -> height = cc -> height;
385 if (av_frame_get_buffer (frame, 32) < 0)
404 if (! (vc = avcodec_find_encoder (
codec_id[vopts ->
codec])))
407 g_warning (_(
"Error in movie encoding : impossible to find codec %s"),
codec_name[vopts ->
codec]);
410 if (! (cc = avcodec_alloc_context3(vc)))
412 g_warning (_(
"Error in movie encoding : impossible to allocate encoding context"));
419 cc -> bit_rate_tolerance = vopts ->
bitrate*1000;
420 cc -> bit_rate = vopts ->
bitrate*1000;
426 cc -> time_base = (AVRational){1, vopts ->
framesec};
427 cc -> framerate = (AVRational){vopts ->
framesec, 1};
429 if (vopts ->
codec != 1 && vopts ->
codec != 4) cc -> max_b_frames = 1;
434 if (vopts ->
codec == 2) av_opt_set (cc -> priv_data,
"preset",
"slow", 0);
439#if LIBAVCODEC_VERSION_MAJOR > 57
440 if (fc -> oformat -> flags & AVFMT_GLOBALHEADER) cc -> flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
442 if (fc -> oformat -> flags & AVFMT_GLOBALHEADER) cc -> flags |= CODEC_FLAG_GLOBAL_HEADER;
460 if (stream -> cc == NULL)
return NULL;
462#if LIBAVCODEC_VERSION_MAJOR > 53
463 stream -> st = avformat_new_stream (fc, vc);
465 st = av_new_stream (fc, vc);
469 g_warning (_(
"Error in movie encoding : impossible to allocate video stream"));
472 stream -> st -> time_base = stream -> cc -> time_base;
473 stream -> frame = alloc_video_frame (stream -> cc);
474 if (stream -> frame == NULL)
476 g_warning (_(
"Error in movie encoding : impossible to allocate raw frame buffer"));
490static void close_stream (AVFormatContext * fc,
VideoStream * vs)
492 avcodec_free_context (& vs -> cc);
493 av_frame_free (& vs -> frame);
494 sws_freeContext (vs -> sws_ctx);
495 avformat_free_context (fc);
528 int stp = img_b ->
step;
530 if ((img_a -> ray_tracing != img_b -> ray_tracing) || (ogl_q == 0 && img_a -> quality != img_b -> quality))
532 view -> create_shaders[
MDBOX] = TRUE;
533 view -> create_shaders[
MAXIS] = TRUE;
534 view -> n_shaders[
ATOMS][stp] = -1;
535 view -> create_shaders[
ATOMS] = TRUE;
536 view -> n_shaders[
BONDS][stp] = -1;
537 view -> create_shaders[
BONDS] = TRUE;
538 view -> n_shaders[
POLYS][stp] = -1;
539 view -> create_shaders[
POLYS] = TRUE;
540 view -> n_shaders[
RINGS][stp] = -1;
541 view -> create_shaders[
RINGS] = TRUE;
542 view -> n_shaders[
VOLMS][stp] = -1;
543 view -> create_shaders[
VOLMS] = TRUE;
544 view -> n_shaders[
SELEC][stp] = -1;
545 view -> create_shaders[
SELEC] = TRUE;
546 view -> create_shaders[
LABEL] = TRUE;
547 view -> create_shaders[
MEASU] = TRUE;
554 if (img_a -> abc -> extra_cell[i] != img_b -> abc -> extra_cell[i])
556 view -> create_shaders[
MDBOX] = TRUE;
557 view -> create_shaders[
MAXIS] = TRUE;
558 view -> n_shaders[
ATOMS][stp] = -1;
559 view -> create_shaders[
ATOMS] = TRUE;
560 view -> n_shaders[
BONDS][stp] = -1;
561 view -> create_shaders[
BONDS] = TRUE;
562 view -> n_shaders[
POLYS][stp] = -1;
563 view -> create_shaders[
POLYS] = TRUE;
564 view -> n_shaders[
RINGS][stp] = -1;
565 view -> create_shaders[
RINGS] = TRUE;
566 view -> n_shaders[
VOLMS][stp] = -1;
567 view -> create_shaders[
VOLMS] = TRUE;
568 view -> n_shaders[
SELEC][stp] = -1;
569 view -> create_shaders[
SELEC] = TRUE;
570 view -> create_shaders[
LABEL] = TRUE;
571 view -> create_shaders[
MEASU] = TRUE;
581 for (j=0; j<this_coord -> totcoord[i]; j++)
583 if (img_a -> show_coord[i][j] != img_b -> show_coord[i][j])
585 view -> n_shaders[
ATOMS][stp] = -1;
586 view -> create_shaders[
ATOMS] = TRUE;
587 view -> n_shaders[
BONDS][stp] = -1;
588 view -> create_shaders[
BONDS] = TRUE;
589 view -> n_shaders[
SELEC][stp] = -1;
590 view -> create_shaders[
SELEC] = TRUE;
591 view -> create_shaders[
LABEL] = TRUE;
592 view -> create_shaders[
MEASU] = TRUE;
597 for (j=0; j<this_coord -> totcoord[i]; j++)
599 if (img_a -> show_poly[i][j] != img_b -> show_poly[i][j])
601 view -> n_shaders[
POLYS][stp] = -1;
602 view -> create_shaders[
POLYS] = TRUE;
608 for (j=0; j<this_coord -> totcoord[i]; j++)
610 if (img_a -> show_poly[i][j] != img_b -> show_poly[i][j])
612 view -> n_shaders[
RINGS][stp] = -1;
613 view -> create_shaders[
RINGS] = TRUE;
618 for (j=0; j<this_coord -> totcoord[9]; j++)
620 if (img_a -> show_coord[9][j] != img_b -> show_coord[9][j])
622 view -> n_shaders[
ATOMS][stp] = -1;
623 view -> create_shaders[
ATOMS] = TRUE;
624 view -> n_shaders[
BONDS][stp] = -1;
625 view -> create_shaders[
BONDS] = TRUE;
626 view -> create_shaders[
LABEL] = TRUE;
627 view -> create_shaders[
MEASU] = TRUE;
631 if (img_a -> draw_clones != img_b -> draw_clones)
633 view -> n_shaders[
ATOMS][stp] = -1;
634 view -> create_shaders[
ATOMS] = TRUE;
635 view -> n_shaders[
BONDS][stp] = -1;
636 view -> create_shaders[
BONDS] = TRUE;
637 view -> n_shaders[
POLYS][stp] = -1;
638 view -> create_shaders[
POLYS] = TRUE;
639 view -> n_shaders[
RINGS][stp] = -1;
640 view -> create_shaders[
RINGS] = TRUE;
641 view -> n_shaders[
SELEC][stp] = -1;
642 view -> create_shaders[
SELEC] = TRUE;
643 view -> create_shaders[
LABEL] = TRUE;
647 if (img_a -> color_map[0] != img_b -> color_map[0] || img_b -> color_map[0] !=
old_cmap[0][stp])
649 view -> n_shaders[
ATOMS][stp] = -1;
650 view -> create_shaders[
ATOMS] = TRUE;
651 view -> n_shaders[
BONDS][stp] = -1;
652 view -> create_shaders[
BONDS] = TRUE;
653 view -> create_shaders[
LABEL] = TRUE;
658 if (img_a -> color_map[1] != img_b -> color_map[1] || img_b -> color_map[1] !=
old_cmap[1][stp])
660 view -> n_shaders[
POLYS][stp] = -1;
661 view -> create_shaders[
POLYS] = TRUE;
668 if (view -> n_shaders[
ATOMS][stp] < 0) view -> create_shaders[
ATOMS] = TRUE;
669 if (view -> n_shaders[
BONDS][stp] < 0) view -> create_shaders[
BONDS] = TRUE;
670 if (view -> n_shaders[
POLYS][stp] < 0) view -> create_shaders[
POLYS] = TRUE;
671 if (view -> n_shaders[
RINGS][stp] < 0) view -> create_shaders[
RINGS] = TRUE;
672 if (view -> n_shaders[
VOLMS][stp] < 0) view -> create_shaders[
VOLMS] = TRUE;
673 if (view -> n_shaders[
SELEC][stp] < 0) view -> create_shaders[
SELEC] = TRUE;
674 view -> create_shaders[
LABEL] = TRUE;
675 view -> create_shaders[
MEASU] = TRUE;
679 gboolean do_volms = FALSE;
682 if (img_a -> show_vol[i] != img_b -> show_vol[i]) do_volms = TRUE;
683 if (img_a -> vol_col[i].red != img_b -> vol_col[i].red) do_volms = TRUE;
684 if (img_a -> vol_col[i].green != img_b -> vol_col[i].green) do_volms = TRUE;
685 if (img_a -> vol_col[i].blue != img_b -> vol_col[i].blue) do_volms = TRUE;
688 if (img_a -> fm_show_vol[j][i] == NULL && img_b -> fm_show_vol[j][i] != NULL)
692 else if (img_a -> fm_show_vol[j][i] != NULL && img_b -> fm_show_vol[j][i] == NULL)
696 else if (img_a -> fm_show_vol[j][i] != NULL && img_b -> fm_show_vol[j][i] != NULL)
698 for (k=0; k<this_coord -> totcoord[j+2]; k++)
700 if (img_a -> fm_show_vol[j][i][k] != img_b -> fm_show_vol[j][i][k]) do_volms = TRUE;
701 if (img_a -> fm_vol_col[j][i][k].red != img_b -> fm_vol_col[j][i][k].red) do_volms = TRUE;
702 if (img_a -> fm_vol_col[j][i][k].green != img_b -> fm_vol_col[j][i][k].green) do_volms = TRUE;
703 if (img_a -> fm_vol_col[j][i][k].blue != img_b -> fm_vol_col[j][i][k].blue) do_volms = TRUE;
711 view -> n_shaders[
VOLMS][stp] = -1;
714 if (img_a -> abc ->
box != img_b -> abc ->
box) view -> create_shaders[
MDBOX] =
shaders = TRUE;
715 if (img_a -> abc -> rad != img_b -> abc -> rad) view -> create_shaders[
MDBOX] =
shaders = TRUE;
716 if (img_a -> abc -> line != img_b -> abc -> line) view -> create_shaders[
MDBOX] =
shaders = TRUE;
721 if (img_a -> xyz ->
axis != img_b -> xyz ->
axis) view -> create_shaders[
MAXIS] =
shaders = TRUE;
722 if (img_a -> xyz -> rad != img_b -> xyz -> rad) view -> create_shaders[
MAXIS] =
shaders = TRUE;
723 if (img_a -> xyz -> line != img_b -> xyz -> line) view -> create_shaders[
MAXIS] =
shaders = TRUE;
724 if (img_a -> xyz -> length != img_b -> xyz -> length) view -> create_shaders[
MAXIS] =
shaders = TRUE;
725 if (img_a -> xyz -> t_pos != img_b -> xyz -> t_pos) view -> create_shaders[
MAXIS] =
shaders = TRUE;
726 if (img_a -> xyz ->
color == NULL && img_b -> xyz ->
color != NULL)
730 else if (img_a -> xyz ->
color != NULL && img_b -> xyz ->
color == NULL)
734 else if (img_a -> xyz ->
color != NULL && img_b -> xyz ->
color != NULL)
738 if (img_a -> xyz ->
color[i].red != img_b -> xyz ->
color[i].red) view -> create_shaders[
MAXIS] =
shaders = TRUE;
739 if (img_a -> xyz ->
color[i].green != img_b -> xyz ->
color[i].green) view -> create_shaders[
MAXIS] =
shaders = TRUE;
740 if (img_a -> xyz ->
color[i].blue != img_b -> xyz ->
color[i].blue) view -> create_shaders[
MAXIS] =
shaders = TRUE;
746 if (g_strcmp0 (img_a -> xyz -> title[i], img_b -> xyz -> title[i]) != 0) view -> create_shaders[
MAXIS] =
shaders = TRUE;
747 if (img_a -> xyz -> c_pos[i] != img_b -> xyz -> c_pos[i]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
749 if (g_strcmp0 (img_a ->
labels[2].font, img_b ->
labels[2].font) != 0) view -> create_shaders[
MAXIS] =
shaders = TRUE;
773 view -> n_shaders[
POLYS][stp] = -1;
774 view -> create_shaders[
POLYS] = TRUE;
775 view -> n_shaders[
RINGS][stp] = -1;
776 view -> create_shaders[
RINGS] = TRUE;
780 gboolean dorings = FALSE;
783 if (view -> ring_max[i])
785 if (img_a -> i_rings[i] && img_b -> i_rings[i])
787 if (img_a -> i_rings[i][0][0] != img_b -> i_rings[i][0][0])
789 view -> n_shaders[
RINGS][stp] = -1;
790 view -> create_shaders[
RINGS] = TRUE;
796 for (j=0; j<img_a -> i_rings[i][0][0]; j++)
798 if ((img_a -> i_rings[i][j+1][0] != img_b -> i_rings[i][j+1][0]) || (img_a -> i_rings[i][j+1][1] != img_b -> i_rings[i][j+1][1]))
800 view -> n_shaders[
RINGS][stp] = -1;
801 view -> create_shaders[
RINGS] = TRUE;
808 else if (img_b -> i_rings[i])
820 if (img_a -> show_label[i][j] != img_b -> show_label[i][j])
824 if (img_a -> show_atom[i][j] != img_b -> show_atom[i][j])
826 view -> n_shaders[
ATOMS][stp] = -1;
827 view -> create_shaders[
ATOMS] = TRUE;
828 view -> n_shaders[
BONDS][stp] = -1;
829 view -> create_shaders[
BONDS] = TRUE;
830 view -> n_shaders[
SELEC][stp] = -1;
831 view -> create_shaders[
SELEC] = TRUE;
832 view -> create_shaders[
LABEL] = TRUE;
833 view -> create_shaders[
MEASU] = TRUE;
838 for (j=0; j<
tmp_proj -> natomes; j++)
840 if (img_a -> at_data[j].show[i] != img_b -> at_data[j].show[i] || img_a -> at_data[j].style != img_b -> at_data[j].style)
842 view -> n_shaders[
ATOMS][stp] = -1;
843 view -> create_shaders[
ATOMS] = TRUE;
844 view -> n_shaders[
BONDS][stp] = -1;
845 view -> create_shaders[
BONDS] = TRUE;
846 view -> n_shaders[
SELEC][stp] = -1;
847 view -> create_shaders[
SELEC] = TRUE;
848 view -> create_shaders[
LABEL] = TRUE;
849 view -> create_shaders[
MEASU] = TRUE;
853 if (img_a -> at_data[j].label[i] != img_b -> at_data[j].label[i])
857 if (img_a -> at_data[j].
pick[0] != img_b -> at_data[j].
pick[0])
859 view -> n_shaders[
SELEC][stp] = -1;
862 if (img_a -> at_data[j].
pick[1] != img_b -> at_data[j].
pick[1])
864 view -> n_shaders[
SELEC][stp] = -1;
870 for (i=0; i<2*
tmp_proj -> nspec; i++)
872 if ((img_a -> sphererad[i] != img_b -> sphererad[i])
873 || (img_a -> pointrad[i] != img_b -> pointrad[i])
874 || (img_a -> atomicrad[i] != img_b -> atomicrad[i]))
876 view -> n_shaders[
ATOMS][stp] = -1;
877 view -> create_shaders[
ATOMS] = TRUE;
878 view -> n_shaders[
SELEC][stp] = -1;
879 view -> create_shaders[
SELEC] = TRUE;
880 view -> create_shaders[
LABEL] = TRUE;
883 for (j=0; j<2*
tmp_proj -> nspec; j++)
885 if ((img_a -> bondrad[i][j] != img_b -> bondrad[i][j])
886 || (img_a -> linerad[i][j] != img_b -> linerad[i][j]))
888 view -> n_shaders[
BONDS][stp] = -1;
889 view -> create_shaders[
BONDS] = TRUE;
890 view -> n_shaders[
SELEC][stp] = -1;
891 view -> create_shaders[
SELEC] = TRUE;
892 view -> create_shaders[
LABEL] = TRUE;
900 if (img_a -> acl_format[i] != img_b -> acl_format[i]) view -> create_shaders[
LABEL] =
shaders = TRUE;
901 if (g_strcmp0 (img_a ->
labels[i].font, img_b ->
labels[i].font) != 0) view -> create_shaders[
LABEL] =
shaders = TRUE;
927 if (img_a -> radall[i] != img_b -> radall[i])
929 view -> n_shaders[
ATOMS][stp] = -1;
930 view -> create_shaders[
ATOMS] = TRUE;
931 view -> n_shaders[
BONDS][stp] = -1;
932 view -> create_shaders[
BONDS] = TRUE;
933 view -> n_shaders[
SELEC][stp] = -1;
934 view -> create_shaders[
SELEC] = TRUE;
935 view -> create_shaders[
LABEL] = TRUE;
942 view -> n_shaders[
ATOMS][stp] = -1;
943 view -> create_shaders[
ATOMS] = TRUE;
944 view -> n_shaders[
BONDS][stp] = -1;
945 view -> create_shaders[
BONDS] = TRUE;
946 view -> n_shaders[
SELEC][stp] = -1;
947 view -> create_shaders[
SELEC] = TRUE;
950 if (img_a -> style != img_b -> style)
952 view -> n_shaders[
ATOMS][stp] = -1;
953 view -> create_shaders[
ATOMS] = TRUE;
954 view -> n_shaders[
BONDS][stp] = -1;
955 view -> create_shaders[
BONDS] = TRUE;
956 view -> n_shaders[
SELEC][stp] = -1;
957 view -> create_shaders[
SELEC] = TRUE;
958 view -> create_shaders[
LABEL] = TRUE;
962 if (img_a -> m_is_pressed != img_b -> m_is_pressed) view -> create_shaders[
MEASU] =
shaders = TRUE;
965 if (img_a -> mtilt[i] != img_b -> mtilt[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
966 if (img_a -> mpattern[i] != img_b -> mpattern[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
967 if (img_a -> mfactor[i] != img_b -> mfactor[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
968 if (img_a -> mwidth[i] != img_b -> mwidth[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
969 if (g_strcmp0 (img_a ->
labels[3+i].font, img_b ->
labels[3+i].font) != 0) view -> create_shaders[
MEASU] =
shaders = TRUE;
1010 const AVOutputFormat * output_format = NULL;
1011 AVFormatContext * format_context = NULL;
1013 const AVCodec * video_codec = NULL;
1018 g_debug (
"VIDEO ENCODING:: frames per seconds:: %d", vopts ->
framesec);
1019 g_debug (
"VIDEO ENCODING:: extra frames every:: %d frame(s)", vopts ->
extraframes);
1020 g_debug (
"VIDEO ENCODING:: bitrate:: %d", vopts ->
bitrate);
1021 g_debug (
"VIDEO ENCODING:: video_x = %d , video_y = %d", vopts ->
video_res[0], vopts ->
video_res[1]);
1026#if LIBAVCODEC_VERSION_MAJOR < 57
1028 avcodec_register_all ();
1031 if (! (format_context = avformat_alloc_context()))
1033 g_warning (_(
"Error in movie encoding : impossible to allocate AV format context"));
1038 if (! (format_context -> oformat = av_guess_format (NULL, videofile, NULL)))
1040 g_warning (_(
"Error in movie encoding : impossible to guess container format : change file name"));
1044 output_format = format_context -> oformat;
1047 if (video_stream == NULL)
1049 g_warning (_(
"Error in movie encoding : impossible to create video stream"));
1054 if ((error = avcodec_open2 (video_stream -> cc, video_codec, NULL)) < 0)
1057 g_warning (_(
"Error in movie encoding : impossible to open codec, error= %s"), av_err2str(error));
1061 avcodec_parameters_from_context (video_stream -> st -> codecpar, video_stream -> cc);
1062#if LIBAVCODEC_VERSION_MAJOR > 52
1063 av_dump_format (format_context, 0, videofile, 1);
1065 dump_format (av_format_context, 0, videofile, 1);
1068#if LIBAVCODEC_VERSION_MAJOR > 52
1069 if (avio_open (& format_context -> pb, videofile,
AVIO_FLAG_WRITE) < 0)
1071 if (url_fopen (& av_format_context -> pb, videofile,
URL_WRONLY) < 0)
1075 g_warning (_(
"Error in movie encoding : impossible to open video file '%s'"), videofile);
1079#if LIBAVCODEC_VERSION_MAJOR > 52
1080 if (avformat_write_header (format_context, NULL) < 0)
1082 if (av_set_parameters (av_format_context, NULL) < 0)
1085 g_warning (_(
"Error in movie encoding : impossible to write the AV format header"));
1089 view -> anim -> last = view -> anim -> first;
1092 q = view -> anim -> last ->
img -> quality;
1093 view -> anim -> last ->
img -> quality = vopts ->
oglquality;
1098 if (vopts ->
codec == 0)
1101 write_video_frame (format_context, video_stream, 0, view);
1103 else if (vopts ->
codec == 2)
1106 for (frame_id = 0; frame_id <
frame_start; frame_id ++)
1108 write_video_frame (format_context, video_stream, frame_id, view);
1113 for (frame_id=0; frame_id<2; frame_id++)
1127 view -> anim -> last ->
img -> quality = vopts ->
oglquality;
1129 write_video_frame (format_context, video_stream, frame_id, view);
1133 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(
encoding_pb), fraction);
1135 while (gtk_events_pending()) gtk_main_iteration();
1143 view -> anim -> last ->
img,
1144 view -> anim -> last -> next ->
img,
1146 view -> anim -> last = view -> anim -> last -> next;
1151 view -> anim -> last ->
img -> quality = q;
1154 av_write_trailer (format_context);
1156 if (!(output_format -> flags & AVFMT_NOFILE))
1159#if LIBAVCODEC_VERSION_MAJOR > 52
1160 avio_closep (& format_context -> pb);
1162 url_fclose (av_format_context -> pb);
1166 close_stream (format_context, video_stream);
1172static GLuint rbo_color;
1173static GLuint rbo_depth;
1184 glGenFramebuffers (1, & fbo);
1185 glBindFramebuffer (GL_FRAMEBUFFER, fbo);
1188 glGenRenderbuffers (1, & rbo_color);
1189 glBindRenderbuffer (GL_RENDERBUFFER, rbo_color);
1194 glRenderbufferStorage (GL_RENDERBUFFER, GL_RGB,
x,
y);
1195 glFramebufferRenderbuffer (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo_color);
1197 glGenRenderbuffers (1, & rbo_depth);
1198 glBindRenderbuffer (GL_RENDERBUFFER, rbo_depth);
1199 glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
x,
y);
1200 glFramebufferRenderbuffer (GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth);
1202 glReadBuffer (GL_COLOR_ATTACHMENT0);
1212 glDeleteFramebuffers (1, &fbo);
1213 glDeleteRenderbuffers (1, &rbo_color);
1214 glDeleteRenderbuffers (1, &rbo_depth);
1227G_MODULE_EXPORT
void run_save_movie (GtkNativeDialog * info, gint response_id, gpointer data)
1229 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1240G_MODULE_EXPORT
void run_save_movie (GtkDialog * info, gint response_id, gpointer data)
1242 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1244 if (response_id == GTK_RESPONSE_ACCEPT)
1254 int x = view -> pixels[0];
1255 int y = view -> pixels[1];
1257 for (i=0; i<2; i++)
tmp_pixels[i] = view -> pixels[i];
1258 view -> pixels[0] = vopts ->
video_res[0];
1259 view -> pixels[1] = vopts ->
video_res[1];
1262 gtk_gl_area_make_current ((GtkGLArea *)view ->
plot);
1271 show_warning (_(
"An error occurred when encoding movie\nyou might want to try again\nsorry for the trouble"), view -> win);
1303 GtkFileChooserNative * info;
1308 GTK_WINDOW(view -> win),
1309 GTK_FILE_CHOOSER_ACTION_SAVE,
1311 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1313 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1317 gtk_file_chooser_set_current_name (chooser, str);
1320 filter = gtk_file_filter_new ();
1322 gtk_file_filter_set_name (GTK_FILE_FILTER(
filter), str);
1325 gtk_file_filter_add_pattern (GTK_FILE_FILTER(
filter), str);
1327 gtk_file_chooser_add_filter (chooser,
filter);
1329 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(
run_save_movie), vopts);
GtkFileFilter * filter[NCFORMATS+1]
double scale(double axe)
find appropriate major tick spacing based on axis length
gboolean in_movie_encoding
int * allocint(int val)
allocate an int * pointer
Global variable declarations Global convenience function declarations Global data structure defin...
GdkPixbuf * convert_to_pixbuf(cairo_surface_t *surf)
convert cairo surface to GdkPixbuf
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
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
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
project * get_project_by_id(int p)
get project pointer using id number
void update(glwin *view)
update the rendering of the OpenGL window
void reshape(glwin *view, int width, int height, gboolean use_ratio)
reshape (resize) the OpenGL window
void init_opengl()
initialize OpenGL rendering parameters
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
void re_create_all_md_shaders(glwin *view)
re-initialize all MD dependent OpenGL shaders
void draw(glwin *view)
main drawing subroutine for the OpenGL window
shaders
The different types of shaders in the atomes program.
Function declarations for the creation of the OpenGL window.
void show_warning(char *warning, GtkWidget *win)
show warning
Messaging function declarations.
G_MODULE_EXPORT void cloned_poly(GtkWidget *widg, gpointer data)
cloned polyehdra callback - GTK3
G_MODULE_EXPORT void run_save_movie(GtkDialog *info, gint response_id, gpointer data)
saving a movie - running the dialog
void close_frame_buffer()
close the frame buffer
void init_frame_buffer(int x, int y)
init a frame buffer
gboolean check_to_update_shaders(glwin *view, image *img_a, image *img_b, int ogl_q)
test if it is required to update the OpenGL shaders, and which one(s)
char * codec_list[VIDEO_CODECS]
#define RGB_TO_V(pixels, loc)
gboolean create_movie(glwin *view, video_options *vopts, gchar *videofile)
render a movie from the saved animation parameters
void set_old_cmap(image *img, int stp, int id)
preserve color map information
void save_movie(glwin *view, video_options *vopts)
saving a movie - prepare the dialog
VideoStream * add_video_stream(AVFormatContext *fc, const AVCodec *vc, video_options *vopts)
create video stream and the associated data buffers
char * codec_name[VIDEO_CODECS]
#define RGB_TO_U(pixels, loc)
void fill_image(VideoStream *vs, int width, int height, glwin *view)
render an image from an OpenGL rendering
void convert_rgb_pixbuf_to_yuv(GdkPixbuf *pixbuf, AVFrame *picture, int w, int h)
convert an RGB pixbuf to an YUV picture frame
int codec_id[VIDEO_CODECS]
#define RGB_TO_Y(pixels, loc)
AVCodecContext * add_codec_context(AVFormatContext *fc, const AVCodec *vc, video_options *vopts)
create a video codec context
Data structure declarations for movie encoding Function declarations for movie encoding.
Function declarations for reading atomes project file Function declarations for saving atomes proje...