Ignore:
Timestamp:
Apr 20, 2011, 9:02:33 PM (11 years ago)
Author:
Sam Hocevar
Message:

imlib: refactor dirty_rect clipping coordiantes so that the upper
bound is no longer inclusive. It will make things easier in the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/timage.cpp

    r515 r518  
    139139void trans_image::put_scan_line(image *screen, int x, int y, int line)   // always transparent
    140140{
    141   int16_t x1,y1,x2,y2;
    142   screen->get_clip(x1,y1,x2,y2);
    143   if (y+line<y1 || y+line>y2 || x>x2 || x+w-1<x1)            // clipped off completely?
    144     return;
     141  int x1, y1, x2, y2;
     142  screen->GetClip(x1, y1, x2, y2);
     143  if (y + line < y1 || y + line >= y2 || x >= x2 || x + w - 1 < x1)
     144    return; // clipped off completely?
    145145
    146146  uint8_t *datap=data;
     
    197197    }
    198198
    199     if (x+ix>x2)                      // clipped totally on the right?
     199    if (x + ix >= x2)                      // clipped totally on the right?
    200200        {
    201201          screen->Unlock();
    202202          return ;                        // we are done, return!
    203203        }
    204     else if (x+ix+run_length-1>x2)    // partially clipped?
    205     {
    206       memcpy(screen_line,datap,(x+ix+run_length-1)-x2);  // slam what we can
    207           screen->Unlock();
     204    else if (x + ix + run_length > x2)    // partially clipped?
     205    {
     206      memcpy(screen_line, datap, x + ix + run_length - x2); // slam what we can
     207      screen->Unlock();
    208208      return ;    // and return 'cause we are done with the line
    209209        } else
     
    259259    ysteps-=(y+ysteps-y2-1);
    260260
    261   screen->add_dirty(Max(x,x1),y,Min(x+width()-1,x2),y+h-1);
     261  screen->AddDirty(Max(x, x1), y, Min(x + width(), x2 + 1), y + h);
    262262  return datap;
    263263}
     
    266266                   uint8_t fill_color)
    267267{
    268  int16_t x1,y1,x2,y2;
     268  int x1, y1, x2, y2;
    269269  int chop_length,ysteps;
    270270
    271   screen->get_clip(x1,y1,x2,y2);
    272   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;
     271  screen->GetClip(x1, y1, x2, y2);
     272  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     273          *screen_line;
    273274  if (!datap) return ;     // if clip_y says nothing to draw, return
    274275
     
    277278  screen_line=screen->scan_line(y)+x;
    278279  int sw=screen->Size().x-w;
    279   x1-=x; x2-=x;
     280  x1 -= x; x2 -= x;
    280281  for (; ysteps>0; ysteps--)
    281282  {
     
    293294    slam_length=*datap;     // find the length of this run
    294295    datap++;
    295     if (ix+slam_length<x1 || ix>x2)  // see if this run is totally clipped
     296    if (ix + slam_length < x1 || ix >= x2)  // see if this run is totally clipped
    296297    {
    297298      datap+=slam_length;
     
    322323      if (slam_length)   // see if there is anything left to slam
    323324      {
    324         if (ix+slam_length>x2) // see if right side needs to be chopped off
    325           memcpy(screen_line,datap,x2-ix+1);
     325        if (ix + slam_length >= x2) // see if right side needs to be chopped off
     326          memcpy(screen_line, datap, x2 - ix);
    326327        else
    327328          memcpy(screen_line,datap,slam_length);
     
    379380void trans_image::put_image(image *screen, int x, int y)
    380381{
    381   int16_t x1,y1,x2,y2;
     382  int x1, y1, x2, y2;
    382383  int chop_length,ysteps;
    383384
    384   screen->get_clip(x1,y1,x2,y2);
    385   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;
     385  screen->GetClip(x1, y1, x2, y2);
     386  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     387          *screen_line;
    386388  if (!datap) return ;     // if clip_y says nothing to draw, return
    387389
     
    389391  screen_line=screen->scan_line(y)+x;
    390392  int sw=screen->Size().x;
    391   x1-=x; x2-=x;
     393  x1 -= x; x2 -= x;
    392394  for (; ysteps>0; ysteps--)
    393395  {
     
    401403    slam_length=*datap;     // find the length of this run
    402404    datap++;
    403     if (ix+slam_length<x1 || ix>x2)  // see if this run is totally clipped
     405    if (ix + slam_length < x1 || ix >= x2)  // see if this run is totally clipped
    404406    {
    405407      datap+=slam_length;
     
    427429      if (slam_length)   // see if there is anything left to slam
    428430      {
    429         if (ix+slam_length>x2) // see if right side needs to be chopped off
    430           memcpy(screen_line+ix,datap,x2-ix+1);
     431        if (ix + slam_length >= x2) // see if right side needs to be chopped off
     432          memcpy(screen_line + ix, datap, x2 - ix);
    431433        else
    432434          memcpy(screen_line+ix,datap,slam_length);
     
    444446void trans_image::put_remaped(image *screen, int x, int y, uint8_t *remap)
    445447{
    446   int16_t x1,y1,x2,y2;
    447   int chop_length,ysteps;
    448 
    449   screen->get_clip(x1,y1,x2,y2);
    450   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;
     448  int x1, y1, x2, y2;
     449  int chop_length, ysteps;
     450
     451  screen->GetClip(x1, y1, x2, y2);
     452  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     453          *screen_line;
    451454  if (!datap) return ;     // if clip_y says nothing to draw, return
    452455
     
    454457  screen_line=screen->scan_line(y)+x;
    455458  int sw=screen->Size().x;
    456   x1-=x; x2-=x;
     459  x1 -= x; x2 -= x;
    457460  for (; ysteps>0; ysteps--)
    458461  {
     
    466469    slam_length=*datap;     // find the length of this run
    467470    datap++;
    468     if (ix+slam_length<x1 || ix>x2)  // see if this run is totally clipped
     471    if (ix + slam_length < x1 || ix >= x2)  // see if this run is totally clipped
    469472    {
    470473      datap+=slam_length;
     
    494497      {
    495498        int counter;
    496         if (ix+slam_length>x2) // see if right side needs to be chopped off
    497           counter=x2-ix+1;
     499        if (ix + slam_length >= x2) // see if right side needs to be chopped off
     500          counter = x2 - ix;
    498501        else
    499           counter=slam_length;
     502          counter = slam_length;
    500503
    501504        uint8_t *sl=screen_line+ix,*sl2=datap;
     
    522525void trans_image::put_double_remaped(image *screen, int x, int y, uint8_t *remap, uint8_t *remap2)
    523526{
    524   int16_t x1,y1,x2,y2;
    525   int chop_length,ysteps;
    526 
    527   screen->get_clip(x1,y1,x2,y2);
    528   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;
     527  int x1, y1, x2, y2;
     528  int chop_length, ysteps;
     529
     530  screen->GetClip(x1, y1, x2, y2);
     531  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     532          *screen_line;
    529533  if (!datap) return ;     // if clip_y says nothing to draw, return
    530534
     
    532536  screen_line=screen->scan_line(y)+x;
    533537  int sw=screen->Size().x;
    534   x1-=x; x2-=x;
     538  x1 -= x; x2 -= x;
    535539  for (; ysteps>0; ysteps--)
    536540  {
     
    544548    slam_length=*datap;     // find the length of this run
    545549    datap++;
    546     if (ix+slam_length<x1 || ix>x2)  // see if this run is totally clipped
     550    if (ix + slam_length < x1 || ix >= x2)  // see if this run is totally clipped
    547551    {
    548552      datap+=slam_length;
     
    572576      {
    573577        int counter;
    574         if (ix+slam_length>x2) // see if right side needs to be chopped off
    575           counter=x2-ix+1;
     578        if (ix + slam_length >= x2) // see if right side needs to be chopped off
     579          counter = x2 - ix;
    576580        else
    577           counter=slam_length;
     581          counter = slam_length;
    578582
    579583        uint8_t *sl=screen_line+ix,*sl2=datap;
     
    602606               color_filter *f, palette *pal)
    603607{
    604   int16_t x1,y1,x2,y2;
     608  int x1, y1, x2, y2;
    605609  int ix,slam_length,chop_length,ysteps;
    606610
    607   screen->get_clip(x1,y1,x2,y2);
    608   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),
    609                 *screen_line;
     611  screen->GetClip(x1, y1, x2, y2);
     612  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     613          *screen_line;
    610614  if (!datap) return ;
    611615
     
    627631    slam_length=*datap;     // find the length of this run
    628632    datap++;
    629     if (x+ix+slam_length<x1 || x+ix>x2)  // see if this run is totally clipped
     633    if (x + ix + slam_length < x1 || x + ix >= x2)  // see if this run is totally clipped
    630634    {
    631635      datap+=slam_length;
     
    653657      if (slam_length)   // see if there is anything left to slam
    654658      {
    655         if (x+ix+slam_length>x2) // see if right side needs to be chopped off
    656           chop_length=x2-x-ix;
    657         else chop_length=slam_length;
     659        if (x + ix + slam_length >= x2) // see if right side needs to be chopped off
     660          chop_length = x2 - 1 - x - ix;
     661        else
     662          chop_length = slam_length;
    658663        screen_run=screen_line+x+ix;
    659664
     
    696701                color_filter *f, palette *pal)
    697702{
    698   int16_t x1,y1,x2,y2;
     703  int x1, y1, x2, y2;
    699704  int ix,slam_length,chop_length,ysteps;
    700705
    701   screen->get_clip(x1,y1,x2,y2);
    702   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),
    703                 *screen_line;
     706  screen->GetClip(x1, y1, x2, y2);
     707  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     708          *screen_line;
    704709  if (!datap) return ;
    705710
     
    721726    slam_length=*datap;     // find the length of this run
    722727    datap++;
    723     if (x+ix+slam_length<x1 || x+ix>x2)  // see if this run is totally clipped
     728    if (x + ix + slam_length < x1 || x + ix >= x2)  // see if this run is totally clipped
    724729    {
    725730      datap+=slam_length;
     
    747752      if (slam_length)   // see if there is anything left to slam
    748753      {
    749         if (x+ix+slam_length>x2) // see if right side needs to be chopped off
    750           chop_length=x2-x-ix;
     754        if (x + ix + slam_length >= x2) // see if right side needs to be chopped off
     755          chop_length = x2 - 1 - x - ix;
    751756        else chop_length=slam_length;
    752757        screen_run=screen_line+x+ix;
     
    784789void trans_image::put_color(image *screen, int x, int y, int color)
    785790{
    786   int16_t x1,y1,x2,y2;
     791  int x1, y1, x2, y2;
    787792  int ix,slam_length,chop_length,ysteps;
    788793
    789   screen->get_clip(x1,y1,x2,y2);
    790   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),
    791                 *screen_line;
     794  screen->GetClip(x1, y1, x2, y2);
     795  uint8_t *datap = clip_y(screen, x1, y1, x2, y2, x, y, ysteps),
     796          *screen_line;
    792797  if (!datap) return ;
    793798
     
    805810    slam_length=*datap;     // find the length of this run
    806811    datap++;
    807     if (x+ix+slam_length<x1 || x+ix>x2)  // see if this run is totally clipped
     812    if (x + ix + slam_length < x1 || x + ix >= x2)  // see if this run is totally clipped
    808813    {
    809814      datap+=slam_length;
     
    831836      if (slam_length)   // see if there is anything left to slam
    832837      {
    833         if (x+ix+slam_length>x2) // see if right side needs to be chopped off
    834           memset(screen_line+x+ix,color,x2-x-ix+1);
     838        if (x + ix + slam_length >= x2) // see if right side needs to be chopped off
     839          memset(screen_line + x + ix, color, x2 - x - ix);
    835840        else
    836           memset(screen_line+x+ix,color,slam_length);
     841          memset(screen_line + x + ix, color, slam_length);
    837842        datap+=slam_length;
    838843        ix+=slam_length;
     
    851856
    852857{
    853   int16_t x1,y1,x2,y2;
     858  int x1, y1, x2, y2;
    854859  int ix,slam_length,chop_length,ysteps;
    855860  uint8_t *paddr=(uint8_t *)pal->addr();
    856861
    857   screen->get_clip(x1,y1,x2,y2);
    858   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),
    859                 *blend_line,*screen_line;
     862  screen->GetClip(x1, y1, x2, y2);
     863  uint8_t *datap=clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     864          *blend_line, *screen_line;
    860865  if (!datap) return ;
    861866  CONDITION(y>=blendy && y+ysteps<blendy+blend->Size().y+1,"Blend doesn't fit on trans_image");
     
    878883    slam_length=*datap;     // find the length of this run
    879884    datap++;
    880     if (x+ix+slam_length<x1 || x+ix>x2)  // see if this run is totally clipped
     885    if (x + ix + slam_length < x1 || x + ix >= x2)  // see if this run is totally clipped
    881886    {
    882887      datap+=slam_length;
     
    905910      {
    906911
    907         if (x+ix+slam_length>x2) // see if right side needs to be chopped off
    908           chop_length=x2-x-ix;
    909         else chop_length=slam_length;
     912        if (x + ix + slam_length >= x2) // see if right side needs to be chopped off
     913          chop_length = x2 - 1 - x - ix;
     914        else
     915          chop_length = slam_length;
    910916
    911917        uint8_t *screen_run=screen_line+x+ix,
     
    951957void trans_image::put_predator(image *screen, int x, int y)
    952958{
    953   int16_t x1,y1,x2,y2;
     959  int x1, y1, x2, y2;
    954960  int chop_length,ysteps;
    955961
    956   screen->get_clip(x1,y1,x2,y2);
    957   uint8_t *datap=clip_y(screen,x1,y1,x2,y2,x,y,ysteps),*screen_line;
     962  screen->GetClip(x1, y1, x2, y2);
     963  uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     964          *screen_line;
    958965  if (!datap) return ;     // if clip_y says nothing to draw, return
    959966
    960967  // see if the last scanline is clipped off
    961   if (y+ysteps==y2) ysteps-=2;
    962   else if (y+ysteps==y2-1) ysteps--;
     968  if (y + ysteps == y2 - 1) ysteps -= 2;
     969  else if (y + ysteps == y2 - 2) ysteps--;
    963970/*  {
    964971    for (int x=0; x<w; )
     
    973980      }
    974981    }
    975     if (y==y2)
     982    if (y==y2 - 1)
    976983      return;
    977984    else
     
    982989  screen_line=screen->scan_line(y)+x;
    983990  int sw=screen->Size().x;
    984   x1-=x; x2-=x;
     991  x1 -= x; x2 -= x;
    985992  for (; ysteps>0; ysteps--)
    986993  {
     
    9941001    slam_length=*datap;     // find the length of this run
    9951002    datap++;
    996     if (ix+slam_length<x1 || ix>x2)  // see if this run is totally clipped
     1003    if (ix + slam_length < x1 || ix >= x2)  // see if this run is totally clipped
    9971004    {
    9981005      datap+=slam_length;
     
    10201027      if (slam_length)   // see if there is anything left to slam
    10211028      {
    1022         if (ix+slam_length>x2) // see if right side needs to be chopped off
    1023           memcpy(screen_line+ix,screen_line+sw+sw+ix,x2-ix+1);
     1029        if (ix + slam_length >= x2) // see if right side needs to be chopped off
     1030          memcpy(screen_line + ix, screen_line + sw + sw + ix, x2 - ix);
    10241031        else
    1025           memcpy(screen_line+ix,screen_line+sw+sw+ix,slam_length);
     1032          memcpy(screen_line + ix, screen_line + sw + sw + ix, slam_length);
    10261033        datap+=slam_length;
    10271034        ix+=slam_length;
Note: See TracChangeset for help on using the changeset viewer.