MyBufferToImage.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 // Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
11 // Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
12 // Decompiler options: packimports(3)
13 // Source File Name: BufferToImage.java
14 
15 package com.generalrobotix.ui.view.tdview;
16 
17 import java.awt.*;
18 import java.awt.image.DirectColorModel;
19 import java.awt.image.MemoryImageSource;
20 import java.util.Vector;
21 import javax.media.*;
22 import javax.media.format.*;
23 
24 public class MyBufferToImage
25 {
26 
27  public MyBufferToImage(VideoFormat format)
28  {
29  converterNotRequired = false;
30  if((format instanceof YUVFormat) || (format instanceof RGBFormat))
31  {
32  this.format = format;
33  size = format.getSize();
34  prefFormat = new RGBFormat(size, size.width * size.height, Format.intArray, format.getFrameRate(), 32, -1, -1, -1, 1, -1, 0, -1);
35  if(format.matches(prefFormat))
36  {
37  converterNotRequired = true;
38  return;
39  }
40  Codec codec = findCodec(format, prefFormat);
41  if(codec != null)
42  converter = codec;
43  outputBuffer = new Buffer();
44  }
45  }
46 
47  private Codec findCodec(VideoFormat input, VideoFormat output)
48  {
49  Vector codecList = PlugInManager.getPlugInList(input, output, 2);
50  if(codecList == null || codecList.size() == 0)
51  return null;
52  for(int i = 0; i < codecList.size(); i++)
53  {
54  String codecName = (String)codecList.elementAt(i);
55  Class<?> codecClass = null;
56  Codec codec = null;
57  try
58  {
59  codecClass = Class.forName(codecName);
60  if(codecClass != null)
61  codec = (Codec)codecClass.newInstance();
62  }
63  catch(ClassNotFoundException _ex) { }
64  catch(IllegalAccessException _ex) { }
65  catch(InstantiationException _ex) { }
66  catch(ClassCastException _ex) { }
67  if(codec != null && codec.setInputFormat(input) != null)
68  {
69  Format outputs[] = codec.getSupportedOutputFormats(input);
70  if(outputs != null && outputs.length != 0)
71  {
72  for(int j = 0; j < outputs.length; j++)
73  if(outputs[j].matches(output))
74  {
75  Format out = codec.setOutputFormat(outputs[j]);
76  if(out != null && out.matches(output))
77  try
78  {
79  codec.open();
80  return codec;
81  }
82  catch(ResourceUnavailableException _ex) { }
83  }
84 
85  }
86  }
87  }
88 
89  return null;
90  }
91 
92  public Image createImage(Buffer buffer)
93  {
94  if(buffer == null || converter == null && !converterNotRequired || prefFormat == null || buffer.getFormat() == null || !buffer.getFormat().matches(format) || buffer.getData() == null || buffer.isEOM() || buffer.isDiscard())
95  return null;
96  int outputData[];
97  RGBFormat vf;
98  try
99  {
101  {
102  outputData = (int[])buffer.getData();
103  vf = (RGBFormat)buffer.getFormat();
104  } else
105  {
106  int retVal = converter.process(buffer, outputBuffer);
107  if(retVal != 0)
108  return null;
109  outputData = (int[])outputBuffer.getData();
110  vf = (RGBFormat)outputBuffer.getFormat();
111  }
112  }
113  catch(Exception ex)
114  {
115  System.err.println("Exception " + ex);
116  return null;
117  }
118  Image outputImage = null;
119 
120  int redMask = vf.getRedMask();
121  int greenMask = vf.getGreenMask();
122  int blueMask = vf.getBlueMask();
123  DirectColorModel dcm = new DirectColorModel(32, redMask, greenMask, blueMask);
124  MemoryImageSource sourceImage = new MemoryImageSource(size.width, size.height, dcm, outputData, 0, size.width);
125  outputImage = Toolkit.getDefaultToolkit().createImage(sourceImage);
126  return outputImage;
127  }
128 
129  private VideoFormat format;
130  private Codec converter;
131  private RGBFormat prefFormat;
132  private Buffer outputBuffer;
133  private Dimension size;
134  private boolean converterNotRequired;
135 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
Codec findCodec(VideoFormat input, VideoFormat output)
png_uint_32 i
Definition: png.h:2735
png_infop png_bytep buffer
Definition: png.h:2042
output(gif_dest_ptr dinfo, int code)
Definition: wrgif.c:105


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:04