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

blit_dynamic.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: blit_dynamic.cpp,v 1.1 2001/03/06 15:09:17 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 
00016 #include "Core/precomp.h"
00017 
00018 #include <Display/Display/Generic/blit_dynamic.h>
00019 #include <Hermes/H_Blit.h>
00020 #include "API/Core/System/cl_assert.h"
00021 #include "API/Display/Display/palette.h"
00022 #include "API/Display/Display/display.h"
00023 #include "API/Display/Display/surfaceprovider.h"
00024 
00025 CL_Blit_Dynamic::CL_Blit_Dynamic(
00026         CL_SurfaceProvider *provider,
00027         CL_Target *target)
00028 {
00029         this->provider = provider;
00030         
00031         src_fmt = Hermes_FormatNewEmpty();
00032         dest_fmt = Hermes_FormatNewEmpty();
00033 
00034         handle = Hermes_BlitterInstance(HERMES_CONVERT_NORMAL);
00035         cl_assert(handle!=0);
00036         
00037         use_palette = false;
00038 
00039         if (provider->is_indexed())
00040         {
00041                 src_fmt->bits = 8;
00042                 src_fmt->indexed = true;
00043                 src_fmt->r = 0;
00044                 src_fmt->g = 0;
00045                 src_fmt->b = 0;
00046                 src_fmt->a = 0; 
00047                   
00048                 palette = Hermes_PaletteInstance();
00049                 cl_assert(palette!=0);
00050                 use_palette = true;
00051 
00052                 int pal[256];
00053                 
00054                 if (provider->get_palette() != NULL)
00055                 {
00056                         for (int i=0; i< provider->get_palette()->num_colors; i++)
00057                         {
00058                                 pal[i] = (provider->get_palette()->palette[3*i] << 16) |
00059                                          (provider->get_palette()->palette[3*i+1] << 8) |
00060                                          (provider->get_palette()->palette[3*i+2]);
00061                         }
00062                 } 
00063                 else
00064                 {
00065                         for (int i=0; i< CL_Display::get_palette()->num_colors; i++)
00066                         {
00067                                 pal[i] = (CL_Display::get_palette()->palette[3*i] << 16) |
00068                                          (CL_Display::get_palette()->palette[3*i+1] << 8) |
00069                                          (CL_Display::get_palette()->palette[3*i+2]);
00070                         }
00071                 }
00072                 
00073                 Hermes_PaletteSet(palette, (int32*) pal);
00074         }
00075         else
00076         {
00077                 src_fmt->bits = provider->get_depth();
00078                 src_fmt->indexed = false;
00079                 src_fmt->r = provider->get_red_mask();
00080                 src_fmt->g = provider->get_green_mask();
00081                 src_fmt->b = provider->get_blue_mask();
00082                 src_fmt->a = provider->get_alpha_mask();
00083         }
00084 
00085         if (provider->uses_src_colorkey())
00086         {
00087                 src_fmt->has_colorkey = 1;
00088                 src_fmt->colorkey = provider->get_src_colorkey();
00089         }
00090 
00091         cl_assert(target!=NULL);
00092         dest_fmt->bits = target->get_depth();
00093         dest_fmt->indexed = false;
00094         dest_fmt->r = target->get_red_mask();
00095         dest_fmt->g = target->get_green_mask();
00096         dest_fmt->b = target->get_blue_mask();
00097         dest_fmt->a = target->get_alpha_mask();
00098 
00099         
00100 /*
00101         cout << "src bits      " << src_fmt->bits << endl;
00102         if (src_fmt->indexed) cout << "src indexed" << endl;
00103         cout << "src r         " << src_fmt->r << endl;
00104         cout << "src g         " << src_fmt->g << endl;
00105         cout << "src b         " << src_fmt->b << endl;
00106         cout << "src a         " << src_fmt->a << endl;
00107         if (src_fmt->has_colorkey==1)
00108                 cout << "src colorkey  " << src_fmt->colorkey << endl;
00109 
00110         cout << endl;
00111         
00112         
00113         cout << "dst bits      " << dest_fmt->bits << endl;
00114         if (dest_fmt->indexed) cout << "dst indexed" << endl;
00115         cout << "dst r         " << dest_fmt->r << endl;
00116         cout << "dst g         " << dest_fmt->g << endl;
00117         cout << "dst b         " << dest_fmt->b << endl;
00118         cout << "dst a         " << dest_fmt->a << endl;
00119         if (dest_fmt->has_colorkey==1)
00120                 cout << "dest colorkey " << dest_fmt->colorkey << endl;
00121 
00122 
00123         cout << endl;
00124         
00125         cout << "handle     " << handle << endl;
00126         cout << "src data   " << provider->get_data() << endl;
00127         cout << "src x     0" << endl;
00128         cout << "src y      " << provider->get_height() << endl;
00129         cout << "src width  " << provider->get_width() << endl;
00130         cout << "src height " << provider->get_height() << endl;
00131         cout << "src pitch  " << provider->get_pitch() << endl;
00132         cout << "dst data   " << target->get_data() << endl;
00133         cout << "dst pitch  " << target->get_pitch() << endl;
00134 */
00135 
00136 }
00137 
00138 CL_Blit_Dynamic::~CL_Blit_Dynamic()
00139 {
00140         Hermes_BlitterReturn(handle);
00141         if (use_palette)
00142                 Hermes_PaletteReturn(palette);
00143 
00144         Hermes_FormatFree(src_fmt);
00145         Hermes_FormatFree(dest_fmt);
00146 }
00147 
00148 void CL_Blit_Dynamic::blt_noclip(
00149         CL_Target *target,
00150         int x, 
00151         int y,
00152         int spr_no)
00153 {
00154         blt_scale_noclip(target, x, y, provider->get_width(), provider->get_height(), spr_no);
00155 }
00156 
00157 void CL_Blit_Dynamic::blt_scale_noclip(
00158         CL_Target *target,
00159         int x,
00160         int y,
00161         int dest_width,
00162         int dest_height,
00163         int spr_no)
00164 {
00165         target->lock();
00166         provider->lock();
00167         
00168         int res = Hermes_BlitterRequest(handle, src_fmt, dest_fmt);
00169         cl_assert(res != 0);
00170 
00171         if (use_palette)
00172         {
00173                 // as described in api.txt
00174                 int res = Hermes_BlitterPalette(handle, palette, palette);
00175                 cl_assert(res != 0);
00176         }
00177         
00178         res = Hermes_BlitterBlit(
00179                 handle,
00180                 provider->get_data(),
00181                 0,
00182                 provider->get_height()*spr_no,
00183                 provider->get_width(),
00184                 provider->get_height(),
00185                 provider->get_pitch(),
00186                 target->get_data(),
00187                 x,
00188                 y,
00189                 dest_width,
00190                 dest_height,
00191                 target->get_pitch());
00192 
00193         cl_assert(res != 0);
00194 
00195         provider->unlock();
00196         target->unlock();
00197 }
00198 
00199 void CL_Blit_Dynamic::blt_clip(
00200         CL_Target *target,
00201         int x,
00202         int y,
00203         int spr_no,
00204         const CL_ClipRect & clip)
00205 {
00206         CL_ClipRect dest_clip(
00207                 x,
00208                 y,
00209                 x + provider->get_width(),
00210                 y + provider->get_height());
00211 
00212         CL_ClipRect clipped = clip.clip(dest_clip);
00213         
00214         if (clipped.m_x1 >= clipped.m_x2 ||
00215             clipped.m_y1 >= clipped.m_y2) return;
00216 
00217         target->lock();
00218         provider->lock();
00219         
00220         int res = Hermes_BlitterRequest(handle, src_fmt, dest_fmt);
00221         cl_assert(res != 0);
00222         
00223         res = Hermes_BlitterBlit(
00224                 handle,
00225                 provider->get_data(),
00226                 clipped.m_x1 - x,
00227                 provider->get_height()*spr_no + clipped.m_y1 - y,
00228                 clipped.m_x2 - clipped.m_x1,
00229                 clipped.m_y2 - clipped.m_y1,
00230                 provider->get_pitch(),
00231                 target->get_data(),
00232                 clipped.m_x1,
00233                 clipped.m_y1,
00234                 clipped.m_x2 - clipped.m_x1,
00235                 clipped.m_y2 - clipped.m_y1,
00236                 target->get_pitch());
00237 
00238         cl_assert(res != 0);
00239         provider->unlock();
00240         target->unlock();
00241 }
00242 
00243 void CL_Blit_Dynamic::blt_scale_clip(
00244         CL_Target * target,
00245         int x,
00246         int y,
00247         int dest_width,
00248         int dest_height,
00249         int spr_no,
00250         const CL_ClipRect & clip)
00251 {
00252         static bool warning = true;
00253         if (warning)
00254         {
00255                 cl_info(info_display, "CL_Blit_Dynamic::blt_scale_clip() not implemented yet.");
00256                 warning = false;
00257         }
00258 }

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