Esempio n. 1
0
/** deliver B-value of bitmap at given position */
unsigned int Vt2IsoImageFreeImage_c::getB( unsigned int aui_x, unsigned int aui_y )
{
 if ( ( aui_x >= ui_width ) || ( aui_y >= ui_height ) ) return 0;

 if (mb_palettized)
 { // we can't raw-access the bitmap buffer with RGB, we need to get the RGB via the palette-index's colour
   fiuint8_t idx;
   FreeImage_GetPixelIndex (bitmap, aui_x, (ui_height - 1) - aui_y, &idx);
   return vtColourTable[idx].bgrBlue;
 }
 else
 {
  #if defined( WIN32 )
  RGBQUAD temp_pixel;
  // ( FreeImage library documentation states, that first scanline in memory is
  //   bottommost -> i.e. upsidedown in relation to other modellings
  //    -> change direction back to usual with ( ui_height - aui_y ) )
  FreeImage_GetPixelColor(bitmap, aui_x, ( (ui_height - 1) - aui_y ), &temp_pixel);
  return temp_pixel.rgbBlue;
  #else
  checkUpdateScanline( aui_y );
  return scanline[FI_RGBA_BLUE + ( bytespp * aui_x )];
  #endif
 }
}
Esempio n. 2
0
// this function is only called for the 8bit case!
int Vt2IsoImageFreeImage_c::getPaletteIndex (unsigned int aui_x, unsigned int aui_y)
{
  if (mb_palettized)
  {
    // do this check here, because in case we only use 4bit bitmap, we don't have to care for the palette matching...
    if (mi_colourMismatch >= 0)
    {
      if (isOstream()) getOstream() << "*** COULDN'T LOAD BITMAP: WRONG PALETTE. See (first) mismatching colour #"<<mi_colourMismatch<<" below. Please use the ISO11783-Part 6 (VT)-Palette for bitmaps you have saved palettized and use in 8bit-mode. Use 'vt2iso -p' to generate an .act file and resample your bitmap to use this palette! ***" << std::endl;
      if (isOstream()) getOstream() << "HAS TO BE | you had" << std::hex << std::setfill('0');
      for (int i=0; i<(16+216); i++)
      {
        if ((i % 8) == 0) { if (isOstream()) getOstream() << std::endl; }
        else { if (isOstream()) getOstream() << "     "; }
        if (isOstream()) getOstream() << std::setw(2) << fiuint16_t(vtColourTable[i].bgrRed) << std::setw(2) << fiuint16_t(vtColourTable[i].bgrGreen) << std::setw(2) << fiuint16_t(vtColourTable[i].bgrBlue);
        if (i == mi_colourMismatch) { if (isOstream()) getOstream() << "*|*"; } else { if (isOstream()) getOstream() << " | "; }
        if (isOstream()) getOstream() << std::setw(2) << fiuint16_t(FreeImage_GetPalette (bitmap)[i].rgbRed) << std::setw(2) << fiuint16_t(FreeImage_GetPalette (bitmap)[i].rgbGreen) << std::setw(2) << fiuint16_t(FreeImage_GetPalette (bitmap)[i].rgbBlue);
      }
      if (isOstream()) getOstream() << std::endl;
      b_isInvalidPalette = true;
      return -1;
    }

    fiuint8_t idx;
    FreeImage_GetPixelIndex (bitmap, aui_x, (ui_height - 1) - aui_y, &idx);
    return idx;
  }
  else return -1;
}
Esempio n. 3
0
/**
 * This method returns the color index value on the given position.
 *
 * @param ulX the horizontal (x) position, from which to get the color index
 * @param ulY the vertical (y) position, from which to get the color index
 * @param colorValue a pointer to the color index value field wher to
 * 	store the color index value
 * @return true if pixel color index was evalued, else false
 */
bool fipImage::getPixelIndex( const unsigned long ulX, const unsigned long ulY,
		BYTE * colorIndexValue ) const{

/*	if ( ( colorIndexValue == NULL ) || ( pImageData == NULL ) ){
		return false;
	}
*/
	return FreeImage_GetPixelIndex( pImageData, ulX, ulY, colorIndexValue );
}
Esempio n. 4
0
BOOL fipImage::getPixelIndex(unsigned x, unsigned y, BYTE *value) const {
	return FreeImage_GetPixelIndex(_dib, x, y, value);
}
Esempio n. 5
0
// parsePNGFile()
// Takes in a PNG file and plugs the indexes into
// the proper art format.
static bool parsePNGFile(uint32_t pngi, FILE* afile)
{
	FILE* pngfile;
	char pngfilename[FILENAME_MAX];
	uint8_t* buffer;
	uint32_t xsize, ysize;
	int32_t xi, yi;
	FIBITMAP *pngas;
	FIBITMAP *pngaspal;
	FIBITMAP *pngasbg;
	FIBITMAP *pngas24;
	FIBITMAP *pngastemp;
	uint32_t m;
	uint32_t n;
	uint32_t _px;
	uint32_t* _pbx;
	
	pngi;

	TilesList[pngi].animdata = 0;
	TilesList[pngi].offset = ftell(afile);
	TilesList[pngi].sizex = 0;
	TilesList[pngi].sizey = 0;

	sprintf(pngfilename, "%s%stile%04u.png", inputdir, PATH_DELIMITER, pngi);
	
	pngastemp = FreeImage_Load(FIF_PNG, pngfilename, 0);

	if (pngastemp == NULL)
		return false;
		
	pngas = FreeImage_AllocateEx(FreeImage_GetWidth(pngastemp), 
		FreeImage_GetHeight(pngastemp), 8, &rgbpal[255], 0, rgbpal, 0, 0, 0);

	FreeImage_FlipVertical(pngastemp);
	
	if (FreeImage_GetBPP(pngastemp) != 8)
	{
		// printf("ssssnaaaaoooo\n");
		
		if (FreeImage_GetBPP(pngastemp) == 32)
		{
			pngasbg = FreeImage_Composite(pngastemp, FALSE, &rgbpal[255], NULL);
			// pngas24 = FreeImage_ConvertTo24Bits(pngasbg);
			
			
			pngaspal = FreeImage_ColorQuantizeEx(pngasbg, FIQ_NNQUANT, 256, 256, rgbpal);
			FreeImage_SetTransparentIndex(pngaspal, 255);
		}
		else
		{
			pngaspal = FreeImage_ColorQuantizeEx(pngastemp, FIQ_NNQUANT, 256, 256, rgbpal);
			FreeImage_SetTransparentIndex(pngaspal, 255);
		}
		
		if (pngaspal == NULL)
		{
			printf("error: tile%04u.png is an invalid 8/24/32bit image\n", pngi);
			return false;
		}	
			
		pngas = pngaspal;
		
	}
	else
	{
		pngas = pngastemp;
	}
	
	xsize = FreeImage_GetWidth(pngas);
	ysize = FreeImage_GetHeight(pngas);

	TilesList[pngi].sizex = xsize;
	TilesList[pngi].sizey = ysize;

	buffer = malloc(xsize * ysize);
	
	if (buffer == NULL)
	{
		printf("error: not enough memory to read image\n");
		return false;
	}

	// This is where the magic happens
	for (xi = 0; xi  < TilesList[pngi].sizex; xi++)
	{
		for (yi = 0; yi < TilesList[pngi].sizey; yi++)
		{
			FreeImage_GetPixelIndex(pngas, xi, yi, &buffer[xi * TilesList[pngi].sizey + yi]);
			fwrite(&buffer[xi * TilesList[pngi].sizey + yi], 1, 1, afile);
		}
	}
	
	free(buffer);	// Gotta free memory explicitly

	return true;
}
static struct graphics_image_priv *
image_new(struct graphics_priv *gr, struct graphics_image_methods *meth,
	  char *path, int *w, int *h, struct point *hot, int rotation)
{
#if USE_FREEIMAGE
	FIBITMAP *image;
	RGBQUAD aPixel;
	unsigned char *data;
	int width, height, i, j;
	struct graphics_image_priv *gi;
	//check if image already exists in hashmap
	struct graphics_image_priv *curr_elem =
	    g_hash_table_lookup(hImageData, path);
	if (curr_elem == &image_error) {
		//found but couldn't be loaded
		return NULL;
	} else if (curr_elem) {
		//found and OK -> use hastable entry
		*w = curr_elem->w;
		*h = curr_elem->h;
		hot->x = curr_elem->w / 2 - 1;
		hot->y = curr_elem->h / 2 - 1;
		return curr_elem;
	} else {
		if (strlen(path) < 4) {
			g_hash_table_insert(hImageData, g_strdup(path),
					    &image_error);
			return NULL;
		}
		char *ext_str = path + strlen(path) - 3;
		if (strstr(ext_str, "png") || strstr(path, "PNG")) {
			if ((image =
			     FreeImage_Load(FIF_PNG, path, 0)) == NULL) {
				g_hash_table_insert(hImageData,
						    g_strdup(path),
						    &image_error);
				return NULL;
			}
		} else if (strstr(ext_str, "xpm") || strstr(path, "XPM")) {
			if ((image =
			     FreeImage_Load(FIF_XPM, path, 0)) == NULL) {
				g_hash_table_insert(hImageData,
						    g_strdup(path),
						    &image_error);
				return NULL;
			}
		} else if (strstr(ext_str, "svg") || strstr(path, "SVG")) {
			char path_new[256];
			snprintf(path_new, strlen(path) - 3, "%s", path);
			strcat(path_new, "_48_48.png");

			if ((image =
			     FreeImage_Load(FIF_PNG, path_new,
					    0)) == NULL) {
				g_hash_table_insert(hImageData,
						    g_strdup(path),
						    &image_error);
				return NULL;
			}
		} else {
			g_hash_table_insert(hImageData, g_strdup(path),
					    &image_error);
			return NULL;
		}

		if (FreeImage_GetBPP(image) == 64) {
			FIBITMAP *image2;
			image2 = FreeImage_ConvertTo32Bits(image);
			FreeImage_Unload(image);
			image = image2;
		}
#if FREEIMAGE_MAJOR_VERSION*100+FREEIMAGE_MINOR_VERSION  >= 313
		if (rotation) {
			FIBITMAP *image2;
			image2 = FreeImage_Rotate(image, rotation, NULL);
			image = image2;
		}
#endif

		gi = g_new0(struct graphics_image_priv, 1);

		width = FreeImage_GetWidth(image);
		height = FreeImage_GetHeight(image);

		if ((*w != width || *h != height) && 0 < *w && 0 < *h) {
			FIBITMAP *image2;
			image2 = FreeImage_Rescale(image, *w, *h, NULL);
			FreeImage_Unload(image);
			image = image2;
			width = *w;
			height = *h;
		}

		data = (unsigned char *) malloc(width * height * 4);

		RGBQUAD *palette = NULL;
		if (FreeImage_GetBPP(image) == 8) {
			palette = FreeImage_GetPalette(image);
		}

		for (i = 0; i < height; i++) {
			for (j = 0; j < width; j++) {
				unsigned char idx;
				if (FreeImage_GetBPP(image) == 8) {
					FreeImage_GetPixelIndex(image, j,
								height -
								i - 1,
								&idx);
					data[4 * width * i + 4 * j + 0] =
					    palette[idx].rgbRed;
					data[4 * width * i + 4 * j + 1] =
					    palette[idx].rgbGreen;
					data[4 * width * i + 4 * j + 2] =
					    palette[idx].rgbBlue;
					data[4 * width * i + 4 * j + 3] =
					    255;
				} else if (FreeImage_GetBPP(image) == 16
					   || FreeImage_GetBPP(image) == 24
					   || FreeImage_GetBPP(image) ==
					   32) {
					FreeImage_GetPixelColor(image, j,
								height -
								i - 1,
								&aPixel);
					int transparent =
					    (aPixel.rgbRed == 0
					     && aPixel.rgbBlue == 0
					     && aPixel.rgbGreen == 0);
					data[4 * width * i + 4 * j + 0] =
					    transparent ? 0 : (aPixel.
							       rgbRed);
					data[4 * width * i + 4 * j + 1] =
					    (aPixel.rgbGreen);
					data[4 * width * i + 4 * j + 2] =
					    transparent ? 0 : (aPixel.
							       rgbBlue);
					data[4 * width * i + 4 * j + 3] =
					    transparent ? 0 : 255;

				}
			}
		}

		FreeImage_Unload(image);

		*w = width;
		*h = height;
		gi->w = width;
		gi->h = height;
		gi->hot_x = width / 2 - 1;
		gi->hot_y = height / 2 - 1;
		hot->x = width / 2 - 1;
		hot->y = height / 2 - 1;
		gi->data = data;
		gi->path = path;
		//add to hashtable
		g_hash_table_insert(hImageData, g_strdup(path), gi);
		return gi;
	}
#else
	return NULL;
#endif
}
Esempio n. 7
0
/*!
 * \brief IPLFileIO::loadFile
 * \param filename
 * \param image pass by pointer reference, because we need to change the pointer
 * \return
 */
bool IPLFileIO::loadFile(const std::string filename, IPLImage*& image, std::string& information)
{
    std::string formatNames[37] =  {"BMP", "ICO", "JPEG", "JNG",
                                    "KOALA", "LBM", "MNG", "PBM",
                                    "PBMRAW", "PCD", "PCX", "PGM", "PGMRAW",
                                    "PNG", "PPM", "PPMRAW", "RAS",
                                    "TARGA", "TIFF", "WBMP", "PSD", "CUT",
                                    "XBM", "XPM", "DDS", "GIF", "HDR",
                                    "FAXG3", "SGI", "EXR", "J2K", "JP2",
                                    "PFM", "PICT", "RAW", "WEBP", "JXR"};

    std::string typeNames[13] =   {"UNKNOWN", "BITMAP", "UINT16", "INT16",
                                    "UINT32", "INT32", "FLOAT", "DOUBLE",
                                    "COMPLEX", "RGB16", "RGBA16", "RGBF",
                                    "RGBAF"};

    FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
    format = FreeImage_GetFileType(filename.c_str());
    if(format == FIF_UNKNOWN)
    {
        return false;
    }

    FIBITMAP *dib = FreeImage_Load(format, filename.c_str());
    int width = FreeImage_GetWidth(dib);
    int height = FreeImage_GetHeight(dib);

    // all files need to be flipped
    FreeImage_FlipVertical(dib);

    if(FreeImage_GetBPP(dib) == 8)
    {
        // grayscale images

        // convert to 32 bit
        FIBITMAP *dib2 = FreeImage_ConvertToGreyscale(dib);

        // clear old image
        delete image;
        // create new instance with the right dimensions
        image = new IPLImage(IPLData::IMAGE_GRAYSCALE, width, height);

        for(int y = 0; y < height; y++)
        {
            for(int x = 0; x < width; x++)
            {
                BYTE value;
                FreeImage_GetPixelIndex(dib2, x, y, &value);
                image->plane(0)->p(x, y) = (value  * FACTOR_TO_FLOAT);
            }
        }

        FreeImage_Unload(dib2);
    }
    else
    {
        // color images

        // convert to 32 bit
        FIBITMAP *dib2 = FreeImage_ConvertTo32Bits(dib);

        // clear old image
        delete image;
        // create new instance with the right dimensions
        image = new IPLImage(IPLData::IMAGE_COLOR, width, height);

        for(int y = 0; y < height; y++)
        {
            for(int x = 0; x < width; x++)
            {
                RGBQUAD rgb;
                FreeImage_GetPixelColor(dib2, x, y, &rgb);
                image->plane(0)->p(x, y) = (rgb.rgbRed   * FACTOR_TO_FLOAT);    // R
                image->plane(1)->p(x, y) = (rgb.rgbGreen * FACTOR_TO_FLOAT);    // G
                image->plane(2)->p(x, y) = (rgb.rgbBlue  * FACTOR_TO_FLOAT);    // B
            }
        }

        FreeImage_Unload(dib2);
    }

    FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib);

    // collect information
    std::stringstream s;
    s << "<b>Type: </b>" << typeNames[type] << "\n";
    s << "<b>Format: </b>" << formatNames[format] << "\n";
    s << "<b>Bits per Pixel: </b>" << FreeImage_GetBPP(dib) << "\n";
    s << "<b>Width: </b>" << width << "\n";
    s << "<b>Height: </b>" << height << "";

    information = s.str();

    // free temporary memory
    FreeImage_Unload(dib);

    return true;
}
Esempio n. 8
0
bool IPLFileIO::loadMemory(void* mem, IPLImage*& image)
{
    FIMEMORY* hmem = (FIMEMORY*) mem;
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    FreeImage_SeekMemory(hmem, 0L, SEEK_SET);
    fif = FreeImage_GetFileTypeFromMemory(hmem, 0);

    if(fif == FIF_UNKNOWN)
    {
        // always close the memory stream
        FreeImage_CloseMemory(hmem);
        return false;
    }

    FIBITMAP *dib = FreeImage_LoadFromMemory(fif, hmem);
    int width = FreeImage_GetWidth(dib);
    int height = FreeImage_GetHeight(dib);

    // all files need to be flipped
    FreeImage_FlipVertical(dib);

    if(FreeImage_GetBPP(dib) == 8)
    {
        // grayscale images

        // convert to 32 bit
        FIBITMAP *dib2 = FreeImage_ConvertToGreyscale(dib);

        // clear old image
        delete image;
        // create new instance with the right dimensions
        image = new IPLImage(IPLData::IMAGE_GRAYSCALE, width, height);

        for(int y = 0; y < height; y++)
        {
            for(int x = 0; x < width; x++)
            {
                BYTE value;
                FreeImage_GetPixelIndex(dib2, x, y, &value);
                image->plane(0)->p(x, y) = (value  * FACTOR_TO_FLOAT);
            }
        }

        FreeImage_Unload(dib2);
    }
    else
    {
        // color images

        // convert to 32 bit
        FIBITMAP *dib2 = FreeImage_ConvertTo32Bits(dib);

        // clear old image
        delete image;
        // create new instance with the right dimensions
        image = new IPLImage(IPLData::IMAGE_COLOR, width, height);

        for(int y = 0; y < height; y++)
        {
            for(int x = 0; x < width; x++)
            {
                RGBQUAD rgb;
                FreeImage_GetPixelColor(dib2, x, y, &rgb);
                image->plane(0)->p(x, y) = (rgb.rgbRed   * FACTOR_TO_FLOAT);    // R
                image->plane(1)->p(x, y) = (rgb.rgbGreen * FACTOR_TO_FLOAT);    // G
                image->plane(2)->p(x, y) = (rgb.rgbBlue  * FACTOR_TO_FLOAT);    // B
            }
        }

        FreeImage_Unload(dib2);
    }

    // always close the memory stream
    FreeImage_CloseMemory(hmem);


    // free temporary memory
    FreeImage_Unload(dib);

    return true;
}