1 /*
   2  * Copyright (c) 1998, 2000, 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 #include "jni.h"
  27 #include "awt_Mlib.h"
  28 #include "java_awt_image_BufferedImage.h"
  29 
  30 #include <windows.h>
  31 #include "alloc.h"
  32 
  33 extern "C"
  34 {
  35     /*
  36  * This is called by awt_ImagingLib.initLib() to figure out if there
  37  * is a native imaging lib tied to the ImagingLib.java (other than
  38  * the shared medialib).
  39  */
  40     mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
  41                                   mlibSysFnS_t *sMlibSysFns) {
  42         static HINSTANCE hDLL = NULL;
  43         mlibSysFnS_t tempSysFns;
  44         mlib_status ret = MLIB_SUCCESS;
  45 
  46         /* Try to receive handle for the library. Routine should find
  47          * the library successfully because this library is already
  48          * loaded to the process space by the System.loadLibrary() call.
  49          * Here we just need to get handle to initialize the pointers to
  50          * required mlib routines.
  51          */
  52         hDLL = ::GetModuleHandle(TEXT("mlib_image.dll"));
  53 
  54         if (hDLL == NULL) {
  55             return MLIB_FAILURE;
  56         }
  57 
  58         /* Initialize pointers to medilib routines... */
  59         tempSysFns.createFP = (MlibCreateFP_t)
  60             ::GetProcAddress(hDLL, "j2d_mlib_ImageCreate");
  61         if (tempSysFns.createFP == NULL) {
  62             ret = MLIB_FAILURE;
  63         }
  64 
  65         if (ret == MLIB_SUCCESS) {
  66             tempSysFns.createStructFP = (MlibCreateStructFP_t)
  67                 ::GetProcAddress(hDLL, "j2d_mlib_ImageCreateStruct");
  68             if (tempSysFns.createStructFP == NULL) {
  69                 ret = MLIB_FAILURE;
  70             }
  71         }
  72 
  73         if (ret == MLIB_SUCCESS) {
  74             tempSysFns.deleteImageFP = (MlibDeleteFP_t)
  75                 ::GetProcAddress(hDLL, "j2d_mlib_ImageDelete");
  76             if (tempSysFns.deleteImageFP == NULL) {
  77                 ret = MLIB_FAILURE;
  78             }
  79         }
  80         if (ret == MLIB_SUCCESS) {
  81             *sMlibSysFns = tempSysFns;
  82         }
  83 
  84         mlib_status (*fPtr)();
  85         mlibFnS_t* pMlibFns = sMlibFns;
  86         int i = 0;
  87         while ((ret == MLIB_SUCCESS) && (pMlibFns[i].fname != NULL)) {
  88             fPtr = (mlib_status (*)())
  89                 ::GetProcAddress(hDLL, pMlibFns[i].fname);
  90             if (fPtr != NULL) {
  91                 pMlibFns[i].fptr = fPtr;
  92             } else {
  93                 ret = MLIB_FAILURE;
  94             }
  95             i++;
  96         }
  97 
  98         return ret;
  99     }
 100 
 101     mlib_start_timer awt_setMlibStartTimer() {
 102         return NULL;
 103     }
 104 
 105     mlib_stop_timer awt_setMlibStopTimer() {
 106         return NULL;
 107     }
 108 
 109     void awt_getBIColorOrder(int type, int *colorOrder) {
 110         switch(type) {
 111         case java_awt_image_BufferedImage_TYPE_INT_ARGB:
 112         case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
 113             colorOrder[0] = 2;
 114             colorOrder[1] = 1;
 115             colorOrder[2] = 0;
 116             colorOrder[3] = 3;
 117             break;
 118         case java_awt_image_BufferedImage_TYPE_INT_BGR:
 119             colorOrder[0] = 0;
 120             colorOrder[1] = 1;
 121             colorOrder[2] = 2;
 122             break;
 123         case java_awt_image_BufferedImage_TYPE_INT_RGB:
 124             colorOrder[0] = 2;
 125             colorOrder[1] = 1;
 126             colorOrder[2] = 0;
 127             break;
 128         case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
 129         case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
 130             colorOrder[0] = 3;
 131             colorOrder[1] = 2;
 132             colorOrder[2] = 1;
 133             colorOrder[3] = 0;
 134             break;
 135         case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
 136             colorOrder[0] = 2;
 137             colorOrder[1] = 1;
 138             colorOrder[2] = 0;
 139             break;
 140         case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
 141         case java_awt_image_BufferedImage_TYPE_USHORT_555_RGB:
 142             colorOrder[0] = 0;
 143             colorOrder[1] = 1;
 144             colorOrder[2] = 2;
 145             break;
 146         case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
 147         case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
 148         case java_awt_image_BufferedImage_TYPE_BYTE_BINARY:
 149         case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
 150             colorOrder[0] = 0;
 151             break;
 152         }
 153     }
 154 }