/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */
#include <windows.h>

#include "common.h"
#include "com_sun_rain_graphics_Image.h"

static jclass jImageClass = NULL;

/*
 * Class:     com_sun_rain_graphics_Image
 * Method:    _initIDs
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_sun_rain_graphics_Image__1initIDs
  (JNIEnv *env, jclass jClass)
{
    jImageClass = (jclass)env->NewGlobalRef(env->FindClass("com/sun/rain/graphics/Image"));
}

/*
 * Class:     com_sun_rain_graphics_Image
 * Method:    _createImage
 * Signature: (IILjava/nio/ByteBuffer;)V
 */
JNIEXPORT void JNICALL Java_com_sun_rain_graphics_Image__1createImage
  (JNIEnv *env, jobject jimage, jint jwidth, jint jheight, jobject jpixels)
{
    void *pixels = env->GetDirectBufferAddress(jpixels);

    HBITMAP hBitmap = ::CreateBitmap(jwidth, jheight, 1, 32, pixels);

    env->SetLongField(jimage, env->GetFieldID(jImageClass, "ptr", "J"), ptr_to_jlong(hBitmap));
}

