Changeset 520


Ignore:
Timestamp:
Apr 21, 2011, 9:03:02 PM (6 years ago)
Author:
sam
Message:

imlib: refactor and simplify trans_image::ClipToLine?().

Location:
abuse/trunk/src/imlib
Files:
2 edited

Legend:

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

    r518 r520  
    221221
    222222
    223 inline uint8_t *trans_image::clip_y(image *screen, int x1, int y1, int x2, int y2,
    224                    int x, int &y, int &ysteps)
    225 {
    226   // check to see if it is total clipped out first
    227   if (y+h<=y1 || y>y2 || x>x2 || x+w<=x1)
    228     return NULL;
    229 
    230   uint8_t *datap=data;
    231 
    232 
    233   ysteps=height();
    234 
    235   if (y<y1)  // check to see if the image gets clipped at the top
    236   {
    237 
    238 
    239     // because data is stored in runs, we need to skip over the top clipped portion
    240     int skips=(y1-y);     // how many lines do we need to skip?
    241     ysteps-=skips;        // reduce h (number of lines to draw)
    242     y=y1;                // start drawing here now
    243     while (skips--)
    244     {
    245       int ix=0;
    246       while (ix<w)
    247       {
    248         ix+=(*datap);       // skip over empty space
    249         datap++;
    250         if (ix<w)
    251         { ix+=*datap;
    252         datap+=(*datap)+1;   // skip over data
    253         }
    254       }
    255     }
    256   }
    257 
    258   if (y+ysteps>y2)  // check to see if it gets clipped at the bottom
    259     ysteps-=(y+ysteps-y2-1);
    260 
    261   screen->AddDirty(Max(x, x1), y, Min(x + width(), x2 + 1), y + h);
    262   return datap;
     223uint8_t *trans_image::ClipToLine(image *screen, int x1, int y1, int x2, int y2,
     224                                 int x, int &y, int &ysteps)
     225{
     226    // check to see if it is totally clipped out first
     227    if (y + h <= y1 || y >= y2 || x >= x2 || x + w <= x1)
     228        return NULL;
     229
     230    uint8_t *parser = data;
     231
     232    int skiplines = Max(y1 - y, 0); // number of lines to skip
     233    ysteps = Min(y2 - y, height() - skiplines); // number of lines to draw
     234    y += skiplines; // first line to draw
     235
     236    while (skiplines--)
     237    {
     238        for (int ix = 0; ix < w; )
     239        {
     240            ix += *parser++; // skip over empty space
     241
     242            if (ix >= w)
     243                break;
     244
     245            ix += *parser;
     246            parser += *parser + 1; // skip over data
     247        }
     248    }
     249
     250    screen->AddDirty(Max(x, x1), y, Min(x + width(), x2), y + h);
     251    return parser;
    263252}
    264253
     
    270259
    271260  screen->GetClip(x1, y1, x2, y2);
    272   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     261  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    273262          *screen_line;
    274   if (!datap) return ;     // if clip_y says nothing to draw, return
     263  if (!datap)
     264    return; // if ClipToLine says nothing to draw, return
    275265
    276266  screen->Lock();
     
    384374
    385375  screen->GetClip(x1, y1, x2, y2);
    386   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     376  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    387377          *screen_line;
    388   if (!datap) return ;     // if clip_y says nothing to draw, return
     378  if (!datap) return; // if ClipToLine says nothing to draw, return
    389379
    390380  screen->Lock();
     
    450440
    451441  screen->GetClip(x1, y1, x2, y2);
    452   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     442  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    453443          *screen_line;
    454   if (!datap) return ;     // if clip_y says nothing to draw, return
     444  if (!datap) return; // if ClipToLine says nothing to draw, return
    455445
    456446  screen->Lock();
     
    529519
    530520  screen->GetClip(x1, y1, x2, y2);
    531   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     521  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    532522          *screen_line;
    533   if (!datap) return ;     // if clip_y says nothing to draw, return
     523  if (!datap) return; // if ClipToLine says nothing to draw, return
    534524
    535525  screen->Lock();
     
    610600
    611601  screen->GetClip(x1, y1, x2, y2);
    612   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     602  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    613603          *screen_line;
    614   if (!datap) return ;
     604  if (!datap) return;
    615605
    616606  uint8_t *screen_run,*paddr=(uint8_t *)pal->addr(),
     
    705695
    706696  screen->GetClip(x1, y1, x2, y2);
    707   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     697  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    708698          *screen_line;
    709   if (!datap) return ;
     699  if (!datap) return;
    710700
    711701  screen->Lock();
     
    793783
    794784  screen->GetClip(x1, y1, x2, y2);
    795   uint8_t *datap = clip_y(screen, x1, y1, x2, y2, x, y, ysteps),
     785  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    796786          *screen_line;
    797   if (!datap) return ;
     787  if (!datap) return;
    798788
    799789  screen->Lock();
     
    861851
    862852  screen->GetClip(x1, y1, x2, y2);
    863   uint8_t *datap=clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     853  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    864854          *blend_line, *screen_line;
    865   if (!datap) return ;
     855  if (!datap) return;
    866856  CONDITION(y>=blendy && y+ysteps<blendy+blend->Size().y+1,"Blend doesn't fit on trans_image");
    867857
     
    961951
    962952  screen->GetClip(x1, y1, x2, y2);
    963   uint8_t *datap = clip_y(screen, x1, y1, x2 - 1, y2 - 1, x, y, ysteps),
     953  uint8_t *datap = ClipToLine(screen, x1, y1, x2, y2, x, y, ysteps),
    964954          *screen_line;
    965   if (!datap) return ;     // if clip_y says nothing to draw, return
     955  if (!datap) return; // if ClipToLine says nothing to draw, return
    966956
    967957  // see if the last scanline is clipped off
  • abuse/trunk/src/imlib/timage.h

    r494 r520  
    4848             color_filter *f, palette *pal);
    4949  void put_color(image *screen, int x, int y, int color);
    50   unsigned char *clip_y(image *screen, int x1, int y1, int x2, int y2,
    51                                    int x, int &y, int &ysteps);
    5250
    5351  void put_blend16(image *screen, image *blend, int x, int y,
     
    6260  image *make_image();
    6361  ~trans_image() { free(data); }
     62
     63private:
     64  uint8_t *ClipToLine(image *screen, int x1, int y1, int x2, int y2,
     65                      int x, int &y, int &ysteps);
    6466} ;
    6567
Note: See TracChangeset for help on using the changeset viewer.