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_malloc (nvals *
sizeof(GLubyte));
251 GLubyte * rgb = g_malloc (nvals *
sizeof(GLubyte));
252 glReadPixels (0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
254 for (i = 0;
i < height;
i++)
256 memcpy (rgb + 4 * width * i, pixels + 4 * width * (height - i - 1), 4 * width);
276 reshape (view, width, height, FALSE);
279 GLubyte *
image = capture_opengl_image (width, height);
283 ffmpeg_encoder_set_frame_yuv_from_rgb (
image, vs);
287 cairo_surface_t * surf = cairo_image_surface_create_for_data ((guchar *)
image, CAIRO_FORMAT_ARGB32,
288 width, height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
290 cairo_surface_destroy (surf);
305static void write_video_frame (AVFormatContext * f_context,
VideoStream * vs,
int frame_id,
glwin * view)
309 fill_image (vs, vs -> cc -> width, vs -> cc -> height, view);
312#if LIBAVCODEC_VERSION_MAJOR > 57
313 out_size = av_new_packet (& packet, 0);
317 g_warning (
"MOVIE_ENCODING:: VIDEO_FRAME:: error:: %s", av_err2str(out_size));
321 av_init_packet (& packet);
326 packet.dts = packet.pts = AV_NOPTS_VALUE;
330 vs ->
frame -> pts = frame_id + 1;
331 out_size = avcodec_send_frame (vs -> cc, vs ->
frame);
335 g_warning (
"MOVIE_ENCODING:: VIDEO_FRAME:: error:: %s", av_err2str (out_size));
339 if (avcodec_receive_packet (vs -> cc, & packet) < 0)
342 if (frame_id + 1 >
frame_start) g_warning (
"MOVIE_ENCODING:: VIDEO_FRAME:: warning:: packet empty, ignoring frame= %d", frame_id);
346 av_packet_rescale_ts (& packet, vs -> cc -> time_base, vs -> st -> time_base);
348 packet.stream_index = vs -> st -> index;
349 packet.flags |= AV_PKT_FLAG_KEY;
350 out_size = av_interleaved_write_frame (f_context, & packet);
354 g_warning (
"MOVIE_ENCODING:: VIDEO_FRAME:: error:: %s", av_err2str(out_size));
356 av_packet_unref(& packet);
369static AVFrame * alloc_video_frame (AVCodecContext * cc)
372 frame = av_frame_alloc ();
377 frame -> format = cc -> pix_fmt;
378 frame -> width = cc -> width;
379 frame -> height = cc -> height;
380 if (av_frame_get_buffer (
frame, 32) < 0)
399 if (! (vc = avcodec_find_encoder (
codec_id[vopts ->
codec])))
402 g_warning (
"MOVIE_ENCODING:: Could not find codec:: %s",
codec_name[vopts ->
codec]);
405 if (! (cc = avcodec_alloc_context3(vc)))
407 g_warning (
"MOVIE_ENCODING:: Could not allocate encoding context");
414 cc -> bit_rate_tolerance = vopts ->
bitrate*1000;
415 cc -> bit_rate = vopts ->
bitrate*1000;
421 cc -> time_base = (AVRational){1, vopts ->
framesec};
422 cc -> framerate = (AVRational){vopts ->
framesec, 1};
424 if (vopts ->
codec != 1 && vopts ->
codec != 4) cc -> max_b_frames = 1;
429 if (vopts ->
codec == 2) av_opt_set (cc -> priv_data,
"preset",
"slow", 0);
434#if LIBAVCODEC_VERSION_MAJOR > 57
435 if (fc -> oformat -> flags & AVFMT_GLOBALHEADER) cc -> flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
437 if (fc -> oformat -> flags & AVFMT_GLOBALHEADER) cc -> flags |= CODEC_FLAG_GLOBAL_HEADER;
455 if (stream -> cc == NULL)
return NULL;
457#if LIBAVCODEC_VERSION_MAJOR > 53
458 stream -> st = avformat_new_stream (fc, vc);
460 st = av_new_stream (fc, vc);
464 g_warning (
"MOVIE_ENCODING:: Could not allocate video stream");
467 stream -> st -> time_base = stream -> cc -> time_base;
468 stream ->
frame = alloc_video_frame (stream -> cc);
469 if (stream ->
frame == NULL)
471 g_warning (
"MOVIE_ENCODING:: Could not allocate raw frame buffer");
485static void close_stream (AVFormatContext * fc,
VideoStream * vs)
487 avcodec_free_context (& vs -> cc);
488 av_frame_free (& vs ->
frame);
489 sws_freeContext (vs -> sws_ctx);
490 avformat_free_context (fc);
523 int stp = img_b ->
step;
525 if (ogl_q == 0 && img_a -> quality != img_b -> quality)
527 view -> create_shaders[
MDBOX] = TRUE;
528 view -> create_shaders[
MAXIS] = TRUE;
529 view -> n_shaders[
ATOMS][stp] = -1;
530 view -> create_shaders[
ATOMS] = TRUE;
531 view -> n_shaders[
BONDS][stp] = -1;
532 view -> create_shaders[
BONDS] = TRUE;
533 view -> n_shaders[
POLYS][stp] = -1;
534 view -> create_shaders[
POLYS] = TRUE;
535 view -> n_shaders[
RINGS][stp] = -1;
536 view -> create_shaders[
RINGS] = TRUE;
537 view -> n_shaders[
VOLMS][stp] = -1;
538 view -> create_shaders[
VOLMS] = TRUE;
539 view -> n_shaders[
SELEC][stp] = -1;
540 view -> create_shaders[
SELEC] = TRUE;
541 view -> create_shaders[
LABEL] = TRUE;
542 view -> create_shaders[
MEASU] = TRUE;
549 if (img_a -> abc -> extra_cell[i] != img_b -> abc -> extra_cell[i])
551 view -> create_shaders[
MDBOX] = TRUE;
552 view -> create_shaders[
MAXIS] = TRUE;
553 view -> n_shaders[
ATOMS][stp] = -1;
554 view -> create_shaders[
ATOMS] = TRUE;
555 view -> n_shaders[
BONDS][stp] = -1;
556 view -> create_shaders[
BONDS] = TRUE;
557 view -> n_shaders[
POLYS][stp] = -1;
558 view -> create_shaders[
POLYS] = TRUE;
559 view -> n_shaders[
RINGS][stp] = -1;
560 view -> create_shaders[
RINGS] = TRUE;
561 view -> n_shaders[
VOLMS][stp] = -1;
562 view -> create_shaders[
VOLMS] = TRUE;
563 view -> n_shaders[
SELEC][stp] = -1;
564 view -> create_shaders[
SELEC] = TRUE;
565 view -> create_shaders[
LABEL] = TRUE;
566 view -> create_shaders[
MEASU] = TRUE;
576 for (j=0; j<this_coord -> totcoord[i]; j++)
578 if (img_a -> show_coord[i][j] != img_b -> show_coord[i][j])
580 view -> n_shaders[
ATOMS][stp] = -1;
581 view -> create_shaders[
ATOMS] = TRUE;
582 view -> n_shaders[
BONDS][stp] = -1;
583 view -> create_shaders[
BONDS] = TRUE;
584 view -> n_shaders[
SELEC][stp] = -1;
585 view -> create_shaders[
SELEC] = TRUE;
586 view -> create_shaders[
LABEL] = TRUE;
587 view -> create_shaders[
MEASU] = TRUE;
592 for (j=0; j<this_coord -> totcoord[i]; j++)
594 if (img_a -> show_poly[i][j] != img_b -> show_poly[i][j])
596 view -> n_shaders[
POLYS][stp] = -1;
597 view -> create_shaders[
POLYS] = TRUE;
603 for (j=0; j<this_coord -> totcoord[i]; j++)
605 if (img_a -> show_poly[i][j] != img_b -> show_poly[i][j])
607 view -> n_shaders[
RINGS][stp] = -1;
608 view -> create_shaders[
RINGS] = TRUE;
613 for (j=0; j<this_coord -> totcoord[9]; j++)
615 if (img_a -> show_coord[9][j] != img_b -> show_coord[9][j])
617 view -> n_shaders[
ATOMS][stp] = -1;
618 view -> create_shaders[
ATOMS] = TRUE;
619 view -> n_shaders[
BONDS][stp] = -1;
620 view -> create_shaders[
BONDS] = TRUE;
621 view -> create_shaders[
LABEL] = TRUE;
622 view -> create_shaders[
MEASU] = TRUE;
626 if (img_a -> draw_clones != img_b -> draw_clones)
628 view -> n_shaders[
ATOMS][stp] = -1;
629 view -> create_shaders[
ATOMS] = TRUE;
630 view -> n_shaders[
BONDS][stp] = -1;
631 view -> create_shaders[
BONDS] = TRUE;
632 view -> n_shaders[
POLYS][stp] = -1;
633 view -> create_shaders[
POLYS] = TRUE;
634 view -> n_shaders[
RINGS][stp] = -1;
635 view -> create_shaders[
RINGS] = TRUE;
636 view -> n_shaders[
SELEC][stp] = -1;
637 view -> create_shaders[
SELEC] = TRUE;
638 view -> create_shaders[
LABEL] = TRUE;
642 if (img_a -> color_map[0] != img_b -> color_map[0] || img_b -> color_map[0] !=
old_cmap[0][stp])
644 view -> n_shaders[
ATOMS][stp] = -1;
645 view -> create_shaders[
ATOMS] = TRUE;
646 view -> n_shaders[
BONDS][stp] = -1;
647 view -> create_shaders[
BONDS] = TRUE;
648 view -> create_shaders[
LABEL] = TRUE;
653 if (img_a -> color_map[1] != img_b -> color_map[1] || img_b -> color_map[1] !=
old_cmap[1][stp])
655 view -> n_shaders[
POLYS][stp] = -1;
656 view -> create_shaders[
POLYS] = TRUE;
663 if (view -> n_shaders[
ATOMS][stp] < 0) view -> create_shaders[
ATOMS] = TRUE;
664 if (view -> n_shaders[
BONDS][stp] < 0) view -> create_shaders[
BONDS] = TRUE;
665 if (view -> n_shaders[
POLYS][stp] < 0) view -> create_shaders[
POLYS] = TRUE;
666 if (view -> n_shaders[
RINGS][stp] < 0) view -> create_shaders[
RINGS] = TRUE;
667 if (view -> n_shaders[
VOLMS][stp] < 0) view -> create_shaders[
VOLMS] = TRUE;
668 if (view -> n_shaders[
SELEC][stp] < 0) view -> create_shaders[
SELEC] = TRUE;
669 view -> create_shaders[
LABEL] = TRUE;
670 view -> create_shaders[
MEASU] = TRUE;
674 gboolean do_volms = FALSE;
677 if (img_a -> show_vol[i] != img_b -> show_vol[i]) do_volms = TRUE;
678 if (img_a -> vol_col[i].red != img_b -> vol_col[i].red) do_volms = TRUE;
679 if (img_a -> vol_col[i].green != img_b -> vol_col[i].green) do_volms = TRUE;
680 if (img_a -> vol_col[i].blue != img_b -> vol_col[i].blue) do_volms = TRUE;
683 if (img_a -> fm_show_vol[j][i] == NULL && img_b -> fm_show_vol[j][i] != NULL)
687 else if (img_a -> fm_show_vol[j][i] != NULL && img_b -> fm_show_vol[j][i] == NULL)
691 else if (img_a -> fm_show_vol[j][i] != NULL && img_b -> fm_show_vol[j][i] != NULL)
693 for (k=0; k<this_coord -> totcoord[j+2]; k++)
695 if (img_a -> fm_show_vol[j][i][k] != img_b -> fm_show_vol[j][i][k]) do_volms = TRUE;
696 if (img_a -> fm_vol_col[j][i][k].red != img_b -> fm_vol_col[j][i][k].red) do_volms = TRUE;
697 if (img_a -> fm_vol_col[j][i][k].green != img_b -> fm_vol_col[j][i][k].green) do_volms = TRUE;
698 if (img_a -> fm_vol_col[j][i][k].blue != img_b -> fm_vol_col[j][i][k].blue) do_volms = TRUE;
706 view -> n_shaders[
VOLMS][stp] = -1;
709 if (img_a -> abc ->
box != img_b -> abc ->
box) view -> create_shaders[
MDBOX] =
shaders = TRUE;
710 if (img_a -> abc -> rad != img_b -> abc -> rad) view -> create_shaders[
MDBOX] =
shaders = TRUE;
711 if (img_a -> abc -> line != img_b -> abc -> line) view -> create_shaders[
MDBOX] =
shaders = TRUE;
716 if (img_a -> xyz ->
axis != img_b -> xyz ->
axis) view -> create_shaders[
MAXIS] =
shaders = TRUE;
717 if (img_a -> xyz -> rad != img_b -> xyz -> rad) view -> create_shaders[
MAXIS] =
shaders = TRUE;
718 if (img_a -> xyz -> line != img_b -> xyz -> line) view -> create_shaders[
MAXIS] =
shaders = TRUE;
719 if (img_a -> xyz -> length != img_b -> xyz -> length) view -> create_shaders[
MAXIS] =
shaders = TRUE;
720 if (img_a -> xyz -> t_pos != img_b -> xyz -> t_pos) view -> create_shaders[
MAXIS] =
shaders = TRUE;
721 if (img_a -> xyz ->
color == NULL && img_b -> xyz ->
color != NULL)
725 else if (img_a -> xyz ->
color != NULL && img_b -> xyz ->
color == NULL)
729 else if (img_a -> xyz ->
color != NULL && img_b -> xyz ->
color != NULL)
733 if (img_a -> xyz ->
color[i].red != img_b -> xyz ->
color[i].red) view -> create_shaders[
MAXIS] =
shaders = TRUE;
734 if (img_a -> xyz ->
color[i].green != img_b -> xyz ->
color[i].green) view -> create_shaders[
MAXIS] =
shaders = TRUE;
735 if (img_a -> xyz ->
color[i].blue != img_b -> xyz ->
color[i].blue) view -> create_shaders[
MAXIS] =
shaders = TRUE;
741 if (g_strcmp0 (img_a -> xyz -> title[i], img_b -> xyz -> title[i]) != 0) view -> create_shaders[
MAXIS] =
shaders = TRUE;
742 if (img_a -> xyz -> c_pos[i] != img_b -> xyz -> c_pos[i]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
744 if (g_strcmp0 (img_a ->
labels[2].font, img_b ->
labels[2].font) != 0) view -> create_shaders[
MAXIS] =
shaders = TRUE;
768 view -> n_shaders[
POLYS][stp] = -1;
769 view -> create_shaders[
POLYS] = TRUE;
770 view -> n_shaders[
RINGS][stp] = -1;
771 view -> create_shaders[
RINGS] = TRUE;
775 gboolean dorings = FALSE;
778 if (view -> ring_max[i])
780 if (img_a -> i_rings[i] && img_b -> i_rings[i])
782 if (img_a -> i_rings[i][0][0] != img_b -> i_rings[i][0][0])
784 view -> n_shaders[
RINGS][stp] = -1;
785 view -> create_shaders[
RINGS] = TRUE;
791 for (j=0; j<img_a -> i_rings[i][0][0]; j++)
793 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]))
795 view -> n_shaders[
RINGS][stp] = -1;
796 view -> create_shaders[
RINGS] = TRUE;
803 else if (img_b -> i_rings[i])
815 if (img_a -> show_label[i][j] != img_b -> show_label[i][j])
819 if (img_a -> show_atom[i][j] != img_b -> show_atom[i][j])
821 view -> n_shaders[
ATOMS][stp] = -1;
822 view -> create_shaders[
ATOMS] = TRUE;
823 view -> n_shaders[
BONDS][stp] = -1;
824 view -> create_shaders[
BONDS] = TRUE;
825 view -> n_shaders[
SELEC][stp] = -1;
826 view -> create_shaders[
SELEC] = TRUE;
827 view -> create_shaders[
LABEL] = TRUE;
828 view -> create_shaders[
MEASU] = TRUE;
833 for (j=0; j<
tmp_proj -> natomes; j++)
835 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)
837 view -> n_shaders[
ATOMS][stp] = -1;
838 view -> create_shaders[
ATOMS] = TRUE;
839 view -> n_shaders[
BONDS][stp] = -1;
840 view -> create_shaders[
BONDS] = TRUE;
841 view -> n_shaders[
SELEC][stp] = -1;
842 view -> create_shaders[
SELEC] = TRUE;
843 view -> create_shaders[
LABEL] = TRUE;
844 view -> create_shaders[
MEASU] = TRUE;
848 if (img_a -> at_data[j].
label[i] != img_b -> at_data[j].
label[i])
852 if (img_a -> at_data[j].
pick[0] != img_b -> at_data[j].
pick[0])
854 view -> n_shaders[
SELEC][stp] = -1;
857 if (img_a -> at_data[j].
pick[1] != img_b -> at_data[j].
pick[1])
859 view -> n_shaders[
SELEC][stp] = -1;
865 for (i=0; i<2*
tmp_proj -> nspec; i++)
867 if ((img_a -> sphererad[i] != img_b -> sphererad[i])
868 || (img_a -> pointrad[i] != img_b -> pointrad[i])
869 || (img_a -> atomicrad[i] != img_b -> atomicrad[i]))
871 view -> n_shaders[
ATOMS][stp] = -1;
872 view -> create_shaders[
ATOMS] = TRUE;
873 view -> n_shaders[
SELEC][stp] = -1;
874 view -> create_shaders[
SELEC] = TRUE;
875 view -> create_shaders[
LABEL] = TRUE;
878 for (j=0; j<2*
tmp_proj -> nspec; j++)
880 if ((img_a -> bondrad[i][j] != img_b -> bondrad[i][j])
881 || (img_a -> linerad[i][j] != img_b -> linerad[i][j]))
883 view -> n_shaders[
BONDS][stp] = -1;
884 view -> create_shaders[
BONDS] = TRUE;
885 view -> n_shaders[
SELEC][stp] = -1;
886 view -> create_shaders[
SELEC] = TRUE;
887 view -> create_shaders[
LABEL] = TRUE;
895 if (img_a -> acl_format[i] != img_b -> acl_format[i]) view -> create_shaders[
LABEL] =
shaders = TRUE;
896 if (g_strcmp0 (img_a ->
labels[i].font, img_b ->
labels[i].font) != 0) view -> create_shaders[
LABEL] =
shaders = TRUE;
922 if (img_a -> radall[i] != img_b -> radall[i])
924 view -> n_shaders[
ATOMS][stp] = -1;
925 view -> create_shaders[
ATOMS] = TRUE;
926 view -> n_shaders[
BONDS][stp] = -1;
927 view -> create_shaders[
BONDS] = TRUE;
928 view -> n_shaders[
SELEC][stp] = -1;
929 view -> create_shaders[
SELEC] = TRUE;
930 view -> create_shaders[
LABEL] = TRUE;
937 view -> n_shaders[
ATOMS][stp] = -1;
938 view -> create_shaders[
ATOMS] = TRUE;
939 view -> n_shaders[
BONDS][stp] = -1;
940 view -> create_shaders[
BONDS] = TRUE;
941 view -> n_shaders[
SELEC][stp] = -1;
942 view -> create_shaders[
SELEC] = TRUE;
945 if (img_a -> style != img_b -> style)
947 view -> n_shaders[
ATOMS][stp] = -1;
948 view -> create_shaders[
ATOMS] = TRUE;
949 view -> n_shaders[
BONDS][stp] = -1;
950 view -> create_shaders[
BONDS] = TRUE;
951 view -> n_shaders[
SELEC][stp] = -1;
952 view -> create_shaders[
SELEC] = TRUE;
953 view -> create_shaders[
LABEL] = TRUE;
957 if (img_a -> m_is_pressed != img_b -> m_is_pressed) view -> create_shaders[
MEASU] =
shaders = TRUE;
960 if (img_a -> mtilt[i] != img_b -> mtilt[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
961 if (img_a -> mpattern[i] != img_b -> mpattern[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
962 if (img_a -> mfactor[i] != img_b -> mfactor[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
963 if (img_a -> mwidth[i] != img_b -> mwidth[i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
964 if (g_strcmp0 (img_a ->
labels[3+i].font, img_b ->
labels[3+i].font) != 0) view -> create_shaders[
MEASU] =
shaders = TRUE;
1005 const AVOutputFormat * output_format = NULL;
1006 AVFormatContext * format_context = NULL;
1008 const AVCodec * video_codec = NULL;
1013 g_debug (
"VIDEO ENCODING:: frames per seconds:: %d", vopts ->
framesec);
1014 g_debug (
"VIDEO ENCODING:: extra frames every:: %d frame(s)", vopts ->
extraframes);
1015 g_debug (
"VIDEO ENCODING:: bitrate:: %d", vopts ->
bitrate);
1016 g_debug (
"VIDEO ENCODING:: video_x = %d , video_y = %d", vopts ->
video_res[0], vopts ->
video_res[1]);
1021#if LIBAVCODEC_VERSION_MAJOR < 57
1023 avcodec_register_all ();
1026 if (! (format_context = avformat_alloc_context()))
1028 g_warning (
"MOVIE_ENCODING:: Could not allocate AV format context");
1033 if (! (format_context -> oformat = av_guess_format (NULL, videofile, NULL)))
1035 g_warning (
"MOVIE_ENCODING:: Could not deduce container format: please change file name");
1039 output_format = format_context -> oformat;
1042 if (video_stream == NULL)
1044 g_warning (
"MOVIE_ENCODING:: Could not create video stream");
1049 if ((error = avcodec_open2 (video_stream -> cc, video_codec, NULL)) < 0)
1052 g_warning (
"MOVIE_ENCODING:: could not open codec, error= %s", av_err2str(error));
1056 avcodec_parameters_from_context (video_stream -> st -> codecpar, video_stream -> cc);
1057#if LIBAVCODEC_VERSION_MAJOR > 52
1058 av_dump_format (format_context, 0, videofile, 1);
1060 dump_format (av_format_context, 0, videofile, 1);
1063#if LIBAVCODEC_VERSION_MAJOR > 52
1064 if (avio_open (& format_context -> pb, videofile,
AVIO_FLAG_WRITE) < 0)
1066 if (url_fopen (& av_format_context -> pb, videofile,
URL_WRONLY) < 0)
1070 g_warning (
"MOVIE_ENCODING:: Impossible to open the video file '%s'", videofile);
1074#if LIBAVCODEC_VERSION_MAJOR > 52
1075 if (avformat_write_header (format_context, NULL) < 0)
1077 if (av_set_parameters (av_format_context, NULL) < 0)
1080 g_warning (
"MOVIE_ENCODING:: Impossible to write the AV format header");
1084 view -> anim -> last = view -> anim -> first;
1087 q = view -> anim -> last ->
img -> quality;
1088 view -> anim -> last ->
img -> quality = vopts ->
oglquality;
1093 if (vopts ->
codec == 0)
1096 write_video_frame (format_context, video_stream, 0, view);
1098 else if (vopts ->
codec == 2)
1101 for (frame_id = 0; frame_id <
frame_start; frame_id ++)
1103 write_video_frame (format_context, video_stream, frame_id, view);
1108 for (frame_id=0; frame_id<2; frame_id++)
1122 view -> anim -> last ->
img -> quality = vopts ->
oglquality;
1124 write_video_frame (format_context, video_stream, frame_id, view);
1128 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(
encoding_pb), fraction);
1130 while (gtk_events_pending()) gtk_main_iteration();
1138 view -> anim -> last ->
img,
1139 view -> anim -> last -> next ->
img,
1141 view -> anim -> last = view -> anim -> last -> next;
1146 view -> anim -> last ->
img -> quality = q;
1149 av_write_trailer (format_context);
1151 if (!(output_format -> flags & AVFMT_NOFILE))
1154#if LIBAVCODEC_VERSION_MAJOR > 52
1155 avio_closep (& format_context -> pb);
1157 url_fclose (av_format_context -> pb);
1161 close_stream (format_context, video_stream);
1167static GLuint rbo_color;
1168static GLuint rbo_depth;
1179 glGenFramebuffers (1, & fbo);
1180 glBindFramebuffer (GL_FRAMEBUFFER, fbo);
1183 glGenRenderbuffers (1, & rbo_color);
1184 glBindRenderbuffer (GL_RENDERBUFFER, rbo_color);
1189 glRenderbufferStorage (GL_RENDERBUFFER, GL_RGB,
x,
y);
1190 glFramebufferRenderbuffer (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo_color);
1192 glGenRenderbuffers (1, & rbo_depth);
1193 glBindRenderbuffer (GL_RENDERBUFFER, rbo_depth);
1194 glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
x,
y);
1195 glFramebufferRenderbuffer (GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth);
1197 glReadBuffer (GL_COLOR_ATTACHMENT0);
1207 glDeleteFramebuffers (1, &fbo);
1208 glDeleteRenderbuffers (1, &rbo_color);
1209 glDeleteRenderbuffers (1, &rbo_depth);
1222G_MODULE_EXPORT
void run_save_movie (GtkNativeDialog * info, gint response_id, gpointer data)
1224 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1235G_MODULE_EXPORT
void run_save_movie (GtkDialog * info, gint response_id, gpointer data)
1237 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1239 if (response_id == GTK_RESPONSE_ACCEPT)
1249 int x = view -> pixels[0];
1250 int y = view -> pixels[1];
1252 for (i=0; i<2; i++)
tmp_pixels[i] = view -> pixels[i];
1253 view -> pixels[0] = vopts ->
video_res[0];
1254 view -> pixels[1] = vopts ->
video_res[1];
1263 show_warning (
"An error occurred when encoding movie\nyou might want to try again\nsorry for the trouble", view -> win);
1295 GtkFileChooserNative * info;
1300 GTK_WINDOW(view -> win),
1301 GTK_FILE_CHOOSER_ACTION_SAVE,
1303 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1305 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1309 gtk_file_chooser_set_current_name (chooser, str);
1312 filter = gtk_file_filter_new ();
1314 gtk_file_filter_set_name (GTK_FILE_FILTER(
filter), str);
1317 gtk_file_filter_add_pattern (GTK_FILE_FILTER(
filter), str);
1319 gtk_file_chooser_add_filter (chooser,
filter);
1321 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
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
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...