• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems while converting

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi @ all

I've got a problem while converting from tiff to png

here is the code and the exception
Does annybody know what the error Bad endianness tag mean
or the Error: One factory fails for the operation "tiff"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry

here is the source code and the exceptions I use an ByteInputstream (ByteArraySeekableStream)

public class TestConvert {
public static void main(String []args) {
TestConvert tc = new TestConvert();
String result = tc.ConvTifPng();
System.out.println(result);
}

private String ConvTifPng(){
String sourcefilename = "4711_2.tif";
String targetfilename = "4711_2b.PNG";
File dstFile = new File("d:\\4711_2c.png/");
File srcFile = new File (sourcefilename);
byte picBytes [] = new byte [(int)srcFile.length() ];
ByteArrayOutputStream bs = new ByteArrayOutputStream();
try {

ByteArraySeekableStream bass =
new ByteArraySeekableStream picBytes);

ParameterBlock params = new ParameterBlock();
params.add(bass);
//Specify to TIFF decoder to decode images as they are and
//not to convert unsigned short images to byte images.
TIFFDecodeParam decodeParam = new TIFFDecodeParam();
decodeParam.setDecodePaletteAsShorts(true);
//Create an operator to decode the TIFF file.

RenderedOp image1 = JAI.create("tiff", params);
System.out.println("nach RenderedOP!");
//Find out the first image�s data type.

int dataType = image1.getSampleModel().getDataType();
RenderedOp image2 = null;
System.out.println("nach getSampleModel!");
if (dataType == DataBuffer.TYPE_BYTE) {
//Display the byte image as it is.
System.out.println("TIFF image is type byte.");
image2 = image1;
} else if (dataType == DataBuffer.TYPE_USHORT) {
//Convert the unsigned short image to byte image.
System.out.println("TIFF image is type ushort.");
//Setup a standard window-level lookup table. */
byte[] tableData = new byte[0x10000];
for (int i = 0; i < 0x10000; i++) {
tableData[i] = (byte)(i >> 8);
}
//Create a LookupTableJAI object to be used with the
//�lookup� operator.
LookupTableJAI table = new LookupTableJAI(tableData);
//Create an operator to lookup image1.
image2 = JAI.create("lookup", image1, table);
} else {
System.out.println("TIFF image is type" + dataType +
", and will not be displayed.");
System.exit(0);
}
// Get the width and height of image2.
int width = image2.getWidth();
int height = image2.getHeight();
System.out.println("width: " + width);
System.out.println("height: " + height);
JAI.create("encode",image2,bs,"PNG",null);



System.out.println("size of ByteArrayOutputStream"+ bs.size());
byte [] bytes = new byte[(int)bs.size()];

System.out.println("write bytes!");
bs.write(bytes);
FileOutputStream fos = new FileOutputStream(dstFile);
fos.write(bytes);
bs.close();
fos.close();

} catch (IOException e1) {
System.out.println("IOException: " + e1.getMessage());
e1.printStackTrace();
}

return "convert successfully";
}
}




Exception:
Error: One factory fails for the operation "tiff"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getSampleModel(RenderedOp.java:2244)
at TestConvert.ConvTifJpg(TestConvert.java:67)
at TestConvert.main(TestConvert.java:40)
Caused by: java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
... 13 more
javax.media.jai.util.ImagingException: All factories fail for the operation "tiff"
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getSampleModel(RenderedOp.java:2244)
at TestConvert.ConvTifJpg(TestConvert.java:67)
at TestConvert.main(TestConvert.java:40)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
... 7 more
Caused by: java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
at com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImageDecoder.java:109)
at com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
... 13 more
Exception in thread "main"
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bug ID: 4996204
reply
    Bookmark Topic Watch Topic
  • New Topic