// 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
}
Esempio n. 2
0
/* =============================================================================
 =============================================================================== */
int C3DSceneMgr::createUITexture(string strFileName, int &width, int &height, int &txWidth)
{
	Fl_Image * img = openTextureFile(strFileName);
	if (img == NULL) {
		return -1;
	}

	width = img->w();
	height = img->h();

	//  need to add an alpha channel to properly overlay on existing textures
	const unsigned char *pData = NULL;
	if (img->d() == 3)
		pData = makeRGBA((const unsigned char *) img->data()[0], width, height);
	else
		pData = (const unsigned char *) img->data()[0];

	GLuint	textureID;
	glGenTextures(1, &textureID);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glBindTexture(GL_TEXTURE_2D, textureID);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

	int txHeight = height;
	txWidth = (width <= 64) ? 64 : (width <= 128) ? 128 : width;

	const unsigned char *pDataNew = NULL;
	if (width != txWidth)
	{
		pDataNew = padOut(pData, width, height, txWidth);
		txHeight = txWidth;
	}

	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, txWidth, txHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pDataNew ? pDataNew : pData);

	if (pDataNew) delete[] pDataNew;
	if (img->d() == 3) delete[] pData;
	delete img;

	return textureID;
}
// 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());
}
Esempio n. 4
0
/* =============================================================================
 =============================================================================== */
int C3DSceneMgr::createTexture(string strFileName, int &width, int &height, int iTxMode)
{
	if (strFileName == "") //  Return from the function if no file name was passed in
		return -1;
	if (!fileexists(strFileName))
		return -1;

	//  Load the image and store the data
	int textureID = -1;
	if (getExt(strFileName) == ".dds")
	{
		DDS_IMAGE_DATA	*pDDSImageData = NULL;
		if ((pDDSImageData = loadDDSTextureFile(strFileName)) != NULL)
		{
			textureID = createTextureDDS(pDDSImageData);
			height = pDDSImageData->sizeY;
			width = pDDSImageData->sizeX;
		}
		else	//  case where worldwind wraps jpegs in dds files
		{
			Fl_RGB_Image *img = new Fl_JPEG_Image(strFileName.c_str());
			if (img->d() == 0)
				return -1;
			width = img->w();
			height = img->h();
			const unsigned char *pData = (const unsigned char *) img->data()[0];
			textureID = createTexture(pData, width, height, GL_RGB, GL_RGB, iTxMode);
			delete img;
		}
	}
	else
	{
		Fl_Image * img = openTextureFile(strFileName);
		if (img == NULL)
			return -1;
		width = img->w();
		height = img->h();
		const unsigned char *pData = (const unsigned char *) img->data()[0];
		textureID = createTexture(pData, width, height, img->d() == 4 ? GL_RGBA : GL_RGB, GL_RGBA, iTxMode);
		delete img;
	}

	return textureID;
}
Esempio n. 5
0
//=============================================================================
Fl_Image * openTextureFile(string strFileName)
{
	Fl_Image *img = NULL;
	try
	{
		if (getExt(strFileName) == ".jpg" || getExt(strFileName) == ".jpeg")
			img = new Fl_JPEG_Image(strFileName.c_str());
		else if (getExt(strFileName) == ".png")
			img = new Fl_PNG_Image(strFileName.c_str());
		else
			img = new Fl_BMP_Image(strFileName.c_str());
	}
	catch(std::bad_alloc x)
	{
		mem_alloc_failure(__FILE__, __LINE__);
		return NULL;
	}

	//  return if no image
	if (img->d() == 0 || img->h() == 0 || img->w() == 0)
	{
		delete img;
		return NULL;
	}

	//  downsize if image is too big
	if (img->h() > 4096 || img->w() > 4096)
	{
		cout << ("Downsizing image to maximum of 4096 a side");
		int h = img->h() >= img->w() ? 4096 : 4096 * img->h() / img->w();
		int w = img->w() >= img->h() ? 4096 : 4096 * img->w() / img->h();
		Fl_Image *img2 = img->copy(w, h);
		delete img;
		img = img2;
	}
	
	return img;
}
    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;
        }
    }