示例#1
0
void CDemoDib::CreateDibSection(CDC* pDC, CImage* pImage)
{
     SetBmpInfo(pImage);
     m_hBmp = ::CreateDIBSection(
          pDC->GetSafeHdc(), GetBmpInfo(),
          DIB_RGB_COLORS, (void**)(&m_pBits), NULL, 0);
}
示例#2
0
int main(int argc, _TCHAR* argv[])
{
	HWND hwnd=GetForegroundWindow();//直接获得前景窗口的句柄         
	SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(NULL,IDI_QUESTION)); 

	FILE * fbmp;
	if(!(fbmp=fopen("sys_g_base022.bmp", "rb")))
	{
		cout<<"No Such File!"<<endl;
		return -1;
	}

	bmp_header_t bmp_header = GetBmpInfo(fbmp);

	BYTE* data = new BYTE[bmp_header.datasize];
	BYTE* rawdata = new BYTE[bmp_header.datasize];

	GetBmpData(fbmp, data, bmp_header);

	RecoverData(rawdata, data, bmp_header);

	unsigned int extra_size = bmp_header.datasize / 0x0f;
	unsigned int extra = bmp_header.datasize % 0x0f;
	DWORD size;
	if(extra != 0)
		size = bmp_header.datasize + extra_size + 1;
	else
		size = bmp_header.datasize + extra_size;

	BYTE* epadata = new BYTE[size];

	Epa_Encompress(epadata, rawdata, bmp_header.datasize);

	FILE* fepa;
	if(!(fepa=fopen("sys_g_base022.epa", "wb")))
	{
		cout<<"Can not Create File!"<<endl;
		return -1;
	}

	fwrite(epadata, 1, size, fepa);

	cout<<"OK!"<<endl;
	delete[]data;
	delete[]rawdata;
	delete[]epadata;

	fclose(fbmp);
	fclose(fepa);

	system("pause");
	return 0;
}
示例#3
0
文件: test.c 项目: dongwencai/NewDVR
HI_S32 SAMPLE_HIFB_LoadBmp(const char *filename, HI_U8 *pAddr)
{
    OSD_SURFACE_S Surface;
    OSD_BITMAPFILEHEADER bmpFileHeader;
    OSD_BITMAPINFO bmpInfo;

    if (GetBmpInfo(filename,&bmpFileHeader,&bmpInfo) < 0)
    {
        printf("GetBmpInfo err!\n");
        return HI_FAILURE;
    }

    Surface.enColorFmt = OSD_COLOR_FMT_RGB1555;

    CreateSurfaceByBitMap(filename,&Surface,pAddr);
    return HI_SUCCESS;
}
示例#4
0
文件: loadbmp.c 项目: MindShow/hi3535
int LoadBMP(const char *filename, OSD_LOGO_T *pVideoLogo)
{
    FILE *pFile;
    HI_U16  i,j;

    HI_U32  w,h;
    HI_U16 Bpp;
    HI_U16 dstBpp;

    OSD_BITMAPFILEHEADER  bmpFileHeader;
    OSD_BITMAPINFO            bmpInfo;

    HI_U8 *pOrigBMPBuf;
    HI_U8 *pRGBBuf;
    HI_U32 stride;
    
    if(NULL == filename)
    {
        printf("OSD_LoadBMP: filename=NULL\n");
        return -1;
    }
    
    if(GetBmpInfo(filename,&bmpFileHeader,&bmpInfo)<0)
    {
        return -1;
    }

    Bpp = bmpInfo.bmiHeader.biBitCount/8;
    if(Bpp < 2)
    {
        /* only support 1555.8888  888 bitmap */
        printf("bitmap format not supported!\n");
        return -1;
    }
    
    if(bmpInfo.bmiHeader.biCompression != 0)
    {
        printf("not support compressed bitmap file!\n");
        return -1;
    }

    if(bmpInfo.bmiHeader.biHeight < 0)
    {
        printf("bmpInfo.bmiHeader.biHeight < 0\n");
        return -1;
    }

    if( (pFile = fopen((char *)filename, "rb")) == NULL)
    {
        printf("Open file faild:%s!\n", filename);
        return -1;
    }

    pVideoLogo->width = (HI_U16)bmpInfo.bmiHeader.biWidth;
    pVideoLogo->height = (HI_U16)((bmpInfo.bmiHeader.biHeight>0)?bmpInfo.bmiHeader.biHeight:(-bmpInfo.bmiHeader.biHeight));
    w = pVideoLogo->width;
    h = pVideoLogo->height;

    stride = w*Bpp;
#if 1    
    if(stride%4)
    {
        stride = stride&&0xfffc + 4;
    }
#endif    
    /* RGB8888 or RGB1555 */
    pOrigBMPBuf = (HI_U8 *)malloc(h*stride);
    if(NULL == pOrigBMPBuf)
    {
        printf("not enough memory to malloc!\n");
        fclose(pFile);
        return -1;
    }
    
    pRGBBuf = pVideoLogo->pRGBBuffer;

    fseek(pFile, bmpFileHeader.bfOffBits, 0);
    if(fread(pOrigBMPBuf, 1, h*stride, pFile) != (h*stride) )
    {
        printf("fread error!line:%d\n",__LINE__);
		perror("fread:");
    }

    if(Bpp > 2)
    {
        dstBpp = 4;
    }
    else
    {
        dstBpp = 2;
    }

    if(0 == pVideoLogo->stride)
    {
     	pVideoLogo->stride = pVideoLogo->width * dstBpp;
     }
    
    for(i=0; i<h; i++)
    {
        for(j=0; j<w; j++)
        {
            memcpy(pRGBBuf + i*pVideoLogo->stride + j*dstBpp, pOrigBMPBuf + ((h-1)-i)*stride+j*Bpp, Bpp);
           
            if(dstBpp == 4)
            {
                //*(pRGBBuf + i*pVideoLogo->stride + j*dstbpp + 3) = random()&0xff; /*alpha*/
                *(pRGBBuf + i*pVideoLogo->stride + j*dstBpp + 3) = 0x80; /*alpha*/
            }
        }
        
    }

    free(pOrigBMPBuf);
    pOrigBMPBuf = NULL;

    fclose(pFile);
    return 0;
}
示例#5
0
文件: loadbmp.c 项目: MindShow/hi3535
int LoadBMPCanvas(const char *filename, OSD_LOGO_T *pVideoLogo, OSD_COLOR_FMT_E enFmt)
{
    FILE *pFile;
    HI_U16  i,j;

    HI_U32  w,h;
    HI_U16 Bpp;

    OSD_BITMAPFILEHEADER  bmpFileHeader;
    OSD_BITMAPINFO            bmpInfo;

    HI_U8 *pOrigBMPBuf;
    HI_U8 *pRGBBuf;
    HI_U32 stride;
    HI_U8 r, g, b;
    HI_U8 *pStart;
    HI_U16 *pDst;

    if(NULL == filename)
    {
        printf("OSD_LoadBMP: filename=NULL\n");
        return -1;
    }
    
    if(GetBmpInfo(filename,&bmpFileHeader,&bmpInfo)<0)
    {
        return -1;
    }

    Bpp = bmpInfo.bmiHeader.biBitCount/8;
    if(Bpp < 2)
    {
        /* only support 1555.8888  888 bitmap */
        printf("bitmap format not supported!\n");
        return -1;
    }
    
    if(bmpInfo.bmiHeader.biCompression != 0)
    {
        printf("not support compressed bitmap file!\n");
        return -1;
    }

    if(bmpInfo.bmiHeader.biHeight < 0)
    {
        printf("bmpInfo.bmiHeader.biHeight < 0\n");
        return -1;
    }

    if( (pFile = fopen((char *)filename, "rb")) == NULL)
    {
        printf("Open file faild:%s!\n", filename);
        return -1;
    }
    
    w = (HI_U16)bmpInfo.bmiHeader.biWidth;
    h = (HI_U16)((bmpInfo.bmiHeader.biHeight>0)?bmpInfo.bmiHeader.biHeight:(-bmpInfo.bmiHeader.biHeight));

    stride = w*Bpp;

#if 1    
	if(stride%4)
	{
        stride = (stride&0xfffc) + 4;
 	}
#endif

    /* RGB8888 or RGB1555 */
    pOrigBMPBuf = (HI_U8 *)malloc(h*stride);
    if(NULL == pOrigBMPBuf)
    {
        printf("not enough memory to malloc!\n");
        fclose(pFile);
        return -1;
    }
    
    pRGBBuf = pVideoLogo->pRGBBuffer;
    
    if(stride > pVideoLogo->stride)
    {
        printf("Bitmap's stride(%d) is bigger than canvas's stide(%d). Load bitmap error!\n", stride, pVideoLogo->stride);
        return -1;
    }

    if(h > pVideoLogo->height)
    {
        printf("Bitmap's height(%d) is bigger than canvas's height(%d). Load bitmap error!\n", h, pVideoLogo->height);
        return -1;
    }

    if(w > pVideoLogo->width)
    {
        printf("Bitmap's width(%d) is bigger than canvas's width(%d). Load bitmap error!\n", w, pVideoLogo->width);
        return -1;
    }
    
    fseek(pFile, bmpFileHeader.bfOffBits, 0);
    if(fread(pOrigBMPBuf, 1, h*stride, pFile) != (h*stride) )
    {
        printf("fread (%d*%d)error!line:%d\n",h,stride,__LINE__);
		perror("fread:");
    }

    for(i=0; i<h; i++)
    {
        for(j=0; j<w; j++)
        {
            if(Bpp == 3)/*.....*/
            {
                switch(enFmt)
                {
                    case OSD_COLOR_FMT_RGB444:
                    case OSD_COLOR_FMT_RGB555:
                    case OSD_COLOR_FMT_RGB565:
                    case OSD_COLOR_FMT_RGB1555:
                    case OSD_COLOR_FMT_RGB4444:    
                        /* start color convert */
                        pStart = pOrigBMPBuf + ((h-1)-i)*stride + j*Bpp;
                        pDst = (HI_U16*)(pRGBBuf + i*pVideoLogo->stride + j*2);
                        r = *(pStart);
                        g = *(pStart + 1);
                        b = *(pStart + 2);
                        //printf("Func: %s, line:%d, Bpp: %d, bmp stride: %d, Canvas stride: %d, h:%d, w:%d.\n",
                        //    __FUNCTION__, __LINE__, Bpp, stride, pVideoLogo->stride, i, j);
                        *pDst = OSD_MAKECOLOR_U16(r, g, b, s_OSDCompInfo[enFmt]);
                        
                        break;
                        
                    case OSD_COLOR_FMT_RGB888:
                    case OSD_COLOR_FMT_RGB8888:
                        memcpy(pRGBBuf + i*pVideoLogo->stride + j*4, pOrigBMPBuf + ((h-1)-i)*stride+j*Bpp, Bpp);
                        *(pRGBBuf + i*pVideoLogo->stride + j*4 + 3) = 0xff; /*alpha*/
                        break;
                        
                    default:
                        printf("file(%s), line(%d), no such format!\n", __FILE__, __LINE__);
                        break;
                }
            }
            else if((Bpp == 2)||(Bpp == 4))/*..............*/
            {
                memcpy(pRGBBuf + i*pVideoLogo->stride + j*Bpp, pOrigBMPBuf + ((h-1)-i)*stride+j*Bpp, Bpp);
            }
           
        }
        
    }

    free(pOrigBMPBuf);
    pOrigBMPBuf = NULL;

    fclose(pFile);
    return 0;
}
示例#6
0
int main(int argc, char *argv[])
{
	if (argc != 4)
	{
		printf("usage: %s in.epa out.bmp out.epa\n", argv[0]);
		return -1;
	}
	FILE * fbmp;
	if (!(fbmp = fopen(argv[2], "rb")))
	{
		printf("No Such File!\n");
		return -1;
	}

	bmp_header_t bmp_header = GetBmpInfo(fbmp);

	BYTE* data = new BYTE[bmp_header.datasize];
	BYTE* rawdata = new BYTE[bmp_header.datasize];

	GetBmpData(fbmp, data, bmp_header);

	RecoverData(rawdata, data, bmp_header);

	unsigned int extra_size = bmp_header.datasize / 0x0f;
	unsigned int extra = bmp_header.datasize % 0x0f;
	DWORD size;
	if (extra != 0)
		size = bmp_header.datasize + extra_size + 1;
	else
		size = bmp_header.datasize + extra_size;

	BYTE* epadata = new BYTE[size];

	Epa_Encompress(epadata, rawdata, bmp_header.datasize);

	FILE *fepa_in;
	FILE *fepa_out;

	if (!(fepa_out = fopen(argv[3], "wb")))
	{
		printf("Can not Create File!\n");
		return -1;
	}
	if (!(fepa_in = fopen(argv[1], "rb")))
	{
		printf("No Such File!\n");
		return -1;
	}

	epa_header_t epa_in;
	fread(&epa_in, sizeof(epa_header_t), 1, fepa_in);
	if (epa_in.epa1.mode == 1)
	{
		fwrite(&epa_in.epa1, sizeof(epa1_header_t), 1, fepa_out);
	}
	else
	{
		fwrite(&epa_in.epa2, sizeof(epa2_header_t), 1, fepa_out);
	}
	fwrite(epadata, size, 1, fepa_out);

	printf("Finished!\n");
	delete[]data;
	delete[]rawdata;
	delete[]epadata;

	fclose(fepa_in);
	fclose(fbmp);
	fclose(fepa_out);

	return 0;
}