Package javax.media.format

Examples of javax.media.format.VideoFormat


 
  //@Override
  @Override
  public Format setInputFormat(Format format)
  {
    VideoFormat chosenFormat =  (VideoFormat) super.setInputFormat(format);
    if (chosenFormat != null) {
      getComponent().setPreferredSize(chosenFormat.getSize());
    }
    return chosenFormat;
  }
View Full Code Here


      }
      assertEquals(f1, f1.clone());
      assertFalse(f1.clone() == f1);
     
      if (f1 instanceof VideoFormat)
      {  final VideoFormat vf1 = (VideoFormat) f1;
        if (vf1.getSize() != null)
          assertFalse(vf1.getSize() == ((VideoFormat) vf1.clone()).getSize());
       
        final VideoFormat fRelax = (VideoFormat) f1.relax();
        assertEquals(fRelax.getEncoding(), vf1.getEncoding());
        assertEquals(fRelax.getDataType(), vf1.getDataType());
        assertEquals(fRelax.getFrameRate(), -1.f);
        assertEquals(fRelax.getMaxDataLength(), -1);
        assertEquals(fRelax.getSize(), null);
                         
      }
     
      if (f1 instanceof RGBFormat)
      {  final RGBFormat vf1 = (RGBFormat) f1;
        if (vf1.getSize() != null)
          assertFalse(vf1.getSize() == ((RGBFormat) vf1.clone()).getSize());
       
        final RGBFormat fRelax = (RGBFormat) f1.relax();
        assertEquals(fRelax.getEncoding(), vf1.getEncoding());
        assertEquals(fRelax.getDataType(), vf1.getDataType());
        assertEquals(fRelax.getFrameRate(), -1.f);
        assertEquals(fRelax.getMaxDataLength(), -1);
        assertEquals(fRelax.getSize(), null);
        assertEquals(fRelax.getLineStride(), -1);
        assertEquals(fRelax.getPixelStride(), -1);
                         
      }
     
      if (f1.getClass() == Format.class)
      {
View Full Code Here

  public void testBufferToImage()
  {
    {
      try
      {
        final VideoFormat format = new RGBFormat();
        final BufferToImage b2i = new BufferToImage(format);
        assertTrue(false);
      }
      catch (NullPointerException e)
      {
      }
    }
   
    {
      final RGBFormat format = new RGBFormat(new Dimension(16, 16), 16 * 16, Format.intArray, 1.3414634f, 32, 0xff, 0xff00, 0xff0000, 1, 16, 0, -1);
     
      assertEquals(format.getLineStride(), 16)
      assertEquals(format.getPixelStride(), 1);
      assertEquals(format.getEndian(), -1);
      assertEquals(format.getFlipped(), 0);
   
     
      final BufferToImage b2i = new BufferToImage(format);
     
      final Buffer buffer = new Buffer();
      buffer.setFormat(format);
      //System.out.println(format.getMaxDataLength());
      final int[] ba = new int[format.getMaxDataLength()];
      ba[0] = 2;
      buffer.setData(ba);
     
      final BufferedImage i = (BufferedImage) b2i.createImage(buffer);
      assertTrue(i != null);
      assertEquals(i.getWidth(), format.getSize().width);
      assertEquals(i.getHeight(), format.getSize().height);
      assertEquals(i.getColorModel().getColorSpace().getType(), ColorSpace.TYPE_RGB);
      assertEquals(i.getType(), BufferedImage.TYPE_INT_BGR);
      // TODO: check other attributes, and pixels
      int[] pix = i.getRaster().getPixel(0, 0, (int[]) null);
      assertEquals(pix[0], 2);
View Full Code Here

    // unhappy.  However, JMF is not very happy if this happens and can
    // throw an NPE.
   
    com.sun.media.codec.audio.ulaw.DePacketizer c = new com.sun.media.codec.audio.ulaw.DePacketizer();
    c.open();
    Format[] f = c.getSupportedOutputFormats(new VideoFormat("xyz"));
    assertTrue(f.length == 1);
    assertTrue(f[0] == null);
   
  }
View Full Code Here

      assertEquals(instance.getFormat(14), new AudioFormat("mpegaudio/rtp", -1.0, -1, -1, -1, -1, -1, -1.0, Format.byteArray));
      assertEquals(instance.getFormat(15), new AudioFormat("g728/rtp", 8000.0, -1, 1, -1, -1, -1, -1.0, Format.byteArray));
      assertEquals(instance.getFormat(16), new AudioFormat("dvi/rtp", 11025.0, 4, 1, -1, -1, -1, -1.0, Format.byteArray));
      assertEquals(instance.getFormat(17), new AudioFormat("dvi/rtp", 22050.0, 4, 1, -1, -1, -1, -1.0, Format.byteArray));
      assertEquals(instance.getFormat(18), new AudioFormat("g729/rtp", 8000.0, -1, 1, -1, -1, -1, -1.0, Format.byteArray));
      assertEquals(instance.getFormat(26), new VideoFormat("jpeg/rtp", null, -1, Format.byteArray, -1.0f));
      assertEquals(instance.getFormat(31), new VideoFormat("h261/rtp", null, -1, Format.byteArray, -1.0f));
      assertEquals(instance.getFormat(32), new VideoFormat("mpeg/rtp", null, -1, Format.byteArray, -1.0f));
      assertEquals(instance.getFormat(34), new VideoFormat("h263/rtp", null, -1, Format.byteArray, -1.0f));
      assertEquals(instance.getFormat(42), new VideoFormat("h263-1998/rtp", null, -1, Format.byteArray, -1.0f));

    }
   

   
View Full Code Here

     
    }     
   
    {
      // to demonstrate that it uses the encoding code:
      final Format f1 = new VideoFormat("abc");
      final Format f2 = new VideoFormat(" abc");
      checkEncodingCode(f1, true);
      checkEncodingCode(f2, true);
      assertEquals(f1, f2);
      checkEncodingCode(f1, false);
      checkEncodingCode(f2, false);
     
    }   
   
    {
      // to demonstrate that it uses the encoding code:
      final Format f1 = new VideoFormat("abc");
      final Format f2 = new VideoFormat(" abc");
      checkEncodingCode(f1, true);
      checkEncodingCode(f2, true);
      assertTrue(f1.isSameEncoding(f2));
      checkEncodingCode(f1, false);
      checkEncodingCode(f2, false);
     
    }   
   
    {
      // to demonstrate that it uses the encoding code:
      final Format f1 = new VideoFormat("abc");
      final Format f2 = new VideoFormat(" abc");
      checkEncodingCode(f1, true);
      checkEncodingCode(f2, true);
      assertTrue(f1.isSameEncoding(" abc"));
      checkEncodingCode(f1, false);
      checkEncodingCode(f2, true);
View Full Code Here

  public void XXXtestBufferToImage()
  {
    {
      try
      {
        final VideoFormat format = new RGBFormat();
        final BufferToImage b2i = new BufferToImage(format);
        assertTrue(false);
      }
      catch (NullPointerException e)
      {
      }
    }
   
    {
      // 24bit rgb: r,g,b:
      final RGBFormat format = new RGBFormat(new Dimension(16, 16), 16 * 16 * 3, Format.byteArray, -1.f, 24, 1, 2, 3);
      assertEquals(format.getLineStride(), 16 * 3)
      assertEquals(format.getPixelStride(), 3);
      assertEquals(format.getEndian(), -1);
      assertEquals(format.getFlipped(), 0);
   
     
      final BufferToImage b2i = new BufferToImage(format);
     
      final Buffer buffer = new Buffer();
      buffer.setFormat(format);
      //System.out.println(format.getMaxDataLength());
      final byte[] ba = new byte[format.getMaxDataLength()];
      ba[0] = 2;
      buffer.setData(ba);
     
      final BufferedImage i = (BufferedImage) b2i.createImage(buffer);
      assertTrue(i != null);
      assertEquals(i.getWidth(), format.getSize().width);
      assertEquals(i.getHeight(), format.getSize().height);
      assertEquals(i.getColorModel().getColorSpace().getType(), ColorSpace.TYPE_RGB);
      assertEquals(i.getType(), BufferedImage.TYPE_INT_RGB);
      // TODO: check other attributes, and pixels
      int[] pix = i.getRaster().getPixel(0, 0, (int[]) null);
      assertEquals(pix[0], 2);
      assertEquals(pix[1], 0);
      assertEquals(pix[2], 0);
     
     
     
      //System.out.println(i.getClass());
    }
   
    {
      // 24bit rgb: r,g,b:
      final RGBFormat format = new RGBFormat(new Dimension(4, 4), 4 * 4 * 3, Format.byteArray, -1.f, 24, 1, 2, 3);
      assertEquals(format.getLineStride(), 4 * 3)
      assertEquals(format.getPixelStride(), 3);
      assertEquals(format.getEndian(), -1);
      assertEquals(format.getFlipped(), 0);
     
     
      final BufferToImage b2i = new BufferToImage(format);
     
      final Buffer buffer = new Buffer();
      buffer.setFormat(format);
      //System.out.println(format.getMaxDataLength());
      final byte[] ba = new byte[format.getMaxDataLength()];
      ba[0] = 2;
      buffer.setData(ba);
     
      final BufferedImage i = (BufferedImage) b2i.createImage(buffer);
      assertTrue(i != null);
      assertEquals(i.getWidth(), format.getSize().width);
      assertEquals(i.getHeight(), format.getSize().height);
      assertEquals(i.getColorModel().getColorSpace().getType(), ColorSpace.TYPE_RGB);
      assertEquals(i.getType(), BufferedImage.TYPE_INT_RGB);
      // TODO: check other attributes, and pixels
      int[] pix = i.getRaster().getPixel(0, 0, (int[]) null);
      assertEquals(pix[0], 2);
View Full Code Here

    }
   
    @Override
    public Format setInputFormat(Format format)
    {
        final VideoFormat videoFormat = (VideoFormat) format;
        if (videoFormat.getSize() == null)
            return null;    // must set a size.
       
        // TODO: check VideoFormat and compatibility
        bufferToImage = new BufferToImage(videoFormat);
View Full Code Here

    this.videoFormatComboBox.setMaximumRowCount(VIDEO_FORMATS.length);
    this.videoFormatComboBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value,
                                                      int index, boolean isSelected, boolean cellHasFocus) {
          VideoFormat videoFormat = (VideoFormat)value;
          String aspectRatio;
          switch (getAspectRatio(videoFormat)) {
            case RATIO_4_3 :
              aspectRatio = "4/3";
              break;
            case RATIO_16_9 :
            default :
              aspectRatio = "16/9";
              break;
          }
          Dimension videoSize = videoFormat.getSize();
          String displayedValue = String.format(videoFormatComboBoxFormat, videoSize.width, videoSize.height,
              aspectRatio, (int)videoFormat.getFrameRate());         
          return super.getListCellRendererComponent(list, displayedValue, index, isSelected,
              cellHasFocus);
        }
      });
    this.videoFormatComboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setWidth(((VideoFormat)videoFormatComboBox.getSelectedItem()).getSize().width);
          controller.setAspectRatio(getAspectRatio((VideoFormat)videoFormatComboBox.getSelectedItem()));
          controller.setFrameRate((int)((VideoFormat)videoFormatComboBox.getSelectedItem()).getFrameRate());
        }
      });
    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          videoFormatComboBox.setSelectedItem(controller.getAspectRatio());
        }
      };
    controller.addPropertyChangeListener(VideoController.Property.WIDTH, propertyChangeListener);
    controller.addPropertyChangeListener(VideoController.Property.HEIGHT, propertyChangeListener);
    controller.addPropertyChangeListener(VideoController.Property.ASPECT_RATIO, propertyChangeListener);
    controller.addPropertyChangeListener(VideoController.Property.FRAME_RATE, propertyChangeListener);

    // Quality label and slider bound to QUALITY controller property
    this.qualityLabel = new JLabel();
    this.qualitySlider = new JSlider(1, controller.getQualityLevelCount()) {
        @Override
        public String getToolTipText(MouseEvent ev) {
          float valueUnderMouse = getSliderValueAt(this, ev.getX(), preferences);
          float valueToTick = valueUnderMouse - (float)Math.floor(valueUnderMouse);
          if (valueToTick < 0.25f || valueToTick > 0.75f) {
            // Display a tooltip that explains the different quality levels
            return "<html><table><tr valign='middle'>"
                + "<td><img border='1' src='"
                + new ResourceURLContent(PhotoPanel.class, "resources/quality" + Math.round(valueUnderMouse - qualitySlider.getMinimum()) + ".jpg").getURL() + "'></td>"
                + "<td>" + preferences.getLocalizedString(VideoPanel.class, "quality" + Math.round(valueUnderMouse - qualitySlider.getMinimum()) + "DescriptionLabel.text") + "</td>"
                + "</tr></table>";
          } else {
            return null;
          }
        }
      };
    // Add a listener that displays also the tool tip when user clicks on the slider
    this.qualitySlider.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent ev) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                float valueUnderMouse = getSliderValueAt(qualitySlider, ev.getX(), preferences);
                if (qualitySlider.getValue() == Math.round(valueUnderMouse)) {
                  ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
                  int initialDelay = toolTipManager.getInitialDelay();
                  toolTipManager.setInitialDelay(Math.min(initialDelay, 150));
                  toolTipManager.mouseMoved(ev);
                  toolTipManager.setInitialDelay(initialDelay);
                }
              }
            });
        }
      });
    this.qualitySlider.setPaintLabels(true);
    this.qualitySlider.setPaintTicks(true);   
    this.qualitySlider.setMajorTickSpacing(1);
    this.qualitySlider.setSnapToTicks(true);
    final boolean offScreenImageSupported = Component3DManager.getInstance().isOffScreenImageSupported();
    this.qualitySlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          if (!offScreenImageSupported) {
            // Can't support 2 first quality levels if offscreen image isn't supported
            qualitySlider.setValue(Math.max(qualitySlider.getMinimum() + 2, qualitySlider.getValue()));
          }
          controller.setQuality(qualitySlider.getValue() - qualitySlider.getMinimum());
        }
      });
    controller.addPropertyChangeListener(VideoController.Property.QUALITY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            qualitySlider.setValue(qualitySlider.getMinimum() + controller.getQuality());
            updateAdvancedComponents();
          }
        });
    this.qualitySlider.setValue(this.qualitySlider.getMinimum() + controller.getQuality());
   
    this.advancedComponentsSeparator = new JSeparator();

    // Create date and time labels and spinners bound to TIME controller property
    Date time = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
    this.dateLabel = new JLabel();
    final SpinnerDateModel dateSpinnerModel = new SpinnerDateModel();
    dateSpinnerModel.setValue(time);
    this.dateSpinner = new JSpinner(dateSpinnerModel);
    String datePattern = ((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT)).toPattern();
    if (datePattern.indexOf("yyyy") == -1) {
      datePattern = datePattern.replace("yy", "yyyy");
    }
    JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(this.dateSpinner, datePattern);
    this.dateSpinner.setEditor(dateEditor);
    SwingTools.addAutoSelectionOnFocusGain(dateEditor.getTextField());
   
    this.timeLabel = new JLabel();
    final SpinnerDateModel timeSpinnerModel = new SpinnerDateModel();
    timeSpinnerModel.setValue(time);
    this.timeSpinner = new JSpinner(timeSpinnerModel);
    // From http://en.wikipedia.org/wiki/12-hour_clock#Use_by_country
    String [] twelveHoursCountries = {
        "AU"// Australia
        "BD"// Bangladesh
        "CA"// Canada (excluding Quebec, in French)
        "CO"// Colombia
        "EG"// Egypt
        "HN"// Honduras
        "JO"// Jordan
        "MX"// Mexico
        "MY"// Malaysia
        "NI"// Nicaragua
        "NZ"// New Zealand
        "PH"// Philippines
        "PK"// Pakistan
        "SA"// Saudi Arabia
        "SV"// El Salvador
        "US"// United States
        "VE"}; // Venezuela        
    SimpleDateFormat timeInstance;
    if ("en".equals(Locale.getDefault().getLanguage())) {
      if (Arrays.binarySearch(twelveHoursCountries, Locale.getDefault().getCountry()) >= 0) {
        timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); // 12 hours notation
      } else {
        timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, Locale.UK); // 24 hours notation
      }
    } else {
      timeInstance = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT);
    }
    JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(this.timeSpinner, timeInstance.toPattern());
    this.timeSpinner.setEditor(timeEditor);
    SwingTools.addAutoSelectionOnFocusGain(timeEditor.getTextField());

    final PropertyChangeListener timeChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        Date date = new Date(Camera.convertTimeToTimeZone(controller.getTime(), TimeZone.getDefault().getID()));
        dateSpinnerModel.setValue(date);
        timeSpinnerModel.setValue(date);
      }
    };
    controller.addPropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
    final ChangeListener dateTimeChangeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
          // Merge date and time
          GregorianCalendar dateCalendar = new GregorianCalendar();
          dateCalendar.setTime((Date)dateSpinnerModel.getValue());
          GregorianCalendar timeCalendar = new GregorianCalendar();
          timeCalendar.setTime((Date)timeSpinnerModel.getValue());
          Calendar utcCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
          utcCalendar.set(GregorianCalendar.YEAR, dateCalendar.get(GregorianCalendar.YEAR));
          utcCalendar.set(GregorianCalendar.MONTH, dateCalendar.get(GregorianCalendar.MONTH));
          utcCalendar.set(GregorianCalendar.DAY_OF_MONTH, dateCalendar.get(GregorianCalendar.DAY_OF_MONTH));
          utcCalendar.set(GregorianCalendar.HOUR_OF_DAY, timeCalendar.get(GregorianCalendar.HOUR_OF_DAY));
          utcCalendar.set(GregorianCalendar.MINUTE, timeCalendar.get(GregorianCalendar.MINUTE));
          utcCalendar.set(GregorianCalendar.SECOND, timeCalendar.get(GregorianCalendar.SECOND));
          controller.setTime(utcCalendar.getTimeInMillis());
          controller.addPropertyChangeListener(VideoController.Property.TIME, timeChangeListener);
        }
      };
    dateSpinnerModel.addChangeListener(dateTimeChangeListener);
    timeSpinnerModel.addChangeListener(dateTimeChangeListener);

    this.dayNightLabel = new JLabel();
    final ImageIcon dayIcon = new ImageIcon(PhotoPanel.class.getResource("resources/day.png"));
    final ImageIcon nightIcon = new ImageIcon(PhotoPanel.class.getResource("resources/night.png"));
    PropertyChangeListener dayNightListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          if (home.getCompass().getSunElevation(
                Camera.convertTimeToTimeZone(controller.getTime(), home.getCompass().getTimeZone())) > 0) {
            dayNightLabel.setIcon(dayIcon);
          } else {
            dayNightLabel.setIcon(nightIcon);
          }
        }
      };
    controller.addPropertyChangeListener(VideoController.Property.TIME, dayNightListener);
    home.getCompass().addPropertyChangeListener(dayNightListener);
    dayNightListener.propertyChange(null);
   
    this.ceilingLightEnabledCheckBox = new JCheckBox();
    this.ceilingLightEnabledCheckBox.setSelected(controller.getCeilingLightColor() > 0);
    controller.addPropertyChangeListener(VideoController.Property.CEILING_LIGHT_COLOR,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            ceilingLightEnabledCheckBox.setSelected(controller.getCeilingLightColor() > 0);
          }
        });
    this.ceilingLightEnabledCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setCeilingLightColor(ceilingLightEnabledCheckBox.isSelected() ? 0xD0D0D0 : 0);
        }
      });

    this.createButton = new JButton(actionMap.get(ActionType.START_VIDEO_CREATION));
    this.saveButton = new JButton(actionMap.get(ActionType.SAVE_VIDEO));
    this.closeButton = new JButton(actionMap.get(ActionType.CLOSE));

    setComponentTexts(preferences);
    updatePlaybackTimer();

    this.videoFormatComboBox.setSelectedItem(new VideoFormat(VideoFormat.JPEG,
        new Dimension(controller.getWidth(), controller.getHeight()), Format.NOT_SPECIFIED, Format.byteArray, controller.getFrameRate()));
  }
View Full Code Here

   //------------------------------------------------------------------------------------------
    void setJPEGQuality(Player p, float val) {

    Control cs[] = p.getControls();
    QualityControl qc = null;
    VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);

    // Loop through the controls to find the Quality control for
     // the JPEG encoder.
    for (int i = 0; i < cs.length; i++) {
View Full Code Here

TOP

Related Classes of javax.media.format.VideoFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.