Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

f_in.cpp

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/07 19:02:06 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: f_in.cpp,v 1.1.1.1 2002/12/07 19:02:06 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: f_in.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:06  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00040 #include            "omicron/internal.h"
00041 #include            "omicron/file.h"
00042 #include            "omicron/list.h"
00043 #include            "omicron/array.h"
00044 #include            <string.h>
00045 
00046 #undef DBGSTAMP
00047 #define DBGSTAMP
00048  
00049 /**************************************************************************** 
00050  **************************************************************************** 
00051  * ROUTINES ***************************************************************** 
00052  **************************************************************************** 
00053  ****************************************************************************/ 
00054 
00055 ulong
00056 file_manager_c::getch
00057 ( 
00058     file_t *            file                            
00059 ) 
00060 { 
00061     ulong    c; 
00062  
00063     c = *(file->buf+file->pos)&0xFF; 
00064     file->pos++; 
00065     return c; 
00066 } // getch 
00067  
00068  
00069 const char *
00070 file_manager_c::gets
00071 ( 
00072     char *                      dst,                            
00073     ulong           count,              
00074     file_t *        file                                
00075 ) 
00076 { 
00077     ulong       c   =   count-1; 
00078     ulong       ch; 
00079     char        *r  =   dst; 
00080  
00081     do 
00082     { 
00083         ch = getch(file); 
00084         *dst = (char)ch; 
00085         c--; dst++; 
00086     } 
00087     while(c && ch && ch!='\n'); 
00088  
00089     *dst = 0; 
00090     return r; 
00091 } // getch 
00092  
00093 void
00094 file_manager_c::getpixel 
00095 ( 
00096     file_t *    file,                   
00097     char *              r,                                              
00098     char *      g,                                              
00099     char *      b,                                              
00100     char *      a,                                              
00101     char        bpp                     
00102 ) 
00103 { 
00104     switch(bpp) 
00105     { 
00106         case 32:                    // 32 bits are easy 
00107             *b = (char)getch( file ); 
00108             *g = (char)getch( file ); 
00109             *r = (char)getch( file ); 
00110             *a = (char)getch( file ); 
00111             break; 
00112  
00113         case 24:                    // 24 too 
00114             *a = (char)255; 
00115             *b = (char)getch( file ); 
00116             *g = (char)getch( file ); 
00117             *r = (char)getch( file ); 
00118             break; 
00119  
00120         case 16:                    // what the... ? ;) 
00121             // msb in byte 1 indicates alpha state if its set 
00122             // make pixel non transparent 
00123  
00124             char c1,c2; 
00125  
00126             c1 = (char)getch( file ); 
00127             c2 = (char)getch( file ); 
00128  
00129             *a = c1&0x80?255:0; 
00130  
00131             *r = (c1&124)<<1; 
00132             *g = (c1&3<<6) | (c2&224)>>2; 
00133             *b = (c2&31)<<3; 
00134             break; 
00135     } 
00136  
00137 } // getpixel 
00138  
00139 ulong
00140 file_manager_c::read
00141 ( 
00142     void *                      out,                            
00143     ulong                       size,               
00144     ulong                       n,                  
00145     file_t *            file                            
00146 )
00147 {
00148     ulong i; 
00149  
00150     if (!file) return 0; 
00151  
00152     for (i=0; i<n; i++) 
00153     { 
00154         if (file->pos+size > file->size) 
00155             break;                  // eof :) 
00156  
00157         memcpy( (char*)out+size*i, file->buf+file->pos, size ); 
00158         file->pos += size; 
00159     } 
00160  
00161     return i; 
00162 } // read 

Generated on Wed Dec 18 15:48:46 2002 for omicron engine by doxygen1.2.18