Example #1
0
/*-----------------------------------------------------------------------------
	PNGのロード
-----------------------------------------------------------------------------*/
int CNkImage::LoadPNG(char* lpszFileName)
{
	HBITMAP 	   hBMP = NULL;
	BITMAP		   bmp;
	DDSURFACEDESC2 ddsd;
	//ビットマップハンドルへPNGをロード
	hBMP = LoadPng( (string)lpszFileName);
	if( hBMP == NULL )
	{
		MB(lpszFileName);
		return 0;
	}
	//BMP情報を所得
	GetObject( hBMP, sizeof(bmp), &bmp );
	//サーフェイスに設定する構造体
	ZeroMemory( &ddsd, sizeof(ddsd) );
	ddsd.dwSize 		= sizeof(ddsd);
	ddsd.dwFlags		= DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;//システムメモリに作る
	
	ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
	ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
	ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
	//RGB565カラー
	ddsd.ddpfPixelFormat.dwRBitMask = 0x0000F800 ;
	ddsd.ddpfPixelFormat.dwGBitMask = 0x000007E0 ;
	ddsd.ddpfPixelFormat.dwBBitMask = 0x0000001F ;
	ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0x00000000 ;

	if(g_pNkLib->GetDouble())
	{
		ddsd.dwWidth		= bmp.bmWidth * 2;
		ddsd.dwHeight		= bmp.bmHeight * 2;
	}
	else
	{
		ddsd.dwWidth		= bmp.bmWidth;
		ddsd.dwHeight		= bmp.bmHeight;
	}
	//メンバにBMP情報を代入
	m_bmpWidth = (int)bmp.bmWidth;
	m_bmpHeight = (int)bmp.bmHeight;
	//サーフェイスを作成
	if(!g_pNkLib->CreateSurface(&ddsd, &m_pdds))
	{
		SAFE_RELEASE(m_pdds);
		return 0;
	}
	//BMPをサーフェイスに描画
	if(!DrawBitmap(hBMP))
	{
		DeleteObject( hBMP );
		return 0;
	}
	DeleteObject( hBMP );
	//カラーキー設定
	SetColorKey(RGB(255,0,255));
	return 1;
}
Example #2
0
int main(int argc, char **argv) {
  int i;

  for (i = 1; i < argc ; i++)
    LoadPng(argv[i]);

  return 0;
}
Example #3
0
bool Texture::Load(const std::string& filename)
{
    unsigned int w = 0;
    unsigned int h = 0;
    unsigned char* data = 0;
    unsigned int bpp = 3; // bytes per pixel

#ifdef AMJU_USE_SDL_IMG

    SDL_Surface* surf = IMG_Load(filename.c_str());
    if (!surf)
    {
        ReportError("Failed to load texture " + filename);
        return false;
    }
    w = surf->w;
    h = surf->h;
    data = (unsigned char*)surf->pixels;
    bpp = surf->format->BytesPerPixel;

#else

    std::string ext = ToLower(GetFileExt(filename));
    if (ext == "bmp")
    {
        data = LoadDIBitmap(filename.c_str(), &w, &h);
    }
    else if (ext == "png")
    {
        data = LoadPng(filename.c_str(), &w, &h, &bpp);
        // TODO I think bmps are upside down, but the rest of the code compensates.. sigh
        FlipBmp(data, w, h, bpp);
    }

    if (!data)
    {
        ReportError("Failed to load texture " + filename);
        return false;
    }

#endif

    Create(data, w, h, bpp);

#ifdef AMJU_USE_SDL_IMAGE
    SDL_FreeSurface(surf);
#else
    delete [] data;
#endif

#ifdef _DEBUG
    m_name = StripPath(filename);
#endif

    return true;
}
Example #4
0
TypedImage LoadImage(const std::string& filename, ImageFileType file_type)
{
    switch (file_type) {
    case ImageFileTypeTga:
        return LoadTga(filename);
    case ImageFileTypePng:
        return LoadPng(filename);
    case ImageFileTypeJpg:
        return LoadJpg(filename);
    case ImageFileTypePpm:
        return LoadPpm(filename);
    default:
        throw std::runtime_error("Unsupported image file type, '" + filename + "'");
    }
}
Example #5
0
TypedImage LoadImage(const std::string& filename, ImageFileType file_type)
{
    switch (file_type) {
    case ImageFileTypeTga:
        return LoadTga(filename);
    case ImageFileTypePng:
        return LoadPng(filename);
    case ImageFileTypeJpg:
        return LoadJpg(filename);
    case ImageFileTypePpm:
        return LoadPpm(filename);
#ifdef PANGOLIN_VIDEO
    case ImageFileTypePango:
        return LoadFromVideo(filename);
#endif
    default:
        throw std::runtime_error("Unsupported image file type, '" + filename + "'");
    }
}
Example #6
0
void SetupRC()
{
  glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

  int iWidth, iHeight;
  bool hasAlpha;
  GLubyte *pByte;
  if (LoadPng("1.png", iWidth, iHeight, hasAlpha, &pByte))
  {
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, hasAlpha ? GL_RGBA : GL_RGB, iWidth, iHeight, 0, hasAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, pByte);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV, GL_REPLACE);
    glEnable(GL_TEXTURE_2D);
  }

}
Example #7
0
// set main window foreground image
long CMUSHclientDoc::SetForegroundImage(LPCTSTR FileName, short Mode) 
{
  if (Mode < 0 || Mode > 13)
    return eBadParameter;  

  if ((HBITMAP) m_ForegroundBitmap)
    m_ForegroundBitmap.DeleteObject ();

  m_strForegroundImageName.Empty ();

  UpdateAllViews (NULL);

  CString strFileName = FileName;

  strFileName.TrimLeft ();
  strFileName.TrimRight ();

  // no file name means get rid of image
  if (strFileName.IsEmpty ())
    return eOK;

  // have to be long enough to have x.bmp
  if (strFileName.GetLength () < 5)
    return eBadParameter;

  HBITMAP hBmp;

  // handle PNG files separately
  if (strFileName.Right (4).CompareNoCase (".png") == 0)
    {
    long result =  LoadPng (FileName, hBmp);

    if (result != eOK) 
      return result;

    }    // png file
  else
    {

    // must be .bmp or .png file
    if (strFileName.Right (4).CompareNoCase (".bmp") != 0)
      return eBadParameter;

    hBmp = (HBITMAP)::LoadImage(
                    NULL,
                    FileName,
                    IMAGE_BITMAP,
                    0,
                    0,
                    LR_LOADFROMFILE|LR_CREATEDIBSECTION
                    );
    }  // bmp file

   if (hBmp) 
     {
      m_ForegroundBitmap.Attach (hBmp);
      m_iForegroundMode = Mode;
      m_strForegroundImageName = FileName;
    	return eOK;
     }  // end of having a bitmap loaded


   if (GetLastError () == 2)
     return eFileNotFound;

   return eCouldNotOpenFile;
  
}   // end of CMUSHclientDoc::SetForegroundImage
		Image* TextureManager::LoadPng(std::string fileName)
		{
			return LoadPng(fileName.c_str(),GU_PSM_8888,1,0);
		}
Example #9
0
TypedImage LoadPng(const std::string& filename)
{
    std::ifstream f(filename);
    return LoadPng(f);
}
Example #10
0
bool CImage::LoadPng (const char *dir, const char *filename, bool mirroring) {
    string path = dir;
    path += SEP;
    path += filename;
    return LoadPng (path.c_str(), mirroring);
}
CRefPtr<CNativeTexture>	CNativeTexture::CreateFromPng( const char * p_filename, ETextureFormat texture_format )
{
	return LoadPng( p_filename, texture_format );
}