Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
il_raw.c
Package: devil-1.7.99.tar.gz [view]
Upload User: wmy0603
Upload Date: 2022-05-02
Package Size: 1808k
Code Size: 4k
Category:
Compress-Decompress algrithms
Development Platform:
Visual C++
- //-----------------------------------------------------------------------------
- //
- // ImageLib Sources
- // Copyright (C) 2000-2009 by Denton Woods
- // Last modified: 03/07/2009
- //
- // Filename: src-IL/src/il_raw.c
- //
- // Description: "Raw" file functions
- //
- //-----------------------------------------------------------------------------
- #include "il_internal.h"
- #ifndef IL_NO_RAW
- ILboolean iLoadRawInternal(void);
- ILboolean iSaveRawInternal(void);
- //! Reads a raw file
- ILboolean ilLoad_RAW(ILconst_string FileName)
- {
- ILHANDLE RawFile;
- ILboolean bRaw = IL_FALSE;
- // No need to check for raw
- /*if (!iCheckExtension(FileName, "raw")) {
- ilSetError(IL_INVALID_EXTENSION);
- return bRaw;
- }*/
- RawFile = iopenr(FileName);
- if (RawFile == NULL) {
- ilSetError(IL_COULD_NOT_OPEN_FILE);
- return bRaw;
- }
- bRaw = ilLoadF_RAW(RawFile);
- icloser(RawFile);
- return bRaw;
- }
- //! Reads an already-opened raw file
- ILboolean ilLoadF_RAW(ILHANDLE File)
- {
- ILuint FirstPos;
- ILboolean bRet;
- iSetInputFile(File);
- FirstPos = itell();
- bRet = iLoadRawInternal();
- iseek(FirstPos, IL_SEEK_SET);
- return bRet;
- }
- //! Reads from a raw memory "lump"
- ILboolean ilLoadL_RAW(const void *Lump, ILuint Size)
- {
- iSetInputLump(Lump, Size);
- return iLoadRawInternal();
- }
- // Internal function to load a raw image
- ILboolean iLoadRawInternal()
- {
- if (iCurImage == NULL) {
- ilSetError(IL_ILLEGAL_OPERATION);
- return IL_FALSE;
- }
- iCurImage->Width = GetLittleUInt();
- iCurImage->Height = GetLittleUInt();
- iCurImage->Depth = GetLittleUInt();
- iCurImage->Bpp = (ILubyte)igetc();
- if (iread(&iCurImage->Bpc, 1, 1) != 1)
- return IL_FALSE;
- if (!ilTexImage(iCurImage->Width, iCurImage->Height, iCurImage->Depth, iCurImage->Bpp, 0, ilGetTypeBpc(iCurImage->Bpc), NULL)) {
- return IL_FALSE;
- }
- iCurImage->Origin = IL_ORIGIN_LOWER_LEFT;
- // Tries to read the correct amount of data
- if (iread(iCurImage->Data, 1, iCurImage->SizeOfData) < iCurImage->SizeOfData)
- return IL_FALSE;
- if (ilIsEnabled(IL_ORIGIN_SET)) {
- iCurImage->Origin = ilGetInteger(IL_ORIGIN_MODE);
- }
- else {
- iCurImage->Origin = IL_ORIGIN_UPPER_LEFT;
- }
- if (iCurImage->Bpp == 1)
- iCurImage->Format = IL_LUMINANCE;
- else if (iCurImage->Bpp == 3)
- iCurImage->Format = IL_RGB;
- else // 4
- iCurImage->Format = IL_RGBA;
- return ilFixImage();
- }
- //! Writes a Raw file
- ILboolean ilSave_RAW(const ILstring FileName)
- {
- ILHANDLE RawFile;
- ILuint RawSize;
- if (ilGetBoolean(IL_FILE_MODE) == IL_FALSE) {
- if (iFileExists(FileName)) {
- ilSetError(IL_FILE_ALREADY_EXISTS);
- return IL_FALSE;
- }
- }
- RawFile = iopenw(FileName);
- if (RawFile == NULL) {
- ilSetError(IL_COULD_NOT_OPEN_FILE);
- return IL_FALSE;
- }
- RawSize = ilSaveF_RAW(RawFile);
- iclosew(RawFile);
- if (RawSize == 0)
- return IL_FALSE;
- return IL_TRUE;
- }
- //! Writes Raw to an already-opened file
- ILuint ilSaveF_RAW(ILHANDLE File)
- {
- ILuint Pos;
- iSetOutputFile(File);
- Pos = itellw();
- if (iSaveRawInternal() == IL_FALSE)
- return 0; // Error occurred
- return itellw() - Pos; // Return the number of bytes written.
- }
- //! Writes Raw to a memory "lump"
- ILuint ilSaveL_RAW(void *Lump, ILuint Size)
- {
- ILuint Pos;
- iSetOutputLump(Lump, Size);
- Pos = itellw();
- if (iSaveRawInternal() == IL_FALSE)
- return 0; // Error occurred
- return itellw() - Pos; // Return the number of bytes written.
- }
- // Internal function used to load the raw data.
- ILboolean iSaveRawInternal()
- {
- if (iCurImage == NULL) {
- ilSetError(IL_ILLEGAL_OPERATION);
- return IL_FALSE;
- }
- SaveLittleUInt(iCurImage->Width);
- SaveLittleUInt(iCurImage->Height);
- SaveLittleUInt(iCurImage->Depth);
- iputc(iCurImage->Bpp);
- iputc(iCurImage->Bpc);
- iwrite(iCurImage->Data, 1, iCurImage->SizeOfData);
- return IL_TRUE;
- }
- #endif//IL_NO_RAW