⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 negativeeffect.java

📁 java 完全探索的随书源码
💻 JAVA
字号:
// NegativeEffect.java

import javax.media.*;
import javax.media.format.*;
       
public class NegativeEffect implements Effect
{
   /** effect name **/

   private static String EffectName = "NegativeEffect";
       
   /** chosen input format **/

   protected RGBFormat inputFormat;
       
   /** chosen output format **/

   protected RGBFormat outputFormat;
       
   /** supported input formats **/

   protected Format [] supportedInputFormats;

   /** supported output formats **/

   protected Format [] supportedOutputFormats;
       
   /** initialize the formats **/

   public NegativeEffect ()
   {
      supportedInputFormats = new Format []
      {
         new RGBFormat ()
      };

      supportedOutputFormats = new Format []
      {
         new RGBFormat ()
      };
   }

   /** get the resources needed by this effect **/

   public void open () throws ResourceUnavailableException
   {
      System.out.println ("open");
   }
       
   /** free the resources allocated by this effect **/

   public void close ()
   {
      System.out.println ("close");
   }
       
   /** reset the effect **/

   public void reset ()
   {
      System.out.println ("reset");
   }
       
   /** no controls for this simple effect **/

   public Object [] getControls ()
   {
      System.out.println ("getControls");

      return new Controls [0];
   }
       
   /** return the control based on a control type for the effect **/

   public Object getControl (String controlType)
   {
      System.out.println ("getControl [controlType = "
                          + controlType + "]");

      try
      {
         Class cls = Class.forName (controlType);

         Object cs [] = getControls ();

         for (int i = 0; i < cs.length; i++)
         {
              if (cls.isInstance (cs [i]))
                  return cs [i];
         }

         return null;
      }
      catch (Exception e)
      {
         // no such controlType or such control

         return null;
      }
   }

   /************** format methods *************/

   /** set the input format **/

   public Format setInputFormat (Format input)
   {
      System.out.println ("setInputFormat [input = " + input + "]");

      // the following code assumes valid format

      inputFormat = (RGBFormat) input;

      return (Format) inputFormat;
   }

   /** set the output format **/

   public Format setOutputFormat (Format output)
   {
      System.out.println ("setOutputFormat [output = " + output + "]");

      // the following code assumes valid format

      outputFormat = (RGBFormat) output;

      return (Format) outputFormat;
   }

   /** get the input format **/

   protected Format getInputFormat ()
   {
      System.out.println ("getInputFormat");

      return inputFormat;
   }

   /** get the output format **/

   protected Format getOutputFormat ()
   {
      System.out.println ("getOutputFormat");

      return outputFormat;
   }
       
   /** supported input formats **/

   public Format [] getSupportedInputFormats ()
   {
      System.out.println ("getSupportedInputFormats");

      return supportedInputFormats;
   }
       
   /** output Formats for the selected input format **/

   public Format [] getSupportedOutputFormats (Format in)
   {
      System.out.println ("getSupportedOutputFormats [in = " + in
                          + "]");

      if (in == null)
          return supportedOutputFormats;

      if (!(in instanceof RGBFormat))
          return new Format [0];
       
      RGBFormat irf = (RGBFormat) in;

      RGBFormat orf = (RGBFormat) in.clone ();

      return new Format [] { orf };
   }
       
   /** return effect name **/

   public String getName ()
   {
      System.out.println ("getName");

      return EffectName;
   }
       
   /** do the processing **/

   public int process (Buffer inBuffer, Buffer outBuffer)
   {
      // == prolog

      Object o1 = inBuffer.getData ();
      int inLength = inBuffer.getLength ();
      int inOffset = inBuffer.getOffset ();

      if (!(o1 instanceof short []) && ! (o1 instanceof int []))
          return BUFFER_PROCESSED_FAILED;
      
      Object o2 = outBuffer.getData ();
      
      if (o2 != null)
      {
          if (!(o2 instanceof short []) && !(o2 instanceof int []))
              return BUFFER_PROCESSED_FAILED;
      }
      else
      {
          if (o1 instanceof short [])
              outBuffer.setData (new short [inLength]);
          else
              outBuffer.setData (new int [inLength]);

          o2 = outBuffer.getData ();
      }

      int outOffset = outBuffer.getOffset ();
 
      // == main

      if (o1 instanceof short [])
      {
          short [] inData = (short []) o1;
          short [] outData = (short []) o2;

          for (int i = 0; i < inLength; i++)
               outData [outOffset++] = (short) ~inData [inOffset++];
      }
      else
      {
          int [] inData = (int []) o1;
          int [] outData = (int []) o2;

          for (int i = 0; i < inLength; i++)
               outData [outOffset++] = ~inData [inOffset++];               
      }

      outBuffer.setFormat (outputFormat);
      outBuffer.setLength (inLength);
      outBuffer.setOffset (0);

      return BUFFER_PROCESSED_OK;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -