Example #1
0
  __declspec(dllexport) bool LoadImage(const char *file, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info)
  {
    if (!file || !info) return false;

	if (IsDir(file))
		return false;

	  // load the image
    DWORD dwImageType = GetImageType(file);
    CxImage *image = new CxImage(dwImageType);
    if (!image) return false;

    int actualwidth = maxwidth;
    int actualheight = maxheight;
    try
    {
      if (!image->Load(file, dwImageType, actualwidth, actualheight) || !image->IsValid())
      {
#if !defined(_LINUX) && !defined(__APPLE__)
	    int nErr = GetLastError();
#else
	    int nErr = errno;
#endif
        printf("PICTURE::LoadImage: Unable to open image: %s Error:%s (%d)\n", file, image->GetLastError(),nErr);
        delete image;
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::LoadImage: Unable to open image: %s\n", file);
      delete image;
      return false;
    }
    // ok, now resample the image down if necessary
    if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0)
    {
      printf("PICTURE::LoadImage: Unable to resample picture: %s\n", file);
      delete image;
      return false;
    }

    // make sure our image is 24bit minimum
    image->IncreaseBpp(24);

    // fill in our struct
    info->width = image->GetWidth();
    info->height = image->GetHeight();
    info->originalwidth = actualwidth;
    info->originalheight = actualheight;
    memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO));

    // create our texture
    info->context = image;
    info->texture = image->GetBits();
    info->alpha = image->AlphaGetBits();
    return (info->texture != NULL);
  };
Example #2
0
BOOL CSonicImage::Load(HGLOBAL hGlobal, DWORD dwSize)
{
	if(m_gif.LoadGif(hGlobal, dwSize) == 1)
	{		
		if(PrepareMemDC(m_gif.GetWidth(), m_gif.GetHeight()) == FALSE)
		{
			m_gif.Clear();
			return FALSE;
		}
		m_gif.Draw(m_Dib.GetSafeHdc());
	}
	else
	{
		BYTE * pData = (BYTE *)GlobalLock(hGlobal);
		CxImage img;
		img.Decode(pData, dwSize, 0);
		GlobalUnlock(hGlobal);
		if(PrepareMemDC(img.GetWidth(), img.GetHeight()) == FALSE)
		{
			img.Clear();
			return FALSE;
		}
		if(!img.AlphaIsValid())
		{
			img.Draw(m_Dib.GetSafeHdc());
			CSSE::DoOr(0xff000000, m_Dib.GetBits(), m_Dib.GetSize());
		}
		else
		{
			if(img.GetBpp() != 24)
			{
				img.Clear();
				return FALSE;
			}
			BYTE * pSrc = img.GetBits();
			BYTE * pAlpha = img.AlphaGetBits();
			BYTE * pMyBits = m_Dib.GetBits();
			int nLineTail = m_nWidth % 4;
			for(int i = 0; i < m_nHeight; i++)
			{
				for(int j = 0; j < m_nWidth; j++)
				{
					*pMyBits++ = *pSrc++;
					*pMyBits++ = *pSrc++;
					*pMyBits++ = *pSrc++;
					*pMyBits++ = *pAlpha++;
				}
				pSrc += nLineTail;
			}
			EnableAlphaChannel();
		}
		img.Clear();
	}	
	return TRUE;
}
Example #3
0
  __declspec(dllexport) bool LoadImageFromMemory(const BYTE *buffer, unsigned int size, const char *mime, unsigned int maxwidth, unsigned int maxheight, ImageInfo *info)
  {
    if (!buffer || !size || !mime || !info) return false;

    // load the image
    DWORD dwImageType = CXIMAGE_FORMAT_UNKNOWN;
    if (strlen(mime))
      dwImageType = GetImageType(mime);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
      dwImageType = DetectFileType(buffer, size);
    if (dwImageType == CXIMAGE_FORMAT_UNKNOWN)
    {
      printf("PICTURE::LoadImageFromMemory: Unable to determine image type.");
      return false;
    }

    CxImage *image = new CxImage(dwImageType);
    if (!image)
      return false;

    int actualwidth = maxwidth;
    int actualheight = maxheight;

    try
    {
      bool success = image->Decode((BYTE*)buffer, size, dwImageType, actualwidth, actualheight);
      if (!success && dwImageType != CXIMAGE_FORMAT_UNKNOWN)
      { // try to decode with unknown imagetype
        success = image->Decode((BYTE*)buffer, size, CXIMAGE_FORMAT_UNKNOWN);
      }
      if (!success || !image->IsValid())
      {
        printf("PICTURE::LoadImageFromMemory: Unable to decode image. Error:%s\n", image->GetLastError());
        delete image;
        return false;
      }
    }
    catch (...)
    {
      printf("PICTURE::LoadImageFromMemory: Unable to decode image.");
      delete image;
      return false;
    }

    // ok, now resample the image down if necessary
    if (ResampleKeepAspect(*image, maxwidth, maxheight) < 0)
    {
      printf("PICTURE::LoadImage: Unable to resample picture\n");
      delete image;
      return false;
    }

    // make sure our image is 24bit minimum
    image->IncreaseBpp(24);

    // fill in our struct
    info->width = image->GetWidth();
    info->height = image->GetHeight();
    info->originalwidth = actualwidth;
    info->originalheight = actualheight;
    memcpy(&info->exifInfo, image->GetExifInfo(), sizeof(EXIFINFO));

    // create our texture
    info->context = image;
    info->texture = image->GetBits();
    info->alpha = image->AlphaGetBits();
    return (info->texture != NULL);
  };