]> git.sesse.net Git - ffmpeg/blob - libavcodec/libwebpenc_common.h
Merge commit '29216d7fd14d1cec16821867d17c90b5c49e8c07'
[ffmpeg] / libavcodec / libwebpenc_common.h
1 /*
2  * WebP encoding support via libwebp
3  * Copyright (c) 2013 Justin Ruggles <justin.ruggles@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 /**
23  * @file
24  * WebP encoder using libwebp: common structs and methods.
25  */
26
27 #include <webp/encode.h>
28
29 #include "libavutil/common.h"
30 #include "libavutil/frame.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/opt.h"
33 #include "avcodec.h"
34 #include "internal.h"
35
36 typedef struct LibWebPContextCommon {
37     AVClass *class;         // class for AVOptions
38     float quality;          // lossy quality 0 - 100
39     int lossless;           // use lossless encoding
40     int preset;             // configuration preset
41     int chroma_warning;     // chroma linesize mismatch warning has been printed
42     int conversion_warning; // pixel format conversion warning has been printed
43     WebPConfig config;      // libwebp configuration
44     AVFrame *ref;
45     int cr_size;
46     int cr_threshold;
47 } LibWebPContextCommon;
48
49 int ff_libwebp_error_to_averror(int err);
50
51 av_cold int ff_libwebp_encode_init_common(AVCodecContext *avctx);
52
53 int ff_libwebp_get_frame(AVCodecContext *avctx, LibWebPContextCommon *s,
54                          const AVFrame *frame, AVFrame **alt_frame_ptr,
55                          WebPPicture **pic_ptr);
56
57 int ff_libwebp_encode_close_common(AVCodecContext *avctx);
58
59 #define OFFSET(x) offsetof(LibWebPContextCommon, x)
60 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
61 static const AVOption options[] = {
62     { "lossless",   "Use lossless mode",       OFFSET(lossless), AV_OPT_TYPE_INT,   { .i64 =  0 },  0, 1,                           VE           },
63     { "preset",     "Configuration preset",    OFFSET(preset),   AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, WEBP_PRESET_TEXT,            VE, "preset" },
64     { "none",       "do not use a preset",                              0, AV_OPT_TYPE_CONST, { .i64 = -1                  }, 0, 0, VE, "preset" },
65     { "default",    "default preset",                                   0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DEFAULT }, 0, 0, VE, "preset" },
66     { "picture",    "digital picture, like portrait, inner shot",       0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PICTURE }, 0, 0, VE, "preset" },
67     { "photo",      "outdoor photograph, with natural lighting",        0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_PHOTO   }, 0, 0, VE, "preset" },
68     { "drawing",    "hand or line drawing, with high-contrast details", 0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_DRAWING }, 0, 0, VE, "preset" },
69     { "icon",       "small-sized colorful images",                      0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_ICON    }, 0, 0, VE, "preset" },
70     { "text",       "text-like",                                        0, AV_OPT_TYPE_CONST, { .i64 = WEBP_PRESET_TEXT    }, 0, 0, VE, "preset" },
71     { "cr_threshold","Conditional replenishment threshold",     OFFSET(cr_threshold), AV_OPT_TYPE_INT, { .i64 =  0  },  0, INT_MAX, VE           },
72     { "cr_size"     ,"Conditional replenishment block size",    OFFSET(cr_size)     , AV_OPT_TYPE_INT, { .i64 =  16 },  0, 256,     VE           },
73     { "quality"     ,"Quality",                OFFSET(quality),  AV_OPT_TYPE_FLOAT, { .dbl =  75 }, 0, 100,                         VE           },
74     { NULL },
75 };
76
77
78 static const AVClass class = {
79     .class_name = "libwebp",
80     .item_name  = av_default_item_name,
81     .option     = options,
82     .version    = LIBAVUTIL_VERSION_INT,
83 };
84
85 static const AVCodecDefault libwebp_defaults[] = {
86     { "compression_level",  "4"  },
87     { "global_quality",     "-1" },
88     { NULL },
89 };