bool Targa::LoadFromMemory(const unsigned char* data,unsigned long size) { delete[] mData; mData = NULL; if(size < sizeof(TargaHeader)) return false; CopyMemory(&mHeader,data,sizeof(TargaHeader)); size -= sizeof(TargaHeader); data += sizeof(TargaHeader); // 0 - No image data included. // 1 - Uncompressed, color-mapped images. // 2 - Uncompressed, RGB images. // 3 - Uncompressed, black and white images. // 9 - Runlength encoded color-mapped images. // 10 - Runlength encoded RGB images. // 11 - Compressed, black and white images. // 32 - Compressed color-mapped data, using Huffman, Delta, and runlength encoding. // 33 - Compressed color-mapped data, using Huffman, Delta, and runlength encoding. 4-pass quadtree-type process. // We only support uncompressed RGB images written in top to bottom order if(mHeader.datatypecode != 2 /*|| mHeader.imagedescriptor != 8*/) return false; if(size < (unsigned long)mHeader.idlength + mHeader.colormaptype * mHeader.colormaplength) return false; data += mHeader.idlength + mHeader.colormaptype * mHeader.colormaplength; size -= mHeader.idlength + mHeader.colormaptype * mHeader.colormaplength; if(mHeader.bitsperpixel == 32) return Get32(data, size); else if(mHeader.bitsperpixel == 24) return Get24(data, size); else if(mHeader.bitsperpixel == 8) return Get8(data, size); return false; }
BYTE GetSBRRec() // read the next record from the current .sbr file // { BYTE col; int cbRead; // read rectype, check for EOF as we go if (cchBuf < CB_SBRMIN) { if (!fAllRead) { // copy what's left over (note there is no overlap) memcpy(sbrBuf, pchBuf, cchBuf); cbRead = _read(fhCur, sbrBuf + cchBuf, CB_SBRBUF - cchBuf); if (cbRead < 0) cbRead = 0; cchBuf += cbRead; pchBuf = sbrBuf; if (cchBuf != CB_SBRBUF) fAllRead = TRUE; } if (cchBuf == 0) { fFoundHeader = FALSE; // this is in case we are reinitialized fAllRead = FALSE; return S_EOF; } } char *pxBuf = pchBuf; GetByte(r_rectyp); int r = GetSbrRecType(r_rectyp); if (r >= SBR_REC_BUMP_N && r < SBR_REC_BUMP_N + 16) { int delta = 1 + r - SBR_REC_BUMP_N; r_lineno += delta; r = SBR_REC_LINDEF; } else switch(r) { case SBR_REC_HEADER: if (fFoundHeader) SBRCorrupt("Multiple Headers"); case SBR_REC_INFOSEP: fFoundHeader = 1; GetByte(r_majv); GetByte(r_minv); GetByte(r_lang); GetByte(r_fcol); fSbr11 = FALSE; if (r_majv == 1 && r_minv == 1) fSbr11 = TRUE; else if (r_majv != SBR_VER_MAJOR || r_minv != SBR_VER_MINOR) break; CopyStr (r_cwd); break; case SBR_REC_MODULE: case SBR_REC_PCHNAME: GetStr(r_bname); break; case SBR_REC_LINDELTA: { short delta; GetWord(delta); r_lineno += delta; r = SBR_REC_LINDEF; break; } case SBR_REC_LINDEF: GetWord(r_lineno); if (r_lineno) r_lineno--; break; case SBR_REC_BASE: if (!FExtRec()) { r_ordinal = 0; GetWord(r_ordinal); GetByte(r_type); if (r_ordinal & 0x8000) r_ordinal |= 0xffff0000; } else { r_ordinal = 0; Get24(r_ordinal); GetByte(r_type); if (r_ordinal & 0x800000) r_ordinal |= 0xff000000; } break; case SBR_REC_SYMDEF: if (!FExtRec()) { if (!fSbr11) { GetByte(r_type); GetWord(r_attrib); } else { GetWord(r_attrib); r_type = (BYTE)(r_attrib >> 11); r_attrib &= 0x07ff; } r_ordinal = 0; GetWord(r_ordinal); if (r_fcol) GetByte(col); GetStr(r_bname); if (r_ordinal & 0x8000) r_ordinal |= 0xffff0000; } else { GetByte(r_type); GetWord(r_attrib); r_ordinal = 0; Get24(r_ordinal); if (r_fcol) GetByte(col); GetStr(r_bname); if (r_ordinal & 0x800000) r_ordinal |= 0xff000000; } break; case SBR_REC_OWNER: case SBR_REC_FRIEND: if (!FExtRec()) { r_ordinal = 0; GetWord(r_ordinal); if (r_ordinal & 0x8000) r_ordinal |= 0xffff0000; } else { r_ordinal = 0; Get24(r_ordinal); if (r_ordinal & 0x800000) r_ordinal |= 0xff000000; } break; case SBR_REC_SYMREFUSE: case SBR_REC_SYMREFSET: if (!FExtRec()) { r_ordinal = 0; GetWord(r_ordinal); if (r_fcol) GetByte(col); if (r_ordinal & 0x8000) r_ordinal |= 0xffff0000; } else { r_ordinal = 0; Get24(r_ordinal); if (r_fcol) GetByte(col); if (r_ordinal & 0x800000) r_ordinal |= 0xff000000; } break; }