ILimage *iUncompressDcxSmall(DCXHEAD *Header) { ILuint i = 0, j, k, c, d, x, y, Bps; ILubyte HeadByte, Colour, Data = 0, *ScanLine = NULL; ILimage *Image; Image = ilNewImage(Header->Xmax - Header->Xmin + 1, Header->Ymax - Header->Ymin + 1, 1, Header->NumPlanes, 1); if (Image == NULL) return NULL; /*if (!ilTexImage(Header->Xmax - Header->Xmin + 1, Header->Ymax - Header->Ymin + 1, 1, 1, 0, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; }*/ Image->Origin = IL_ORIGIN_UPPER_LEFT; switch (Header->NumPlanes) { case 1: Image->Format = IL_LUMINANCE; break; case 4: Image->Format = IL_COLOUR_INDEX; break; default: ilSetError(IL_ILLEGAL_FILE_VALUE); ilCloseImage(Image); return NULL; } if (Header->NumPlanes == 1) { for (j = 0; j < Image->Height; j++) { i = 0; while (i < Image->Width) { if (iread(&HeadByte, 1, 1) != 1) goto file_read_error; if (HeadByte >= 192) { HeadByte -= 192; if (iread(&Data, 1, 1) != 1) goto file_read_error; for (c = 0; c < HeadByte; c++) { k = 128; for (d = 0; d < 8 && i < Image->Width; d++) { Image->Data[j * Image->Width + i++] = (!!(Data & k) == 1 ? 255 : 0); k >>= 1; } } } else { k = 128; for (c = 0; c < 8 && i < Image->Width; c++) { Image->Data[j * Image->Width + i++] = (!!(HeadByte & k) == 1 ? 255 : 0); k >>= 1; } } } if (Data != 0) igetc(); // Skip pad byte if last byte not a 0 }
// Internal function used to get the .hdr header from the current file. ILboolean iGetHdrHead(HDRHEADER *Header) { ILboolean done = IL_FALSE; char a, b; char x[3], y[3]; //changed 20050217: added space for the '\0' char char buff[80]; ILuint count = 0; iread(Header->Signature, 1, 10); //skip lines until an empty line is found. //this marks the end of header information, //the next line contains the image's dimension. //TODO: read header contents into variables //(EXPOSURE, orientation, xyz correction, ...) if (iread(&a, 1, 1) != 1) return IL_FALSE; while (!done) { if (iread(&b, 1, 1) != 1) return IL_FALSE; if (b == '\n' && a == '\n') done = IL_TRUE; else a = b; } //read dimensions (note that this assumes a somewhat valid image) if (iread(&a, 1, 1) != 1) return IL_FALSE; while (a != '\n') { if (count >= 80) { // Line shouldn't be this long at all. ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } buff[count] = a; if (iread(&a, 1, 1) != 1) return IL_FALSE; ++count; } buff[count] = '\0'; //note that this is not the 100% correct way to load hdr images: //in a perfect world we would check if there's a +/- X/Y in front //of width and heigth and mirror + rotate the image after decoding //according to that. But HDRShop doesn't do that either (and that's //my reference program :) ) and it's just a rotate and a mirror, //nothing that really changes the appearance of the loaded image... //(The code as it is now assumes that y contains "-Y" and x contains //"+X" after the following line) // The 2 has to be in the %s format specifier to prevent buffer overruns. sscanf(buff, "%2s %d %2s %d", y, &Header->Height, x, &Header->Width); return IL_TRUE; }
ILboolean channelReadMixed(ILubyte *scan, ILint width, ILint noCol, ILint *off, ILint bytes) { ILint count; int i, j, k; ILubyte col[4]; for(i = 0; i < width; i += count) { if (ieof()) return IL_FALSE; count = igetc(); if (count == IL_EOF) return IL_FALSE; if (count >= 128) { // Repeated sequence if (count == 128) { // Long run count = GetLittleUShort(); if (ieof()) return IL_FALSE; } else count -= 127; // We've run past... if ((i + count) > width) { //fprintf(stderr, "ERROR: FF_PIC_load(): Overrun scanline (Repeat) [%d + %d > %d] (NC=%d)\n", i, count, width, noCol); return IL_FALSE; } for (j = 0; j < noCol; j++) if (iread(&col[j], 1, 1) != 1) return IL_FALSE; for (k = 0; k < count; k++, scan += bytes) { for (j = 0; j < noCol; j++) scan[off[j]] = col[j]; } } else { // Raw sequence count++; if ((i + count) > width) { //fprintf(stderr, "ERROR: FF_PIC_load(): Overrun scanline (Raw) [%d + %d > %d] (NC=%d)\n", i, count, width, noCol); return IL_FALSE; } for (k = count; k > 0; k--, scan += bytes) { for (j = 0; j < noCol; j++) if (iread(&scan[off[j]], 1, 1) != 1) return IL_FALSE; } } } return IL_TRUE; }
// Internal function used to get the Psd header from the current file. ILboolean iGetPsdHead(PSDHEAD *Header) { iread(Header->Signature, 1, 4); Header->Version = GetBigUShort(); iread(Header->Reserved, 1, 6); Header->Channels = GetBigUShort(); Header->Height = GetBigUInt(); Header->Width = GetBigUInt(); Header->Depth = GetBigUShort(); Header->Mode = GetBigUShort(); return IL_TRUE; }
ILboolean iLoadDcxInternal() { DCXHEAD Header; ILuint Signature, i, Entries[1024], Num = 0; ILimage *Image, *Base; if (iCurImage == NULL) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (!iIsValidDcx()) return IL_FALSE; iread(&Signature, 1, 4); do { if (iread(&Entries[Num], 1, 4) != 4) return IL_FALSE; Num++; } while (Entries[Num-1] != 0); iCurImage->NumNext = Num - 1; for (i = 0; i < Num; i++) { iseek(Entries[i], IL_SEEK_SET); iGetDcxHead(&Header); /*if (!iCheckDcx(&Header)) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; }*/ Image = iUncompressDcx(&Header); if (Image == NULL) return IL_FALSE; if (i == 0) { ilTexImage(Image->Width, Image->Height, 1, Image->Bpp, Image->Format, Image->Type, Image->Data); Base = iCurImage; Base->Origin = IL_ORIGIN_UPPER_LEFT; ilCloseImage(Image); } else { iCurImage->Next = Image; iCurImage = iCurImage->Next; } } ilFixImage(); return IL_TRUE; }
// Internal function used to get the .pic header from the current file. ILboolean iGetPicHead(PIC_HEAD *Header) { Header->Magic = GetBigInt(); Header->Version = GetBigFloat(); iread(Header->Comment, 1, 80); iread(Header->Id, 1, 4); Header->Width = GetBigShort(); Header->Height = GetBigShort(); Header->Ratio = GetBigFloat(); Header->Fields = GetBigShort(); Header->Padding = GetBigShort(); return IL_TRUE; }
ILint iGetScanLine(ILubyte *ScanLine, iSgiHeader *Head, ILuint Length) { ILushort Pixel, Count; // For current pixel ILuint BppRead = 0, CurPos = 0, Bps = Head->XSize * Head->Bpc; while (BppRead < Length && CurPos < Bps) { Pixel = 0; if (iread(&Pixel, Head->Bpc, 1) != 1) return -1; #ifndef __LITTLE_ENDIAN__ iSwapUShort(&Pixel); #endif if (!(Count = (Pixel & 0x7f))) // If 0, line ends return CurPos; if (Pixel & 0x80) { // If top bit set, then it is a "run" if (iread(ScanLine, Head->Bpc, Count) != Count) return -1; BppRead += Head->Bpc * Count + Head->Bpc; ScanLine += Head->Bpc * Count; CurPos += Head->Bpc * Count; } else { if (iread(&Pixel, Head->Bpc, 1) != 1) return -1; #ifndef __LITTLE_ENDIAN__ iSwapUShort(&Pixel); #endif if (Head->Bpc == 1) { while (Count--) { *ScanLine = (ILubyte)Pixel; ScanLine++; CurPos++; } } else { while (Count--) { *(ILushort*)ScanLine = Pixel; ScanLine += 2; CurPos += 2; } } BppRead += Head->Bpc + Head->Bpc; } } return CurPos; }
ILboolean ReadGenAttributes() { BLOCKHEAD AttHead; ILint Padding; ILuint ChunkLen; if (iread(&AttHead, sizeof(AttHead), 1) != 1) return IL_FALSE; UShort(&AttHead.BlockID); UInt(&AttHead.BlockLen); if (AttHead.HeadID[0] != 0x7E || AttHead.HeadID[1] != 0x42 || AttHead.HeadID[2] != 0x4B || AttHead.HeadID[3] != 0x00) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } if (AttHead.BlockID != PSP_IMAGE_BLOCK) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } ChunkLen = GetLittleUInt(); if (Header.MajorVersion != 3) ChunkLen -= 4; if (iread(&AttChunk, IL_MIN(sizeof(AttChunk), ChunkLen), 1) != 1) return IL_FALSE; // Can have new entries in newer versions of the spec (4.0). Padding = (ChunkLen) - sizeof(AttChunk); if (Padding > 0) iseek(Padding, IL_SEEK_CUR); // @TODO: Anything but 24 not supported yet... if (AttChunk.BitDepth != 24 && AttChunk.BitDepth != 8) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } // @TODO; Add support for compression... if (AttChunk.Compression != PSP_COMP_NONE && AttChunk.Compression != PSP_COMP_RLE) { ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } // @TODO: Check more things in the general attributes chunk here. return IL_TRUE; }
int sockRead(int sockfd,char *buf,size_t n) { int total_nbytes=0; int nbytes; int saved_errno; while (total_nbytes < n) { nbytes=iread(sockfd,&buf[total_nbytes], n-total_nbytes); if (nbytes < 0) { saved_errno=errno; if (saved_errno == ECONNRESET) { return (-3); } else return (-1); } else if (nbytes == 0) return (total_nbytes); else total_nbytes += nbytes; } return (total_nbytes); }
/* * Forget what we know about an inode without removing it * * N.B: ordering of iwrite and dfree is important */ int iupdate(Icache *ic, uint32_t ino, Qid qid) { Ibuf *b; Imap *m; Dptr d; if(statson) cfsstat.nupdate++; b = iread(ic, ino); if(b == 0) return -1; /* * update inode and map */ b->inode.qid = qid; b->inode.length = 0x7fffffffffffffffLL; /* Set to maximum */ m = &ic->map[ino]; m->qid = qid; /* * the free is not done if the write fails! * this is important */ d = b->inode.ptr; b->inode.ptr.bno = Notabno; if(iwrite(ic, b) < 0) return -1; dfree(ic, &d); return 0; }
/* * Get a character from the keyboard. */ int getchr(void) { unsigned char c; int result; do { result = iread(tty, &c, sizeof (char)); if (result == READ_INTR) return (READ_INTR); if (result < 0) { /* * Don't call error() here, * because error calls getchr! */ quit(QUIT_ERROR); } /* * Various parts of the program cannot handle * an input character of '\0'. * If a '\0' was actually typed, convert it to '\340' here. */ if (c == '\0') c = 0340; } while (result != 1); return (c & 0xFF); }
// Internal function used to get the Lif header from the current file. ILboolean iGetLifHead(LIF_HEAD *Header) { iread(Header->Id, 1, 8); Header->Version = GetLittleUInt(); Header->Flags = GetLittleUInt(); Header->Width = GetLittleUInt(); Header->Height = GetLittleUInt(); Header->PaletteCRC = GetLittleUInt(); Header->ImageCRC = GetLittleUInt(); Header->PalOffset = GetLittleUInt(); Header->TeamEffect0 = GetLittleUInt(); Header->TeamEffect1 = GetLittleUInt(); return IL_TRUE; }
fill_input_buffer (j_decompress_ptr cinfo) { iread_ptr src = (iread_ptr) cinfo->src; ILint nbytes; nbytes = iread(src->buffer, 1, INPUT_BUF_SIZE); if (nbytes <= 0) { if (src->start_of_file) { // Treat empty input file as fatal error //ERREXIT(cinfo, JERR_INPUT_EMPTY); jpgErrorOccured = IL_TRUE; } //WARNMS(cinfo, JWRN_JPEG_EOF); // Insert a fake EOI marker src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; return IL_FALSE; } if (nbytes < INPUT_BUF_SIZE) { ilGetError(); // Gets rid of the IL_FILE_READ_ERROR. } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = IL_FALSE; return IL_TRUE; }
char *iffReadUncompressedTile(ILushort width, ILushort height, ILbyte depth) { char *data = NULL; char *iniPixel; char *finPixel; int i, j; int tam = width* height * depth * sizeof(char); data = ialloc(tam); if (data == NULL) return NULL; if (iread(data, tam, 1) != 1) { ifree(data); return NULL; } iniPixel = data; for (i = 0; i < tam / depth; i++) { finPixel = iniPixel + depth; for (j = 0; j < (depth /2); j++) { char aux; aux = *iniPixel; *(finPixel--) = *iniPixel; *(iniPixel++) = aux; } } return data; }
// Internal function used to load the Pxr. ILboolean iLoadPxrInternal() { ILushort Width, Height; ILubyte Bpp; Width = sizeof(PIXHEAD); iseek(416, IL_SEEK_SET); Height = GetLittleUShort(); Width = GetLittleUShort(); iseek(424, IL_SEEK_SET); Bpp = igetc(); switch (Bpp) { case 0x08: ilTexImage(Width, Height, 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, NULL); break; case 0x0E: ilTexImage(Width, Height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL); break; case 0x0F: ilTexImage(Width, Height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, NULL); break; default: ilSetError(IL_INVALID_FILE_HEADER); return IL_FALSE; } iseek(1024, IL_SEEK_SET); iread(iCurImage->Data, 1, iCurImage->SizeOfData); iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; return IL_TRUE; }
// Internal function to load a raw data image ILboolean iLoadDataInternal(ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp) { if (iCurImage == NULL || ((Bpp != 1) && (Bpp != 3) && (Bpp != 4))) { ilSetError(IL_ILLEGAL_OPERATION); return IL_FALSE; } if (!ilTexImage(Width, Height, Depth, Bpp, 0, IL_UNSIGNED_BYTE, NULL)) { return IL_FALSE; } iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; // Tries to read the correct amount of data if (iread(iCurImage->Data, Width * Height * Depth * Bpp, 1) != 1) return IL_FALSE; 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(); }
ILboolean channelReadPure(ILubyte *scan, ILint width, ILint noCol, ILint *off, ILint bytes) { ILubyte col[4]; ILint count; int i, j, k; for (i = width; i > 0; ) { count = igetc(); if (count == IL_EOF) return IL_FALSE; if (count > width) count = width; i -= count; if (ieof()) return IL_FALSE; for (j = 0; j < noCol; j++) if (iread(&col[j], 1, 1) != 1) return IL_FALSE; for (k = 0; k < count; k++, scan += bytes) { for(j = 0; j < noCol; j++) scan[off[j] + k] = col[j]; } } return IL_TRUE; }
//--------------------------------------------------------------------------------------------- // feed data to the decoder //--------------------------------------------------------------------------------------------- mng_bool MNG_DECL mymngreadstream(mng_handle mng, mng_ptr buffer, mng_size_t size, mng_uint32 *bytesread) { // read the requested amount of data from the file *bytesread = iread(buffer, 1, size); return MNG_TRUE; }
// Much easier to read - just assemble from planes, no decompression ILboolean iReadNonRleSgi(iSgiHeader *Head) { ILuint i, c; // ILint ChanInt = 0; Unused ILint ChanSize; ILboolean Cache = IL_FALSE; if (!iNewSgi(Head)) { return IL_FALSE; } if (iGetHint(IL_MEM_SPEED_HINT) == IL_FASTEST) { Cache = IL_TRUE; ChanSize = Head->XSize * Head->YSize * Head->Bpc; iPreCache(ChanSize); } for (c = 0; c < iCurImage->Bpp; c++) { for (i = c; i < iCurImage->SizeOfData; i += iCurImage->Bpp) { if (iread(iCurImage->Data + i, 1, 1) != 1) { if (Cache) iUnCache(); return IL_FALSE; } } } if (Cache) iUnCache(); return IL_TRUE; }
ILboolean ReadPalette(ILuint BlockLen) { ILuint ChunkSize, PalCount, Padding; if (Header.MajorVersion >= 4) { ChunkSize = GetLittleUInt(); PalCount = GetLittleUInt(); Padding = (ChunkSize - 4 - 4); if (Padding > 0) iseek(Padding, IL_SEEK_CUR); } else { PalCount = GetLittleUInt(); } Pal.PalSize = PalCount * 4; Pal.PalType = IL_PAL_BGRA32; Pal.Palette = (ILubyte*)ialloc(Pal.PalSize); if (Pal.Palette == NULL) return IL_FALSE; if (iread(Pal.Palette, Pal.PalSize, 1) != 1) { ifree(Pal.Palette); return IL_FALSE; } return IL_TRUE; }
ERR iReadWS_File(struct WMPStream* pWS, void* pv, size_t cb) { // For some reason, the WDP images load just fine, but it tries to read too much, // so IL_FILE_READ_ERROR is set. So we get rid of the error. if (iread(pv, 1, (ILuint)cb) != cb) ilGetError(); return WMP_errSuccess; }
/// Updates the downbuffer internal variable. /// Returns true if new data was received, false otherwise. bool Socket::Connection::spool() { /// \todo Provide better mechanism to prevent overbuffering. if (downbuffer.size() > 10000) { return true; } else { return iread(downbuffer); } }
// Internal function used to get the .sgi header from the current file. ILboolean iGetSgiHead(iSgiHeader *Header) { Header->MagicNum = GetBigUShort(); Header->Storage = (ILbyte)igetc(); Header->Bpc = (ILbyte)igetc(); Header->Dim = GetBigUShort(); Header->XSize = GetBigUShort(); Header->YSize = GetBigUShort(); Header->ZSize = GetBigUShort(); Header->PixMin = GetBigInt(); Header->PixMax = GetBigInt(); Header->Dummy1 = GetBigInt(); iread(Header->Name, 1, 80); Header->ColMap = GetBigInt(); iread(Header->Dummy, 1, 404); return IL_TRUE; }
// Internal function used to get the Psp header from the current file. ILboolean iGetPspHead() { if (iread(Header.FileSig, 1, 32) != 32) return IL_FALSE; Header.MajorVersion = GetLittleUShort(); Header.MinorVersion = GetLittleUShort(); return IL_TRUE; }
/// Read call that is compatible with Socket::Buffer. /// Data is read using iread (which is nonblocking if the Socket::Connection itself is), /// then appended to end of buffer. /// \param buffer Socket::Buffer to append data to. /// \return True if new data arrived, false otherwise. bool Socket::Connection::iread(Buffer & buffer){ char cbuffer[BUFFER_BLOCKSIZE]; int num = iread(cbuffer, BUFFER_BLOCKSIZE); if (num < 1){ return false; } buffer.append(cbuffer, num); return true; } //iread
/* * get an inode into the cache. if no inode exists for this qid, create one * from an unused qid/inode map. */ Ibuf * iget(Icache *ic, Qid qid) { Imap *m, *me; Ibuf *b; /* * find map entry with same qid.path */ for(m = ic->map, me = &ic->map[ic->nino]; m < me; m++) if(m->inuse && m->qid.path==qid.path){ if(m->qid.vers != qid.vers){ /* * our info is old, forget it */ DPRINT(2, "updating old file %llu.%lu\n", qid.path, qid.vers); m->qid = qid; iupdate(ic, m - ic->map, qid); } break; } /* * if an already existing inode, just get it */ if(m != me) return iread(ic, m - ic->map); /* * create a new inode, throw out the least recently used inode * if necessary */ m = (Imap*)ic->mlru.lnext; if(m->inuse){ DPRINT(2, "superceding file %llu.%ld by %llu.%ld\n", m->qid.path, m->qid.vers, qid.path, qid.vers); if(iremove(ic, m - ic->map) < 0) return 0; } if(statson) cfsstat.ninsert++; /* * init inode and write to disk */ DPRINT(2, "new file %llu.%ld ino %ld\n", qid.path, qid.vers, m - ic->map); b = ialloc(ic, m - ic->map); b->inode.inuse = m->inuse = 1; b->inode.qid = qid; b->inode.length = 0x7fffffffffffffffLL; m->qid = qid; b->inode.ptr.bno = Notabno; iwrite(ic, b); return b; }
ILboolean ReadGrey(PSDHEAD *Head) { ILuint ColorMode, ResourceSize, MiscInfo; ILushort Compressed; ILenum Type; ILubyte *Resources = NULL; ColorMode = GetBigUInt(); // Skip over the 'color mode data section' iseek(ColorMode, IL_SEEK_CUR); ResourceSize = GetBigUInt(); // Read the 'image resources section' Resources = (ILubyte*)ialloc(ResourceSize); if (Resources == NULL) { return IL_FALSE; } if (iread(Resources, 1, ResourceSize) != ResourceSize) goto cleanup_error; MiscInfo = GetBigUInt(); iseek(MiscInfo, IL_SEEK_CUR); Compressed = GetBigUShort(); ChannelNum = Head->Channels; Head->Channels = 1; // Temporary to read only one channel...some greyscale .psd files have 2. if (Head->Channels != 1) { ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; } switch (Head->Depth) { case 8: Type = IL_UNSIGNED_BYTE; break; case 16: Type = IL_UNSIGNED_SHORT; break; default: ilSetError(IL_FORMAT_NOT_SUPPORTED); return IL_FALSE; } if (!ilTexImage(Head->Width, Head->Height, 1, 1, IL_LUMINANCE, Type, NULL)) goto cleanup_error; if (!PsdGetData(Head, iCurImage->Data, (ILboolean)Compressed)) goto cleanup_error; if (!ParseResources(ResourceSize, Resources)) goto cleanup_error; ifree(Resources); return IL_TRUE; cleanup_error: ifree(Resources); return IL_FALSE; }
int rbuf_read_bufferful (struct rbuf *rbuf) { #ifdef HAVE_SSL if (rbuf->ssl) return ssl_iread (rbuf->ssl, rbuf->buffer, sizeof (rbuf->buffer)); else #endif return iread (rbuf->fd, rbuf->buffer, sizeof (rbuf->buffer)); }
// 删除用户,用户目录不空不能删除 int MFD::del(char *s) { int uid = find(s); if (uid == -1) return e_not; UFD ufd; // 先读取该用户空间的目录 iread(&ufd, UFD_SZ, superblock.ufd+uid*UFD_SZ); if (ufd.n > 0) return e_invalid; // 目录不为空 users[uid].init("", -1); n--; return 0; }
ILboolean iIsValidDcx() { ILuint Signature; if (iread(&Signature, 1, 4) != 4) return IL_FALSE; iseek(-4, IL_SEEK_CUR); return (Signature == 987654321); }