1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.jfxmedia.control;
  27 
  28 import java.util.EnumSet;
  29 import java.util.HashMap;
  30 import java.util.Map;
  31 
  32 public enum VideoFormat {
  33     /** Packed ARGB, in memory A,R,G,B alpha is NOT pre-multiplied.
  34      *  This is synonymous with BYTE_ARGB */
  35     ARGB(FormatTypes.FORMAT_TYPE_ARGB),
  36     /** Packed BGRA, in memory B,G,R,A alpha is pre-multiplied.
  37      *  This format is synonymous with BYTE_BGRA_PRE or little endian INT_ARGB_PRE */
  38     BGRA_PRE(FormatTypes.FORMAT_TYPE_BGRA_PRE),
  39     /** Planar YCbCr 4:2:0, alpha channel is optional. The presence of a fourth
  40      *  plane indicates alpha is present */
  41     YCbCr_420p(FormatTypes.FORMAT_TYPE_YCBCR_420P),
  42     /** Packed YCbCr 4:2:2, no alpha support (Only used on Mac currently). This
  43      *  format is synonymous with the 'yuvs' pixel format in QuickTime (tm) */
  44     YCbCr_422(FormatTypes.FORMAT_TYPE_YCBCR_422);
  45 
  46     private int nativeType; // value passed down to native code to represent this format
  47     private static final Map<Integer, VideoFormat> lookupMap = new HashMap<Integer, VideoFormat>();
  48     static {
  49         for (VideoFormat fmt : EnumSet.allOf(VideoFormat.class)) {
  50             lookupMap.put(fmt.getNativeType(), fmt);
  51         }
  52     }
  53 
  54     private VideoFormat(int ntype) {
  55         nativeType = ntype;
  56     }
  57 
  58     public int getNativeType() {
  59         return nativeType;
  60     }
  61 
  62     public boolean isRGB() {
  63         return this == ARGB || this == BGRA_PRE;
  64     }
  65 
  66     public boolean isEqualTo(int ntype) {
  67         return nativeType == ntype;
  68     }
  69 
  70     public static VideoFormat formatForType(int ntype) {
  71         return lookupMap.get(Integer.valueOf(ntype));
  72     }
  73 
  74     // Constants for JNI headers
  75     public static class FormatTypes {
  76         public static final int FORMAT_TYPE_ARGB = 1;
  77         public static final int FORMAT_TYPE_BGRA_PRE = 2;
  78         public static final int FORMAT_TYPE_YCBCR_420P = 100;
  79         public static final int FORMAT_TYPE_YCBCR_422 = 101;
  80     }
  81 }