// Tests Open SLImage
TEST(ImageControllerTest, loadSLImageWithImageController) {
    ImageController imageController;
    imageController.open(filename);
    Fl_Image * image = imageController.getCurrentImage();
    ASSERT_NE((void *)NULL, image ) << "File did not open " << filename;
    EXPECT_EQ(30, image->w());
    EXPECT_EQ(30, image->h());
    EXPECT_EQ(3, image->d());
    EXPECT_EQ(92, image->ld()); //4 byte aligned under OpenCV not under FLTK
}
// Tests load OpenCVImage
TEST(ImageControllerTest, loadOpenCVImage) {
	OpenCVImage * openCVImage = OpenCVImage::NULL_OBJECT->load(filename);
    ASSERT_NE((void *)NULL, openCVImage ) << "File did not open " << filename;
    Fl_Image * image = openCVImage->getFlImage();
    ASSERT_NE((void *)NULL, image ) << "File did not open " << filename;
    EXPECT_EQ(30, image->w());
    EXPECT_EQ(30, image->h());
    EXPECT_EQ(3, image->d());
    EXPECT_EQ(92, image->ld()); //4 byte aligned under OpenCV not under FLTK
    EXPECT_EQ(8, openCVImage->getDepth());
    EXPECT_EQ(92, openCVImage->getWidthStep());
}
    virtual Bitmap *Load(IStream *stream) {
        SPADES_MARK_FUNCTION();

        // read all
        std::string data = stream->ReadAllBytes();

        // copy to buffer
        Fl_Image *img = LoadFltkImage(data);

        SPAssert(img);
        SPAssert(img->count() >= 1);

        const unsigned char* inPixels =
            (const unsigned char *)img->data()[0];
        int depth = img->d();
        int width = img->w();
        int height = img->h();
        int pitch = width * depth + img->ld();

        Handle<Bitmap> bmp;
        try {
            bmp = new Bitmap(width, height);
        } catch(...) {
            delete img;
            throw;
        }
        try {
            unsigned char *outPixels = (unsigned char *)bmp->GetPixels();

            if(pitch == width * 4 && depth == 4) {
                // if the format matches the requirement of Bitmap,
                // just use it
                memcpy(outPixels, inPixels, pitch * height);
            } else {
                // convert
                const unsigned char* line;
                for(int y = 0; y < height; y++) {
                    line = inPixels;
                    for(int x = 0; x < width; x++) {
                        uint8_t r, g, b, a;
                        switch(depth) {
                        case 1:
                            r = g = b = *(line++);
                            a = 255;
                            break;
                        case 2:
                            r = g = b = *(line++);
                            a = *(line++);
                            break;
                        case 3:
                            r = *(line++);
                            g = *(line++);
                            b = *(line++);
                            a = 255;
                            break;
                        case 4:
                            r = *(line++);
                            g = *(line++);
                            b = *(line++);
                            a = *(line++);
                            break;
                        default:
                            SPAssert(false);
                        }
                        *(outPixels++) = r;
                        *(outPixels++) = g;
                        *(outPixels++) = b;
                        *(outPixels++) = a;
                    }
                    inPixels += pitch;
                }
            }
            delete img;
            return bmp.Unmanage();
        } catch(...) {
            delete img;
            throw;
        }
    }