summaryrefslogtreecommitdiffstats
path: root/Gui/bitmap
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-08-25 21:04:29 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-08-25 21:04:29 +0000
commit9f6529b3d3a1ec681a84735d57a9f2d8656809af (patch)
tree4943e4a95c68932a956ce7a693c58f5b2ed79b37 /Gui/bitmap
parent05f7ab93841eef7bf50c31b64bf723c100e0c123 (diff)
downloadmpv-9f6529b3d3a1ec681a84735d57a9f2d8656809af.tar.bz2
mpv-9f6529b3d3a1ec681a84735d57a9f2d8656809af.tar.xz
GUI version n-1
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1694 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'Gui/bitmap')
-rw-r--r--Gui/bitmap/Makefile89
-rw-r--r--Gui/bitmap/bitmap.c174
-rw-r--r--Gui/bitmap/bitmap.h21
-rw-r--r--Gui/bitmap/bitmap.mak13
-rw-r--r--Gui/bitmap/bmp/bmp.c113
-rw-r--r--Gui/bitmap/bmp/bmp.h28
-rw-r--r--Gui/bitmap/png/png.c133
-rw-r--r--Gui/bitmap/png/png.h9
-rw-r--r--Gui/bitmap/tga/tga.c189
-rw-r--r--Gui/bitmap/tga/tga.h21
10 files changed, 790 insertions, 0 deletions
diff --git a/Gui/bitmap/Makefile b/Gui/bitmap/Makefile
new file mode 100644
index 0000000000..da6bf55618
--- /dev/null
+++ b/Gui/bitmap/Makefile
@@ -0,0 +1,89 @@
+
+include ../config.mak
+
+SRCS = bitmap.c tga/tga.c jpeg/jpeg.c bmp/bmp.c
+OBJS = bitmap.o tga/tga.o jpeg/jpeg.o bmp/bmp.o
+
+.SUFFIXES: .c .o
+
+.c.o:
+ $(CC) -c $(CFLAGS) -o $@ $<
+
+### TARGETS ###
+
+all:
+ @( [ -e $(JPEGLIB) ] || \
+ make -C jpeg/jpeg-6b libjpeg.a )
+# ( make -C jpeg/jpeg-6b libjpeg.a && mv jpeg/jpeg-6b/libjpeg.a "$(JPEGLIB)" ) )
+ $(MAKE) $(OBJS)
+ ar rc libbitmap.a $(OBJS) jpeg/jpeg-6b/*.o
+ ranlib libbitmap.a
+ mv libbitmap.a ../libs
+
+#comp:
+# $(MAKE) $(OBJS)
+
+clean:
+ $(MAKE) -C jpeg/jpeg-6b clean
+ -rm -rf $(OBJS) *.o *~ *.bak $(JPEGLIB)
+
+dep: depend
+
+depend:
+ makedepend -- $(CFLAGS) -- $(SRCS) &>/dev/null
+
+# DO NOT DELETE
+
+bitmap.o: /usr/include/stdlib.h /usr/include/features.h
+bitmap.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
+bitmap.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stddef.h
+bitmap.o: /usr/include/sys/types.h /usr/include/bits/types.h
+bitmap.o: /usr/include/time.h /usr/include/endian.h
+bitmap.o: /usr/include/bits/endian.h /usr/include/sys/select.h
+bitmap.o: /usr/include/bits/select.h /usr/include/bits/sigset.h
+bitmap.o: /usr/include/sys/sysmacros.h /usr/include/alloca.h
+bitmap.o: /usr/include/stdio.h
+bitmap.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stdarg.h
+bitmap.o: /usr/include/libio.h /usr/include/_G_config.h
+bitmap.o: /usr/include/bits/stdio_lim.h bitmap.h tga/tga.h bitmap.h
+bitmap.o: jpeg/jpeg.h bmp/bmp.h
+tga/tga.o: /usr/include/string.h /usr/include/features.h
+tga/tga.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
+tga/tga.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stddef.h
+tga/tga.o: /usr/include/stdio.h
+tga/tga.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stdarg.h
+tga/tga.o: /usr/include/bits/types.h /usr/include/libio.h
+tga/tga.o: /usr/include/_G_config.h /usr/include/bits/stdio_lim.h
+tga/tga.o: /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h
+tga/tga.o: /usr/include/endian.h /usr/include/bits/endian.h
+tga/tga.o: /usr/include/sys/select.h /usr/include/bits/select.h
+tga/tga.o: /usr/include/bits/sigset.h /usr/include/sys/sysmacros.h
+tga/tga.o: /usr/include/alloca.h tga/tga.h bitmap.h
+jpeg/jpeg.o: /usr/include/setjmp.h /usr/include/features.h
+jpeg/jpeg.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
+jpeg/jpeg.o: /usr/include/bits/setjmp.h /usr/include/bits/sigset.h
+jpeg/jpeg.o: /usr/include/string.h
+jpeg/jpeg.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stddef.h
+jpeg/jpeg.o: /usr/include/stdlib.h /usr/include/sys/types.h
+jpeg/jpeg.o: /usr/include/bits/types.h /usr/include/time.h
+jpeg/jpeg.o: /usr/include/endian.h /usr/include/bits/endian.h
+jpeg/jpeg.o: /usr/include/sys/select.h /usr/include/bits/select.h
+jpeg/jpeg.o: /usr/include/sys/sysmacros.h /usr/include/alloca.h
+jpeg/jpeg.o: /usr/include/stdio.h
+jpeg/jpeg.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stdarg.h
+jpeg/jpeg.o: /usr/include/libio.h /usr/include/_G_config.h
+jpeg/jpeg.o: /usr/include/bits/stdio_lim.h jpeg/jpeg-6b/jpeglib.h
+jpeg/jpeg.o: jpeg/jpeg-6b/jconfig.h jpeg/jpeg-6b/jmorecfg.h bitmap.h
+jpeg/jpeg.o: jpeg/jpeg.h
+bmp/bmp.o: /usr/include/stdlib.h /usr/include/features.h
+bmp/bmp.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h
+bmp/bmp.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stddef.h
+bmp/bmp.o: /usr/include/sys/types.h /usr/include/bits/types.h
+bmp/bmp.o: /usr/include/time.h /usr/include/endian.h
+bmp/bmp.o: /usr/include/bits/endian.h /usr/include/sys/select.h
+bmp/bmp.o: /usr/include/bits/select.h /usr/include/bits/sigset.h
+bmp/bmp.o: /usr/include/sys/sysmacros.h /usr/include/alloca.h
+bmp/bmp.o: /usr/include/stdio.h
+bmp/bmp.o: /usr/lib/gcc-lib/i386-linux/2.95.2/include/stdarg.h
+bmp/bmp.o: /usr/include/libio.h /usr/include/_G_config.h
+bmp/bmp.o: /usr/include/bits/stdio_lim.h bmp/bmp.h bitmap.h
diff --git a/Gui/bitmap/bitmap.c b/Gui/bitmap/bitmap.c
new file mode 100644
index 0000000000..8343058ce2
--- /dev/null
+++ b/Gui/bitmap/bitmap.c
@@ -0,0 +1,174 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "bitmap.h"
+#include "../error.h"
+
+#define BMP 1
+#define TGA 2
+#define PNG 3
+#define TGAPACKED 4
+
+extern char * strcat( char * dest,const char * src );
+
+int conv24to32( txSample * bf )
+{
+ 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=malloc( bf->ImageSize ) ) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bitmap] Not enough memory for image.\n" );
+ #endif
+ return 1;
+ }
+ memset( bf->Image,0,bf->ImageSize );
+ for ( c=0,i=0;i < bf->Width * bf->Height * 3; )
+ {
+ bf->Image[c++]=tmpImage[i++];
+ bf->Image[c++]=tmpImage[i++];
+ bf->Image[c++]=tmpImage[i++]; c++;
+ }
+ free( tmpImage );
+ }
+ return 0;
+}
+
+void bgr2rgb( txSample * bf )
+{
+ unsigned char c;
+ int i;
+
+ for ( i=0;i < bf->ImageSize;i+=4 )
+ {
+ c=bf->Image[i];
+ bf->Image[i]=bf->Image[i+2];
+ bf->Image[i+2]=c;
+ }
+}
+
+void Normalize( txSample * bf )
+{
+ int i;
+
+ for ( i=0;i < bf->ImageSize;i+=4 ) bf->Image[i+3]=0;
+}
+
+unsigned char tmp[512];
+
+unsigned char * fExist( unsigned char * fname )
+{
+ FILE * fl;
+ unsigned char ext[][6] = { ".tga\0",".TGA\0",".png\0",".PNG\0",".bmp\0",".BMP\0" };
+ int i;
+
+ fl=fopen( fname,"rb" );
+ if ( fl != NULL )
+ {
+ fclose( fl );
+ return fname;
+ }
+ for ( i=0;i<10;i++ )
+ {
+ strcpy( tmp,fname );
+ strcat( tmp,ext[i] );
+ fl=fopen( tmp,"rb" );
+ if ( fl != NULL )
+ {
+ fclose( fl );
+ return tmp;
+ }
+ }
+ return NULL;
+}
+
+int aComp( unsigned char * b1,unsigned char * b2,int size )
+{
+ int i;
+ for( i=0;i<size;i++ ) if ( b1[i] != b2[i] ) return 0;
+ return 1;
+}
+
+int GetFileType( char * fname )
+{
+ FILE * fl;
+ unsigned char buffer[10];
+ unsigned char bmp[2] = { 0x42,0x4d };
+ unsigned char tga[7] = { 0x00,0x02,0x00,0x00,0x00,0x00,0x00 };
+ unsigned char ptga[7] = { 0x00,0x0a,0x00,0x00,0x00,0x00,0x00 };
+ unsigned char png[8] = { 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a };
+
+ if ( ( fl=fopen( fname,"rb" ) ) == NULL ) return -1;
+ fread( buffer,1,10,fl );
+ fclose( fl );
+
+ if ( aComp( buffer,bmp,2 ) ) return BMP; // --- bmp
+ if ( aComp( &buffer[1],tga,8 ) ) return TGA; // --- tga
+ if ( aComp( &buffer[1],ptga,7 ) ) return TGAPACKED; // --- tga
+ if ( aComp( buffer,png,8 ) ) return PNG; // --- png
+ return 0; // --- others
+}
+
+int bpRead( char * fname, txSample * bf )
+{
+ int bgr = 0;
+ int i;
+
+ fname=fExist( fname );
+ if ( fname == NULL ) return -2;
+ switch ( GetFileType( fname ) )
+ {
+ case BMP:
+ i=bmpRead( fname,bf );
+ switch ( i )
+ {
+ case 0: break;
+ case 3: return -1;
+ default: return -3;
+ }
+ break;
+ case TGA:
+ i=tgaRead( fname,bf );
+ switch ( i )
+ {
+ case 0: break;
+ case 3: return -1;
+ default: return -4;
+ }
+ break;
+ case PNG:
+ if ( pngRead( fname,bf ) ) return -5;
+ bgr=1;
+ break;
+ case TGAPACKED:
+ #ifdef DEBUG
+ dbprintf( 4,"[bitmap] sorry, packed TGA not supported.\n" );
+ #endif
+ return -6;
+ default:
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bitmap] Unknown file type ( %s ).\n",fname );
+ #endif
+ return -7;
+ }
+ }
+ if ( bf->BPP < 24 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bitmap] sorry, 16 or less bitmaps not supported.\n" );
+ #endif
+ return -1;
+ }
+ if ( conv24to32( bf ) ) return -8;
+ if ( bgr ) bgr2rgb( bf );
+ Normalize( bf );
+ return 0;
+}
diff --git a/Gui/bitmap/bitmap.h b/Gui/bitmap/bitmap.h
new file mode 100644
index 0000000000..c9d18b123c
--- /dev/null
+++ b/Gui/bitmap/bitmap.h
@@ -0,0 +1,21 @@
+
+#ifndef __MYSAMPLE
+#define __MYSAMPLE
+
+typedef struct _txSample
+{
+ unsigned int Width;
+ unsigned int Height;
+ unsigned int BPP;
+ unsigned long ImageSize;
+ char * Image;
+} txSample;
+
+#include "tga/tga.h"
+#include "bmp/bmp.h"
+#include "png/png.h"
+
+extern int bpRead( char * fname, txSample * bf );
+extern int conv24to32( txSample * bf );
+
+#endif \ No newline at end of file
diff --git a/Gui/bitmap/bitmap.mak b/Gui/bitmap/bitmap.mak
new file mode 100644
index 0000000000..b7785bdcc7
--- /dev/null
+++ b/Gui/bitmap/bitmap.mak
@@ -0,0 +1,13 @@
+
+BITMAPOBJS = \
+bitmap/bitmap.o \
+bitmap/tga/tga.o \
+bitmap/bmp/bmp.o \
+bitmap/png/png.o
+
+
+BITMAPSRCS = \
+bitmap/bitmap.c \
+bitmap/tga/tga.c \
+bitmap/bmp/bmp.c \
+bitmap/png/png.c
diff --git a/Gui/bitmap/bmp/bmp.c b/Gui/bitmap/bmp/bmp.c
new file mode 100644
index 0000000000..f4a80308bf
--- /dev/null
+++ b/Gui/bitmap/bmp/bmp.c
@@ -0,0 +1,113 @@
+
+#ifndef __MY_BMP
+#define __MY_BMP
+
+/*
+ 0.1 : BMP type.
+ 2.5 : File size.
+ 6.7 : Res.
+ 8.9 : Res.
+ 10.13 : Offset of bitmap.
+ 14.17 : Header size.
+ 18.21 : X size.
+ 22.25 : Y size.
+ 26.27 : Number of planes.
+ 28.29 : Number of bits per pixel.
+ 30.33 : Compression flag.
+ 34.37 : Image data size in bytes.
+ 38.41 : Res
+ 42.45 : Res
+ 46.49 : Res
+ 50.53 : Res
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "bmp.h"
+#include "../bitmap.h"
+#include "../../error.h"
+
+int bmpRead( unsigned char * fname,txSample * bF )
+{
+ unsigned char bmpHeader[54];
+ FILE * BMP;
+ unsigned long i;
+ unsigned char * line;
+ int linesize;
+
+
+ if ( (BMP=fopen( fname,"rt" )) == NULL )
+ {
+#ifdef DEBUG
+ dbprintf( 4,"[bmp] File not found ( %s ).\n",fname );
+#endif
+ return 1;
+ }
+ if ( (i=fread( bmpHeader,54,1,BMP )) != 1 )
+ {
+#ifdef DEBUG
+ dbprintf( 4,"[bmp] Header read error ( %s ).\n",fname );
+#endif
+ return 2;
+ }
+// memcpy( &bF->Size,&bmpHeader[2],4 );
+ memcpy( &bF->Width,&bmpHeader[18],4 );
+ memcpy( &bF->Height,&bmpHeader[22],4 );
+ memcpy( &bF->BPP,&bmpHeader[28],2 );
+// memcpy( &bF->ImageSize,&bmpHeader[34],4 );
+ bF->ImageSize=( bF->Width * bF->Height ) * ( bF->BPP / 8 );
+
+ if ( bF->BPP < 24 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bmp] Sorry, this loader not supported 16 bit or less ...\n" );
+ #endif
+ return 3;
+ }
+
+#ifdef DEBUG
+ dbprintf( 4,"[bmp] filename: %s\n",fname );
+ dbprintf( 4,"[bmp] size: %dx%d bits: %d\n",bF->Width,bF->Height,bF->BPP );
+ dbprintf( 4,"[bmp] imagesize: %lu\n",bF->ImageSize );
+#endif
+
+ if ( ( bF->Image=malloc( bF->ImageSize ) ) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bmp] Not enough memory for image buffer.\n" );
+ #endif
+ return 4;
+ }
+
+ if ( (i=fread( bF->Image,bF->ImageSize,1,BMP )) != 1 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bmp] Image read error.\n" );
+ #endif
+ return 5;
+ }
+
+ fclose( BMP );
+
+ linesize=bF->Width * ( bF->BPP / 8 );
+ if ( (line=malloc( linesize )) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[bmp] Not enough memory for flipping.\n" );
+ #endif
+ return 6;
+ }
+
+ for ( i=0;i < bF->Height / 2;i++ )
+ {
+ memcpy( line,&bF->Image[ i * linesize ],linesize );
+ memcpy( &bF->Image[ i * linesize ],&bF->Image[ ( bF->Height - i - 1 ) * linesize ],linesize );
+ memcpy( &bF->Image[ ( bF->Height - i - 1 ) * linesize ],line,linesize );
+ }
+ free( line );
+
+ return 0;
+}
+
+#endif \ No newline at end of file
diff --git a/Gui/bitmap/bmp/bmp.h b/Gui/bitmap/bmp/bmp.h
new file mode 100644
index 0000000000..9a58a955ee
--- /dev/null
+++ b/Gui/bitmap/bmp/bmp.h
@@ -0,0 +1,28 @@
+
+#ifndef __MY_BMP
+#define __MY_BMP
+
+#include "../bitmap.h"
+
+/*
+ 0.1 : BMP type.
+ 2.5 : File size.
+ 6.7 : Res.
+ 8.9 : Res.
+ 10.13 : Offset of bitmap.
+ 14.17 : Header size.
+ 18.21 : X size.
+ 22.25 : Y size.
+ 26.27 : Number of planes.
+ 28.29 : Number of bits per pixel.
+ 30.33 : Compression flag.
+ 34.37 : Image data size in bytes.
+ 38.41 : Res
+ 42.45 : Res
+ 46.49 : Res
+ 50.53 : Res
+*/
+
+extern int bmpRead( unsigned char * fname,txSample * bF );
+
+#endif \ No newline at end of file
diff --git a/Gui/bitmap/png/png.c b/Gui/bitmap/png/png.c
new file mode 100644
index 0000000000..524796bedf
--- /dev/null
+++ b/Gui/bitmap/png/png.c
@@ -0,0 +1,133 @@
+
+#include <stdlib.h>
+
+#include "./png.h"
+#include "../../error.h"
+#include <png.h>
+
+typedef struct
+{
+ unsigned int Width;
+ unsigned int Height;
+ unsigned int Depth;
+ unsigned int Alpha;
+
+ unsigned int Components;
+ unsigned char * Data;
+ unsigned char * Palette;
+} pngRawInfo;
+
+int pngLoadRawF( FILE *fp,pngRawInfo *pinfo )
+{
+ unsigned char header[8];
+ png_structp png;
+ png_infop info;
+ png_infop endinfo;
+ png_bytep data;
+ png_bytep * row_p;
+ png_uint_32 width,height;
+ int depth,color;
+ png_uint_32 i;
+
+ if ( !pinfo ) return 1;
+
+ fread( header,1,8,fp );
+ if ( !png_check_sig( header,8 ) ) return 1;
+
+ png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
+ info=png_create_info_struct( png );
+ endinfo=png_create_info_struct( png );
+
+ png_init_io( png,fp );
+ png_set_sig_bytes( png,8 );
+ png_read_info( png,info );
+ png_get_IHDR( png,info,&width,&height,&depth,&color,NULL,NULL,NULL );
+
+ pinfo->Width=width;
+ pinfo->Height=height;
+ pinfo->Depth=depth;
+
+ data=( png_bytep ) malloc( png_get_rowbytes( png,info )*height );
+ row_p=( png_bytep * ) malloc( sizeof( png_bytep )*height );
+ for ( i=0; i < height; i++ ) row_p[i]=&data[png_get_rowbytes( png,info )*i];
+
+ png_read_image( png,row_p );
+ free( row_p );
+
+ if ( color == PNG_COLOR_TYPE_PALETTE )
+ {
+ int cols;
+ png_get_PLTE( png,info,( png_colorp * ) &pinfo->Palette,&cols );
+ }
+ else pinfo->Palette=NULL;
+
+ if ( color&PNG_COLOR_MASK_ALPHA )
+ {
+ if ( color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY_ALPHA ) pinfo->Components=2;
+ else pinfo->Components=4;
+ pinfo->Alpha=8;
+ }
+ else
+ {
+ if ( color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY ) pinfo->Components=1;
+ else pinfo->Components=3;
+ pinfo->Alpha=0;
+ }
+ pinfo->Data=data;
+
+ png_read_end( png,endinfo );
+ png_destroy_read_struct( &png,&info,&endinfo );
+
+ return 0;
+}
+
+int pngLoadRaw( const char * filename,pngRawInfo * pinfo )
+{
+ int result;
+ FILE *fp=fopen( filename,"rb" );
+
+ if ( !fp ) return 1;
+ result=pngLoadRawF( fp,pinfo );
+ if ( fclose( fp ) != 0 )
+ {
+ if ( result )
+ {
+ free( pinfo->Data );
+ free( pinfo->Palette );
+ }
+ return 1;
+ }
+ return 0;
+}
+
+int pngRead( unsigned char * fname,txSample * bf )
+{
+ pngRawInfo raw;
+
+ if ( pngLoadRaw( fname,&raw ) )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[png] file read error ( %s ).\n",fname );
+ #endif
+ return 1;
+ }
+ bf->Width=raw.Width;
+ bf->Height=raw.Height;
+ bf->BPP=( raw.Depth * raw.Components ) + raw.Alpha;
+ bf->ImageSize=bf->Width * bf->Height * ( bf->BPP / 8 );
+ if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[png] Not enough memory for image buffer.\n" );
+ #endif
+ return 2;
+ }
+ memcpy( bf->Image,raw.Data,bf->ImageSize );
+ free( raw.Data );
+ #ifdef DEBUG
+ dbprintf( 4,"[png] filename: %s.\n",fname );
+ dbprintf( 4,"[png] size: %dx%d bits: %d\n",bf->Width,bf->Height,bf->BPP );
+ dbprintf( 4,"[png] imagesize: %lu\n",bf->ImageSize );
+ #endif
+ return 0;
+}
diff --git a/Gui/bitmap/png/png.h b/Gui/bitmap/png/png.h
new file mode 100644
index 0000000000..111d96915d
--- /dev/null
+++ b/Gui/bitmap/png/png.h
@@ -0,0 +1,9 @@
+
+#ifndef __MYPNG
+#define __MYPNG
+
+#include "../bitmap.h"
+
+extern int pngRead( unsigned char * fname, txSample * bf );
+
+#endif
diff --git a/Gui/bitmap/tga/tga.c b/Gui/bitmap/tga/tga.c
new file mode 100644
index 0000000000..bf8e3e849c
--- /dev/null
+++ b/Gui/bitmap/tga/tga.c
@@ -0,0 +1,189 @@
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tga.h"
+#include "../../error.h"
+
+int tgaRead( char * filename,txSample * bf )
+{
+ FILE * BMP;
+ unsigned long i;
+ char tmp[255];
+ unsigned char * line;
+ int linesize;
+ char * comment;
+ tgaHeadert tgaHeader;
+
+ strcpy( tmp,filename );
+ if ( !strstr( tmp,".tga" ) ) strcat( tmp,".tga" );
+ if ( (BMP=fopen( tmp,"rb" )) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] File not found ( %s ).\n",tmp );
+ #endif
+ return 1;
+ }
+ if ( (i=fread( &tgaHeader,sizeof( tgaHeader ),1,BMP )) != 1 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Header read error ( %s ).\n",tmp );
+ #endif
+ return 2;
+ }
+ if ( tgaHeader.depth < 24 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Sorry, this loader not supported 16 bit or less ...\n" );
+ #endif
+ return 3;
+ }
+ bf->Width=tgaHeader.sx;
+ bf->Height=tgaHeader.sy;
+ bf->BPP=tgaHeader.depth;
+ bf->ImageSize=bf->Width * bf->Height * ( bf->BPP / 8 );
+
+ if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Not enough memory for image buffer.\n" );
+ #endif
+ return 4;
+ }
+
+ comment=NULL;
+ if ( tgaHeader.tmp[0] != 0 )
+ {
+ if ( ( comment=malloc( tgaHeader.tmp[0] + 1 ) ) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Not enough memory for comment string.\n" );
+ #endif
+ return 5;
+ }
+ memset( comment,0,tgaHeader.tmp[0] + 1 );
+ if ( fread( comment,tgaHeader.tmp[0],1,BMP ) != 1 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Comment read error.\n" );
+ #endif
+ return 6;
+ }
+ }
+
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] filename ( read ): %s\n",tmp );
+ dbprintf( 4,"[tga] size: %dx%d bits: %d\n",bf->Width,bf->Height,bf->BPP );
+ dbprintf( 4,"[tga] imagesize: %lu\n",bf->ImageSize );
+ if ( comment ) dbprintf( 4,"[tga] comment: %s\n",comment );
+ #endif
+
+ if ( comment ) free( comment );
+
+ if ( fread( bf->Image,bf->ImageSize,1,BMP ) != 1 )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Image read error.\n" );
+ #endif
+ return 7;
+ }
+
+ fclose( BMP );
+
+ if ( tgaHeader.ctmp == 0 )
+ {
+ linesize=bf->Width * ( bf->BPP / 8 );
+ if ( (line=malloc( linesize )) == NULL )
+ {
+ #ifdef DEBUG
+ dbprintf( 4,"[tga] Not enough memory for flipping.\n" );
+ #endif
+ return 8;
+ }
+
+ for ( i=0;i < bf->Height / 2;i++ )
+ {
+ memcpy( line,&bf->Image[ i * linesize ],linesize );
+ memcpy( &bf->Image[ i * linesize ],&bf->Image[ ( bf->Height - i - 1 ) * linesize ],linesize );
+ memcpy( &bf->Image[ ( bf->Height - i - 1 ) * linesize ],line,linesize );
+ }
+ free( line );
+ }
+
+ return 0;
+}
+
+char comment[] = "fresh!mindworkz's TGA Filter. v0.1";
+
+void tgaWriteTexture( char * filename,txSample * bf )
+{
+ FILE * BMP;
+ int i;
+ unsigned char * line;
+ int linesize;
+ tgaHeadert tgaHeader;
+ char tmp[255];
+
+ strcpy( tmp,filename );
+ if ( !strstr( tmp,".tga" ) ) strcat( tmp,".tga" );
+ if ( ( BMP=fopen( tmp,"wb+" ) ) == NULL )
+ {
+ dbprintf( 0,"[tga] File not open ( %s ).\n",tmp );
+ exit( 0 );
+ }
+ memset( &tgaHeader,0,sizeof( tgaHeader ) );
+ tgaHeader.sx=bf->Width;
+ tgaHeader.sy=bf->Height;
+ tgaHeader.depth=bf->BPP;
+ tgaHeader.ctmp=0;
+ tgaHeader.tmp[0]=strlen( comment );
+ if ( bf->BPP != 8 ) tgaHeader.tmp[2]=2;
+ else tgaHeader.tmp[2]=3;
+
+ #ifdef DEBUG
+ dbprintf( 4,"\n[tga] filename ( write ): %s\n",tmp );
+ dbprintf( 4,"[tga] size: %dx%d\n",bf->Width,bf->Height );
+ dbprintf( 4,"[tga] bits: %d\n",bf->BPP );
+ dbprintf( 4,"[tga] imagesize: %lu\n",bf->ImageSize );
+ dbprintf( 4,"[tga] comment: %s\n",comment );
+ dbprintf( 4,"\n" );
+ #endif
+
+ if ( tgaHeader.ctmp == 0 )
+ {
+ linesize=bf->Width * ( bf->BPP / 8 );
+ if ( (line=malloc( linesize )) == NULL )
+ {
+ dbprintf( 0,"[tga] Not enough memory for flipping.\n" );
+ exit( 0 );
+ }
+
+ for ( i=0;i < bf->Height / 2;i++ )
+ {
+ memcpy( line,&bf->Image[ i * linesize ],linesize );
+ memcpy( &bf->Image[ i * linesize ],&bf->Image[ ( bf->Height - i - 1 ) * linesize ],linesize );
+ memcpy( &bf->Image[ ( bf->Height - i - 1 ) * linesize ],line,linesize );
+ }
+ free( line );
+ }
+
+ fwrite( &tgaHeader,sizeof( tgaHeader ),1,BMP );
+ fwrite( comment,strlen( comment ),1,BMP );
+ fwrite( bf->Image,bf->ImageSize,1,BMP );
+
+ fclose( BMP );
+}
+
+void tgaWriteBuffer( char * fname,unsigned char * Buffer,int sx,int sy,int BPP )
+{
+ txSample tmp;
+
+ memset( &tmp,0,sizeof( tmp ) );
+ tmp.Width=sx;
+ tmp.Height=sy;
+ tmp.BPP=BPP;
+ tmp.ImageSize=sx * sy * ( BPP / 8 );
+ tmp.Image=Buffer;
+ tgaWriteTexture( fname,&tmp );
+} \ No newline at end of file
diff --git a/Gui/bitmap/tga/tga.h b/Gui/bitmap/tga/tga.h
new file mode 100644
index 0000000000..fae0b915e2
--- /dev/null
+++ b/Gui/bitmap/tga/tga.h
@@ -0,0 +1,21 @@
+
+#ifndef _MYTGA
+#define _MYTGA
+
+#include "../bitmap.h"
+
+typedef struct
+{
+ char tmp[12];
+ unsigned short sx;
+ unsigned short sy;
+ unsigned char depth;
+ unsigned char ctmp;
+} tgaHeadert;
+
+extern int tgaRead( char * filename,txSample * bf );
+extern void tgaWriteBuffer( char * fname,unsigned char * Buffer,int sx,int sy,int BPP );
+extern void tgaWriteTexture( char * filename,txSample * bf );
+
+
+#endif \ No newline at end of file