00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Core/precomp.h"
00020 #include "API/Display/SurfaceProviders/sprite_subarray_provider.h"
00021 #include "API/Core/System/cl_assert.h"
00022
00023 CL_Surface *CL_SpriteSubarrayProvider::create(CL_SurfaceProvider *parent_provider,
00024 int start_x, int start_y,
00025 int width, int height,
00026 int array_width, int array_height)
00027 {
00028 return CL_Surface::create(new CL_SpriteSubarrayProvider(parent_provider, start_x, start_y, width, height, array_width, array_height), true);
00029 }
00030
00031 CL_SpriteSubarrayProvider::CL_SpriteSubarrayProvider(CL_SurfaceProvider *_parent_provider,
00032 int _start_x, int _start_y,
00033 int _width, int _height,
00034 int _array_width, int _array_height)
00035 {
00036 parent_provider = _parent_provider;
00037 start_x = _start_x;
00038 start_y = _start_y;
00039 width = _width;
00040 height = _height;
00041 array_width = _array_width;
00042 array_height = _array_height;
00043 locked = false;
00044 surface_data = NULL;
00045 }
00046
00047 CL_SpriteSubarrayProvider::~CL_SpriteSubarrayProvider()
00048 {
00049 delete parent_provider;
00050 }
00051
00052 unsigned int CL_SpriteSubarrayProvider::get_pitch() const
00053 {
00054 return width*((get_depth()+7)/8);
00055 }
00056
00057 int CL_SpriteSubarrayProvider::get_translate_x() const
00058 {
00059 return 0;
00060 }
00061
00062 int CL_SpriteSubarrayProvider::get_translate_y() const
00063 {
00064 return 0;
00065 }
00066
00067 unsigned int CL_SpriteSubarrayProvider::get_depth() const
00068 {
00069 return parent_provider->get_depth();
00070 }
00071
00072 unsigned int CL_SpriteSubarrayProvider::get_width() const
00073 {
00074 return width;
00075 }
00076
00077 unsigned int CL_SpriteSubarrayProvider::get_height() const
00078 {
00079 return height;
00080 }
00081
00082 unsigned int CL_SpriteSubarrayProvider::get_num_frames() const
00083 {
00084 return array_width*array_height;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093 bool CL_SpriteSubarrayProvider::is_indexed() const
00094 {
00095 return parent_provider->is_indexed();
00096 }
00097
00098 unsigned int CL_SpriteSubarrayProvider::get_red_mask() const
00099 {
00100 return parent_provider->get_red_mask();
00101 }
00102
00103 unsigned int CL_SpriteSubarrayProvider::get_green_mask() const
00104 {
00105 return parent_provider->get_green_mask();
00106 }
00107
00108 unsigned int CL_SpriteSubarrayProvider::get_blue_mask() const
00109 {
00110 return parent_provider->get_blue_mask();
00111 }
00112
00113 unsigned int CL_SpriteSubarrayProvider::get_alpha_mask() const
00114 {
00115 return parent_provider->get_alpha_mask();
00116 }
00117
00118 CL_Palette *CL_SpriteSubarrayProvider::get_palette() const
00119 {
00120 return parent_provider->get_palette();
00121 }
00122
00123 bool CL_SpriteSubarrayProvider::uses_src_colorkey() const
00124 {
00125 return parent_provider->uses_src_colorkey();
00126 }
00127
00128 unsigned int CL_SpriteSubarrayProvider::get_src_colorkey() const
00129 {
00130 return parent_provider->get_src_colorkey();
00131 }
00132
00133 void *CL_SpriteSubarrayProvider::get_data() const
00134 {
00135 cl_assert(surface_data != NULL);
00136 return surface_data;
00137 }
00138
00139 void CL_SpriteSubarrayProvider::perform_lock()
00140 {
00141 if (locked) return;
00142
00143 parent_provider->lock();
00144
00145 int bytes_per_pixel = ((parent_provider->get_depth()+7)/8);
00146
00147 surface_data = new unsigned char[
00148 bytes_per_pixel*width*height*array_width*array_height];
00149
00150 int bytes_pr_line = bytes_per_pixel*width;
00151
00152 unsigned char *parent_data = (unsigned char *) parent_provider->get_data();
00153 int pos = 0;
00154
00155 int offset_source =
00156 start_x*bytes_per_pixel +
00157 start_y*parent_provider->get_pitch();
00158
00159 for (int y=0;y<array_height;y++)
00160 {
00161 int cur_offset = offset_source + y*height*parent_provider->get_pitch();
00162
00163 for (int x=0;x<array_width;x++)
00164 {
00165 for (int yp=0;yp<height;yp++)
00166 {
00167 memcpy(
00168 &surface_data[pos],
00169 &parent_data[cur_offset+yp*parent_provider->get_pitch()], bytes_pr_line);
00170
00171 pos += bytes_pr_line;
00172 }
00173 cur_offset += width*bytes_per_pixel;
00174 }
00175 }
00176
00177 locked = true;
00178 }
00179
00180 void CL_SpriteSubarrayProvider::perform_unlock()
00181 {
00182 parent_provider->unlock();
00183 delete[] surface_data;
00184 locked = false;
00185 }
00186