Wait for first frame of image in image loader.
This commit is contained in:
		
							parent
							
								
									5025f5fb96
								
							
						
					
					
						commit
						19d4126b51
					
				
					 1 changed files with 13 additions and 4 deletions
				
			
		|  | @ -105,10 +105,12 @@ public class ImageGenerator { | |||
| 	Image img; | ||||
| 	int w, h; | ||||
| 	boolean waiting; | ||||
| 	boolean firstFrameLoaded; | ||||
| 
 | ||||
| 	ImageLoader (Image img) { | ||||
| 	    this.img = img; | ||||
| 	    waiting = true; | ||||
| 	    firstFrameLoaded = false; | ||||
| 	} | ||||
| 
 | ||||
| 	int getWidth () { | ||||
|  | @ -147,14 +149,21 @@ public class ImageGenerator { | |||
| 	        w = width; | ||||
| 	    if (h == -1 && (infoflags & HEIGHT) > 0) | ||||
| 	        h = height; | ||||
| 	    if (h > -1 && w > -1) { | ||||
| 	        // we know all we want to know. notify waiting thread that | ||||
| 	        // the image is loaded and ready to be used. | ||||
| 	    if ((infoflags & ALLBITS) > 0 || | ||||
| 	        (infoflags & FRAMEBITS) > 0) | ||||
| 	        firstFrameLoaded = true; | ||||
| 	    // check if we have everything we need | ||||
| 	    if (w > -1 && h > -1 && firstFrameLoaded) { | ||||
| 	        // we know both the width and the height of the image and | ||||
| 	        // the bits of the first frame have been loaded. notify waiting thread that | ||||
| 	        // the image is loaded and ready to be used and tell the loader thread | ||||
| 	        // that we need no further updates. | ||||
| 	        notifyAll (); | ||||
| 	        return false; | ||||
| 	    } | ||||
| 	    // check if there was an error | ||||
| 	    if (!waiting || (infoflags & ERROR) > 0 || (infoflags & ABORT) > 0) { | ||||
| 	        // we either timed out or there was an error. | ||||
| 	        notifyAll (); | ||||
| 	        return false; | ||||
| 	    } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue