?? imgapi.c
字號(hào):
//// imgapi.c: The GIF and JPG Image Support API module.//// Copyright (C) 1999, Li Zhuo.// Copyright (C) 1999, 2000, EESG of ICT.//// Current maintainer: Wei Yongming./*** This library is free software; you can redistribute it and/or** modify it under the terms of the GNU Library General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This library is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU** Library General Public License for more details.**** You should have received a copy of the GNU Library General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*/// Create date: 1999.04.19//// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------//// TODO://#include <stdio.h>#include <stddef.h>#include <stdlib.h>#ifndef __ECOS# include <malloc.h>#endif#include <string.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "gdi.h"#include "gif.h"#include "jpg.h"#ifndef lintstatic char fileid[] = "$Id: imgapi.c,v 1.4 2000/08/28 03:08:22 weiym Exp $";#endifint GUIAPI CreateBitmapFromGIFMemory (HDC hdc, PBITMAP pBitmap, void* buffer, int buffer_length){ unsigned char* pBmpSurface; unsigned char* pGifSurface; int i,j; int bpp = GetGDCapability (hdc, GDCAP_BPP); gif_info_t *ginfo; ginfo = (gif_info_t*)calloc(1, sizeof(gif_info_t)); ginfo->gif_buffer_length=buffer_length; ginfo->gif_buffer=buffer; unpack_gif(ginfo); if (pBitmap!=NULL) { pBitmap->bmWidth=ginfo->gif_global.width; pBitmap->bmHeight=ginfo->gif_global.height; pBitmap->bmBits=malloc( pBitmap->bmWidth*pBitmap->bmHeight*bpp); } pGifSurface=ginfo->gif_surface; pBmpSurface=pBitmap->bmBits; for(i=0;i<ginfo->gif_global.height;i++) { for(j=0;j<ginfo->gif_global.width;j++) { int c; int r,g,b; r=*pGifSurface++; g=*pGifSurface++; b=*pGifSurface++; c = RGB2Pixel (hdc, r, g, b); switch (bpp) { case 1: *pBmpSurface = c; pBmpSurface++; break; case 2: *(ushort *) pBmpSurface = c; pBmpSurface += 2; break; case 3: *(ushort *) pBmpSurface = c; *(pBmpSurface + 2) = c >> 16; pBmpSurface += 3; break; case 4: *(uint *) pBmpSurface = c; pBmpSurface += 4; break; } } } free(ginfo); //destroy_gif(ginfo); return 0;}int GUIAPI CreateBitmapFromGIFFile (HDC hdc, PBITMAP pBitmap, const char* filename){ int buffer_length; FILE* file; char* buffer; int retval; if ((file=fopen(filename,"rb"))==NULL) { return -1; } fseek(file,0,SEEK_END); buffer_length = ftell(file)+1; buffer=(char*)malloc(buffer_length); fseek(file,0,SEEK_SET); fread(buffer, sizeof(char), buffer_length, file); fclose(file); retval=CreateBitmapFromGIFMemory (hdc, pBitmap,buffer,buffer_length); free(buffer); return retval;}int GUIAPI CreateBitmapFromJPGMemory (HDC hdc, PBITMAP pBitmap, void* buffer, int buffer_length){ unsigned char* pBmpSurface; unsigned char* pJPGSurface; int i,j; int bpp = GetGDCapability (hdc, GDCAP_BPP); jpg_info_t *jinfo; jinfo = (jpg_info_t*)calloc(1, sizeof(jpg_info_t)); jinfo->jpg_buffer_length=buffer_length; jinfo->jpg_buffer=buffer; unpack_jpg(jinfo); if (pBitmap!=NULL) { pBitmap->bmWidth=jinfo->width; pBitmap->bmHeight=jinfo->height; pBitmap->bmBits= malloc(pBitmap->bmWidth*pBitmap->bmHeight*bpp); } pJPGSurface=jinfo->jpg_surface; pBmpSurface=pBitmap->bmBits; for(i=0;i<jinfo->height;i++) { for(j=0;j<jinfo->width;j++) { int c; int r,g,b; r=*pJPGSurface++; g=*pJPGSurface++; b=*pJPGSurface++; c = RGB2Pixel (hdc, r, g, b); switch (bpp) { case 1: *pBmpSurface = c; pBmpSurface++; break; case 2: *(ushort *) pBmpSurface = c; pBmpSurface += 2; break; case 3: *(ushort *) pBmpSurface = c; *(pBmpSurface + 2) = c >> 16; pBmpSurface += 3; break; case 4: *(uint *) pBmpSurface = c; pBmpSurface += 4; break; } } } free(jinfo); //destroy_jpg(jinfo); return 0;}int GUIAPI CreateBitmapFromJPGFile (HDC hdc, PBITMAP pBitmap, const char* filename){ int buffer_length; FILE* file; char* buffer; int retval; if ((file=fopen(filename,"rb"))==NULL) { return -1; } fseek(file,0,SEEK_END); buffer_length = ftell(file)+1; buffer=(char*)malloc(buffer_length); fseek(file,0,SEEK_SET); fread(buffer, sizeof(char), buffer_length, file); fclose(file); retval = CreateBitmapFromJPGMemory (hdc, pBitmap,buffer,buffer_length); free(buffer); return retval;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -