Ejemplo n.º 1
0
void DesktopIcon::load_icon(int face) {
	const char* ic = NULL;

	if(face != ICON_FACE_TWO) {
		if(!settings->icon.empty())
			ic = settings->icon.c_str();
	} else {
		if(!settings->icon2.empty())
			ic = settings->icon2.c_str();
	}

	if(!ic)
		return;

	if(!IconLoader::set(this, ic, ICON_SIZE_HUGE)) {
		E_DEBUG(E_STRLOC ": Unable to load %s icon\n", ic);
		return;
	}	

	/* fetch image object for sizes */
	Fl_Image* img = image();

	int img_w = img->w();
	int img_h = img->h();

	/* resize box if icon is larger */
	if(img_w > ICON_SIZE_MIN_W || img_h > ICON_SIZE_MIN_H)
		size(img_w + OFFSET_W, img_h + OFFSET_H);

	/* darker icon version for selection */
	delete darker_img;

	darker_img = img->copy(img->w(), img->h());
	darker_img->color_average(FL_BLUE, 0.6);
}
Ejemplo n.º 2
0
void DerivedShared_Image::reload ()
{
    int i;
    FILE * fp;
    uchar header[64];
    Fl_Image * img;

    if (!name_)
        return;

    if ((fp = fl_fopen (name_, "rb")) != NULL)
    {
        if (fread (header, 1, sizeof (header), fp) == 0)
        { /* ignore */
        }
        fclose (fp);
    }
    else
    {
        return;
    }

    if (memcmp (header, "#define", 7) == 0) // XBM file
        img = new Fl_XBM_Image (name_);
    else if (memcmp (header, "/* XPM */", 9) == 0) // XPM file
        img = new Fl_XPM_Image (name_);
    else
    {
        for (i = 0, img = 0; i < num_handlers_; i++)
        {
            // The only difference is the cast
            img = (static_cast<Fl_Image *> (
                (fl_handlers_[i]) (name_, header, sizeof (header))));

            if (img)
                break;
        }
    }

    if (img)
    {
        if (alloc_image_)
            delete image_;

        alloc_image_ = 1;

        if ((img->w () != w () && w ()) || (img->h () != h () && h ()))
        {
            Fl_Image * temp = img->copy (w (), h ());
            delete img;
            image_ = temp;
        }
        else
        {
            image_ = img;
        }

        update ();
    }
};
// 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());
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
MovableIcon::MovableIcon(DesktopIcon* ic) : Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0) {
	E_ASSERT(icon != NULL);

	set_override();
	color(ic->color());

	begin();
		/*
		 * Force box be same width/height as icon so it
		 * can fit inside masked window.
		 */
#ifdef HAVE_SHAPE 
		Fl_Image* img = ic->icon_image();
		if(img)
			icon_box = new Fl_Box(0, 0, img->w(), img->h());
		else
			icon_box = new Fl_Box(0, 0, w(), h());
#else
		icon_box = new Fl_Box(0, 0, w(), h());
#endif
		icon_box->image(ic->icon_image());
	end();
}
Ejemplo n.º 8
0
void C3DSceneMgr::createNewTileTexture(string strFileName)
{
	Fl_Image * img = openTextureFile(strFileName);
	if (img == NULL)
		return;
	int width = img->w();
	int height = img->h();
	const unsigned char *pOld = (const unsigned char *) img->data()[0];

	//image processing on water
	unsigned char	*pData = NULL;
	if (!mem_alloc(pData, width * height * 3))
		return;

	unsigned char	*p = pData;
	for (int i = 0; i < width * height; i++, p+=3, pOld+=3)
	{
		p[0] = pOld[0];		//red
		p[1] = pOld[1];		//green
		if (pOld[2] < 220 && pOld[2] > pOld[1]*5/4 && pOld[2] > pOld[0]*5/4)
			p[2] = pOld[2] + (220-pOld[2])/4;
		else
			p[2] = pOld[2];		//blue
	}

	string strnew = strFileName;
	setExt(strnew, ".png");
	saveImage(strnew, pData, width, height);
	int txID = createTexture(pData, width, height, GL_RGB, GL_RGB, TX_CLAMP_EDGE);

	delete pData;
	delete img;

	setExt(strFileName, ".dds");
	saveDDSTextureFile(strFileName, txID);
	deleteTexture(txID);
}
Ejemplo n.º 9
0
MovableIcon::MovableIcon(DesktopIcon* ic) :
Fl_Window(ic->x(), ic->y(), ic->w(), ic->h()), icon(ic), mask(0), opacity_atom(0) 
{
	E_ASSERT(icon != NULL);

	set_override();
	color(ic->color());

	begin();
		/* force box be same width/height as icon so it can fit inside masked window */
#ifdef HAVE_SHAPE 
		Fl_Image* img = ic->image();
		if(img)
			icon_box = new Fl_Box(0, 0, img->w(), img->h());
		else
			icon_box = new Fl_Box(0, 0, w(), h());
#else
		icon_box = new Fl_Box(0, 0, w(), h());
#endif
		icon_box->image(ic->image());
	end();

	opacity_atom = XInternAtom(fl_display, "_NET_WM_WINDOW_OPACITY", False);
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
    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;
        }
    }
Ejemplo n.º 12
0
void DesktopIcon::draw(void) { 
	// draw_box(FL_UP_BOX, FL_BLACK);

	if(image() && (damage() & FL_DAMAGE_ALL)) {
		Fl_Image* im = image();

		/* center image in the box */
		int ix = (w()/2) - (im->w()/2);
		int iy = (h()/2) - (im->h()/2);
		ix += x();
		iy += y();

		/* darker_img is always present if image() is present */
		if(is_focused())
			darker_img->draw(ix, iy);
		else
			im->draw(ix, iy);

		E_DEBUG(E_STRLOC ": DesktopIcon icon redraw\n");
	}

	if(gsettings->label_draw && (damage() & (FL_DAMAGE_ALL | EDAMAGE_CHILD_LABEL))) {
		int X = x() + w()-(w()/2)-(lwidth/2);
		int Y = y() + h() + LABEL_OFFSET;

		Fl_Color old = fl_color();

		if(!gsettings->label_transparent) {
			fl_color(gsettings->label_background);
			fl_rectf(X, Y, lwidth, lheight);
		}

		int old_font = fl_font();
		int old_font_sz = fl_size();

		/* draw with icon's font */
		fl_font(labelfont(), labelsize());

		/* pseudo-shadow */
		fl_color(FL_BLACK);
		fl_draw(label(), X+1, Y+1, lwidth, lheight, align(), 0, 0);

		fl_color(gsettings->label_foreground);
		fl_draw(label(), X, Y, lwidth, lheight, align(), 0, 0);

		/* restore old font */
		fl_font(old_font, old_font_sz);

		if(is_focused()) {
			/* draw focused box on our way so later this can be used to draw customised boxes */
			fl_color(gsettings->label_foreground);
			fl_line_style(FL_DOT);

			fl_push_matrix();
			fl_begin_loop();
				fl_vertex(X, Y);
				fl_vertex(X + lwidth, Y);
				fl_vertex(X + lwidth, Y + lheight);
				fl_vertex(X, Y + lheight);
				fl_vertex(X, Y);
			fl_end_loop();
			fl_pop_matrix();

			/* revert to default line style */
			fl_line_style(0);
		}

		/* revert to old color whatever that be */
		fl_color(old);
		E_DEBUG(E_STRLOC ": DesktopIcon label redraw\n");
	}
}