Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

blit_transparent_rle.cpp

Go to the documentation of this file.
00001 /*
00002         ------------------------------------------------------------------------
00003         ClanLib, the platform independent game SDK.
00004 
00005         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00006         version 2. See COPYING for details.
00007 
00008         For a total list of contributers see CREDITS.
00009 
00010         ------------------------------------------------------------------------
00011 */
00012 
00013 #include "Core/precomp.h"
00014 #include <Display/Display/Generic/blit_transparent_rle.h>
00015 #include "API/Display/Display/surfaceprovider.h"
00016 
00017 CL_Blit_Transparent_RLE::CL_Blit_Transparent_RLE(
00018         CL_SurfaceProvider *provider,
00019         int bytes_per_pixel)
00020 {
00021         width = provider->get_width();
00022         height = provider->get_height();
00023         no_sprs = provider->get_num_frames();
00024 
00025         this->bytes_per_pixel = bytes_per_pixel;
00026         
00027         rle_lines = new unsigned char*[height*no_sprs]; 
00028 }
00029 
00030 
00031 CL_Blit_Transparent_RLE::~CL_Blit_Transparent_RLE()
00032 {
00033         for (int y=0; y<height; y++) delete[] rle_lines[y];
00034         delete[] rle_lines;
00035 }
00036 
00037 
00038 int CL_Blit_Transparent_RLE::calc_rle_size(unsigned char *alpha_line)
00039 {
00040         int size = 0;
00041         
00042         int last_state = cmd_end;
00043         for (int x=0; x<width; x++)
00044         {
00045                 switch(alpha_line[x])
00046                 {
00047                 case 0 :   // transparent pixel         
00048                 
00049                         if (last_state != cmd_skip) size += 3; // cmd_skip+word
00050                         last_state = cmd_skip;
00051                         break;
00052                 
00053                 case 255:  // opaque pixel
00054                 
00055                         if (last_state != cmd_copy) size += 3; // cmd_skip+word
00056                         last_state = cmd_copy;
00057                         size += bytes_per_pixel;
00058                         break;
00059                 
00060                 default:   // alpha value
00061                         
00062                         if (last_state != cmd_alpha) size += 3; // cmd_alpha+word
00063                         last_state = cmd_alpha;
00064                         size += bytes_per_pixel + 1; // pixel data + alpha value
00065                         break;
00066                 }       
00067         }
00068         
00069         size++; // cmd_end
00070         
00071         return size;
00072 }
00073 
00074 
00075 void CL_Blit_Transparent_RLE::blt_noclip(
00076         CL_Target *target,
00077         int x,
00078         int y,
00079         int spr_no)
00080 {
00081         target->lock();
00082         
00083         unsigned int dest_bytes_per_pixel = (target->get_depth()+7)/8;
00084         unsigned int dest_pitch = target->get_pitch();
00085         unsigned char *dest = (unsigned char *) target->get_data();
00086 
00087         dest += x*dest_bytes_per_pixel + y*dest_pitch;
00088 
00089         int begin = height*spr_no;
00090         for (int yy=0; yy<height; yy++)
00091         {
00092                 blt_line(rle_lines[yy+begin], dest);
00093                 dest += dest_pitch;
00094         }
00095 
00096         target->unlock();
00097 }

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001