source: abuse/trunk/src/transp.cpp @ 682

Last change on this file since 682 was 682, checked in by Sam Hocevar, 8 years ago

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

File size: 2.0 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "common.h"
16
17#include "transp.h"
18
19void transp_put(image *im, image *screen, uint8_t *table, int x, int y)
20{
21    ivec2 caa, cbb;
22    screen->GetClip(caa, cbb);
23
24    ivec2 aa(0), bb = im->Size();
25    ivec2 pos(x, y);
26
27    aa += Max(caa - pos, ivec2(0));
28    bb -= Max(caa - pos, ivec2(0));
29    pos = Max(caa, pos);
30
31    bb = Min(bb, cbb - ivec2(1) - pos);
32
33    if (!(bb >= ivec2(0)))
34        return;
35    screen->AddDirty(pos, pos + bb);
36
37  int ye=aa.y+bb.y;
38  int xe=aa.x+bb.x;
39
40  uint8_t *isl=im->scan_line(aa.y)+aa.x;
41  uint8_t *ssl=screen->scan_line(y)+x;
42  int iw=im->Size().x,sw=screen->Size().x;
43
44  for (int iy=aa.y; iy<ye; iy++,y++,isl+=iw,ssl+=sw)
45  {
46    uint8_t *s=ssl,*i=isl;
47    for (int ix=aa.x; ix<xe; ix++,s++,i++)
48    {
49      if (*i)
50        *s=*i;
51      else *s=table[*s];
52    }
53  }
54}
55
56
57/*
58void transp_put(image *im, image *screen, uint8_t *table, int x, int y)
59{
60  int cx1, cy1, cx2, cy2;
61  screen->GetClip(cx1, cy1, cx2, cy2);
62  int xs=0,ys=0,xl=im->width(),yl=im->height();
63  if (x<cx1)
64  {
65    int chop=cx1-x;
66    xs+=chop;
67    xl-=chop;
68    x+=chop;
69  }
70  if (y<cy1)
71  {
72    int chop=cy1-y;
73    ys+=chop;
74    yl-=chop;
75    y+=chop;
76  }
77  if (x + xl >= cx2)
78    xl = cx2 - 1 - x;
79  if (y + yl >= cy2)
80    yl = cy2 - 1 - y;
81
82  if (xl<0 || yl<0) return ;
83  screen->AddDirty(x, y, x + xl - 1, y + yl);
84
85  int ye=ys+yl;
86  int xe=xs+xl;
87
88  uint8_t *isl=im->scan_line(ys)+xs;
89  uint8_t *ssl=screen->scan_line(y)+x;
90  int iw=im->width(),sw=screen->width();
91
92  for (int iy=ys; iy<ye; iy++,y++,isl+=iw,ssl+=sw)
93  {
94    uint8_t *s=ssl,*i=isl;
95    for (int ix=xs; ix<xe; ix++,s++,i++)
96      *s=table[((*i)<<8)|(*s)];
97  }
98}
99
100
101*/
Note: See TracBrowser for help on using the repository browser.