| 1 |
|
package com.atlassian.core.util.thumbnail; |
| 2 |
|
|
| 3 |
|
import java.awt.image.BufferedImage; |
| 4 |
|
import java.awt.image.ColorModel; |
| 5 |
|
import java.awt.image.ImageConsumer; |
| 6 |
|
import java.awt.image.WritableRaster; |
| 7 |
|
import java.util.Hashtable; |
| 8 |
|
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 18 |
Complexity Density: 0.67 |
|
| 9 |
|
public class SimpleImageConsumer implements ImageConsumer |
| 10 |
|
{ |
| 11 |
|
private final Object holder; |
| 12 |
|
|
| 13 |
|
private ColorModel colorModel; |
| 14 |
|
private WritableRaster raster; |
| 15 |
|
private int width; |
| 16 |
|
private int height; |
| 17 |
|
|
| 18 |
|
private BufferedImage image; |
| 19 |
|
private int[] intBuffer; |
| 20 |
|
private volatile boolean loadComplete; |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 22 |
0
|
public SimpleImageConsumer()... |
| 23 |
|
{ |
| 24 |
0
|
holder = new Object(); |
| 25 |
0
|
width = -1; |
| 26 |
0
|
height = -1; |
| 27 |
0
|
loadComplete = false; |
| 28 |
|
} |
| 29 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 30 |
0
|
public void imageComplete(int status)... |
| 31 |
|
{ |
| 32 |
0
|
synchronized(holder) |
| 33 |
|
{ |
| 34 |
0
|
loadComplete = true; |
| 35 |
0
|
holder.notify(); |
| 36 |
|
} |
| 37 |
|
} |
| 38 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 39 |
0
|
public void setColorModel(ColorModel model)... |
| 40 |
|
{ |
| 41 |
0
|
colorModel = model; |
| 42 |
0
|
createImage(); |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@param |
| 49 |
|
@param |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 51 |
0
|
public void setDimensions(int w, int h)... |
| 52 |
|
{ |
| 53 |
0
|
width = w; |
| 54 |
0
|
height = h; |
| 55 |
0
|
createImage(); |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@param |
| 63 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 64 |
0
|
public void setHints(int flags)... |
| 65 |
|
{ |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
@param |
| 73 |
|
@param |
| 74 |
|
@param |
| 75 |
|
@param |
| 76 |
|
@param |
| 77 |
|
@param |
| 78 |
|
@param |
| 79 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 80 |
0
|
public void setPixels(int x,... |
| 81 |
|
int y, |
| 82 |
|
int w, |
| 83 |
|
int h, |
| 84 |
|
ColorModel model, |
| 85 |
|
byte[] pixels, |
| 86 |
|
int offset, |
| 87 |
|
int scansize) |
| 88 |
|
{ |
| 89 |
0
|
if((intBuffer == null) || (pixels.length > intBuffer.length)) |
| 90 |
0
|
intBuffer = new int[pixels.length]; |
| 91 |
|
|
| 92 |
0
|
for(int i = pixels.length; --i >= 0 ; ) |
| 93 |
0
|
intBuffer[i] = (int)pixels[i] & 0xFF; |
| 94 |
|
|
| 95 |
0
|
raster.setPixels(x, y, w, h, intBuffer); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
@param |
| 103 |
|
@param |
| 104 |
|
@param |
| 105 |
|
@param |
| 106 |
|
@param |
| 107 |
|
@param |
| 108 |
|
@param |
| 109 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0
|
public void setPixels(int x,... |
| 111 |
|
int y, |
| 112 |
|
int w, |
| 113 |
|
int h, |
| 114 |
|
ColorModel model, |
| 115 |
|
int[] pixels, |
| 116 |
|
int offset, |
| 117 |
|
int scansize) |
| 118 |
|
{ |
| 119 |
0
|
image.setRGB(x, y, w, h, pixels, offset, scansize); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
@param |
| 126 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
0
|
public void setProperties(Hashtable props)... |
| 128 |
|
{ |
| 129 |
0
|
createImage(); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@return |
| 143 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 144 |
0
|
public BufferedImage getImage()... |
| 145 |
|
{ |
| 146 |
0
|
if(!loadComplete) |
| 147 |
|
{ |
| 148 |
0
|
synchronized(holder) |
| 149 |
|
{ |
| 150 |
0
|
try |
| 151 |
|
{ |
| 152 |
0
|
holder.wait(); |
| 153 |
|
} |
| 154 |
|
catch(InterruptedException ie) |
| 155 |
|
{ |
| 156 |
|
} |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
|
| 160 |
0
|
return image; |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
| 172 |
0
|
private void createImage()... |
| 173 |
|
{ |
| 174 |
|
|
| 175 |
0
|
if((image != null) || |
| 176 |
|
(width == -1) || |
| 177 |
|
(colorModel == null)) |
| 178 |
0
|
return; |
| 179 |
|
|
| 180 |
0
|
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
| 181 |
|
} |
| 182 |
|
} |