1 33 package com.lowagie.text.pdf.codec; 34 35 import java.io.Serializable ; 36 37 53 public class TIFFField extends Object implements Comparable , Serializable { 54 55 private static final long serialVersionUID = 9088332901412823834L; 56 57 58 public static final int TIFF_BYTE = 1; 59 60 61 public static final int TIFF_ASCII = 2; 62 63 64 public static final int TIFF_SHORT = 3; 65 66 67 public static final int TIFF_LONG = 4; 68 69 70 public static final int TIFF_RATIONAL = 5; 71 72 73 public static final int TIFF_SBYTE = 6; 74 75 76 public static final int TIFF_UNDEFINED = 7; 77 78 79 public static final int TIFF_SSHORT = 8; 80 81 82 public static final int TIFF_SLONG = 9; 83 84 85 public static final int TIFF_SRATIONAL = 10; 86 87 88 public static final int TIFF_FLOAT = 11; 89 90 91 public static final int TIFF_DOUBLE = 12; 92 93 94 int tag; 95 96 97 int type; 98 99 100 int count; 101 102 103 Object data; 104 105 106 TIFFField() {} 107 108 144 public TIFFField(int tag, int type, int count, Object data) { 145 this.tag = tag; 146 this.type = type; 147 this.count = count; 148 this.data = data; 149 } 150 151 154 public int getTag() { 155 return tag; 156 } 157 158 165 public int getType() { 166 return type; 167 } 168 169 172 public int getCount() { 173 return count; 174 } 175 176 188 public byte[] getAsBytes() { 189 return (byte[])data; 190 } 191 192 199 public char[] getAsChars() { 200 return (char[])data; 201 } 202 203 210 public short[] getAsShorts() { 211 return (short[])data; 212 } 213 214 221 public int[] getAsInts() { 222 return (int[])data; 223 } 224 225 232 public long[] getAsLongs() { 233 return (long[])data; 234 } 235 236 242 public float[] getAsFloats() { 243 return (float[])data; 244 } 245 246 252 public double[] getAsDoubles() { 253 return (double[])data; 254 } 255 256 262 public int[][] getAsSRationals() { 263 return (int[][])data; 264 } 265 266 272 public long[][] getAsRationals() { 273 return (long[][])data; 274 } 275 276 289 public int getAsInt(int index) { 290 switch (type) { 291 case TIFF_BYTE: case TIFF_UNDEFINED: 292 return ((byte[])data)[index] & 0xff; 293 case TIFF_SBYTE: 294 return ((byte[])data)[index]; 295 case TIFF_SHORT: 296 return ((char[])data)[index] & 0xffff; 297 case TIFF_SSHORT: 298 return ((short[])data)[index]; 299 case TIFF_SLONG: 300 return ((int[])data)[index]; 301 default: 302 throw new ClassCastException (); 303 } 304 } 305 306 319 public long getAsLong(int index) { 320 switch (type) { 321 case TIFF_BYTE: case TIFF_UNDEFINED: 322 return ((byte[])data)[index] & 0xff; 323 case TIFF_SBYTE: 324 return ((byte[])data)[index]; 325 case TIFF_SHORT: 326 return ((char[])data)[index] & 0xffff; 327 case TIFF_SSHORT: 328 return ((short[])data)[index]; 329 case TIFF_SLONG: 330 return ((int[])data)[index]; 331 case TIFF_LONG: 332 return ((long[])data)[index]; 333 default: 334 throw new ClassCastException (); 335 } 336 } 337 338 349 public float getAsFloat(int index) { 350 switch (type) { 351 case TIFF_BYTE: 352 return ((byte[])data)[index] & 0xff; 353 case TIFF_SBYTE: 354 return ((byte[])data)[index]; 355 case TIFF_SHORT: 356 return ((char[])data)[index] & 0xffff; 357 case TIFF_SSHORT: 358 return ((short[])data)[index]; 359 case TIFF_SLONG: 360 return ((int[])data)[index]; 361 case TIFF_LONG: 362 return ((long[])data)[index]; 363 case TIFF_FLOAT: 364 return ((float[])data)[index]; 365 case TIFF_DOUBLE: 366 return (float)((double[])data)[index]; 367 case TIFF_SRATIONAL: 368 int[] ivalue = getAsSRational(index); 369 return (float)((double)ivalue[0]/ivalue[1]); 370 case TIFF_RATIONAL: 371 long[] lvalue = getAsRational(index); 372 return (float)((double)lvalue[0]/lvalue[1]); 373 default: 374 throw new ClassCastException (); 375 } 376 } 377 378 387 public double getAsDouble(int index) { 388 switch (type) { 389 case TIFF_BYTE: 390 return ((byte[])data)[index] & 0xff; 391 case TIFF_SBYTE: 392 return ((byte[])data)[index]; 393 case TIFF_SHORT: 394 return ((char[])data)[index] & 0xffff; 395 case TIFF_SSHORT: 396 return ((short[])data)[index]; 397 case TIFF_SLONG: 398 return ((int[])data)[index]; 399 case TIFF_LONG: 400 return ((long[])data)[index]; 401 case TIFF_FLOAT: 402 return ((float[])data)[index]; 403 case TIFF_DOUBLE: 404 return ((double[])data)[index]; 405 case TIFF_SRATIONAL: 406 int[] ivalue = getAsSRational(index); 407 return (double)ivalue[0]/ivalue[1]; 408 case TIFF_RATIONAL: 409 long[] lvalue = getAsRational(index); 410 return (double)lvalue[0]/lvalue[1]; 411 default: 412 throw new ClassCastException (); 413 } 414 } 415 416 422 public String getAsString(int index) { 423 return ((String [])data)[index]; 424 } 425 426 433 public int[] getAsSRational(int index) { 434 return ((int[][])data)[index]; 435 } 436 437 444 public long[] getAsRational(int index) { 445 if (type == TIFF_LONG) 446 return getAsLongs(); 447 return ((long[][])data)[index]; 448 } 449 450 461 public int compareTo(Object o) { 462 if(o == null) { 463 throw new IllegalArgumentException (); 464 } 465 466 int oTag = ((TIFFField)o).getTag(); 467 468 if(tag < oTag) { 469 return -1; 470 } else if(tag > oTag) { 471 return 1; 472 } else { 473 return 0; 474 } 475 } 476 } 477 | Popular Tags |