GLubyte * read_alpha_texture(char *name, int *width, int *height) { unsigned char *base, *lptr; ImageRec *image; int y; image = ImageOpen(name); if (!image) { return NULL; } (*width)=image->xsize; (*height)=image->ysize; if (image->zsize != 1) { ImageClose(image); return NULL; } base = (unsigned char *)malloc(image->xsize*image->ysize*sizeof(unsigned char)); lptr = base; for(y=0; y<image->ysize; y++) { ImageGetRow(image,lptr,y,0); lptr += image->xsize; } ImageClose(image); return (GLubyte *) base; }
GLubyte * read_rgb_texture(char *name, int *width, int *height) { unsigned char *base, *ptr; unsigned char *rbuf, *gbuf, *bbuf, *abuf; ImageRec *image; int y; image = ImageOpen(name); if (!image) { return NULL; } (*width)=image->xsize; (*height)=image->ysize; if (image->zsize != 3 && image->zsize != 4) { ImageClose(image); return NULL; } base = (unsigned char*)malloc(image->xsize*image->ysize*sizeof(unsigned int)*3); rbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); gbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); bbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); abuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); if(!base || !rbuf || !gbuf || !bbuf || !abuf) { if (base) free(base); if (rbuf) free(rbuf); if (gbuf) free(gbuf); if (bbuf) free(bbuf); if (abuf) free(abuf); return NULL; } ptr = base; for(y=0; y<image->ysize; y++) { if(image->zsize == 4) { ImageGetRow(image,rbuf,y,0); ImageGetRow(image,gbuf,y,1); ImageGetRow(image,bbuf,y,2); ImageGetRow(image,abuf,y,3); /* Discard. */ rgbtorgb(rbuf,gbuf,bbuf,ptr,image->xsize); ptr += (image->xsize * 3); } else { ImageGetRow(image,rbuf,y,0); ImageGetRow(image,gbuf,y,1); ImageGetRow(image,bbuf,y,2); rgbtorgb(rbuf,gbuf,bbuf,ptr,image->xsize); ptr += (image->xsize * 3); } } ImageClose(image); free(rbuf); free(gbuf); free(bbuf); free(abuf); return (GLubyte *) base; }
static void RemoveDisk(const int iDrive) { Disk_t *pFloppy = &g_aFloppyDisk[iDrive]; if (pFloppy->imagehandle) { if (pFloppy->trackimage && pFloppy->trackimagedirty) WriteTrack( iDrive); ImageClose(pFloppy->imagehandle); pFloppy->imagehandle = (HIMAGE)0; } if (pFloppy->trackimage) { VirtualFree(pFloppy->trackimage,0,MEM_RELEASE); pFloppy->trackimage = NULL; pFloppy->trackimagedata = 0; } memset( pFloppy->imagename, 0, MAX_DISK_IMAGE_NAME+1 ); memset( pFloppy->fullname , 0, MAX_DISK_FULL_NAME +1 ); pFloppy->strFilenameInZip = ""; DiskSetDiskPathFilename(iDrive, ""); Disk_SaveLastDiskImage( iDrive ); Video_ResetScreenshotCounter( NULL ); }
unsigned char * load_luminance(char *name, int *width, int *height, int *components) { unsigned char *base, *lptr; ImageRec *image; int y; image = ImageOpen(name); if (!image) return NULL; if (image->zsize != 1) return NULL; *width = image->xsize; *height = image->ysize; *components = image->zsize; base = (unsigned char *) malloc(image->xsize * image->ysize * sizeof(unsigned char)); if (!base) return NULL; lptr = base; for (y = 0; y < image->ysize; y++) { ImageGetRow(image, lptr, y, 0); lptr += image->xsize; } ImageClose(image); return base; }
void Disk2InterfaceCard::RemoveDisk(const int drive) { FloppyDisk* pFloppy = &m_floppyDrive[drive].m_disk; if (pFloppy->m_imagehandle) { FlushCurrentTrack(drive); ImageClose(pFloppy->m_imagehandle); pFloppy->m_imagehandle = NULL; } if (pFloppy->m_trackimage) { VirtualFree(pFloppy->m_trackimage, 0, MEM_RELEASE); pFloppy->m_trackimage = NULL; pFloppy->m_trackimagedata = false; } memset( pFloppy->m_imagename, 0, MAX_DISK_IMAGE_NAME+1 ); memset( pFloppy->m_fullname , 0, MAX_DISK_FULL_NAME +1 ); pFloppy->m_strFilenameInZip = ""; SaveLastDiskImage( drive ); Video_ResetScreenshotCounter( NULL ); }
unsigned * read_texture(const char *name, int *width, int *height, int *components) { unsigned *base, *lptr; unsigned char *rbuf, *gbuf, *bbuf, *abuf; ImageRec *image; int y; image = ImageOpen(name); if(!image) return NULL; (*width)=image->xsize; (*height)=image->ysize; (*components)=image->zsize; base = (unsigned *)malloc(image->xsize*image->ysize*sizeof(unsigned)); rbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); gbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); bbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); abuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); if(!base || !rbuf || !gbuf || !bbuf) return NULL; lptr = base; for(y=0; y<image->ysize; y++) { if(image->zsize>=4) { ImageGetRow(image,rbuf,y,0); ImageGetRow(image,gbuf,y,1); ImageGetRow(image,bbuf,y,2); ImageGetRow(image,abuf,y,3); rgbatorgba(rbuf,gbuf,bbuf,abuf,(unsigned char *)lptr,image->xsize); lptr += image->xsize; } else if(image->zsize==3) { ImageGetRow(image,rbuf,y,0); ImageGetRow(image,gbuf,y,1); ImageGetRow(image,bbuf,y,2); rgbtorgba(rbuf,gbuf,bbuf,(unsigned char *)lptr,image->xsize); lptr += image->xsize; } else { ImageGetRow(image,rbuf,y,0); bwtorgba(rbuf,(unsigned char *)lptr,image->xsize); lptr += image->xsize; } } ImageClose(image); free(rbuf); free(gbuf); free(bbuf); free(abuf); return (unsigned *) base; }
/* * doReadCursor */ BOOL doReadCursor( char *fname, an_img_file *cursorfile, an_img *cursor, WRInfo *info, WResLangNode *lnode ) { img_node node; HDC hdc; char filename[_MAX_FNAME + _MAX_EXT]; if( cursorfile == NULL || cursor == NULL ) { return( FALSE ); } GetFnameFromPath( fname, filename ); node.imgtype = CURSOR_IMG; node.width = cursor->bm->bmiHeader.biWidth; node.height = cursor->bm->bmiHeader.biHeight; if( node.height == 0 ) { node.height = node.width; } node.bitcount = cursor->bm->bmiHeader.biBitCount; node.hotspot.x = cursorfile->resources->xhotspot; node.hotspot.y = cursorfile->resources->yhotspot; node.issaved = TRUE; node.num_of_images = 1; node.next = NULL; node.nexticon = NULL; node.wrinfo = info; node.lnode = lnode; hdc = GetDC( NULL ); node.handbitmap = ImgToAndBitmap( hdc, cursor ); node.hxorbitmap = ImgToXorBitmap( hdc, cursor ); ReleaseDC( NULL, hdc ); strcpy( node.fname, strupr( fname ) ); ImageFini( cursor ); ImageClose( cursorfile ); PrintHintTextByID( WIE_OPENEDTEXT, filename ); MakeIcon( &node, FALSE ); // also makes cursors CreateNewDrawPad( &node ); return( TRUE ); } /* doReadCursor */
// Pre: *pWriteProtected_ already set to file's r/w status - see DiskInsert() ImageError_e ImageOpen( LPCTSTR pszImageFilename, HIMAGE* hDiskImage_, bool* pWriteProtected_, const bool bCreateIfNecessary, std::string& strFilenameInZip) { if (! (pszImageFilename && hDiskImage_ && pWriteProtected_ && sg_DiskImageHelper.GetWorkBuffer())) return eIMAGE_ERROR_BAD_POINTER; // CREATE A RECORD FOR THE FILE, AND RETURN AN IMAGE HANDLE *hDiskImage_ = (HIMAGE) VirtualAlloc(NULL, sizeof(ImageInfo), MEM_COMMIT, PAGE_READWRITE); if (*hDiskImage_ == NULL) return eIMAGE_ERROR_BAD_POINTER; ZeroMemory(*hDiskImage_, sizeof(ImageInfo)); ImageInfo* pImageInfo = (ImageInfo*) *hDiskImage_; pImageInfo->bWriteProtected = *pWriteProtected_; ImageError_e Err = sg_DiskImageHelper.Open(pszImageFilename, pImageInfo, bCreateIfNecessary, strFilenameInZip); if (pImageInfo->pImageType != NULL && Err == eIMAGE_ERROR_NONE && pImageInfo->pImageType->GetType() == eImageHDV) Err = eIMAGE_ERROR_UNSUPPORTED_HDV; if (Err != eIMAGE_ERROR_NONE) { ImageClose(*hDiskImage_, true); *hDiskImage_ = (HIMAGE)0; return Err; } // THE FILE MATCHES A KNOWN FORMAT pImageInfo->uNumTracks = sg_DiskImageHelper.GetNumTracksInImage(pImageInfo->pImageType); for (UINT uTrack = 0; uTrack < pImageInfo->uNumTracks; uTrack++) pImageInfo->ValidTrack[uTrack] = (pImageInfo->uImageSize > 0) ? 1 : 0; *pWriteProtected_ = pImageInfo->bWriteProtected; return eIMAGE_ERROR_NONE; }
//=========================================================================== static void RemoveDisk (int iDrive) { Disk_t *pFloppy = &g_aFloppyDisk[iDrive]; if (pFloppy->imagehandle) { if (pFloppy->trackimage && pFloppy->trackimagedirty) WriteTrack( iDrive); ImageClose(pFloppy->imagehandle); pFloppy->imagehandle = (HIMAGE)0; } if (pFloppy->trackimage) { VirtualFree(pFloppy->trackimage,0,MEM_RELEASE); pFloppy->trackimage = NULL; pFloppy->trackimagedata = 0; } memset( pFloppy->imagename, 0, MAX_DISK_IMAGE_NAME+1 ); memset( pFloppy->fullname , 0, MAX_DISK_FULL_NAME +1 ); }
/* * ReadIconFromData - read the icon data and set up structures */ BOOL ReadIconFromData( void *data, char *fname, WRInfo *info, WResLangNode *lnode ) { unsigned pos; an_img_file *iconfile; img_node *node; int num_of_images; HDC hdc; int i; an_img *icon; char filename[_MAX_FNAME + _MAX_EXT]; pos = 0; GetFnameFromPath( fname, filename ); iconfile = ImageOpenData( (BYTE *)data, &pos ); if( iconfile == NULL ) { WImgEditError( WIE_ERR_BAD_ICON_DATA, filename ); return( FALSE ); } num_of_images = iconfile->count; #if 0 /* See biBitCount test below... */ for( i = 0; i < num_of_images; i++ ) { if( iconfile->resources[i].color_count != 2 && iconfile->resources[i].color_count != 8 && iconfile->resources[i].color_count != 16 && iconfile->resources[i].color_count != 0 ) { WImgEditError( WIE_ERR_BAD_ICON_CLR, filename ); ImageClose( iconfile ); return( FALSE ); } } #endif node = MemAlloc( sizeof( img_node ) * num_of_images ); hdc = GetDC( NULL ); for( i = 0; i < num_of_images; i++ ) { icon = ImgResourceToImgData( (BYTE *)data, &pos, iconfile, i ); if( icon->bm->bmiHeader.biBitCount != 4 && icon->bm->bmiHeader.biBitCount != 1 && icon->bm->bmiHeader.biBitCount != 8 ) { WImgEditError( WIE_ERR_BAD_ICON_CLR, filename ); ReleaseDC( NULL, hdc ); ImageFini( icon ); ImageClose( iconfile ); MemFree( node ); return( FALSE ); } node[i].imgtype = ICON_IMG; node[i].bitcount = icon->bm->bmiHeader.biBitCount; node[i].width = icon->bm->bmiHeader.biWidth; node[i].height = icon->bm->bmiHeader.biHeight; node[i].hotspot.x = 0; node[i].hotspot.y = 0; node[i].handbitmap = ImgToAndBitmap( hdc, icon ); node[i].hxorbitmap = ImgToXorBitmap( hdc, icon ); node[i].num_of_images = num_of_images; node[i].viewhwnd = NULL; if( i > 0 ) { node[i - 1].nexticon = &node[i]; } node[i].wrinfo = NULL; node[i].lnode = NULL; if( i == 0 ) { node[i].wrinfo = info; node[i].lnode = lnode; } node[i].issaved = TRUE; node[i].next = NULL; strcpy( node[i].fname, strupr( fname ) ); ImageFini( icon ); } node[i - 1].nexticon = NULL; ReleaseDC( NULL, hdc ); ImageClose( iconfile ); WriteIconLoadedText( filename, node->num_of_images ); CreateNewDrawPad( node ); MemFree( node ); SetupMenuAfterOpen(); return( TRUE ); } /* ReadIconFromData */
/* * readInIconFile - read the icon file and set up structures */ static BOOL readInIconFile( char *fname ) { FILE *fp; an_img_file *iconfile; img_node *node; int num_of_images; HDC hdc; int i; an_img *icon; char filename[_MAX_FNAME + _MAX_EXT]; fp = fopen( fname, "rb" ); if( fp == NULL ) { WImgEditError( WIE_ERR_FILE_NOT_OPENED, fname ); return( FALSE ); } GetFnameFromPath( fname, filename ); #ifdef JAMIE { char msg[80]; sprintf( msg, "Jamie: IconHeader size = %d", sizeof( an_img_file ) ); MessageBox( HMainWindow, msg, "FYI", MB_OK ); } #endif iconfile = ImageOpen( fp ); if( iconfile == NULL ) { fclose( fp ); WImgEditError( WIE_ERR_BAD_ICON_FILE, filename ); return( FALSE ); } num_of_images = iconfile->count; #if 0 /* See biBitCount test below... */ for( i = 0; i < num_of_images; i++ ) { if( iconfile->resources[i].color_count != 2 && iconfile->resources[i].color_count != 8 && iconfile->resources[i].color_count != 16 && iconfile->resources[i].color_count != 0 ) { WImgEditError( WIE_ERR_BAD_ICON_CLR, filename ); ImageClose( iconfile ); fclose( fp ); return( FALSE ); } } #endif node = MemAlloc( sizeof( img_node ) * num_of_images ); hdc = GetDC( NULL ); for( i = 0; i < num_of_images; i++ ) { icon = ImgResourceToImg( fp, iconfile, i ); if( icon->bm->bmiHeader.biBitCount != 4 && icon->bm->bmiHeader.biBitCount != 1 && icon->bm->bmiHeader.biBitCount != 8 ) { WImgEditError( WIE_ERR_BAD_ICON_CLR, filename ); ReleaseDC( NULL, hdc ); ImageFini( icon ); ImageClose( iconfile ); fclose( fp ); MemFree( node ); return( FALSE ); } node[i].imgtype = ICON_IMG; node[i].bitcount = icon->bm->bmiHeader.biBitCount; node[i].width = icon->bm->bmiHeader.biWidth; node[i].height = icon->bm->bmiHeader.biHeight; node[i].hotspot.x = 0; node[i].hotspot.y = 0; node[i].handbitmap = ImgToAndBitmap( hdc, icon ); node[i].hxorbitmap = ImgToXorBitmap( hdc, icon ); node[i].num_of_images = num_of_images; node[i].viewhwnd = NULL; node[i].wrinfo = NULL; node[i].lnode = NULL; if( i > 0 ) { node[i - 1].nexticon = &node[i]; } node[i].issaved = TRUE; node[i].next = NULL; strcpy( node[i].fname, strupr( fname ) ); ImageFini( icon ); } node[i - 1].nexticon = NULL; ReleaseDC( NULL, hdc ); ImageClose( iconfile ); fclose( fp ); WriteIconLoadedText( filename, node->num_of_images ); CreateNewDrawPad( node ); MemFree( node ); return( TRUE ); } /* readInIconFile */