Changeset 11648


Ignore:
Timestamp:
2006-04-12T09:33:14+12:00 (18 years ago)
Author:
shaoqun
Message:

add code to guard ArryOutofBound error in handlepixels method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java

    r11572 r11648  
    146146        next_frame_ =  new Thread(new Runnable(){
    147147                public void run() {
    148             try {
    149 
    150             Thread curr_thread = Thread.currentThread();
    151        
    152             while (curr_thread == next_frame_) {
    153                 next_frame();
    154                
    155                 Thread.sleep(app_. refreshDelay_);
    156                 curr_thread = Thread.currentThread();
     148         
     149            Thread curr_thread = Thread.currentThread();
     150           
     151            while (curr_thread == next_frame_) {
     152            try {       
     153                 next_frame();
     154                 Thread.sleep(app_. refreshDelay_);
     155                 curr_thread = Thread.currentThread();
     156            } catch (Exception e) {
     157                break;
    157158            }
    158 
    159        
    160             } catch (Exception e) {
    161             e.printStackTrace();
    162159            }
     160                   
     161           
    163162        }
    164163
     
    175174     *  @param y the y co-ordinate of the mouse
    176175     *  @return the image that the user has clicked on or null if the user has clicked whitespace */
    177    public synchronized CollageImage clickedOnImage(int x, int y)
     176   public CollageImage clickedOnImage(int x, int y)
    178177    {
    179178    if (app_.verbosity() > 1)
     
    182181    }
    183182
    184     int no_images = inuse_.size() - 1;
     183   
    185184    // checks from last image down, as last images place will be at the top of the collage
    186     for (int i= no_images; i >= 0; i--)
     185    for (int i= inuse_.size() - 1; i >= 0; i--)
    187186    {
    188187        CollageImage collage_image = (CollageImage)inuse_.elementAt(i);
     
    256255                 = restoreAlpha(collage_image.image_, 0, 0,
    257256                           collage_image.image_x_dim_, collage_image.image_y_dim_);
    258                
     257             
    259258            }
    260259           
     
    266265        {
    267266             
    268  
    269267            // conducts fading and colouring of image
    270268            Image img = handlepixels(collage_image.image_, 0, 0, collage_image.image_x_dim_,
     
    512510    public  Image handlepixels(Image img, int x, int y, int w, int h, int p, boolean fresh) {
    513511   
     512   
    514513    // declare an array to hold the pixels
    515514    int[] pixels = new int[w * h];
     
    536535    else
    537536        bound *= h;
     537
    538538    int upperboundheight = h - (int) bound;
    539539    int upperboundwidth = w - (int) bound;
    540540    int lowerbound = (int) bound;
    541541
    542     // loop through every pixel in the picture and handle it
     542        // loop through every pixel in the picture and handle it
    543543    for (int j = lowerbound; j < upperboundheight; j++) {
    544544        for (int i = lowerbound; i < upperboundwidth; i++) {
     
    558558        fader = 0;
    559559       
    560         for (int m = 0; m < w; m++)
    561         pixels[n * w + m] = handlesinglepixel(pixels[n * w + m], p, fresh, true, fader);
     560        for (int m = 0; m < w; m++){
     561        int index = n* w + m;
     562        if (index <pixels.length){
     563            pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
     564           
     565        }
     566        }
     567       
     568   
    562569       
    563570        fade+= FADEVALUE;
     
    570577        if (fader < 0)
    571578        fader = 0;
    572         for (int m = 0; m < w; m++)
    573         pixels[n * w + m] = handlesinglepixel(pixels[n * w + m], p, fresh, true, fader);
     579        for (int m = 0; m < w; m++){
     580        int index = n * w + m;
     581        if (index <pixels.length){
     582            pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
     583           
     584        }
     585        }
    574586       
    575587        fade += FADEVALUE;
     
    585597        if ( m < lowerbound && n > m);
    586598        else if ( m > upperboundheight && n > (h - m));
    587         else
    588             pixels[m * w + n] = handlesinglepixel(pixels[m * w + n], p, fresh, true, fader);
     599        else {
     600            int index = m * w + n;
     601                    if (index <pixels.length){
     602            pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
     603   
     604            }
     605        }
     606                   
    589607        }
    590608        fade += FADEVALUE;   
     
    600618        if ( m < lowerbound && (w - n) > m);
    601619        else if ( m > upperboundheight && (w - n) > (h - m));
    602         else
    603             pixels[m * w + n] = handlesinglepixel(pixels[m * w + n], p, fresh, true, fader);
     620        else {
     621            int index = m * w + n;
     622                    if (index <pixels.length){
     623            pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
     624   
     625            }
     626        }
     627           
    604628        }
    605629       
     
    694718    int corealpha = (pixels[(h/2) * w + (w/2)] >> 24) & 0xff;
    695719   
    696     if (corealpha < 2)
     720    if (corealpha < 10)
    697721        return true;
    698722
     
    792816       
    793817    } catch (Exception e) {
    794         //e.printStackTrace();
     818       e.printStackTrace();
    795819           System.out.println("Display images thread is interrupted");
    796820    }
Note: See TracChangeset for help on using the changeset viewer.