Changeset 533 for abuse/trunk/src/imlib/timage.cpp
- Timestamp:
- Apr 22, 2011, 7:32:13 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/timage.cpp
r532 r533 11 11 #include "config.h" 12 12 13 #include <cstdio> 14 #include <cstring> 15 13 16 #include "common.h" 14 17 15 18 #include "timage.h" 16 19 17 trans_image::trans_image(image *im, char const *name)20 TImage::TImage(image *im, char const *name) 18 21 { 19 22 m_size = im->Size(); … … 50 53 if (!parser) 51 54 { 52 printf("size = %d %d (%d bytes)\n", im->Size().x,im->Size().y,bytes);53 CONDITION(parser, "malloc error for trans_image::m_data");55 printf("size = %d %d (%d bytes)\n", m_size.x, m_size.y, bytes); 56 CONDITION(parser, "malloc error for TImage::m_data"); 54 57 } 55 58 … … 88 91 } 89 92 90 trans_image::~trans_image()93 TImage::~TImage() 91 94 { 92 95 free(m_data); 93 96 } 94 97 95 image * trans_image::ToImage()98 image *TImage::ToImage() 96 99 { 97 100 image *im = new image(m_size); … … 102 105 im->Unlock(); 103 106 104 PutImage(im, 0, 0);107 PutImage(im, vec2i(0)); 105 108 return im; 106 109 } 107 110 108 uint8_t * trans_image::ClipToLine(image *screen, int x1, int y1, int x2, int y2,109 int x, int &y, int &ysteps)111 uint8_t *TImage::ClipToLine(image *screen, vec2i pos1, vec2i pos2, 112 vec2i &pos, int &ysteps) 110 113 { 111 114 // check to see if it is totally clipped out first 112 if (y + m_size.y <= y1 || y >= y2 || x >= x2 || x + m_size.x <= x1) 115 if (pos.y + m_size.y <= pos1.y || pos.y >= pos2.y 116 || pos.x >= pos2.x || pos.x + m_size.x <= pos1.x) 113 117 return NULL; 114 118 115 119 uint8_t *parser = m_data; 116 120 117 int skiplines = Max(y1 - y, 0); // number of lines to skip 118 ysteps = Min(y2 - y, m_size.y - skiplines); // number of lines to draw 119 y += skiplines; // first line to draw 121 // Number of lines to skip, number of lines to draw, first line to draw 122 int skiplines = Max(pos1.y - pos.y, 0); 123 ysteps = Min(pos2.y - pos.y, m_size.y - skiplines); 124 pos.y += skiplines; 120 125 121 126 while (skiplines--) … … 133 138 } 134 139 135 screen->AddDirty(Max(x, x1), y, Min(x + m_size.x, x2), y + m_size.y); 140 screen->AddDirty(Max(pos.x, pos1.x), pos.y, 141 Min(pos.x + m_size.x, pos2.x), pos.y + m_size.y); 136 142 return parser; 137 143 } 138 144 139 145 template<int N> 140 void trans_image::PutImageGeneric(image *screen, int x, int y, uint8_t color, 141 image *blend, int bx, int by, 142 uint8_t *remap, uint8_t *remap2, 143 int amount, int total_frames, 144 uint8_t *tint, color_filter *f, palette *pal) 145 { 146 int x1, y1, x2, y2; 146 void TImage::PutImageGeneric(image *screen, vec2i pos, uint8_t color, 147 image *blend, vec2i bpos, uint8_t *map, 148 uint8_t *map2, int amount, int total_frames, 149 uint8_t *tint, color_filter *f, palette *pal) 150 { 151 vec2i pos1, pos2; 147 152 int ysteps, mul = 0; 148 153 149 screen->GetClip( x1, y1, x2, y2);154 screen->GetClip(pos1.x, pos1.y, pos2.x, pos2.y); 150 155 151 156 if (N == SCANLINE) 152 157 { 153 y1 = Max(y1,y + amount);154 y2 = Min(y2,y + amount + 1);155 if ( y1 >= y2)158 pos1.y = Max(pos1.y, pos.y + amount); 159 pos2.y = Min(pos2.y, pos.y + amount + 1); 160 if (pos1.y >= pos2.y) 156 161 return; 157 162 } 158 163 159 uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),164 uint8_t *datap = ClipToLine(screen, pos1, pos2, pos, ysteps), 160 165 *screen_line, *blend_line = NULL, *paddr = NULL; 161 166 if (!datap) 162 167 return; // if ClipToLine says nothing to draw, return 163 168 164 CONDITION(N == BLEND && y >= by && y + ysteps < by + blend->Size().y + 1, 165 "Blend doesn't fit on trans_image"); 169 CONDITION(N == BLEND && pos.y >= bpos.y 170 && pos.y + ysteps < bpos.y + blend->Size().y + 1, 171 "Blend doesn't fit on TImage"); 166 172 167 173 if (N == FADE || N == FADE_TINT || N == BLEND) … … 174 180 175 181 if (N == PREDATOR) 176 ysteps = Min(ysteps, y2 - 1 -y - 2);182 ysteps = Min(ysteps, pos2.y - 1 - pos.y - 2); 177 183 178 184 screen->Lock(); 179 185 180 screen_line = screen->scan_line( y) +x;186 screen_line = screen->scan_line(pos.y) + pos.x; 181 187 int sw = screen->Size().x; 182 x1 -= x; x2 -=x;183 184 for (; ysteps > 0; ysteps--, y++)188 pos1.x -= pos.x; pos2.x -= pos.x; 189 190 for (; ysteps > 0; ysteps--, pos.y++) 185 191 { 186 192 if (N == BLEND) 187 blend_line = blend->scan_line( y - by);193 blend_line = blend->scan_line(pos.y - bpos.y); 188 194 189 195 for (int ix = 0; ix < m_size.x; ) … … 203 209 204 210 // Chop left side if necessary, but no more than todo 205 int tochop = Min(todo, Max( x1- ix, 0));211 int tochop = Min(todo, Max(pos1.x - ix, 0)); 206 212 207 213 ix += tochop; … … 211 217 212 218 // Chop right side if necessary and process the remaining pixels 213 int count = Min(todo, Max( x2- ix, 0));219 int count = Min(todo, Max(pos2.x - ix, 0)); 214 220 215 221 if (N == NORMAL || N == SCANLINE) … … 229 235 uint8_t *sl = screen_line, *sl2 = datap; 230 236 while (count--) 231 *sl++ = remap[*sl2++];237 *sl++ = map[*sl2++]; 232 238 } 233 239 else if (N == REMAP2) … … 235 241 uint8_t *sl = screen_line, *sl2 = datap; 236 242 while (count--) 237 *sl++ = remap2[remap[*sl2++]];243 *sl++ = map2[map[*sl2++]]; 238 244 } 239 245 else if (N == FADE || N == FADE_TINT || N == BLEND) 240 246 { 241 247 uint8_t *sl = screen_line; 242 uint8_t *sl2 = (N == BLEND) ? blend_line + x + ix - bx : sl; 248 uint8_t *sl2 = (N == BLEND) ? blend_line + pos.x + ix - bpos.x 249 : sl; 243 250 uint8_t *sl3 = datap; 244 251 … … 246 253 { 247 254 uint8_t *p1 = paddr + 3 * *sl2++; 248 uint8_t *p2 = paddr + 3 * (N == FADE_TINT ? tint[*sl3++] : *sl3++); 255 uint8_t *p2 = paddr + 3 * (N == FADE_TINT ? tint[*sl3++] 256 : *sl3++); 249 257 250 258 uint8_t r = ((((int)p1[0] - p2[0]) * mul) >> 16) + p2[0]; … … 265 273 } 266 274 267 void trans_image::PutImage(image *screen, int x, int y)268 { 269 PutImageGeneric<NORMAL>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,275 void TImage::PutImage(image *screen, vec2i pos) 276 { 277 PutImageGeneric<NORMAL>(screen, pos, 0, NULL, 0, NULL, NULL, 270 278 0, 1, NULL, NULL, NULL); 271 279 } 272 280 273 void trans_image::PutRemap(image *screen, int x, int y, uint8_t *remap)274 { 275 PutImageGeneric<REMAP>(screen, x, y, 0, NULL, 0, 0, remap, NULL,281 void TImage::PutRemap(image *screen, vec2i pos, uint8_t *map) 282 { 283 PutImageGeneric<REMAP>(screen, pos, 0, NULL, 0, map, NULL, 276 284 0, 1, NULL, NULL, NULL); 277 285 } 278 286 279 void trans_image::PutDoubleRemap(image *screen, int x, int y,280 uint8_t *remap, uint8_t *remap2)281 { 282 PutImageGeneric<REMAP2>(screen, x, y, 0, NULL, 0, 0, remap, remap2,287 void TImage::PutDoubleRemap(image *screen, vec2i pos, 288 uint8_t *map, uint8_t *map2) 289 { 290 PutImageGeneric<REMAP2>(screen, pos, 0, NULL, 0, map, map2, 283 291 0, 1, NULL, NULL, NULL); 284 292 } 285 293 286 294 // Used when eg. the player teleports, or in rocket trails 287 void trans_image::PutFade(image *screen, int x, int y, 288 int amount, int total_frames, 289 color_filter *f, palette *pal) 290 { 291 PutImageGeneric<FADE>(screen, x, y, 0, NULL, 0, 0, NULL, NULL, 295 void TImage::PutFade(image *screen, vec2i pos, int amount, int total_frames, 296 color_filter *f, palette *pal) 297 { 298 PutImageGeneric<FADE>(screen, pos, 0, NULL, 0, NULL, NULL, 292 299 amount, total_frames, NULL, f, pal); 293 300 } 294 301 295 void trans_image::PutFadeTint(image *screen, int x, int y, 296 int amount, int total_frames, 297 uint8_t *tint, color_filter *f, palette *pal) 298 { 299 PutImageGeneric<FADE_TINT>(screen, x, y, 0, NULL, 0, 0, NULL, NULL, 302 void TImage::PutFadeTint(image *screen, vec2i pos, int amount, int total_frames, 303 uint8_t *tint, color_filter *f, palette *pal) 304 { 305 PutImageGeneric<FADE_TINT>(screen, pos, 0, NULL, 0, NULL, NULL, 300 306 amount, total_frames, tint, f, pal); 301 307 } 302 308 303 void trans_image::PutColor(image *screen, int x, int y, uint8_t color)304 { 305 PutImageGeneric<COLOR>(screen, x, y, color, NULL, 0, 0, NULL, NULL,309 void TImage::PutColor(image *screen, vec2i pos, uint8_t color) 310 { 311 PutImageGeneric<COLOR>(screen, pos, color, NULL, 0, NULL, NULL, 306 312 0, 1, NULL, NULL, NULL); 307 313 } … … 309 315 // This method is unused but is believed to work. 310 316 // Assumes that the blend image completely covers the transparent image. 311 void trans_image::PutBlend(image *screen, int x, int y, 312 image *blend, int bx, int by, 313 int amount, color_filter *f, palette *pal) 314 { 315 PutImageGeneric<BLEND>(screen, x, y, 0, blend, bx, by, NULL, NULL, 317 void TImage::PutBlend(image *screen, vec2i pos, image *blend, vec2i bpos, 318 int amount, color_filter *f, palette *pal) 319 { 320 PutImageGeneric<BLEND>(screen, pos, 0, blend, bpos, NULL, NULL, 316 321 amount, 1, NULL, f, pal); 317 322 } 318 323 319 void trans_image::PutFilled(image *screen, int x, int y, uint8_t color)320 { 321 PutImageGeneric<FILLED>(screen, x, y, color, NULL, 0, 0, NULL, NULL,324 void TImage::PutFilled(image *screen, vec2i pos, uint8_t color) 325 { 326 PutImageGeneric<FILLED>(screen, pos, color, NULL, 0, NULL, NULL, 322 327 0, 1, NULL, NULL, NULL); 323 328 } 324 329 325 void trans_image::PutPredator(image *screen, int x, int y)326 { 327 PutImageGeneric<PREDATOR>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,330 void TImage::PutPredator(image *screen, vec2i pos) 331 { 332 PutImageGeneric<PREDATOR>(screen, pos, 0, NULL, 0, NULL, NULL, 328 333 0, 1, NULL, NULL, NULL); 329 334 } 330 335 331 void trans_image::PutScanLine(image *screen, int x, int y, int line)332 { 333 PutImageGeneric<SCANLINE>(screen, x, y, 0, NULL, 0, 0, NULL, NULL,336 void TImage::PutScanLine(image *screen, vec2i pos, int line) 337 { 338 PutImageGeneric<SCANLINE>(screen, pos, 0, NULL, 0, NULL, NULL, 334 339 line, 1, NULL, NULL, NULL); 335 340 } 336 341 337 size_t trans_image::MemUsage()342 size_t TImage::MemUsage() 338 343 { 339 344 uint8_t *d = m_data;
Note: See TracChangeset
for help on using the changeset viewer.