1 /*
2  * This file is part of mpv.
3  *
4  * mpv is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * mpv is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "options/m_option.h"
19 
20 struct mp_image;
21 struct mp_log;
22 
23 struct image_writer_opts {
24     int format;
25     int high_bit_depth;
26     int png_compression;
27     int png_filter;
28     int jpeg_quality;
29     int jpeg_optimize;
30     int jpeg_smooth;
31     int jpeg_dpi;
32     int jpeg_progressive;
33     int jpeg_baseline;
34     int jpeg_source_chroma;
35     int webp_lossless;
36     int webp_quality;
37     int webp_compression;
38     int tag_csp;
39 };
40 
41 extern const struct image_writer_opts image_writer_opts_defaults;
42 
43 extern const struct m_option image_writer_opts[];
44 
45 // Return the file extension that will be used, e.g. "png".
46 const char *image_writer_file_ext(const struct image_writer_opts *opts);
47 
48 // Return whether the selected format likely supports >8 bit per component.
49 bool image_writer_high_depth(const struct image_writer_opts *opts);
50 
51 // Map file extension to format ID - return 0 (which is invalid) if unknown.
52 int image_writer_format_from_ext(const char *ext);
53 
54 /*
55  * Save the given image under the given filename. The parameters csp and opts
56  * are optional. All pixel formats supported by swscale are supported.
57  *
58  * File format and compression settings are controlled via the opts parameter.
59  *
60  * If global!=NULL, use command line scaler options etc.
61  *
62  * NOTE: The fields w/h/width/height of the passed mp_image must be all set
63  *       accordingly. Setting w and width or h and height to different values
64  *       can be used to store snapshots of anamorphic video.
65  */
66 bool write_image(struct mp_image *image, const struct image_writer_opts *opts,
67                 const char *filename, struct mpv_global *global,
68                  struct mp_log *log);
69 
70 // Debugging helper.
71 void dump_png(struct mp_image *image, const char *filename, struct mp_log *log);
72