[PATCH 1/3] cljrenc: add AVOption to disable dither
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index 950b46a..2c3cf1e 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -25,12 +25,15 @@ */ #include "avcodec.h" +#include "libavutil/opt.h" #include "get_bits.h" #include "put_bits.h" typedef struct CLJRContext { + AVClass *avclass; AVCodecContext *avctx; AVFrame picture; + int dither_type; } CLJRContext; static av_cold int common_init(AVCodecContext *avctx) @@ -129,6 +132,7 @@ AVCodec ff_cljr_decoder = { static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { + CLJRContext *a = avctx->priv_data; PutBitContext pb; AVFrame *p = data; int x, y; @@ -144,6 +148,10 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, uint8_t *cb = &p->data[1][y * p->linesize[1]]; uint8_t *cr = &p->data[2][y * p->linesize[2]]; for (x = 0; x < avctx->width; x += 4) { + switch(a->dither_type){ + case 0: dither = 0; break; + case 1: dither = dither*1664525+1013904223; break; + } put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3); put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3); put_bits(&pb, 5, (luma[1] + ((dither>>23)&7)) >> 3); @@ -151,7 +159,6 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, luma += 4; put_bits(&pb, 6, (*(cb++) + ((dither>>18)&3)) >> 2); put_bits(&pb, 6, (*(cr++) + ((dither>>16)&3)) >> 2); - dither = dither*1664525+1013904223; } } @@ -160,6 +167,20 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, return put_bits_count(&pb) / 8; } +#define OFFSET(x) offsetof(CLJRContext, x) +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + { "dither_type", "Dither type", OFFSET(dither_type), AV_OPT_TYPE_INT, { .dbl=1 }, 0, 2, VE}, + { NULL }, +}; + +static const AVClass class = { + .class_name = "cljr encoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_cljr_encoder = { .name = "cljr", .type = AVMEDIA_TYPE_VIDEO, @@ -170,5 +191,6 @@ AVCodec ff_cljr_encoder = { .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P, PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), + .priv_class = &class, }; #endif -- 1.7.5.4
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index 2c3cf1e..ea95901 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -149,7 +149,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, uint8_t *cr = &p->data[2][y * p->linesize[2]]; for (x = 0; x < avctx->width; x += 4) { switch(a->dither_type){ - case 0: dither = 0; break; + case 0: dither = 0x492A0000; break; case 1: dither = dither*1664525+1013904223; break; } put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3); -- 1.7.5.4
On 12/9/11, Michael Niedermayer <michaelni@gmx.at> wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
This should be squashed with previous patch.
On Fri, Dec 09, 2011 at 03:10:34PM +0000, Paul B Mahol wrote:
On 12/9/11, Michael Niedermayer <michaelni@gmx.at> wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
This should be squashed with previous patch.
ok, will do [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index ea95901..3d35d8f 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -137,6 +137,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, AVFrame *p = data; int x, y; uint32_t dither= avctx->frame_number; + static const uint32_t ordered_dither[2][2]= + { + {0x10400000, 0x104F0000}, + {0xCB2A0000, 0xCB250000}, + }; p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -151,6 +156,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, switch(a->dither_type){ case 0: dither = 0x492A0000; break; case 1: dither = dither*1664525+1013904223; break; + case 2: dither = ordered_dither[y&1][(x>>2)&1]; break; } put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3); put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3); -- 1.7.5.4
On 12/9/11, Michael Niedermayer <michaelni@gmx.at> wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index ea95901..3d35d8f 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -137,6 +137,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, AVFrame *p = data; int x, y; uint32_t dither= avctx->frame_number; + static const uint32_t ordered_dither[2][2]=
space before =
+ { + {0x10400000, 0x104F0000}, + {0xCB2A0000, 0xCB250000},
spaces after { and before }
+ };
p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -151,6 +156,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, switch(a->dither_type){ case 0: dither = 0x492A0000; break; case 1: dither = dither*1664525+1013904223; break; + case 2: dither = ordered_dither[y&1][(x>>2)&1]; break;
add spaces around operators, it is harder to read it otherwise.
} put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3); put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3);
also new patch which fixes style issues introduced in commit 43a36ad2 which was not submitted here for review would be nice.
On Fri, Dec 09, 2011 at 03:11:13PM +0000, Paul B Mahol wrote:
On 12/9/11, Michael Niedermayer <michaelni@gmx.at> wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index ea95901..3d35d8f 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -137,6 +137,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, AVFrame *p = data; int x, y; uint32_t dither= avctx->frame_number; + static const uint32_t ordered_dither[2][2]=
space before =
+ { + {0x10400000, 0x104F0000}, + {0xCB2A0000, 0xCB250000},
spaces after { and before }
+ };
p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; @@ -151,6 +156,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, switch(a->dither_type){ case 0: dither = 0x492A0000; break; case 1: dither = dither*1664525+1013904223; break; + case 2: dither = ordered_dither[y&1][(x>>2)&1]; break;
add spaces around operators, it is harder to read it otherwise.
added some within the available space, changed the rest suggestions to improve it are welcome
} put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3); put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3);
also new patch which fixes style issues introduced in commit 43a36ad2 which was not submitted here for review would be nice.
I think we should concentrate on technical and not so much style issues. Also style is generally the choice of the maintainer, i dont want to mess with it unless iam the maintainer or the maintainer asks me to do it. Its generally considered rude and childish to reformat a file maintained by someone else without asking. Now cljr is close to unmaintained sadly so i dont even know who to ask. But id say before a big reformat, someone should come forth and volunteer as maintainer of cljr, its a small file and would likely only take a few minutes to maintain per month. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB When the tyrant has disposed of foreign enemies by conquest or treaty, and there is nothing more to fear from them, then he is always stirring up some war or other, in order that the people may require a leader. -- Plato
On 12/9/11, Michael Niedermayer <michaelni@gmx.at> wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index 950b46a..2c3cf1e 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -25,12 +25,15 @@ */
#include "avcodec.h" +#include "libavutil/opt.h" #include "get_bits.h" #include "put_bits.h"
typedef struct CLJRContext { + AVClass *avclass;
align vertically
AVCodecContext *avctx; AVFrame picture; + int dither_type; } CLJRContext;
static av_cold int common_init(AVCodecContext *avctx) @@ -129,6 +132,7 @@ AVCodec ff_cljr_decoder = { static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { + CLJRContext *a = avctx->priv_data; PutBitContext pb; AVFrame *p = data; int x, y; @@ -144,6 +148,10 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, uint8_t *cb = &p->data[1][y * p->linesize[1]]; uint8_t *cr = &p->data[2][y * p->linesize[2]]; for (x = 0; x < avctx->width; x += 4) { + switch(a->dither_type){
switch (a->dither_type) {
+ case 0: dither = 0; break; + case 1: dither = dither*1664525+1013904223; break;
indentation is wrong adding spaces around * and + is imho better, and it keeps it in sync with rest of file.
+ } put_bits(&pb, 5, (luma[3] + (dither>>29) ) >> 3); put_bits(&pb, 5, (luma[2] + ((dither>>26)&7)) >> 3); put_bits(&pb, 5, (luma[1] + ((dither>>23)&7)) >> 3); @@ -151,7 +159,6 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, luma += 4; put_bits(&pb, 6, (*(cb++) + ((dither>>18)&3)) >> 2); put_bits(&pb, 6, (*(cr++) + ((dither>>16)&3)) >> 2); - dither = dither*1664525+1013904223; } }
@@ -160,6 +167,20 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, return put_bits_count(&pb) / 8; }
+#define OFFSET(x) offsetof(CLJRContext, x) +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +static const AVOption options[] = { + { "dither_type", "Dither type", OFFSET(dither_type), AV_OPT_TYPE_INT, { .dbl=1 }, 0, 2, VE}, + { NULL }, +}; + +static const AVClass class = { + .class_name = "cljr encoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_cljr_encoder = { .name = "cljr", .type = AVMEDIA_TYPE_VIDEO, @@ -170,5 +191,6 @@ AVCodec ff_cljr_encoder = { .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P, PIX_FMT_NONE }, .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), + .priv_class = &class, }; #endif
On Fri, Dec 09, 2011 at 03:10:01PM +0000, Paul B Mahol wrote:
On 12/9/11, Michael Niedermayer <michaelni@gmx.at> wrote:
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavcodec/cljr.c | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/libavcodec/cljr.c b/libavcodec/cljr.c index 950b46a..2c3cf1e 100644 --- a/libavcodec/cljr.c +++ b/libavcodec/cljr.c @@ -25,12 +25,15 @@ */
#include "avcodec.h" +#include "libavutil/opt.h" #include "get_bits.h" #include "put_bits.h"
typedef struct CLJRContext { + AVClass *avclass;
align vertically
AVCodecContext *avctx; AVFrame picture; + int dither_type; } CLJRContext;
static av_cold int common_init(AVCodecContext *avctx) @@ -129,6 +132,7 @@ AVCodec ff_cljr_decoder = { static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { + CLJRContext *a = avctx->priv_data; PutBitContext pb; AVFrame *p = data; int x, y; @@ -144,6 +148,10 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, uint8_t *cb = &p->data[1][y * p->linesize[1]]; uint8_t *cr = &p->data[2][y * p->linesize[2]]; for (x = 0; x < avctx->width; x += 4) { + switch(a->dither_type){
switch (a->dither_type) {
+ case 0: dither = 0; break; + case 1: dither = dither*1664525+1013904223; break;
indentation is wrong
adding spaces around * and + is imho better, and it keeps it in sync with rest of file.
changed and applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Complexity theory is the science of finding the exact solution to an approximation. Benchmarking OTOH is finding an approximation of the exact
participants (2)
-
Michael Niedermayer -
Paul B Mahol