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 -> extra_cell[i] != img_b -> 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 -> box_axis[0] != img_b -> box_axis[0]) view -> create_shaders[
MDBOX] =
shaders = TRUE;
710 if (img_a -> box_axis_rad[0] != img_b -> box_axis_rad[0]) view -> create_shaders[
MDBOX] =
shaders = TRUE;
711 if (img_a -> box_axis_line[0] != img_b -> box_axis_line[0]) view -> create_shaders[
MDBOX] =
shaders = TRUE;
712 if (img_a -> box_color.red != img_b -> box_color.red) view -> create_shaders[
MDBOX] =
shaders = TRUE;
713 if (img_a -> box_color.green != img_b -> box_color.green) view -> create_shaders[
MDBOX] =
shaders = TRUE;
714 if (img_a -> box_color.blue != img_b -> box_color.blue) view -> create_shaders[
MDBOX] =
shaders = TRUE;
716 if (img_a -> box_axis[1] != img_b -> box_axis[1]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
717 if (img_a -> box_axis_rad[1] != img_b -> box_axis_rad[1]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
718 if (img_a -> box_axis_line[1] != img_b -> box_axis_line[1]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
719 if (img_a -> axis_length != img_b -> axis_length) view -> create_shaders[
MAXIS] =
shaders = TRUE;
720 if (img_a -> axispos != img_b -> axispos) view -> create_shaders[
MAXIS] =
shaders = TRUE;
721 if (img_a -> axis_color == NULL && img_b -> axis_color != NULL)
725 else if (img_a -> axis_color != NULL && img_b -> axis_color == NULL)
729 else if (img_a -> axis_color != NULL && img_b -> axis_color != NULL)
733 if (img_a -> axis_color[i].red != img_b -> axis_color[i].red) view -> create_shaders[
MAXIS] =
shaders = TRUE;
734 if (img_a -> axis_color[i].green != img_b -> axis_color[i].green) view -> create_shaders[
MAXIS] =
shaders = TRUE;
735 if (img_a -> axis_color[i].blue != img_b -> axis_color[i].blue) view -> create_shaders[
MAXIS] =
shaders = TRUE;
738 if (img_a -> axis_labels != img_b -> axis_labels) view -> create_shaders[
MAXIS] =
shaders = TRUE;
742 if (img_a -> axis_pos[i] != img_b -> axis_pos[i]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
744 if (img_a -> labels_format[2] != img_b -> labels_format[2]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
745 if (g_strcmp0 (img_a -> labels_font[2], img_b -> labels_font[2]) != 0) view -> create_shaders[
MAXIS] =
shaders = TRUE;
746 if (img_a -> labels_position[2] != img_b -> labels_position[2]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
747 if (img_a -> labels_scale[2] != img_b -> labels_scale[2]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
748 if (img_a -> labels_render[2] != img_b -> labels_render[2]) view -> create_shaders[
MAXIS] =
shaders = TRUE;
749 if (img_a -> labels_color[2] == NULL && img_b -> labels_color[2] != NULL)
753 else if (img_a -> labels_color[2] != NULL && img_b -> labels_color[2] == NULL)
757 else if (img_a -> labels_color[2] != NULL && img_b -> labels_color[2] != NULL)
761 if (img_a -> labels_color[2][i].red != img_b -> labels_color[2][i].red) view -> create_shaders[
MAXIS] =
shaders = TRUE;
762 if (img_a -> labels_color[2][i].green != img_b -> labels_color[2][i].green) view -> create_shaders[
MAXIS] =
shaders = TRUE;
763 if (img_a -> labels_color[2][i].blue != img_b -> labels_color[2][i].blue) view -> create_shaders[
MAXIS] =
shaders = TRUE;
769 view -> n_shaders[
POLYS][stp] = -1;
770 view -> create_shaders[
POLYS] = TRUE;
771 view -> n_shaders[
RINGS][stp] = -1;
772 view -> create_shaders[
RINGS] = TRUE;
776 gboolean dorings = FALSE;
779 if (view -> ring_max[i])
781 if (img_a -> i_rings[i] && img_b -> i_rings[i])
783 if (img_a -> i_rings[i][0][0] != img_b -> i_rings[i][0][0])
785 view -> n_shaders[
RINGS][stp] = -1;
786 view -> create_shaders[
RINGS] = TRUE;
792 for (j=0; j<img_a -> i_rings[i][0][0]; j++)
794 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]))
796 view -> n_shaders[
RINGS][stp] = -1;
797 view -> create_shaders[
RINGS] = TRUE;
804 else if (img_b -> i_rings[i])
816 if (img_a -> show_label[i][j] != img_b -> show_label[i][j])
820 if (img_a -> show_atom[i][j] != img_b -> show_atom[i][j])
822 view -> n_shaders[
ATOMS][stp] = -1;
823 view -> create_shaders[
ATOMS] = TRUE;
824 view -> n_shaders[
BONDS][stp] = -1;
825 view -> create_shaders[
BONDS] = TRUE;
826 view -> n_shaders[
SELEC][stp] = -1;
827 view -> create_shaders[
SELEC] = TRUE;
828 view -> create_shaders[
LABEL] = TRUE;
829 view -> create_shaders[
MEASU] = TRUE;
834 for (j=0; j<
tmp_proj -> natomes; j++)
836 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)
838 view -> n_shaders[
ATOMS][stp] = -1;
839 view -> create_shaders[
ATOMS] = TRUE;
840 view -> n_shaders[
BONDS][stp] = -1;
841 view -> create_shaders[
BONDS] = TRUE;
842 view -> n_shaders[
SELEC][stp] = -1;
843 view -> create_shaders[
SELEC] = TRUE;
844 view -> create_shaders[
LABEL] = TRUE;
845 view -> create_shaders[
MEASU] = TRUE;
849 if (img_a -> at_data[j].
label[i] != img_b -> at_data[j].
label[i])
853 if (img_a -> at_data[j].
pick[0] != img_b -> at_data[j].
pick[0])
855 view -> n_shaders[
SELEC][stp] = -1;
858 if (img_a -> at_data[j].
pick[1] != img_b -> at_data[j].
pick[1])
860 view -> n_shaders[
SELEC][stp] = -1;
866 for (i=0; i<2*
tmp_proj -> nspec; i++)
868 if ((img_a -> sphererad[i] != img_b -> sphererad[i])
869 || (img_a -> pointrad[i] != img_b -> pointrad[i])
870 || (img_a -> atomicrad[i] != img_b -> atomicrad[i]))
872 view -> n_shaders[
ATOMS][stp] = -1;
873 view -> create_shaders[
ATOMS] = TRUE;
874 view -> n_shaders[
SELEC][stp] = -1;
875 view -> create_shaders[
SELEC] = TRUE;
876 view -> create_shaders[
LABEL] = TRUE;
879 for (j=0; j<2*
tmp_proj -> nspec; j++)
881 if ((img_a -> bondrad[i][j] != img_b -> bondrad[i][j])
882 || (img_a -> linerad[i][j] != img_b -> linerad[i][j]))
884 view -> n_shaders[
BONDS][stp] = -1;
885 view -> create_shaders[
BONDS] = TRUE;
886 view -> n_shaders[
SELEC][stp] = -1;
887 view -> create_shaders[
SELEC] = TRUE;
888 view -> create_shaders[
LABEL] = TRUE;
896 if (img_a -> labels_format[i] != img_b -> labels_format[i]) view -> create_shaders[
LABEL] =
shaders = TRUE;
897 if (g_strcmp0 (img_a -> labels_font[i], img_b -> labels_font[i]) != 0) view -> create_shaders[
LABEL] =
shaders = TRUE;
898 if (img_a -> labels_position[i] != img_b -> labels_position[i]) view -> create_shaders[
LABEL] =
shaders = TRUE;
899 if (img_a -> labels_scale[i] != img_b -> labels_scale[i]) view -> create_shaders[
LABEL] =
shaders = TRUE;
900 if (img_a -> labels_render[i] != img_b -> labels_render[i]) view -> create_shaders[
LABEL] =
shaders = TRUE;
903 if (img_a -> labels_shift[i][j] != img_b -> labels_shift[i][j]) view -> create_shaders[
LABEL] =
shaders = TRUE;
905 if (img_a -> labels_color[i] == NULL && img_b -> labels_color[i] != NULL)
909 else if (img_a -> labels_color[i] != NULL && img_b -> labels_color[i] == NULL)
913 else if (img_a -> labels_color[i] != NULL && img_b -> labels_color[i] != NULL)
917 if (img_a -> labels_color[i][j].red != img_b -> labels_color[i][j].red) view -> create_shaders[
LABEL] =
shaders = TRUE;
918 if (img_a -> labels_color[i][j].green != img_b -> labels_color[i][j].green) view -> create_shaders[
LABEL] =
shaders = TRUE;
919 if (img_a -> labels_color[i][j].blue != img_b -> labels_color[i][j].blue) view -> create_shaders[
LABEL] =
shaders = TRUE;
923 if (img_a -> radall[i] != img_b -> radall[i])
925 view -> n_shaders[
ATOMS][stp] = -1;
926 view -> create_shaders[
ATOMS] = TRUE;
927 view -> n_shaders[
BONDS][stp] = -1;
928 view -> create_shaders[
BONDS] = TRUE;
929 view -> n_shaders[
SELEC][stp] = -1;
930 view -> create_shaders[
SELEC] = TRUE;
931 view -> create_shaders[
LABEL] = TRUE;
938 view -> n_shaders[
ATOMS][stp] = -1;
939 view -> create_shaders[
ATOMS] = TRUE;
940 view -> n_shaders[
BONDS][stp] = -1;
941 view -> create_shaders[
BONDS] = TRUE;
942 view -> n_shaders[
SELEC][stp] = -1;
943 view -> create_shaders[
SELEC] = TRUE;
946 if (img_a -> style != img_b -> style)
948 view -> n_shaders[
ATOMS][stp] = -1;
949 view -> create_shaders[
ATOMS] = TRUE;
950 view -> n_shaders[
BONDS][stp] = -1;
951 view -> create_shaders[
BONDS] = TRUE;
952 view -> n_shaders[
SELEC][stp] = -1;
953 view -> create_shaders[
SELEC] = TRUE;
954 view -> create_shaders[
LABEL] = TRUE;
958 if (img_a -> m_is_pressed != img_b -> m_is_pressed) view -> create_shaders[
MEASU] =
shaders = TRUE;
959 if (img_a -> mtilt != img_b -> mtilt) view -> create_shaders[
MEASU] =
shaders = TRUE;
960 if (img_a -> mpattern != img_b -> mpattern) view -> create_shaders[
MEASU] =
shaders = TRUE;
961 if (img_a -> mfactor != img_b -> mfactor) view -> create_shaders[
MEASU] =
shaders = TRUE;
962 if (img_a -> mwidth != img_b -> mwidth) view -> create_shaders[
MEASU] =
shaders = TRUE;
965 if (g_strcmp0 (img_a -> labels_font[3+i], img_b -> labels_font[3+i]) != 0) view -> create_shaders[
MEASU] =
shaders = TRUE;
966 if (img_a -> labels_position[3+i] != img_b -> labels_position[3+i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
967 if (img_a -> labels_scale[3+i] != img_b -> labels_scale[3+i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
968 if (img_a -> labels_render[3+i] != img_b -> labels_render[3+i]) view -> create_shaders[
MEASU] =
shaders = TRUE;
969 if (img_a -> labels_color[3+i][0].red != img_b -> labels_color[3+i][0].red) view -> create_shaders[
MEASU] =
shaders = TRUE;
970 if (img_a -> labels_color[3+i][0].green != img_b -> labels_color[3+i][0].green) view -> create_shaders[
MEASU] =
shaders = TRUE;
971 if (img_a -> labels_color[3+i][0].blue != img_b -> labels_color[3+i][0].blue) view -> create_shaders[
MEASU] =
shaders = TRUE;
974 if (img_a -> labels_shift[3+i][j] != img_b -> labels_shift[3+i][j]) view -> create_shaders[
MEASU] =
shaders = TRUE;
1006 const AVOutputFormat * output_format = NULL;
1007 AVFormatContext * format_context = NULL;
1009 const AVCodec * video_codec = NULL;
1014 g_debug (
"VIDEO ENCODING:: frames per seconds:: %d", vopts ->
framesec);
1015 g_debug (
"VIDEO ENCODING:: extra frames every:: %d frame(s)", vopts ->
extraframes);
1016 g_debug (
"VIDEO ENCODING:: bitrate:: %d", vopts ->
bitrate);
1017 g_debug (
"VIDEO ENCODING:: video_x = %d , video_y = %d", vopts ->
video_res[0], vopts ->
video_res[1]);
1022#if LIBAVCODEC_VERSION_MAJOR < 57
1024 avcodec_register_all ();
1027 if (! (format_context = avformat_alloc_context()))
1029 g_warning (
"MOVIE_ENCODING:: Could not allocate AV format context");
1034 if (! (format_context -> oformat = av_guess_format (NULL, videofile, NULL)))
1036 g_warning (
"MOVIE_ENCODING:: Could not deduce container format: please change file name");
1040 output_format = format_context -> oformat;
1043 if (video_stream == NULL)
1045 g_warning (
"MOVIE_ENCODING:: Could not create video stream");
1050 if ((error = avcodec_open2 (video_stream -> cc, video_codec, NULL)) < 0)
1053 g_warning (
"MOVIE_ENCODING:: could not open codec, error= %s", av_err2str(error));
1057 avcodec_parameters_from_context (video_stream -> st -> codecpar, video_stream -> cc);
1058#if LIBAVCODEC_VERSION_MAJOR > 52
1059 av_dump_format (format_context, 0, videofile, 1);
1061 dump_format (av_format_context, 0, videofile, 1);
1064#if LIBAVCODEC_VERSION_MAJOR > 52
1065 if (avio_open (& format_context -> pb, videofile,
AVIO_FLAG_WRITE) < 0)
1067 if (url_fopen (& av_format_context -> pb, videofile,
URL_WRONLY) < 0)
1071 g_warning (
"MOVIE_ENCODING:: Impossible to open the video file '%s'", videofile);
1075#if LIBAVCODEC_VERSION_MAJOR > 52
1076 if (avformat_write_header (format_context, NULL) < 0)
1078 if (av_set_parameters (av_format_context, NULL) < 0)
1081 g_warning (
"MOVIE_ENCODING:: Impossible to write the AV format header");
1085 view -> anim -> last = view -> anim -> first;
1088 q = view -> anim -> last ->
img -> quality;
1089 view -> anim -> last ->
img -> quality = vopts ->
oglquality;
1094 if (vopts ->
codec == 0)
1097 write_video_frame (format_context, video_stream, 0, view);
1099 else if (vopts ->
codec == 2)
1102 for (frame_id = 0; frame_id <
frame_start; frame_id ++)
1104 write_video_frame (format_context, video_stream, frame_id, view);
1109 for (frame_id=0; frame_id<2; frame_id++)
1123 view -> anim -> last ->
img -> quality = vopts ->
oglquality;
1125 write_video_frame (format_context, video_stream, frame_id, view);
1129 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(
encoding_pb), fraction);
1131 while (gtk_events_pending()) gtk_main_iteration();
1139 view -> anim -> last ->
img,
1140 view -> anim -> last -> next ->
img,
1142 view -> anim -> last = view -> anim -> last -> next;
1147 view -> anim -> last ->
img -> quality = q;
1150 av_write_trailer (format_context);
1152 if (!(output_format -> flags & AVFMT_NOFILE))
1155#if LIBAVCODEC_VERSION_MAJOR > 52
1156 avio_closep (& format_context -> pb);
1158 url_fclose (av_format_context -> pb);
1162 close_stream (format_context, video_stream);
1168static GLuint rbo_color;
1169static GLuint rbo_depth;
1180 glGenFramebuffers (1, & fbo);
1181 glBindFramebuffer (GL_FRAMEBUFFER, fbo);
1184 glGenRenderbuffers (1, & rbo_color);
1185 glBindRenderbuffer (GL_RENDERBUFFER, rbo_color);
1190 glRenderbufferStorage (GL_RENDERBUFFER, GL_RGB,
x,
y);
1191 glFramebufferRenderbuffer (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo_color);
1193 glGenRenderbuffers (1, & rbo_depth);
1194 glBindRenderbuffer (GL_RENDERBUFFER, rbo_depth);
1195 glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
x,
y);
1196 glFramebufferRenderbuffer (GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth);
1198 glReadBuffer (GL_COLOR_ATTACHMENT0);
1208 glDeleteFramebuffers (1, &fbo);
1209 glDeleteRenderbuffers (1, &rbo_color);
1210 glDeleteRenderbuffers (1, &rbo_depth);
1223G_MODULE_EXPORT
void run_save_movie (GtkNativeDialog * info, gint response_id, gpointer data)
1225 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1236G_MODULE_EXPORT
void run_save_movie (GtkDialog * info, gint response_id, gpointer data)
1238 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1240 if (response_id == GTK_RESPONSE_ACCEPT)
1250 int x = view -> pixels[0];
1251 int y = view -> pixels[1];
1253 for (i=0; i<2; i++)
tmp_pixels[i] = view -> pixels[i];
1254 view -> pixels[0] = vopts ->
video_res[0];
1255 view -> pixels[1] = vopts ->
video_res[1];
1264 show_warning (
"An error occurred when encoding movie\nyou might want to try again\nsorry for the trouble", view -> win);
1296 GtkFileChooserNative * info;
1301 GTK_WINDOW(view -> win),
1302 GTK_FILE_CHOOSER_ACTION_SAVE,
1304 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1306 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1310 gtk_file_chooser_set_current_name (chooser, str);
1313 filter = gtk_file_filter_new ();
1315 gtk_file_filter_set_name (GTK_FILE_FILTER(
filter), str);
1318 gtk_file_filter_add_pattern (GTK_FILE_FILTER(
filter), str);
1320 gtk_file_chooser_add_filter (chooser,
filter);
1322 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(
run_save_movie), vopts);
GtkFileFilter * filter[NCFORMATS+1]
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...