| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
package com.atlassian.core.util; |
| 15 |
|
|
| 16 |
|
import java.io.DataInput; |
| 17 |
|
import java.io.EOFException; |
| 18 |
|
import java.io.FileInputStream; |
| 19 |
|
import java.io.InputStream; |
| 20 |
|
import java.io.IOException; |
| 21 |
|
import java.net.URL; |
| 22 |
|
import java.util.Vector; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@link |
| 95 |
|
@link |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
@link |
| 99 |
|
|
| 100 |
|
@link |
| 101 |
|
@link |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
@link |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
@author |
| 128 |
|
|
|
|
|
| 14.5% |
Uncovered Elements: 656 (767) |
Complexity: 233 |
Complexity Density: 0.49 |
|
| 129 |
|
public class ImageInfo |
| 130 |
|
{ |
| 131 |
|
|
| 132 |
|
@link |
| 133 |
|
|
| 134 |
|
@link |
| 135 |
|
|
| 136 |
|
public static final int FORMAT_JPEG = 0; |
| 137 |
|
|
| 138 |
|
|
| 139 |
|
@link |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@link |
| 143 |
|
|
| 144 |
|
public static final int FORMAT_GIF = 1; |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
@link |
| 148 |
|
|
| 149 |
|
@link |
| 150 |
|
|
| 151 |
|
public static final int FORMAT_PNG = 2; |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
@link |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
public static final int FORMAT_BMP = 3; |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
@link |
| 161 |
|
|
| 162 |
|
|
| 163 |
|
public static final int FORMAT_PCX = 4; |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
@link |
| 167 |
|
|
| 168 |
|
public static final int FORMAT_IFF = 5; |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
@link |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
public static final int FORMAT_RAS = 6; |
| 175 |
|
|
| 176 |
|
@link |
| 177 |
|
public static final int FORMAT_PBM = 7; |
| 178 |
|
|
| 179 |
|
@link |
| 180 |
|
public static final int FORMAT_PGM = 8; |
| 181 |
|
|
| 182 |
|
@link |
| 183 |
|
public static final int FORMAT_PPM = 9; |
| 184 |
|
|
| 185 |
|
@link |
| 186 |
|
public static final int FORMAT_PSD = 10; |
| 187 |
|
|
| 188 |
|
@link |
| 189 |
|
public static final int FORMAT_SWF = 11; |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
private static final String[] FORMAT_NAMES = { "JPEG", "GIF", "PNG", "BMP", "PCX", "IFF", "RAS", "PBM", "PGM", |
| 195 |
|
"PPM", "PSD", "SWF" }; |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
private static final String[] MIME_TYPE_STRINGS = { "image/jpeg", "image/gif", "image/png", "image/bmp", |
| 202 |
|
"image/pcx", "image/iff", "image/ras", "image/x-portable-bitmap", "image/x-portable-graymap", |
| 203 |
|
"image/x-portable-pixmap", "image/psd", "application/x-shockwave-flash" }; |
| 204 |
|
|
| 205 |
|
private int width; |
| 206 |
|
private int height; |
| 207 |
|
private int bitsPerPixel; |
| 208 |
|
private boolean progressive; |
| 209 |
|
private int format; |
| 210 |
|
private InputStream in; |
| 211 |
|
private DataInput din; |
| 212 |
|
private boolean collectComments = true; |
| 213 |
|
private Vector comments; |
| 214 |
|
private boolean determineNumberOfImages; |
| 215 |
|
private int numberOfImages; |
| 216 |
|
private int physicalHeightDpi; |
| 217 |
|
private int physicalWidthDpi; |
| 218 |
|
private int bitBuf; |
| 219 |
|
private int bitPos; |
| 220 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 221 |
0
|
private void addComment(String s)... |
| 222 |
|
{ |
| 223 |
0
|
if (comments == null) |
| 224 |
|
{ |
| 225 |
0
|
comments = new Vector(); |
| 226 |
|
} |
| 227 |
0
|
comments.addElement(s); |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
|
| 231 |
|
@link |
| 232 |
|
@link |
| 233 |
|
|
| 234 |
|
|
| 235 |
|
@return |
| 236 |
|
|
|
|
|
| 39.6% |
Uncovered Elements: 32 (53) |
Complexity: 23 |
Complexity Density: 0.7 |
|
| 237 |
4
|
public boolean check()... |
| 238 |
|
{ |
| 239 |
4
|
format = -1; |
| 240 |
4
|
width = -1; |
| 241 |
4
|
height = -1; |
| 242 |
4
|
bitsPerPixel = -1; |
| 243 |
4
|
numberOfImages = 1; |
| 244 |
4
|
physicalHeightDpi = -1; |
| 245 |
4
|
physicalWidthDpi = -1; |
| 246 |
4
|
comments = null; |
| 247 |
4
|
try |
| 248 |
|
{ |
| 249 |
4
|
int b1 = read() & 0xff; |
| 250 |
4
|
int b2 = read() & 0xff; |
| 251 |
4
|
if (b1 == 0x47 && b2 == 0x49) |
| 252 |
|
{ |
| 253 |
0
|
return checkGif(); |
| 254 |
|
} |
| 255 |
4
|
else if (b1 == 0x89 && b2 == 0x50) |
| 256 |
|
{ |
| 257 |
1
|
return checkPng(); |
| 258 |
|
} |
| 259 |
3
|
else if (b1 == 0xff && b2 == 0xd8) |
| 260 |
|
{ |
| 261 |
3
|
return checkJpeg(); |
| 262 |
|
} |
| 263 |
0
|
else if (b1 == 0x42 && b2 == 0x4d) |
| 264 |
|
{ |
| 265 |
0
|
return checkBmp(); |
| 266 |
|
} |
| 267 |
0
|
else if (b1 == 0x0a && b2 < 0x06) |
| 268 |
|
{ |
| 269 |
0
|
return checkPcx(); |
| 270 |
|
} |
| 271 |
0
|
else if (b1 == 0x46 && b2 == 0x4f) |
| 272 |
|
{ |
| 273 |
0
|
return checkIff(); |
| 274 |
|
} |
| 275 |
0
|
else if (b1 == 0x59 && b2 == 0xa6) |
| 276 |
|
{ |
| 277 |
0
|
return checkRas(); |
| 278 |
|
} |
| 279 |
0
|
else if (b1 == 0x50 && b2 >= 0x31 && b2 <= 0x36) |
| 280 |
|
{ |
| 281 |
0
|
return checkPnm(b2 - '0'); |
| 282 |
|
} |
| 283 |
0
|
else if (b1 == 0x38 && b2 == 0x42) |
| 284 |
|
{ |
| 285 |
0
|
return checkPsd(); |
| 286 |
|
} |
| 287 |
0
|
else if (b1 == 0x46 && b2 == 0x57) |
| 288 |
|
{ |
| 289 |
0
|
return checkSwf(); |
| 290 |
|
} |
| 291 |
|
else |
| 292 |
|
{ |
| 293 |
0
|
return false; |
| 294 |
|
} |
| 295 |
|
} |
| 296 |
|
catch (IOException ioe) |
| 297 |
|
{ |
| 298 |
1
|
return false; |
| 299 |
|
} |
| 300 |
|
} |
| 301 |
|
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 12 |
Complexity Density: 0.67 |
|
| 302 |
0
|
private boolean checkBmp() throws IOException... |
| 303 |
|
{ |
| 304 |
0
|
byte[] a = new byte[44]; |
| 305 |
0
|
if (read(a) != a.length) |
| 306 |
|
{ |
| 307 |
0
|
return false; |
| 308 |
|
} |
| 309 |
0
|
width = getIntLittleEndian(a, 16); |
| 310 |
0
|
height = getIntLittleEndian(a, 20); |
| 311 |
0
|
if (width < 1 || height < 1) |
| 312 |
|
{ |
| 313 |
0
|
return false; |
| 314 |
|
} |
| 315 |
0
|
bitsPerPixel = getShortLittleEndian(a, 26); |
| 316 |
0
|
if (bitsPerPixel != 1 && bitsPerPixel != 4 && bitsPerPixel != 8 && bitsPerPixel != 16 && bitsPerPixel != 24 |
| 317 |
|
&& bitsPerPixel != 32) |
| 318 |
|
{ |
| 319 |
0
|
return false; |
| 320 |
|
} |
| 321 |
0
|
int x = (int) (getIntLittleEndian(a, 36) * 0.0254); |
| 322 |
0
|
if (x > 0) |
| 323 |
|
{ |
| 324 |
0
|
setPhysicalWidthDpi(x); |
| 325 |
|
} |
| 326 |
0
|
int y = (int) (getIntLittleEndian(a, 40) * 0.0254); |
| 327 |
0
|
if (y > 0) |
| 328 |
|
{ |
| 329 |
0
|
setPhysicalHeightDpi(y); |
| 330 |
|
} |
| 331 |
0
|
format = FORMAT_BMP; |
| 332 |
0
|
return true; |
| 333 |
|
} |
| 334 |
|
|
|
|
|
| 0% |
Uncovered Elements: 110 (110) |
Complexity: 26 |
Complexity Density: 0.37 |
|
| 335 |
0
|
private boolean checkGif() throws IOException... |
| 336 |
|
{ |
| 337 |
0
|
final byte[] GIF_MAGIC_87A = { 0x46, 0x38, 0x37, 0x61 }; |
| 338 |
0
|
final byte[] GIF_MAGIC_89A = { 0x46, 0x38, 0x39, 0x61 }; |
| 339 |
0
|
byte[] a = new byte[11]; |
| 340 |
0
|
if (read(a) != 11) |
| 341 |
|
{ |
| 342 |
0
|
return false; |
| 343 |
|
} |
| 344 |
0
|
if ((!equals(a, 0, GIF_MAGIC_89A, 0, 4)) && (!equals(a, 0, GIF_MAGIC_87A, 0, 4))) |
| 345 |
|
{ |
| 346 |
0
|
return false; |
| 347 |
|
} |
| 348 |
0
|
format = FORMAT_GIF; |
| 349 |
0
|
width = getShortLittleEndian(a, 4); |
| 350 |
0
|
height = getShortLittleEndian(a, 6); |
| 351 |
0
|
int flags = a[8] & 0xff; |
| 352 |
0
|
bitsPerPixel = ((flags >> 4) & 0x07) + 1; |
| 353 |
|
|
| 354 |
0
|
if (!determineNumberOfImages) |
| 355 |
|
{ |
| 356 |
0
|
return true; |
| 357 |
|
} |
| 358 |
|
|
| 359 |
0
|
if ((flags & 0x80) != 0) |
| 360 |
|
{ |
| 361 |
0
|
int tableSize = (1 << ((flags & 7) + 1)) * 3; |
| 362 |
0
|
skip(tableSize); |
| 363 |
|
} |
| 364 |
0
|
numberOfImages = 0; |
| 365 |
0
|
int blockType; |
| 366 |
0
|
do |
| 367 |
|
{ |
| 368 |
0
|
blockType = read(); |
| 369 |
0
|
switch (blockType) |
| 370 |
|
{ |
| 371 |
0
|
case (0x2c): |
| 372 |
|
{ |
| 373 |
0
|
if (read(a, 0, 9) != 9) |
| 374 |
|
{ |
| 375 |
0
|
return false; |
| 376 |
|
} |
| 377 |
0
|
flags = a[8] & 0xff; |
| 378 |
0
|
progressive = (flags & 0x40) != 0; |
| 379 |
0
|
int localBitsPerPixel = (flags & 0x07) + 1; |
| 380 |
0
|
if (localBitsPerPixel > bitsPerPixel) |
| 381 |
|
{ |
| 382 |
0
|
bitsPerPixel = localBitsPerPixel; |
| 383 |
|
} |
| 384 |
0
|
if ((flags & 0x80) != 0) |
| 385 |
|
{ |
| 386 |
0
|
skip((1 << localBitsPerPixel) * 3); |
| 387 |
|
} |
| 388 |
0
|
skip(1); |
| 389 |
0
|
int n; |
| 390 |
0
|
do |
| 391 |
|
{ |
| 392 |
0
|
n = read(); |
| 393 |
0
|
if (n > 0) |
| 394 |
|
{ |
| 395 |
0
|
skip(n); |
| 396 |
|
} |
| 397 |
0
|
else if (n == -1) |
| 398 |
|
{ |
| 399 |
0
|
return false; |
| 400 |
|
} |
| 401 |
|
} |
| 402 |
0
|
while (n > 0); |
| 403 |
0
|
numberOfImages++; |
| 404 |
0
|
break; |
| 405 |
|
} |
| 406 |
0
|
case (0x21): |
| 407 |
|
{ |
| 408 |
0
|
int extensionType = read(); |
| 409 |
0
|
if (collectComments && extensionType == 0xfe) |
| 410 |
|
{ |
| 411 |
0
|
StringBuffer sb = new StringBuffer(); |
| 412 |
0
|
int n; |
| 413 |
0
|
do |
| 414 |
|
{ |
| 415 |
0
|
n = read(); |
| 416 |
0
|
if (n == -1) |
| 417 |
|
{ |
| 418 |
0
|
return false; |
| 419 |
|
} |
| 420 |
0
|
if (n > 0) |
| 421 |
|
{ |
| 422 |
0
|
for (int i = 0; i < n; i++) |
| 423 |
|
{ |
| 424 |
0
|
int ch = read(); |
| 425 |
0
|
if (ch == -1) |
| 426 |
|
{ |
| 427 |
0
|
return false; |
| 428 |
|
} |
| 429 |
0
|
sb.append((char) ch); |
| 430 |
|
} |
| 431 |
|
} |
| 432 |
|
} |
| 433 |
0
|
while (n > 0); |
| 434 |
|
} |
| 435 |
|
else |
| 436 |
|
{ |
| 437 |
0
|
int n; |
| 438 |
0
|
do |
| 439 |
|
{ |
| 440 |
0
|
n = read(); |
| 441 |
0
|
if (n > 0) |
| 442 |
|
{ |
| 443 |
0
|
skip(n); |
| 444 |
|
} |
| 445 |
0
|
else if (n == -1) |
| 446 |
|
{ |
| 447 |
0
|
return false; |
| 448 |
|
} |
| 449 |
|
} |
| 450 |
0
|
while (n > 0); |
| 451 |
|
} |
| 452 |
0
|
break; |
| 453 |
|
} |
| 454 |
0
|
case (0x3b): |
| 455 |
|
{ |
| 456 |
0
|
break; |
| 457 |
|
} |
| 458 |
0
|
default: |
| 459 |
|
{ |
| 460 |
0
|
return false; |
| 461 |
|
} |
| 462 |
|
} |
| 463 |
|
} |
| 464 |
0
|
while (blockType != 0x3b); |
| 465 |
0
|
return true; |
| 466 |
|
} |
| 467 |
|
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 10 |
Complexity Density: 0.4 |
|
| 468 |
0
|
private boolean checkIff() throws IOException... |
| 469 |
|
{ |
| 470 |
0
|
byte[] a = new byte[10]; |
| 471 |
|
|
| 472 |
|
|
| 473 |
0
|
if (read(a, 0, 10) != 10) |
| 474 |
|
{ |
| 475 |
0
|
return false; |
| 476 |
|
} |
| 477 |
0
|
final byte[] IFF_RM = { 0x52, 0x4d }; |
| 478 |
0
|
if (!equals(a, 0, IFF_RM, 0, 2)) |
| 479 |
|
{ |
| 480 |
0
|
return false; |
| 481 |
|
} |
| 482 |
0
|
int type = getIntBigEndian(a, 6); |
| 483 |
0
|
if (type != 0x494c424d && |
| 484 |
|
type != 0x50424d20) |
| 485 |
|
{ |
| 486 |
0
|
return false; |
| 487 |
|
} |
| 488 |
|
|
| 489 |
0
|
do |
| 490 |
|
{ |
| 491 |
0
|
if (read(a, 0, 8) != 8) |
| 492 |
|
{ |
| 493 |
0
|
return false; |
| 494 |
|
} |
| 495 |
0
|
int chunkId = getIntBigEndian(a, 0); |
| 496 |
0
|
int size = getIntBigEndian(a, 4); |
| 497 |
0
|
if ((size & 1) == 1) |
| 498 |
|
{ |
| 499 |
0
|
size++; |
| 500 |
|
} |
| 501 |
0
|
if (chunkId == 0x424d4844) |
| 502 |
|
{ |
| 503 |
0
|
if (read(a, 0, 9) != 9) |
| 504 |
|
{ |
| 505 |
0
|
return false; |
| 506 |
|
} |
| 507 |
0
|
format = FORMAT_IFF; |
| 508 |
0
|
width = getShortBigEndian(a, 0); |
| 509 |
0
|
height = getShortBigEndian(a, 2); |
| 510 |
0
|
bitsPerPixel = a[8] & 0xff; |
| 511 |
0
|
return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel < 33); |
| 512 |
|
} |
| 513 |
|
else |
| 514 |
|
{ |
| 515 |
0
|
skip(size); |
| 516 |
|
} |
| 517 |
|
} |
| 518 |
|
while (true); |
| 519 |
|
} |
| 520 |
|
|
|
|
|
| 56.1% |
Uncovered Elements: 29 (66) |
Complexity: 19 |
Complexity Density: 0.45 |
|
| 521 |
3
|
private boolean checkJpeg() throws IOException... |
| 522 |
|
{ |
| 523 |
3
|
byte[] data = new byte[12]; |
| 524 |
3
|
while (true) |
| 525 |
|
{ |
| 526 |
10
|
if (read(data, 0, 4) != 4) |
| 527 |
|
{ |
| 528 |
0
|
return false; |
| 529 |
|
} |
| 530 |
10
|
int marker = getShortBigEndian(data, 0); |
| 531 |
10
|
int size = getShortBigEndian(data, 2); |
| 532 |
10
|
if ((marker & 0xff00) != 0xff00) |
| 533 |
|
{ |
| 534 |
0
|
return false; |
| 535 |
|
} |
| 536 |
10
|
if (marker == 0xffe0) |
| 537 |
|
{ |
| 538 |
3
|
if (size < 14) |
| 539 |
|
{ |
| 540 |
0
|
return false; |
| 541 |
|
} |
| 542 |
3
|
if (read(data, 0, 12) != 12) |
| 543 |
|
{ |
| 544 |
0
|
return false; |
| 545 |
|
} |
| 546 |
3
|
final byte[] APP0_ID = { 0x4a, 0x46, 0x49, 0x46, 0x00 }; |
| 547 |
3
|
if (equals(APP0_ID, 0, data, 0, 5)) |
| 548 |
|
{ |
| 549 |
3
|
if (data[7] == 1) |
| 550 |
|
{ |
| 551 |
0
|
setPhysicalWidthDpi(getShortBigEndian(data, 8)); |
| 552 |
0
|
setPhysicalHeightDpi(getShortBigEndian(data, 10)); |
| 553 |
|
} |
| 554 |
3
|
else if (data[7] == 2) |
| 555 |
|
{ |
| 556 |
0
|
int x = getShortBigEndian(data, 8); |
| 557 |
0
|
int y = getShortBigEndian(data, 10); |
| 558 |
0
|
setPhysicalWidthDpi((int) (x * 2.54f)); |
| 559 |
0
|
setPhysicalHeightDpi((int) (y * 2.54f)); |
| 560 |
|
} |
| 561 |
|
} |
| 562 |
3
|
skip(size - 14); |
| 563 |
|
} |
| 564 |
7
|
else if (collectComments && size > 2 && marker == 0xfffe) |
| 565 |
|
{ |
| 566 |
0
|
size -= 2; |
| 567 |
0
|
byte[] chars = new byte[size]; |
| 568 |
0
|
if (read(chars, 0, size) != size) |
| 569 |
|
{ |
| 570 |
0
|
return false; |
| 571 |
|
} |
| 572 |
0
|
String comment = new String(chars, "iso-8859-1"); |
| 573 |
0
|
comment = comment.trim(); |
| 574 |
0
|
addComment(comment); |
| 575 |
|
} |
| 576 |
7
|
else if (marker >= 0xffc0 && marker <= 0xffcf && marker != 0xffc4 && marker != 0xffc8) |
| 577 |
|
{ |
| 578 |
2
|
if (read(data, 0, 6) != 6) |
| 579 |
|
{ |
| 580 |
0
|
return false; |
| 581 |
|
} |
| 582 |
2
|
format = FORMAT_JPEG; |
| 583 |
2
|
bitsPerPixel = (data[0] & 0xff) * (data[5] & 0xff); |
| 584 |
2
|
progressive = marker == 0xffc2 || marker == 0xffc6 || marker == 0xffca || marker == 0xffce; |
| 585 |
2
|
width = getShortBigEndian(data, 3); |
| 586 |
2
|
height = getShortBigEndian(data, 1); |
| 587 |
2
|
return true; |
| 588 |
|
} |
| 589 |
|
else |
| 590 |
|
{ |
| 591 |
5
|
skip(size - 2); |
| 592 |
|
} |
| 593 |
|
} |
| 594 |
|
} |
| 595 |
|
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 14 |
Complexity Density: 0.58 |
|
| 596 |
0
|
private boolean checkPcx() throws IOException... |
| 597 |
|
{ |
| 598 |
0
|
byte[] a = new byte[64]; |
| 599 |
0
|
if (read(a) != a.length) |
| 600 |
|
{ |
| 601 |
0
|
return false; |
| 602 |
|
} |
| 603 |
0
|
if (a[0] != 1) |
| 604 |
|
{ |
| 605 |
0
|
return false; |
| 606 |
|
} |
| 607 |
|
|
| 608 |
0
|
int x1 = getShortLittleEndian(a, 2); |
| 609 |
0
|
int y1 = getShortLittleEndian(a, 4); |
| 610 |
0
|
int x2 = getShortLittleEndian(a, 6); |
| 611 |
0
|
int y2 = getShortLittleEndian(a, 8); |
| 612 |
0
|
if (x1 < 0 || x2 < x1 || y1 < 0 || y2 < y1) |
| 613 |
|
{ |
| 614 |
0
|
return false; |
| 615 |
|
} |
| 616 |
0
|
width = x2 - x1 + 1; |
| 617 |
0
|
height = y2 - y1 + 1; |
| 618 |
|
|
| 619 |
0
|
int bits = a[1]; |
| 620 |
0
|
int planes = a[63]; |
| 621 |
0
|
if (planes == 1 && (bits == 1 || bits == 2 || bits == 4 || bits == 8)) |
| 622 |
|
{ |
| 623 |
|
|
| 624 |
0
|
bitsPerPixel = bits; |
| 625 |
|
} |
| 626 |
0
|
else if (planes == 3 && bits == 8) |
| 627 |
|
{ |
| 628 |
|
|
| 629 |
0
|
bitsPerPixel = 24; |
| 630 |
|
} |
| 631 |
|
else |
| 632 |
|
{ |
| 633 |
0
|
return false; |
| 634 |
|
} |
| 635 |
0
|
setPhysicalWidthDpi(getShortLittleEndian(a, 10)); |
| 636 |
0
|
setPhysicalHeightDpi(getShortLittleEndian(a, 10)); |
| 637 |
0
|
format = FORMAT_PCX; |
| 638 |
0
|
return true; |
| 639 |
|
} |
| 640 |
|
|
|
|
|
| 76.2% |
Uncovered Elements: 5 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
| 641 |
1
|
private boolean checkPng() throws IOException... |
| 642 |
|
{ |
| 643 |
1
|
final byte[] PNG_MAGIC = { 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; |
| 644 |
1
|
byte[] a = new byte[27]; |
| 645 |
1
|
if (read(a) != 27) |
| 646 |
|
{ |
| 647 |
0
|
return false; |
| 648 |
|
} |
| 649 |
1
|
if (!equals(a, 0, PNG_MAGIC, 0, 6)) |
| 650 |
|
{ |
| 651 |
0
|
return false; |
| 652 |
|
} |
| 653 |
1
|
format = FORMAT_PNG; |
| 654 |
1
|
width = getIntBigEndian(a, 14); |
| 655 |
1
|
height = getIntBigEndian(a, 18); |
| 656 |
1
|
bitsPerPixel = a[22] & 0xff; |
| 657 |
1
|
int colorType = a[23] & 0xff; |
| 658 |
1
|
if (colorType == 2 || colorType == 6) |
| 659 |
|
{ |
| 660 |
1
|
bitsPerPixel *= 3; |
| 661 |
|
} |
| 662 |
1
|
progressive = (a[26] & 0xff) != 0; |
| 663 |
1
|
return true; |
| 664 |
|
} |
| 665 |
|
|
|
|
|
| 0% |
Uncovered Elements: 76 (76) |
Complexity: 22 |
Complexity Density: 0.46 |
|
| 666 |
0
|
private boolean checkPnm(int id) throws IOException... |
| 667 |
|
{ |
| 668 |
0
|
if (id < 1 || id > 6) |
| 669 |
|
{ |
| 670 |
0
|
return false; |
| 671 |
|
} |
| 672 |
0
|
final int[] PNM_FORMATS = { FORMAT_PBM, FORMAT_PGM, FORMAT_PPM }; |
| 673 |
0
|
format = PNM_FORMATS[(id - 1) % 3]; |
| 674 |
0
|
boolean hasPixelResolution = false; |
| 675 |
0
|
String s; |
| 676 |
0
|
while (true) |
| 677 |
|
{ |
| 678 |
0
|
s = readLine(); |
| 679 |
0
|
if (s != null) |
| 680 |
|
{ |
| 681 |
0
|
s = s.trim(); |
| 682 |
|
} |
| 683 |
0
|
if (s == null || s.length() < 1) |
| 684 |
|
{ |
| 685 |
0
|
continue; |
| 686 |
|
} |
| 687 |
0
|
if (s.charAt(0) == '#') |
| 688 |
|
{ |
| 689 |
0
|
if (collectComments && s.length() > 1) |
| 690 |
|
{ |
| 691 |
0
|
addComment(s.substring(1)); |
| 692 |
|
} |
| 693 |
0
|
continue; |
| 694 |
|
} |
| 695 |
0
|
if (!hasPixelResolution) |
| 696 |
|
{ |
| 697 |
0
|
int spaceIndex = s.indexOf(' '); |
| 698 |
0
|
if (spaceIndex == -1) |
| 699 |
|
{ |
| 700 |
0
|
return false; |
| 701 |
|
} |
| 702 |
0
|
String widthString = s.substring(0, spaceIndex); |
| 703 |
0
|
spaceIndex = s.lastIndexOf(' '); |
| 704 |
0
|
if (spaceIndex == -1) |
| 705 |
|
{ |
| 706 |
0
|
return false; |
| 707 |
|
} |
| 708 |
0
|
String heightString = s.substring(spaceIndex + 1); |
| 709 |
0
|
try |
| 710 |
|
{ |
| 711 |
0
|
width = Integer.parseInt(widthString); |
| 712 |
0
|
height = Integer.parseInt(heightString); |
| 713 |
|
} |
| 714 |
|
catch (NumberFormatException nfe) |
| 715 |
|
{ |
| 716 |
0
|
return false; |
| 717 |
|
} |
| 718 |
0
|
if (width < 1 || height < 1) |
| 719 |
|
{ |
| 720 |
0
|
return false; |
| 721 |
|
} |
| 722 |
0
|
if (format == FORMAT_PBM) |
| 723 |
|
{ |
| 724 |
0
|
bitsPerPixel = 1; |
| 725 |
0
|
return true; |
| 726 |
|
} |
| 727 |
0
|
hasPixelResolution = true; |
| 728 |
|
} |
| 729 |
|
else |
| 730 |
|
{ |
| 731 |
0
|
int maxSample; |
| 732 |
0
|
try |
| 733 |
|
{ |
| 734 |
0
|
maxSample = Integer.parseInt(s); |
| 735 |
|
} |
| 736 |
|
catch (NumberFormatException nfe) |
| 737 |
|
{ |
| 738 |
0
|
return false; |
| 739 |
|
} |
| 740 |
0
|
if (maxSample < 0) |
| 741 |
|
{ |
| 742 |
0
|
return false; |
| 743 |
|
} |
| 744 |
0
|
for (int i = 0; i < 25; i++) |
| 745 |
|
{ |
| 746 |
0
|
if (maxSample < (1 << (i + 1))) |
| 747 |
|
{ |
| 748 |
0
|
bitsPerPixel = i + 1; |
| 749 |
0
|
if (format == FORMAT_PPM) |
| 750 |
|
{ |
| 751 |
0
|
bitsPerPixel *= 3; |
| 752 |
|
} |
| 753 |
0
|
return true; |
| 754 |
|
} |
| 755 |
|
} |
| 756 |
0
|
return false; |
| 757 |
|
} |
| 758 |
|
} |
| 759 |
|
} |
| 760 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 761 |
0
|
private boolean checkPsd() throws IOException... |
| 762 |
|
{ |
| 763 |
0
|
byte[] a = new byte[24]; |
| 764 |
0
|
if (read(a) != a.length) |
| 765 |
|
{ |
| 766 |
0
|
return false; |
| 767 |
|
} |
| 768 |
0
|
final byte[] PSD_MAGIC = { 0x50, 0x53 }; |
| 769 |
0
|
if (!equals(a, 0, PSD_MAGIC, 0, 2)) |
| 770 |
|
{ |
| 771 |
0
|
return false; |
| 772 |
|
} |
| 773 |
0
|
format = FORMAT_PSD; |
| 774 |
0
|
width = getIntBigEndian(a, 16); |
| 775 |
0
|
height = getIntBigEndian(a, 12); |
| 776 |
0
|
int channels = getShortBigEndian(a, 10); |
| 777 |
0
|
int depth = getShortBigEndian(a, 20); |
| 778 |
0
|
bitsPerPixel = channels * depth; |
| 779 |
0
|
return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 64); |
| 780 |
|
} |
| 781 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 782 |
0
|
private boolean checkRas() throws IOException... |
| 783 |
|
{ |
| 784 |
0
|
byte[] a = new byte[14]; |
| 785 |
0
|
if (read(a) != a.length) |
| 786 |
|
{ |
| 787 |
0
|
return false; |
| 788 |
|
} |
| 789 |
0
|
final byte[] RAS_MAGIC = { 0x6a, (byte) 0x95 }; |
| 790 |
0
|
if (!equals(a, 0, RAS_MAGIC, 0, 2)) |
| 791 |
|
{ |
| 792 |
0
|
return false; |
| 793 |
|
} |
| 794 |
0
|
format = FORMAT_RAS; |
| 795 |
0
|
width = getIntBigEndian(a, 2); |
| 796 |
0
|
height = getIntBigEndian(a, 6); |
| 797 |
0
|
bitsPerPixel = getIntBigEndian(a, 10); |
| 798 |
0
|
return (width > 0 && height > 0 && bitsPerPixel > 0 && bitsPerPixel <= 24); |
| 799 |
|
} |
| 800 |
|
|
| 801 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
| 802 |
0
|
private boolean checkSwf() throws IOException... |
| 803 |
|
{ |
| 804 |
|
|
| 805 |
0
|
byte[] a = new byte[6]; |
| 806 |
0
|
if (read(a) != a.length) |
| 807 |
|
{ |
| 808 |
0
|
return false; |
| 809 |
|
} |
| 810 |
0
|
format = FORMAT_SWF; |
| 811 |
0
|
int bitSize = (int) readUBits(5); |
| 812 |
0
|
int maxX = readSBits(bitSize); |
| 813 |
0
|
int maxY = readSBits(bitSize); |
| 814 |
0
|
width = maxX / 20; |
| 815 |
0
|
height = maxY / 20; |
| 816 |
0
|
setPhysicalWidthDpi(72); |
| 817 |
0
|
setPhysicalHeightDpi(72); |
| 818 |
0
|
return (width > 0 && height > 0); |
| 819 |
|
} |
| 820 |
|
|
| 821 |
|
|
| 822 |
|
|
| 823 |
|
|
| 824 |
|
@param |
| 825 |
|
|
| 826 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 1 |
|
| 827 |
0
|
private static boolean determineVerbosity(String[] args)... |
| 828 |
|
{ |
| 829 |
0
|
if (args != null && args.length > 0) |
| 830 |
|
{ |
| 831 |
0
|
for (int i = 0; i < args.length; i++) |
| 832 |
|
{ |
| 833 |
0
|
if ("-c".equals(args[i])) |
| 834 |
|
{ |
| 835 |
0
|
return false; |
| 836 |
|
} |
| 837 |
|
} |
| 838 |
|
} |
| 839 |
0
|
return true; |
| 840 |
|
} |
| 841 |
|
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 842 |
4
|
private static boolean equals(byte[] a1, int offs1, byte[] a2, int offs2, int num)... |
| 843 |
|
{ |
| 844 |
25
|
while (num-- > 0) |
| 845 |
|
{ |
| 846 |
21
|
if (a1[offs1++] != a2[offs2++]) |
| 847 |
|
{ |
| 848 |
0
|
return false; |
| 849 |
|
} |
| 850 |
|
} |
| 851 |
4
|
return true; |
| 852 |
|
} |
| 853 |
|
|
| 854 |
|
|
| 855 |
|
@link |
| 856 |
|
|
| 857 |
|
|
| 858 |
|
@return |
| 859 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 860 |
0
|
public int getBitsPerPixel()... |
| 861 |
|
{ |
| 862 |
0
|
return bitsPerPixel; |
| 863 |
|
} |
| 864 |
|
|
| 865 |
|
|
| 866 |
|
|
| 867 |
|
|
| 868 |
|
@param |
| 869 |
|
|
| 870 |
|
@throws |
| 871 |
|
|
| 872 |
|
@see |
| 873 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
| 874 |
0
|
public String getComment(int index)... |
| 875 |
|
{ |
| 876 |
0
|
if (comments == null || index < 0 || index >= comments.size()) |
| 877 |
|
{ |
| 878 |
0
|
throw new IllegalArgumentException("Not a valid comment index: " + index); |
| 879 |
|
} |
| 880 |
0
|
return (String) comments.elementAt(index); |
| 881 |
|
} |
| 882 |
|
|
| 883 |
|
|
| 884 |
|
@link |
| 885 |
|
@link |
| 886 |
|
|
| 887 |
|
@return |
| 888 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 889 |
0
|
public int getFormat()... |
| 890 |
|
{ |
| 891 |
0
|
return format; |
| 892 |
|
} |
| 893 |
|
|
| 894 |
|
|
| 895 |
|
@link@link |
| 896 |
|
|
| 897 |
|
|
| 898 |
|
@return |
| 899 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 900 |
0
|
public String getFormatName()... |
| 901 |
|
{ |
| 902 |
0
|
if (format >= 0 && format < FORMAT_NAMES.length) |
| 903 |
|
{ |
| 904 |
0
|
return FORMAT_NAMES[format]; |
| 905 |
|
} |
| 906 |
|
else |
| 907 |
|
{ |
| 908 |
0
|
return "?"; |
| 909 |
|
} |
| 910 |
|
} |
| 911 |
|
|
| 912 |
|
|
| 913 |
|
@link |
| 914 |
|
|
| 915 |
|
@return |
| 916 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 917 |
0
|
public int getHeight()... |
| 918 |
|
{ |
| 919 |
0
|
return height; |
| 920 |
|
} |
| 921 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 922 |
2
|
private static int getIntBigEndian(byte[] a, int offs)... |
| 923 |
|
{ |
| 924 |
2
|
return (a[offs] & 0xff) << 24 | (a[offs + 1] & 0xff) << 16 | (a[offs + 2] & 0xff) << 8 | a[offs + 3] & 0xff; |
| 925 |
|
} |
| 926 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 927 |
0
|
private static int getIntLittleEndian(byte[] a, int offs)... |
| 928 |
|
{ |
| 929 |
0
|
return (a[offs + 3] & 0xff) << 24 | (a[offs + 2] & 0xff) << 16 | (a[offs + 1] & 0xff) << 8 | a[offs] & 0xff; |
| 930 |
|
} |
| 931 |
|
|
| 932 |
|
|
| 933 |
|
@link |
| 934 |
|
|
| 935 |
|
@return |
| 936 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
| 937 |
0
|
public String getMimeType()... |
| 938 |
|
{ |
| 939 |
0
|
if (format >= 0 && format < MIME_TYPE_STRINGS.length) |
| 940 |
|
{ |
| 941 |
0
|
if (format == FORMAT_JPEG && progressive) |
| 942 |
|
{ |
| 943 |
0
|
return "image/pjpeg"; |
| 944 |
|
} |
| 945 |
0
|
return MIME_TYPE_STRINGS[format]; |
| 946 |
|
} |
| 947 |
|
else |
| 948 |
|
{ |
| 949 |
0
|
return null; |
| 950 |
|
} |
| 951 |
|
} |
| 952 |
|
|
| 953 |
|
|
| 954 |
|
@link@link |
| 955 |
|
|
| 956 |
|
@link |
| 957 |
|
|
| 958 |
|
@return |
| 959 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 960 |
0
|
public int getNumberOfComments()... |
| 961 |
|
{ |
| 962 |
0
|
if (comments == null) |
| 963 |
|
{ |
| 964 |
0
|
return 0; |
| 965 |
|
} |
| 966 |
|
else |
| 967 |
|
{ |
| 968 |
0
|
return comments.size(); |
| 969 |
|
} |
| 970 |
|
} |
| 971 |
|
|
| 972 |
|
|
| 973 |
|
|
| 974 |
|
@link |
| 975 |
|
|
| 976 |
|
|
| 977 |
|
@return |
| 978 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 979 |
0
|
public int getNumberOfImages()... |
| 980 |
|
{ |
| 981 |
0
|
return numberOfImages; |
| 982 |
|
} |
| 983 |
|
|
| 984 |
|
|
| 985 |
|
@link |
| 986 |
|
|
| 987 |
|
|
| 988 |
|
@return |
| 989 |
|
@see |
| 990 |
|
@see |
| 991 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 992 |
0
|
public int getPhysicalHeightDpi()... |
| 993 |
|
{ |
| 994 |
0
|
return physicalHeightDpi; |
| 995 |
|
} |
| 996 |
|
|
| 997 |
|
|
| 998 |
|
@link |
| 999 |
|
|
| 1000 |
|
|
| 1001 |
|
@return |
| 1002 |
|
@see |
| 1003 |
|
@see |
| 1004 |
|
@see |
| 1005 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 1006 |
0
|
public float getPhysicalHeightInch()... |
| 1007 |
|
{ |
| 1008 |
0
|
int h = getHeight(); |
| 1009 |
0
|
int ph = getPhysicalHeightDpi(); |
| 1010 |
0
|
if (h > 0 && ph > 0) |
| 1011 |
|
{ |
| 1012 |
0
|
return ((float) h) / ((float) ph); |
| 1013 |
|
} |
| 1014 |
|
else |
| 1015 |
|
{ |
| 1016 |
0
|
return -1.0f; |
| 1017 |
|
} |
| 1018 |
|
} |
| 1019 |
|
|
| 1020 |
|
|
| 1021 |
|
@link |
| 1022 |
|
|
| 1023 |
|
|
| 1024 |
|
@return |
| 1025 |
|
@see |
| 1026 |
|
@see |
| 1027 |
|
@see |
| 1028 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1029 |
0
|
public int getPhysicalWidthDpi()... |
| 1030 |
|
{ |
| 1031 |
0
|
return physicalWidthDpi; |
| 1032 |
|
} |
| 1033 |
|
|
| 1034 |
|
|
| 1035 |
|
|
| 1036 |
|
@link |
| 1037 |
|
|
| 1038 |
|
@return |
| 1039 |
|
@see |
| 1040 |
|
@see |
| 1041 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 1042 |
0
|
public float getPhysicalWidthInch()... |
| 1043 |
|
{ |
| 1044 |
0
|
int w = getWidth(); |
| 1045 |
0
|
int pw = getPhysicalWidthDpi(); |
| 1046 |
0
|
if (w > 0 && pw > 0) |
| 1047 |
|
{ |
| 1048 |
0
|
return ((float) w) / ((float) pw); |
| 1049 |
|
} |
| 1050 |
|
else |
| 1051 |
|
{ |
| 1052 |
0
|
return -1.0f; |
| 1053 |
|
} |
| 1054 |
|
} |
| 1055 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1056 |
24
|
private static int getShortBigEndian(byte[] a, int offs)... |
| 1057 |
|
{ |
| 1058 |
24
|
return (a[offs] & 0xff) << 8 | (a[offs + 1] & 0xff); |
| 1059 |
|
} |
| 1060 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1061 |
0
|
private static int getShortLittleEndian(byte[] a, int offs)... |
| 1062 |
|
{ |
| 1063 |
0
|
return (a[offs] & 0xff) | (a[offs + 1] & 0xff) << 8; |
| 1064 |
|
} |
| 1065 |
|
|
| 1066 |
|
|
| 1067 |
|
@link |
| 1068 |
|
|
| 1069 |
|
@return |
| 1070 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1071 |
0
|
public int getWidth()... |
| 1072 |
|
{ |
| 1073 |
0
|
return width; |
| 1074 |
|
} |
| 1075 |
|
|
| 1076 |
|
|
| 1077 |
|
|
| 1078 |
|
|
| 1079 |
|
@return |
| 1080 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1081 |
0
|
public boolean isProgressive()... |
| 1082 |
|
{ |
| 1083 |
0
|
return progressive; |
| 1084 |
|
} |
| 1085 |
|
|
| 1086 |
|
|
| 1087 |
|
|
| 1088 |
|
|
| 1089 |
|
|
| 1090 |
|
|
| 1091 |
|
@param |
| 1092 |
|
|
| 1093 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.33 |
|
| 1094 |
0
|
public static void main(String[] args)... |
| 1095 |
|
{ |
| 1096 |
0
|
ImageInfo imageInfo = new ImageInfo(); |
| 1097 |
0
|
imageInfo.setDetermineImageNumber(true); |
| 1098 |
0
|
boolean verbose = determineVerbosity(args); |
| 1099 |
0
|
if (args.length == 0) |
| 1100 |
|
{ |
| 1101 |
0
|
run(null, System.in, imageInfo, verbose); |
| 1102 |
|
} |
| 1103 |
|
else |
| 1104 |
|
{ |
| 1105 |
0
|
int index = 0; |
| 1106 |
0
|
while (index < args.length) |
| 1107 |
|
{ |
| 1108 |
0
|
InputStream in = null; |
| 1109 |
0
|
try |
| 1110 |
|
{ |
| 1111 |
0
|
String name = args[index++]; |
| 1112 |
0
|
System.out.print(name + ";"); |
| 1113 |
0
|
if (name.startsWith("http://")) |
| 1114 |
|
{ |
| 1115 |
0
|
in = new URL(name).openConnection().getInputStream(); |
| 1116 |
|
} |
| 1117 |
|
else |
| 1118 |
|
{ |
| 1119 |
0
|
in = new FileInputStream(name); |
| 1120 |
|
} |
| 1121 |
0
|
run(name, in, imageInfo, verbose); |
| 1122 |
0
|
in.close(); |
| 1123 |
|
} |
| 1124 |
|
catch (IOException e) |
| 1125 |
|
{ |
| 1126 |
0
|
try |
| 1127 |
|
{ |
| 1128 |
0
|
in.close(); |
| 1129 |
|
} |
| 1130 |
|
catch (IOException ee) |
| 1131 |
|
{ |
| 1132 |
|
} |
| 1133 |
|
} |
| 1134 |
|
} |
| 1135 |
|
} |
| 1136 |
|
} |
| 1137 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 1138 |
0
|
private static void print(String sourceName, ImageInfo ii, boolean verbose)... |
| 1139 |
|
{ |
| 1140 |
0
|
if (verbose) |
| 1141 |
|
{ |
| 1142 |
0
|
printVerbose(sourceName, ii); |
| 1143 |
|
} |
| 1144 |
|
else |
| 1145 |
|
{ |
| 1146 |
0
|
printCompact(sourceName, ii); |
| 1147 |
|
} |
| 1148 |
|
} |
| 1149 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1150 |
0
|
private static void printCompact(String sourceName, ImageInfo imageInfo)... |
| 1151 |
|
{ |
| 1152 |
0
|
final String SEP = "\t"; |
| 1153 |
0
|
System.out.println(sourceName + SEP + imageInfo.getFormatName() + SEP + imageInfo.getMimeType() + SEP |
| 1154 |
|
+ imageInfo.getWidth() + SEP + imageInfo.getHeight() + SEP + imageInfo.getBitsPerPixel() + SEP |
| 1155 |
|
+ imageInfo.getNumberOfImages() + SEP + imageInfo.getPhysicalWidthDpi() + SEP |
| 1156 |
|
+ imageInfo.getPhysicalHeightDpi() + SEP + imageInfo.getPhysicalWidthInch() + SEP |
| 1157 |
|
+ imageInfo.getPhysicalHeightInch() + SEP + imageInfo.isProgressive()); |
| 1158 |
|
} |
| 1159 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 1160 |
0
|
private static void printLine(int indentLevels, String text, float value, float minValidValue)... |
| 1161 |
|
{ |
| 1162 |
0
|
if (value < minValidValue) |
| 1163 |
|
{ |
| 1164 |
0
|
return; |
| 1165 |
|
} |
| 1166 |
0
|
printLine(indentLevels, text, Float.toString(value)); |
| 1167 |
|
} |
| 1168 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 1169 |
0
|
private static void printLine(int indentLevels, String text, int value, int minValidValue)... |
| 1170 |
|
{ |
| 1171 |
0
|
if (value >= minValidValue) |
| 1172 |
|
{ |
| 1173 |
0
|
printLine(indentLevels, text, Integer.toString(value)); |
| 1174 |
|
} |
| 1175 |
|
} |
| 1176 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 6 |
Complexity Density: 0.75 |
|
| 1177 |
0
|
private static void printLine(int indentLevels, String text, String value)... |
| 1178 |
|
{ |
| 1179 |
0
|
if (value == null || value.length() == 0) |
| 1180 |
|
{ |
| 1181 |
0
|
return; |
| 1182 |
|
} |
| 1183 |
0
|
while (indentLevels-- > 0) |
| 1184 |
|
{ |
| 1185 |
0
|
System.out.print("\t"); |
| 1186 |
|
} |
| 1187 |
0
|
if (text != null && text.length() > 0) |
| 1188 |
|
{ |
| 1189 |
0
|
System.out.print(text); |
| 1190 |
0
|
System.out.print(" "); |
| 1191 |
|
} |
| 1192 |
0
|
System.out.println(value); |
| 1193 |
|
} |
| 1194 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 3 |
Complexity Density: 0.18 |
|
| 1195 |
0
|
private static void printVerbose(String sourceName, ImageInfo ii)... |
| 1196 |
|
{ |
| 1197 |
0
|
printLine(0, null, sourceName); |
| 1198 |
0
|
printLine(1, "File format: ", ii.getFormatName()); |
| 1199 |
0
|
printLine(1, "MIME type: ", ii.getMimeType()); |
| 1200 |
0
|
printLine(1, "Width (pixels): ", ii.getWidth(), 1); |
| 1201 |
0
|
printLine(1, "Height (pixels): ", ii.getHeight(), 1); |
| 1202 |
0
|
printLine(1, "Bits per pixel: ", ii.getBitsPerPixel(), 1); |
| 1203 |
0
|
printLine(1, "Progressive: ", ii.isProgressive() ? "yes" : "no"); |
| 1204 |
0
|
printLine(1, "Number of images: ", ii.getNumberOfImages(), 1); |
| 1205 |
0
|
printLine(1, "Physical width (dpi): ", ii.getPhysicalWidthDpi(), 1); |
| 1206 |
0
|
printLine(1, "Physical height (dpi): ", ii.getPhysicalHeightDpi(), 1); |
| 1207 |
0
|
printLine(1, "Physical width (inches): ", ii.getPhysicalWidthInch(), 1.0f); |
| 1208 |
0
|
printLine(1, "Physical height (inches): ", ii.getPhysicalHeightInch(), 1.0f); |
| 1209 |
0
|
int numComments = ii.getNumberOfComments(); |
| 1210 |
0
|
printLine(1, "Number of textual comments: ", numComments, 1); |
| 1211 |
0
|
if (numComments > 0) |
| 1212 |
|
{ |
| 1213 |
0
|
for (int i = 0; i < numComments; i++) |
| 1214 |
|
{ |
| 1215 |
0
|
printLine(2, null, ii.getComment(i)); |
| 1216 |
|
} |
| 1217 |
|
} |
| 1218 |
|
} |
| 1219 |
|
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 1220 |
315
|
private int read() throws IOException... |
| 1221 |
|
{ |
| 1222 |
315
|
if (in != null) |
| 1223 |
|
{ |
| 1224 |
315
|
return in.read(); |
| 1225 |
|
} |
| 1226 |
|
else |
| 1227 |
|
{ |
| 1228 |
0
|
return din.readByte(); |
| 1229 |
|
} |
| 1230 |
|
} |
| 1231 |
|
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 1232 |
1
|
private int read(byte[] a) throws IOException... |
| 1233 |
|
{ |
| 1234 |
1
|
if (in != null) |
| 1235 |
|
{ |
| 1236 |
1
|
return in.read(a); |
| 1237 |
|
} |
| 1238 |
|
else |
| 1239 |
|
{ |
| 1240 |
0
|
din.readFully(a); |
| 1241 |
0
|
return a.length; |
| 1242 |
|
} |
| 1243 |
|
} |
| 1244 |
|
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 1245 |
15
|
private int read(byte[] a, int offset, int num) throws IOException... |
| 1246 |
|
{ |
| 1247 |
15
|
if (in != null) |
| 1248 |
|
{ |
| 1249 |
15
|
return in.read(a, offset, num); |
| 1250 |
|
} |
| 1251 |
|
else |
| 1252 |
|
{ |
| 1253 |
0
|
din.readFully(a, offset, num); |
| 1254 |
0
|
return num; |
| 1255 |
|
} |
| 1256 |
|
} |
| 1257 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1258 |
0
|
private String readLine() throws IOException... |
| 1259 |
|
{ |
| 1260 |
0
|
return readLine(new StringBuffer()); |
| 1261 |
|
} |
| 1262 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 1263 |
0
|
private String readLine(StringBuffer sb) throws IOException... |
| 1264 |
|
{ |
| 1265 |
0
|
boolean finished; |
| 1266 |
0
|
do |
| 1267 |
|
{ |
| 1268 |
0
|
int value = read(); |
| 1269 |
0
|
finished = (value == -1 || value == 10); |
| 1270 |
0
|
if (!finished) |
| 1271 |
|
{ |
| 1272 |
0
|
sb.append((char) value); |
| 1273 |
|
} |
| 1274 |
|
} |
| 1275 |
0
|
while (!finished); |
| 1276 |
0
|
return sb.toString(); |
| 1277 |
|
} |
| 1278 |
|
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 7 |
Complexity Density: 0.32 |
|
| 1279 |
0
|
private long readUBits(int numBits) throws IOException... |
| 1280 |
|
{ |
| 1281 |
0
|
if (numBits == 0) |
| 1282 |
|
{ |
| 1283 |
0
|
return 0; |
| 1284 |
|
} |
| 1285 |
0
|
int bitsLeft = numBits; |
| 1286 |
0
|
long result = 0; |
| 1287 |
0
|
if (bitPos == 0) |
| 1288 |
|
{ |
| 1289 |
0
|
if (in != null) |
| 1290 |
|
{ |
| 1291 |
0
|
bitBuf = in.read(); |
| 1292 |
|
} |
| 1293 |
|
else |
| 1294 |
|
{ |
| 1295 |
0
|
bitBuf = din.readByte(); |
| 1296 |
|
} |
| 1297 |
0
|
bitPos = 8; |
| 1298 |
|
} |
| 1299 |
|
|
| 1300 |
0
|
while (true) |
| 1301 |
|
{ |
| 1302 |
0
|
int shift = bitsLeft - bitPos; |
| 1303 |
0
|
if (shift > 0) |
| 1304 |
|
{ |
| 1305 |
|
|
| 1306 |
0
|
result |= bitBuf << shift; |
| 1307 |
0
|
bitsLeft -= bitPos; |
| 1308 |
|
|
| 1309 |
|
|
| 1310 |
0
|
if (in != null) |
| 1311 |
|
{ |
| 1312 |
0
|
bitBuf = in.read(); |
| 1313 |
|
} |
| 1314 |
|
else |
| 1315 |
|
{ |
| 1316 |
0
|
bitBuf = din.readByte(); |
| 1317 |
|
} |
| 1318 |
0
|
bitPos = 8; |
| 1319 |
|
} |
| 1320 |
|
else |
| 1321 |
|
{ |
| 1322 |
|
|
| 1323 |
0
|
result |= bitBuf >> -shift; |
| 1324 |
0
|
bitPos -= bitsLeft; |
| 1325 |
0
|
bitBuf &= 0xff >> (8 - bitPos); |
| 1326 |
|
|
| 1327 |
0
|
return result; |
| 1328 |
|
} |
| 1329 |
|
} |
| 1330 |
|
} |
| 1331 |
|
|
| 1332 |
|
|
| 1333 |
|
|
| 1334 |
|
|
| 1335 |
|
@param |
| 1336 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 1337 |
0
|
private int readSBits(int numBits) throws IOException... |
| 1338 |
|
{ |
| 1339 |
|
|
| 1340 |
0
|
long uBits = readUBits(numBits); |
| 1341 |
|
|
| 1342 |
|
|
| 1343 |
0
|
if ((uBits & (1L << (numBits - 1))) != 0) |
| 1344 |
|
{ |
| 1345 |
|
|
| 1346 |
0
|
uBits |= -1L << numBits; |
| 1347 |
|
} |
| 1348 |
|
|
| 1349 |
0
|
return (int) uBits; |
| 1350 |
|
} |
| 1351 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 1352 |
0
|
private static void run(String sourceName, InputStream in, ImageInfo imageInfo, boolean verbose)... |
| 1353 |
|
{ |
| 1354 |
0
|
imageInfo.setInput(in); |
| 1355 |
0
|
imageInfo.setDetermineImageNumber(true); |
| 1356 |
0
|
imageInfo.setCollectComments(verbose); |
| 1357 |
0
|
if (imageInfo.check()) |
| 1358 |
|
{ |
| 1359 |
0
|
print(sourceName, imageInfo, verbose); |
| 1360 |
|
} |
| 1361 |
|
} |
| 1362 |
|
|
| 1363 |
|
|
| 1364 |
|
|
| 1365 |
|
|
| 1366 |
|
|
| 1367 |
|
@param |
| 1368 |
|
|
| 1369 |
|
@see |
| 1370 |
|
@see |
| 1371 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1372 |
0
|
public void setCollectComments(boolean newValue)... |
| 1373 |
|
{ |
| 1374 |
0
|
collectComments = newValue; |
| 1375 |
|
} |
| 1376 |
|
|
| 1377 |
|
|
| 1378 |
|
|
| 1379 |
|
|
| 1380 |
|
|
| 1381 |
|
@link |
| 1382 |
|
@link |
| 1383 |
|
|
| 1384 |
|
@param |
| 1385 |
|
|
| 1386 |
|
@see |
| 1387 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1388 |
0
|
public void setDetermineImageNumber(boolean newValue)... |
| 1389 |
|
{ |
| 1390 |
0
|
determineNumberOfImages = newValue; |
| 1391 |
|
} |
| 1392 |
|
|
| 1393 |
|
|
| 1394 |
|
@link |
| 1395 |
|
@link |
| 1396 |
|
|
| 1397 |
|
@param |
| 1398 |
|
|
| 1399 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1400 |
0
|
public void setInput(DataInput dataInput)... |
| 1401 |
|
{ |
| 1402 |
0
|
din = dataInput; |
| 1403 |
0
|
in = null; |
| 1404 |
|
} |
| 1405 |
|
|
| 1406 |
|
|
| 1407 |
|
|
| 1408 |
|
|
| 1409 |
|
@param |
| 1410 |
|
|
| 1411 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 1412 |
4
|
public void setInput(InputStream inputStream)... |
| 1413 |
|
{ |
| 1414 |
4
|
in = inputStream; |
| 1415 |
4
|
din = null; |
| 1416 |
|
} |
| 1417 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1418 |
0
|
private void setPhysicalHeightDpi(int newValue)... |
| 1419 |
|
{ |
| 1420 |
0
|
physicalWidthDpi = newValue; |
| 1421 |
|
} |
| 1422 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 1423 |
0
|
private void setPhysicalWidthDpi(int newValue)... |
| 1424 |
|
{ |
| 1425 |
0
|
physicalHeightDpi = newValue; |
| 1426 |
|
} |
| 1427 |
|
|
| 1428 |
|
|
| 1429 |
|
|
| 1430 |
|
|
| 1431 |
|
|
| 1432 |
|
|
| 1433 |
|
|
| 1434 |
|
@param |
| 1435 |
|
@throws |
| 1436 |
|
@throws |
| 1437 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
| 1438 |
8
|
private void skip(int numBytesToSkip) throws IOException... |
| 1439 |
|
{ |
| 1440 |
314
|
for (int bytesSkipped = 0; bytesSkipped < numBytesToSkip; bytesSkipped++) |
| 1441 |
|
{ |
| 1442 |
307
|
if (read() == -1) |
| 1443 |
1
|
throw new EOFException("Reached end of stream before " |
| 1444 |
|
+ numBytesToSkip + " bytes could be skipped"); |
| 1445 |
|
} |
| 1446 |
|
} |
| 1447 |
|
} |