Browse code

cljr: add encoder

Signed-off-by: Diego Biurrun <diego@biurrun.de>

Paul B Mahol authored on 2011/12/08 09:05:23
Showing 6 changed files
... ...
@@ -105,6 +105,7 @@ easier to use. The changes are:
105 105
 - CRI ADX audio format demuxer
106 106
 - Playstation Portable PMP format demuxer
107 107
 - PCM format support in OMA demuxer
108
+- CLJR encoder
108 109
 
109 110
 
110 111
 version 0.7:
... ...
@@ -382,7 +382,7 @@ following image formats are supported:
382 382
     @tab Codec used in Delphine Software International games.
383 383
 @item Discworld II BMV Video @tab     @tab  X
384 384
 @item Cinepak                @tab     @tab  X
385
-@item Cirrus Logic AccuPak   @tab     @tab  X
385
+@item Cirrus Logic AccuPak   @tab  X  @tab  X
386 386
     @tab fourcc: CLJR
387 387
 @item Creative YUV (CYUV)    @tab     @tab  X
388 388
 @item DFA                    @tab     @tab  X
... ...
@@ -87,7 +87,7 @@ void avcodec_register_all(void)
87 87
     REGISTER_DECODER (CAVS, cavs);
88 88
     REGISTER_DECODER (CDGRAPHICS, cdgraphics);
89 89
     REGISTER_DECODER (CINEPAK, cinepak);
90
-    REGISTER_DECODER (CLJR, cljr);
90
+    REGISTER_ENCDEC  (CLJR, cljr);
91 91
     REGISTER_DECODER (CSCD, cscd);
92 92
     REGISTER_DECODER (CYUV, cyuv);
93 93
     REGISTER_DECODER (DFA, dfa);
... ...
@@ -25,12 +25,8 @@
25 25
  */
26 26
 
27 27
 #include "avcodec.h"
28
-#include "dsputil.h"
29 28
 #include "get_bits.h"
30
-
31
-/* Disable the encoder. */
32
-#undef CONFIG_CLJR_ENCODER
33
-#define CONFIG_CLJR_ENCODER 0
29
+#include "put_bits.h"
34 30
 
35 31
 typedef struct CLJRContext{
36 32
     AVCodecContext *avctx;
... ...
@@ -92,24 +88,35 @@ static int decode_frame(AVCodecContext *avctx,
92 92
 
93 93
 #if CONFIG_CLJR_ENCODER
94 94
 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
95
-    CLJRContext * const a = avctx->priv_data;
96
-    AVFrame *pict = data;
97
-    AVFrame * const p= (AVFrame*)&a->picture;
98
-    int size;
95
+    PutBitContext pb;
96
+    AVFrame *p = data;
97
+    int x, y;
99 98
 
100
-    *p = *pict;
101 99
     p->pict_type= AV_PICTURE_TYPE_I;
102 100
     p->key_frame= 1;
103 101
 
104
-    emms_c();
102
+    init_put_bits(&pb, buf, buf_size / 8);
103
+
104
+    for (y = 0; y < avctx->height; y++) {
105
+        uint8_t *luma = &p->data[0][y * p->linesize[0]];
106
+        uint8_t *cb   = &p->data[1][y * p->linesize[1]];
107
+        uint8_t *cr   = &p->data[2][y * p->linesize[2]];
108
+        for (x = 0; x < avctx->width; x += 4) {
109
+            put_bits(&pb, 5, luma[3] >> 3);
110
+            put_bits(&pb, 5, luma[2] >> 3);
111
+            put_bits(&pb, 5, luma[1] >> 3);
112
+            put_bits(&pb, 5, luma[0] >> 3);
113
+            luma += 4;
114
+            put_bits(&pb, 6, *(cb++) >> 2);
115
+            put_bits(&pb, 6, *(cr++) >> 2);
116
+        }
117
+    }
105 118
 
106
-    avpriv_align_put_bits(&a->pb);
107
-    while(get_bit_count(&a->pb)&31)
108
-        put_bits(&a->pb, 8, 0);
119
+    flush_put_bits(&pb);
109 120
 
110
-    size= get_bit_count(&a->pb)/32;
121
+    emms_c();
111 122
 
112
-    return size*4;
123
+    return put_bits_count(&pb) / 8;
113 124
 }
114 125
 #endif
115 126
 
... ...
@@ -165,6 +172,8 @@ AVCodec ff_cljr_encoder = {
165 165
     .priv_data_size = sizeof(CLJRContext),
166 166
     .init           = encode_init,
167 167
     .encode         = encode_frame,
168
-    .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
168
+    .pix_fmts       = (const enum PixelFormat[]) { PIX_FMT_YUV411P,
169
+                                                   PIX_FMT_NONE },
170
+    .long_name      = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
169 171
 };
170 172
 #endif
... ...
@@ -21,7 +21,7 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 53
24
-#define LIBAVCODEC_VERSION_MINOR 26
24
+#define LIBAVCODEC_VERSION_MINOR 27
25 25
 #define LIBAVCODEC_VERSION_MICRO  0
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -264,7 +264,7 @@ const AVCodecTag ff_codec_bmp_tags[] = {
264 264
     { CODEC_ID_TARGA,        MKTAG('t', 'g', 'a', ' ') },
265 265
     { CODEC_ID_PNG,          MKTAG('M', 'P', 'N', 'G') },
266 266
     { CODEC_ID_PNG,          MKTAG('P', 'N', 'G', '1') },
267
-    { CODEC_ID_CLJR,         MKTAG('c', 'l', 'j', 'r') },
267
+    { CODEC_ID_CLJR,         MKTAG('C', 'L', 'J', 'R') },
268 268
     { CODEC_ID_DIRAC,        MKTAG('d', 'r', 'a', 'c') },
269 269
     { CODEC_ID_RPZA,         MKTAG('a', 'z', 'p', 'r') },
270 270
     { CODEC_ID_RPZA,         MKTAG('R', 'P', 'Z', 'A') },