/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */
#ifndef PIXELS_H
#define PIXELS_H

#include <windows.h>
#include <jni.h>

class Pixels;

class BaseBitmap {
    public:
        BaseBitmap() : hBitmap(NULL) {}
        virtual ~BaseBitmap() { if (hBitmap) ::DeleteObject(hBitmap); }
        void Attach(HBITMAP hBmp)
        {
            if (hBitmap) ::DeleteObject(hBitmap);
            hBitmap = hBmp;
        }

        operator HBITMAP() { return hBitmap; }
        operator HGDIOBJ() { return (HGDIOBJ)hBitmap; }

        HANDLE GetGlobalDIB();

    private:
        HBITMAP hBitmap;
};

class Bitmap : public BaseBitmap {
    public:
        Bitmap(int width, int height);
        Bitmap(int width, int height, void **data);
        Bitmap(Pixels & pixels);
};

class DIBitmap : public BaseBitmap {
    public:
        DIBitmap(Pixels & pixels);
};

class Pixels {
    public:
        static HICON CreateIcon(JNIEnv *env, jobject jPixels, BOOL fIcon = TRUE, jint x = 0, jint y = 0);
        static HCURSOR CreateCursor(JNIEnv *env, jobject jPixels, jint x, jint y)
        {
            return (HCURSOR)CreateIcon(env, jPixels, FALSE, x, y);
        }

        Pixels(JNIEnv *env, jobject jPixels);

        void AttachInt(JNIEnv *env, jint w, jint h, jobject buf, jintArray array, jint offset);
        void AttachByte(JNIEnv *env, jint w, jint h, jobject buf, jbyteArray array, jint offset);

        int GetWidth() { return width; }
        int GetHeight() { return height; }
        void* GetBits();

    private:
        int width, height;
        JBufferArray<jint> ints;
        JBufferArray<jbyte> bytes;
};

#endif //PIXELS_H

