]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/svq1.c
Change some leftover __attribute__((unused)) and __attribute__((used)) to
[ffmpeg] / libavcodec / svq1.c
index 2308c69456bf2bd53586fcfde1fcc831d7080616..42fc6be196946783c96ca602998b66f7be33eec0 100644 (file)
@@ -3,19 +3,21 @@
  * Copyright (C) 2002 the xine project
  * Copyright (C) 2002 the ffmpeg project
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
  * (SVQ1 Decoder)
  * Ported to mplayer by Arpi <arpi@thot.banki.hu>
@@ -39,7 +41,6 @@
 #include <unistd.h>
 #include <limits.h>
 
-#include "common.h"
 #include "avcodec.h"
 #include "dsputil.h"
 #include "mpegvideo.h"
@@ -63,7 +64,7 @@ static VLC svq1_inter_mean;
 #define SVQ1_BLOCK_INTRA        3
 
 typedef struct SVQ1Context {
-    MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independant of MpegEncContext, so this will be removed then (FIXME/XXX)
+    MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX)
     AVCodecContext *avctx;
     DSPContext dsp;
     AVFrame picture;
@@ -617,6 +618,7 @@ static uint16_t svq1_component_checksum (uint16_t *pixels, int pitch,
 }
 #endif
 
+#ifdef CONFIG_DECODERS
 static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) {
   uint8_t seed;
   int     i;
@@ -655,9 +657,9 @@ static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) {
     }
 
     if ((s->f_code ^ 0x10) >= 0x50) {
-      char msg[256];
+      uint8_t msg[256];
 
-      svq1_parse_string (bitbuf, (char *) msg);
+      svq1_parse_string (bitbuf, msg);
 
       av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg);
     }
@@ -879,7 +881,9 @@ static int svq1_decode_end(AVCodecContext *avctx)
     MPV_common_end(s);
     return 0;
 }
+#endif /* CONFIG_DECODERS */
 
+#ifdef CONFIG_ENCODERS
 static void svq1_write_header(SVQ1Context *s, int frame_type)
 {
     int i;
@@ -900,7 +904,7 @@ static void svq1_write_header(SVQ1Context *s, int frame_type)
         /* no embedded string either */
 
         /* output 5 unknown bits (2 + 2 + 1) */
-        put_bits(&s->pb, 5, 0);
+        put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */
 
         for (i = 0; i < 7; i++)
         {
@@ -987,22 +991,16 @@ static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *dec
 
             for(i=0; i<16; i++){
                 int sum= codebook_sum[stage*16 + i];
-                int sqr=0;
-                int diff, mean, score;
+                int sqr, diff, score;
 
                 vector = codebook + stage*size*16 + i*size;
-
-                for(j=0; j<size; j++){
-                    int v= vector[j];
-                    sqr += (v - block[stage][j])*(v - block[stage][j]);
-                }
+                sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
                 diff= block_sum[stage] - sum;
-                mean= (diff + (size>>1)) >> (level+3);
-                assert(mean >-300 && mean<300);
-                if(intra) mean= clip(mean, 0, 255);
-                else      mean= clip(mean, -256, 255);
                 score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow
                 if(score < best_vector_score){
+                    int mean= (diff + (size>>1)) >> (level+3);
+                    assert(mean >-300 && mean<300);
+                    mean= av_clip(mean, intra?0:-256, 255);
                     best_vector_score= score;
                     best_vector[stage]= i;
                     best_vector_sum= sum;
@@ -1081,7 +1079,6 @@ static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *dec
     return best_score;
 }
 
-#ifdef CONFIG_ENCODERS
 
 static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane, unsigned char *ref_plane, unsigned char *decoded_plane,
     int width, int height, int src_stride, int stride)
@@ -1351,7 +1348,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf,
     init_put_bits(&s->pb, buf, buf_size);
 
     *p = *pict;
-    p->pict_type = avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE;
+    p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE;
     p->key_frame = p->pict_type == I_TYPE;
 
     svq1_write_header(s, p->pict_type);
@@ -1395,6 +1392,7 @@ static int svq1_encode_end(AVCodecContext *avctx)
 
 #endif //CONFIG_ENCODERS
 
+#ifdef CONFIG_DECODERS
 AVCodec svq1_decoder = {
     "svq1",
     CODEC_TYPE_VIDEO,
@@ -1408,6 +1406,7 @@ AVCodec svq1_decoder = {
     .flush= ff_mpeg_flush,
     .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1},
 };
+#endif
 
 #ifdef CONFIG_ENCODERS