[MPlayer-cvslog] r33000 - in trunk/gui: bitmap.c bitmap.h

ib subversion at mplayerhq.hu
Wed Mar 2 18:17:19 CET 2011


Author: ib
Date: Wed Mar  2 18:17:19 2011
New Revision: 33000

Log:
Cosmetic: Format to MPlayer coding style.

Additionally: remove needless identifiers, group and sort includes,
group statements by adding or removing new lines and rearrange statements
and variables to ease reading.

Modified:
   trunk/gui/bitmap.c
   trunk/gui/bitmap.h

Modified: trunk/gui/bitmap.c
==============================================================================
--- trunk/gui/bitmap.c	Wed Mar  2 17:05:37 2011	(r32999)
+++ trunk/gui/bitmap.c	Wed Mar  2 18:17:19 2011	(r33000)
@@ -20,178 +20,234 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "mp_msg.h"
-#include "help_mp.h"
 #include "bitmap.h"
+
+#include "help_mp.h"
 #include "libavcodec/avcodec.h"
 #include "libavutil/intreadwrite.h"
 #include "libvo/fastmemcpy.h"
+#include "mp_msg.h"
 
-static int pngRead( unsigned char * fname,txSample * bf )
+static int pngRead(unsigned char *fname, txSample *bf)
 {
- int             decode_ok;
- void           *data;
- int             len;
- AVCodecContext *avctx;
- AVFrame        *frame;
- AVPacket       pkt;
+    FILE *fp;
+    int decode_ok;
+    void *data;
+    int len;
+    AVCodecContext *avctx;
+    AVFrame *frame;
+    AVPacket pkt;
 
- FILE *fp=fopen( fname,"rb" );
- if ( !fp )
-  {
-   mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] file read error ( %s )\n",fname );
-   return 1;
-  }
+    fp = fopen(fname, "rb");
 
- fseek(fp, 0, SEEK_END);
- len = ftell(fp);
- if (len > 50 * 1024 * 1024)
-  {
-   fclose(fp);
-   return 2;
-  }
- data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
- fseek(fp, 0, SEEK_SET);
- fread(data, len, 1, fp);
- fclose(fp);
- avctx = avcodec_alloc_context();
- frame = avcodec_alloc_frame();
- avcodec_register_all();
- avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG));
- av_init_packet(&pkt);
- pkt.data = data;
- pkt.size = len;
- // HACK: make PNGs decode normally instead of as CorePNG delta frames
- pkt.flags = AV_PKT_FLAG_KEY;
- avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
- memset(bf, 0, sizeof(*bf));
- switch (avctx->pix_fmt) {
-   case PIX_FMT_GRAY8:    bf->BPP =  8; break;
-   case PIX_FMT_GRAY16BE: bf->BPP = 16; break;
-   case PIX_FMT_RGB24:    bf->BPP = 24; break;
-   case PIX_FMT_BGRA:
-   case PIX_FMT_ARGB:     bf->BPP = 32; break;
-   default:               bf->BPP =  0; break;
- }
- if (decode_ok && bf->BPP) {
-   int bpl;
-   bf->Width = avctx->width; bf->Height = avctx->height;
-   bpl = bf->Width * (bf->BPP / 8);
-   bf->ImageSize = bpl * bf->Height;
-   bf->Image = malloc(bf->ImageSize);
-   memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]);
- }
- avcodec_close(avctx);
- av_freep(&frame);
- av_freep(&avctx);
- av_freep(&data);
+    if (!fp) {
+        mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] file read error ( %s )\n", fname);
+        return 1;
+    }
 
- mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] filename: %s.\n",fname );
- mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png]  size: %dx%d bits: %d\n",bf->Width,bf->Height,bf->BPP );
- mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png]  imagesize: %lu\n",bf->ImageSize );
- return !(decode_ok && bf->BPP);
+    fseek(fp, 0, SEEK_END);
+    len = ftell(fp);
+
+    if (len > 50 * 1024 * 1024) {
+        fclose(fp);
+        return 2;
+    }
+
+    data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
+
+    fseek(fp, 0, SEEK_SET);
+    fread(data, len, 1, fp);
+    fclose(fp);
+
+    avctx = avcodec_alloc_context();
+    frame = avcodec_alloc_frame();
+    avcodec_register_all();
+    avcodec_open(avctx, avcodec_find_decoder(CODEC_ID_PNG));
+    av_init_packet(&pkt);
+    pkt.data = data;
+    pkt.size = len;
+    // HACK: make PNGs decode normally instead of as CorePNG delta frames
+    pkt.flags = AV_PKT_FLAG_KEY;
+    avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
+    memset(bf, 0, sizeof(*bf));
+
+    switch (avctx->pix_fmt) {
+    case PIX_FMT_GRAY8:
+        bf->BPP = 8;
+        break;
+
+    case PIX_FMT_GRAY16BE:
+        bf->BPP = 16;
+        break;
+
+    case PIX_FMT_RGB24:
+        bf->BPP = 24;
+        break;
+
+    case PIX_FMT_BGRA:
+    case PIX_FMT_ARGB:
+        bf->BPP = 32;
+        break;
+
+    default:
+        bf->BPP = 0;
+        break;
+    }
+
+    if (decode_ok && bf->BPP) {
+        int bpl;
+
+        bf->Width  = avctx->width;
+        bf->Height = avctx->height;
+        bpl = bf->Width * (bf->BPP / 8);
+        bf->ImageSize = bpl * bf->Height;
+        bf->Image     = malloc(bf->ImageSize);
+        memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]);
+    }
+
+    avcodec_close(avctx);
+    av_freep(&frame);
+    av_freep(&avctx);
+    av_freep(&data);
+
+    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png] filename: %s.\n", fname);
+    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png]  size: %dx%d bits: %d\n", bf->Width, bf->Height, bf->BPP);
+    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[png]  imagesize: %lu\n", bf->ImageSize);
+
+    return !(decode_ok && bf->BPP);
 }
 
-static int conv24to32( txSample * bf )
+static int conv24to32(txSample *bf)
 {
- unsigned char * tmpImage;
- int             i,c;
+    unsigned char *tmpImage;
+    int i, c;
 
- if ( bf->BPP == 24 )
-  {
-   tmpImage=bf->Image;
-   bf->ImageSize=bf->Width * bf->Height * 4;
-   bf->BPP=32;
-   if ( ( bf->Image=calloc( 1, bf->ImageSize ) ) == NULL )
-    {
-     free( tmpImage );
-     mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] not enough memory for image\n" );
-     return 1;
-    }
-   for ( c=0,i=0; c < bf->ImageSize; c += 4, i += 3)
-    {
-     *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]);
+    if (bf->BPP == 24) {
+        tmpImage      = bf->Image;
+        bf->BPP       = 32;
+        bf->ImageSize = bf->Width * bf->Height * 4;
+        bf->Image     = calloc(1, bf->ImageSize);
+
+        if (!bf->Image) {
+            free(tmpImage);
+            mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory for image\n");
+            return 1;
+        }
+
+        for (c = 0, i = 0; c < bf->ImageSize; c += 4, i += 3)
+            *(uint32_t *)&bf->Image[c] = AV_RB24(&tmpImage[i]);
+
+        free(tmpImage);
     }
-   free( tmpImage );
-  }
- return 0;
+
+    return 0;
 }
 
-static void Normalize( txSample * bf )
+static void Normalize(txSample *bf)
 {
- int           i;
+    int i;
+
+    for (i = 0; i < (int)bf->ImageSize; i += 4)
 #if !HAVE_BIGENDIAN
- for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i+3]=0;
+        bf->Image[i + 3] = 0;
 #else
- for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i]=0;
+        bf->Image[i] = 0;
 #endif
 }
 
 static unsigned char tmp[512];
 
-static unsigned char * fExist( unsigned char * fname )
+static unsigned char *fExist(unsigned char *fname)
 {
- FILE          * fl;
- unsigned char   ext[][6] = { ".png\0",".PNG\0" };
- int             i;
+    FILE *fl;
+    unsigned char ext[][6] = { ".png\0", ".PNG\0" };
+    int i;
 
- fl=fopen( fname,"rb" );
- if ( fl != NULL )
-  {
-   fclose( fl );
-   return fname;
-  }
- for ( i=0;i<2;i++ )
-  {
-   snprintf( tmp,511,"%s%s",fname,ext[i] );
-   fl=fopen( tmp,"rb" );
-   if ( fl != NULL )
-    {
-     fclose( fl );
-     return tmp;
+    fl = fopen(fname, "rb");
+
+    if (fl != NULL) {
+        fclose(fl);
+        return fname;
     }
-  }
- return NULL;
+
+    for (i = 0; i < 2; i++) {
+        snprintf(tmp, 511, "%s%s", fname, ext[i]);
+        fl = fopen(tmp, "rb");
+
+        if (fl != NULL) {
+            fclose(fl);
+            return tmp;
+        }
+    }
+
+    return NULL;
 }
 
-int bpRead( char * fname, txSample * bf )
+int bpRead(char *fname, txSample *bf)
 {
- fname=fExist( fname );
- if ( fname == NULL ) return -2;
- if ( pngRead( fname,bf ) )
-  {
-   mp_dbg( MSGT_GPLAYER,MSGL_FATAL,"[bitmap] unknown file type ( %s )\n",fname );
-   return -5;
-  }
- if ( bf->BPP < 24 )
-  {
-   mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n" );
-   return -1;
-  }
- if ( conv24to32( bf ) ) return -8;
- Normalize( bf );
- return 0;
+    fname = fExist(fname);
+
+    if (fname == NULL)
+        return -2;
+
+    if (pngRead(fname, bf)) {
+        mp_dbg(MSGT_GPLAYER, MSGL_FATAL, "[bitmap] unknown file type ( %s )\n", fname);
+        return -5;
+    }
+
+    if (bf->BPP < 24) {
+        mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n");
+        return -1;
+    }
+
+    if (conv24to32(bf))
+        return -8;
+
+    Normalize(bf);
+    return 0;
 }
 
-void Convert32to1( txSample * in,txSample * out,int adaptivlimit )
+void Convert32to1(txSample *in, txSample *out, int adaptivlimit)
 {
- out->Width=in->Width;
- out->Height=in->Height;
- out->BPP=1;
- out->ImageSize=(out->Width * out->Height + 7) / 8;
- mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c32to1] imagesize: %d\n",out->ImageSize );
- out->Image=calloc( 1,out->ImageSize );
- if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotEnoughMemoryC32To1 );
- {
-  int i,b,c=0; unsigned int * buf = NULL; unsigned char tmp = 0; int nothaveshape = 1;
-  buf=(unsigned int *)in->Image;
-  for ( b=0,i=0;i < (int)(out->Width * out->Height);i++ )
-   {
-    if ( (int)buf[i] != adaptivlimit ) tmp=( tmp >> 1 )|128;
-     else { tmp=tmp >> 1; buf[i]=nothaveshape=0; }
-    if ( b++ == 7 ) { out->Image[c++]=tmp; tmp=b=0; }
-   }
-  if ( b ) out->Image[c]=tmp;
-  if ( nothaveshape ) { free( out->Image ); out->Image=NULL; }
- }
+    out->Width     = in->Width;
+    out->Height    = in->Height;
+    out->BPP       = 1;
+    out->ImageSize = (out->Width * out->Height + 7) / 8;
+
+    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[c32to1] imagesize: %d\n", out->ImageSize);
+
+    out->Image = calloc(1, out->ImageSize);
+
+    if (out->Image == NULL)
+        mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_NotEnoughMemoryC32To1);
+    {
+        int i, b, c = 0;
+        unsigned int *buf = NULL;
+        unsigned char tmp = 0;
+        int nothaveshape  = 1;
+
+        buf = (unsigned int *)in->Image;
+
+        for (b = 0, i = 0; i < (int)(out->Width * out->Height); i++) {
+            if ((int)buf[i] != adaptivlimit)
+                tmp = (tmp >> 1) | 128;
+            else {
+                tmp    = tmp >> 1;
+                buf[i] = nothaveshape = 0;
+            }
+
+            if (b++ == 7) {
+                out->Image[c++] = tmp;
+                tmp = b = 0;
+            }
+        }
+
+        if (b)
+            out->Image[c] = tmp;
+
+        if (nothaveshape) {
+            free(out->Image);
+            out->Image = NULL;
+        }
+    }
 }

Modified: trunk/gui/bitmap.h
==============================================================================
--- trunk/gui/bitmap.h	Wed Mar  2 17:05:37 2011	(r32999)
+++ trunk/gui/bitmap.h	Wed Mar  2 18:17:19 2011	(r33000)
@@ -19,16 +19,15 @@
 #ifndef MPLAYER_GUI_BITMAP_H
 #define MPLAYER_GUI_BITMAP_H
 
-typedef struct txSample
-{
- unsigned long Width;
- unsigned long Height;
- unsigned int  BPP;
- unsigned long ImageSize;
- char *        Image;
+typedef struct {
+    unsigned long Width;
+    unsigned long Height;
+    unsigned int BPP;
+    unsigned long ImageSize;
+    char *Image;
 } txSample;
 
-int bpRead( char * fname, txSample * bf );
-void Convert32to1( txSample * in,txSample * out,int adaptivlimit );
+int bpRead(char *, txSample *);
+void Convert32to1(txSample *, txSample *, int);
 
 #endif /* MPLAYER_GUI_BITMAP_H */


More information about the MPlayer-cvslog mailing list