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

f_out.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_out.cpp,v 1.1.1.1 2002/12/07 19:02:06 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: f_out.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 /**************************************************************************** 
00047  **************************************************************************** 
00048  * ROUTINES ***************************************************************** 
00049  **************************************************************************** 
00050  ****************************************************************************/ 
00051 
00052 slong
00053 file_manager_c::putch
00054 ( 
00055     slong                       c,                                      
00056     file_t *            file                            
00057 ) 
00058 { 
00059     AssertReturnValue2(file, file->buf, EOF);
00060 
00061     char        ch = c & 0xFF;
00062 
00063     write(&ch, 1, 1, file);
00064 
00065     return c;
00066 } // putch 
00067  
00068 slong
00069 file_manager_c::puts
00070 ( 
00071     const char *        string,                         
00072     file_t *            file                            
00073 ) 
00074 { 
00075     slong           c   =   strlen(string); 
00076     slong           count = 0;
00077 
00078     AssertReturnValue3(string, file, file->buf, EOF);
00079  
00080     do
00081     { 
00082         putch(*string, file);
00083         c--; string++; count ++;
00084     } 
00085     while(c);
00086  
00087     return count; 
00088 } // puts
00089 
00090 void
00091 file_manager_c::putpixel 
00092 ( 
00093     file_t *            file,                           
00094     char                        r,                                      
00095     char                        g,                                      
00096     char                        b,                                      
00097     char                        a,                                      
00098     char                        bpp                 
00099 ) 
00100 { 
00101     AssertReturn1(file);
00102 
00103     switch(bpp) 
00104     { 
00105         case 32:                    // 32 bits are easy 
00106             putch( r, file ); 
00107             putch( g, file ); 
00108             putch( b, file ); 
00109             putch( a, file ); 
00110             break; 
00111  
00112         case 24:                    // 24 too 
00113             putch( r, file ); 
00114             putch( g, file ); 
00115             putch( b, file ); 
00116             break; 
00117  
00118         case 16:                    // wtf... ? ;) 
00119             // msb in byte 1 indicates alpha state if its set 
00120             // make pixel non transparent 
00121  
00122             char c1,c2; 
00123  
00124             c1 = ((a?0x80:0)) | ((r>>1)&124) | ((g>>6)&3);
00125             c2 = ((g<<2)&224) | ((b>>3)&31);
00126  
00127             putch( c1, file ); 
00128             putch( c2, file ); 
00129             break; 
00130     } 
00131  
00132 }
00133  
00134 ulong
00135 file_manager_c::write
00136 ( 
00137     void *                      buf,                            
00138     ulong                       size,               
00139     ulong                       n,                  
00140     file_t *            file                            
00141 ) 
00142 { 
00143     ulong i; 
00144 
00145     AssertReturnValue2(buf, file, 0);
00146  
00147     if (file->pos+size*n>file->size) 
00148         resize(file, file->pos+size*n); 
00149  
00150     for (i=0; i<n; i++) 
00151     { 
00152         if (file->pos+size > file->size) 
00153             break;                  // eof :) 
00154  
00155         memcpy( file->buf+file->pos, (char*)buf+size*i, size ); 
00156         file->pos += size; 
00157     } 
00158  
00159     return i; 
00160 } // write 

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