Ejemplo n.º 1
0
	//------------------------------------------------------------------------
	bool platform_specific::load_pmap(const char* fn, unsigned idx, 
									  rendering_buffer* dst)
	{
		pixel_map pmap_tmp;
		if(!pmap_tmp.load_from_bmp(fn)) return false;

		rendering_buffer rbuf_tmp;
		rbuf_tmp.attach(pmap_tmp.buf(),
						pmap_tmp.width(),
						pmap_tmp.height(),
						m_flip_y ?
						  pmap_tmp.stride() :
						 -pmap_tmp.stride());

		m_pmap_img[idx].create(pmap_tmp.width(), 
							   pmap_tmp.height(), 
							   org_e(m_bpp),
							   0);

		dst->attach(m_pmap_img[idx].buf(),
					m_pmap_img[idx].width(),
					m_pmap_img[idx].height(),
					m_flip_y ?
					   m_pmap_img[idx].stride() :
					  -m_pmap_img[idx].stride());

		switch(m_format)
		{
		case pix_format_gray8:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_gray8()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_gray8()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_gray8()); break;
			}
			break;

		case pix_format_gray16:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_gray16()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_gray16()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_gray16()); break;
			}
			break;

		case pix_format_rgb555:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgb555()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgb555()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb555()); break;
			}
			break;

		case pix_format_rgb565:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgb565()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgb565()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb565()); break;
			}
			break;

		case pix_format_rgb24:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgb24()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgb24()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb24()); break;
			}
			break;

		case pix_format_bgr24:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_bgr24()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_bgr24()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgr24()); break;
			}
			break;

		case pix_format_rgb48:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgb48()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgb48()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb48()); break;
			}
			break;

		case pix_format_bgr48:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_bgr48()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_bgr48()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgr48()); break;
			}
			break;

		case pix_format_abgr32:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_abgr32()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_abgr32()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_abgr32()); break;
			}
			break;

		case pix_format_argb32:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_argb32()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_argb32()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_argb32()); break;
			}
			break;

		case pix_format_bgra32:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_bgra32()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_bgra32()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgra32()); break;
			}
			break;

		case pix_format_rgba32:
			switch(pmap_tmp.bpp())
			{
			case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgba32()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgba32()); break;
			case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba32()); break;
			}
			break;

		case pix_format_abgr64:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_abgr64()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_abgr64()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_abgr64()); break;
			}
			break;

		case pix_format_argb64:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_argb64()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_argb64()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_argb64()); break;
			}
			break;

		case pix_format_bgra64:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_bgra64()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_bgra64()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgra64()); break;
			}
			break;

		case pix_format_rgba64:
			switch(pmap_tmp.bpp())
			{
			//case 16: color_conv(dst, &rbuf_tmp, color_conv_rgb555_to_rgba64()); break;
			case 24: color_conv(dst, &rbuf_tmp, color_conv_bgr24_to_rgba64()); break;
			//case 32: color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba64()); break;
			}
			break;

		}

		return true;
	}
Ejemplo n.º 2
0
    //------------------------------------------------------------------------
    bool platform_support::load_img(unsigned idx, const char* file)
    {
        if (idx < max_images)
        {
            char path[B_PATH_NAME_LENGTH];
            sprintf(path, "%s/%s%s", m_specific->fAppPath, file, img_ext());
            BBitmap* transBitmap = BTranslationUtils::GetBitmap(path);
            if (transBitmap && transBitmap->IsValid()) {
                if(transBitmap->ColorSpace() != B_RGB32 && transBitmap->ColorSpace() != B_RGBA32) {
                    // ups we got a smart ass Translator making our live harder
                    delete transBitmap;
                    return false;
                }

                color_space format = B_RGB24;

                switch (m_format) {
                    case pix_format_gray8:
                        format = B_GRAY8;
                        break;
                    case pix_format_rgb555:
                        format = B_RGB15;
                        break;
                    case pix_format_rgb565:
                        format = B_RGB16;
                        break;
                    case pix_format_rgb24:
                        format = B_RGB24_BIG;
                        break;
                    case pix_format_bgr24:
                        format = B_RGB24;
                        break;
                    case pix_format_abgr32:
                    case pix_format_argb32:
                    case pix_format_bgra32:
                        format = B_RGB32;
                        break;
                    case pix_format_rgba32:
                        format = B_RGB32_BIG;
                        break;
                }
                BBitmap* bitmap = new (nothrow) BBitmap(transBitmap->Bounds(), 0, format);
                if (!bitmap || !bitmap->IsValid()) {
                    fprintf(stderr, "failed to allocate temporary bitmap!\n");
                    delete transBitmap;
                    delete bitmap;
                    return false;
                }

                delete m_specific->fImages[idx];

                rendering_buffer rbuf_tmp;
                attach_buffer_to_BBitmap(rbuf_tmp, transBitmap, m_flip_y);
        
                m_specific->fImages[idx] = bitmap;
        
                attach_buffer_to_BBitmap(m_rbuf_img[idx], bitmap, m_flip_y);
        
                rendering_buffer* dst = &m_rbuf_img[idx];

                switch(m_format)
                {
                case pix_format_gray8:
                    return false;
//                  color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_gray8()); break;
                    break;
        
                case pix_format_rgb555:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb555()); break;
                    break;
        
                case pix_format_rgb565:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb565()); break;
                    break;
        
                case pix_format_rgb24:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgb24()); break;
                    break;
        
                case pix_format_bgr24:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgr24()); break;
                    break;
        
                case pix_format_abgr32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_abgr32()); break;
                    break;
        
                case pix_format_argb32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_argb32()); break;
                    break;
        
                case pix_format_bgra32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_bgra32()); break;
                    break;
        
                case pix_format_rgba32:
                    color_conv(dst, &rbuf_tmp, color_conv_bgra32_to_rgba32()); break;
                    break;
                }
                delete transBitmap;
                
                return true;

            } else {
                fprintf(stderr, "failed to load bitmap: '%s'\n", full_file_name(file));
            }
        }
        return false;
    }