int ReadWinZipJPEGHeader(WinZipJPEGDecompressor *self) { // Read 4-byte header. uint8_t header[4]; int error=FullRead(self,header,sizeof(header)); if(error) return error; // Sanity check the header, and make sure it contains only versions we can handle. if(header[0]<4) return WinZipJPEGInvalidHeaderError; if(header[1]!=0x10) return WinZipJPEGInvalidHeaderError; if(header[2]!=0x01) return WinZipJPEGInvalidHeaderError; if(header[3]&0xe0) return WinZipJPEGInvalidHeaderError; // The header can possibly be bigger than 4 bytes, so skip the rest. // (Unlikely to happen). if(header[0]>4) { int error=SkipBytes(self,header[0]-4); if(error) return error; } // Parse slice value. self->slicevalue=header[3]&0x1f; return WinZipJPEGNoError; }
SDIFresult SDIF_SkipMatrix(const SDIF_MatrixHeader *head, FILE *f) { int32_t size = SDIF_GetMatrixDataSize(head); if (size < 0) { return ESDIF_BAD_MATRIX_HEADER; } return SkipBytes(f, size); }
HRESULT DataTargetReader::SkipPointer() { HRESULT hr = S_OK; if (m_remotePointerSize == 0) { IfFailRet(GetRemotePointerSize(&m_remotePointerSize)); } _ASSERTE(m_remotePointerSize == 4 || m_remotePointerSize == 8); Align(m_remotePointerSize); return SkipBytes(m_remotePointerSize); }
SDIFresult SDIF_SkipFrame(const SDIF_FrameHeader *head, FILE *f) { /* The header's size count includes the 8-byte time tag, 4-byte stream ID and 4-byte matrix count that we already read. */ int32_t bytesToSkip = head->size - 16; if (bytesToSkip < 0) { return ESDIF_BAD_FRAME_HEADER; } return SkipBytes(f, bytesToSkip); }
CHARLS_IMEXPORT(JLS_ERROR) JpegLsEncodeStream(ByteStreamInfo compressedStreamInfo, size_t* pcbyteWritten, ByteStreamInfo rawStreamInfo, struct JlsParameters* pparams) { if (pcbyteWritten == NULL) return InvalidJlsParameters; JLS_ERROR parameterError = CheckInput(rawStreamInfo, pparams); if (parameterError != OK) return parameterError; try { JlsParameters info = *pparams; if (info.bytesperline == 0) { info.bytesperline = info.width * ((info.bitspersample + 7)/8); if (info.ilv != ILV_NONE) { info.bytesperline *= info.components; } } Size size = Size(info.width, info.height); JpegMarkerWriter writer(info.jfif, size, info.bitspersample, info.components); if (info.colorTransform != 0) { writer.AddColorTransform(info.colorTransform); } if (info.ilv == ILV_NONE) { LONG cbyteComp = size.cx*size.cy*((info.bitspersample +7)/8); for (LONG component = 0; component < info.components; ++component) { writer.AddScan(rawStreamInfo, &info); SkipBytes(&rawStreamInfo, cbyteComp); } } else { writer.AddScan(rawStreamInfo, &info); } writer.Write(compressedStreamInfo); *pcbyteWritten = writer.GetBytesWritten(); return OK; } catch (const JlsException& e) { return e._error; } }
CHARLS_IMEXPORT(JLS_ERROR) JpegLsEncodeStream(void* compressedData, size_t compressedLength, size_t* pcbyteWritten, ByteStreamInfo rawStreamInfo, struct JlsParameters* pparams) { JlsParameters info = *pparams; if(info.bytesperline == 0) { info.bytesperline = info.width * ((info.bitspersample + 7)/8); if (info.ilv != ILV_NONE) { info.bytesperline *= info.components; } } JLS_ERROR parameterError = CheckInput(compressedData, compressedLength, rawStreamInfo, &info); if (parameterError != OK) return parameterError; if (pcbyteWritten == NULL) return InvalidJlsParameters; Size size = Size(info.width, info.height); JLSOutputStream stream; stream.Init(size, info.bitspersample, info.components); if (info.colorTransform != 0) { stream.AddColorTransform(info.colorTransform); } if (info.ilv == ILV_NONE) { LONG cbyteComp = size.cx*size.cy*((info.bitspersample +7)/8); for (LONG component = 0; component < info.components; ++component) { stream.AddScan(rawStreamInfo, &info); SkipBytes(&rawStreamInfo, cbyteComp); } } else { stream.AddScan(rawStreamInfo, &info); } stream.Write((BYTE*)compressedData, compressedLength); *pcbyteWritten = stream.GetBytesWritten(); return OK; }
CHARLS_IMEXPORT(JLS_ERROR) JpegLsVerifyEncode(const void* uncompressedData, size_t uncompressedLength, const void* compressedData, size_t compressedLength) { JlsParameters info = JlsParameters(); JLS_ERROR error = JpegLsReadHeader(compressedData, compressedLength, &info); if (error != OK) return error; ByteStreamInfo rawStreamInfo = FromByteArray(uncompressedData, uncompressedLength); error = CheckInput(compressedData, compressedLength, rawStreamInfo, &info); if (error != OK) return error; Size size = Size(info.width, info.height); JLSOutputStream stream; stream.Init(size, info.bitspersample, info.components); if (info.ilv == ILV_NONE) { LONG fieldLength = size.cx*size.cy*((info.bitspersample +7)/8); for (LONG component = 0; component < info.components; ++component) { stream.AddScan(rawStreamInfo, &info); SkipBytes(&rawStreamInfo, fieldLength); } } else { stream.AddScan(rawStreamInfo, &info); } std::vector<BYTE> rgbyteCompressed(compressedLength + 16); memcpy(&rgbyteCompressed[0], compressedData, compressedLength); stream.EnableCompare(true); stream.Write(&rgbyteCompressed[0], rgbyteCompressed.size()); return OK; }
/* Read in data from the ring buffer to another ring buffer object specified by * 'rBuf'. */ bool CRingBuffer::ReadData(CRingBuffer &rBuf, unsigned int size) { CSingleLock lock(m_critSection); if (rBuf.getBuffer() == NULL) rBuf.Create(size); bool bOk = size <= rBuf.getMaxWriteSize() && size <= getMaxReadSize(); if (bOk) { unsigned int chunksize = std::min(size, m_size - m_readPtr); bOk = rBuf.WriteData(&getBuffer()[m_readPtr], chunksize); if (bOk && chunksize < size) bOk = rBuf.WriteData(&getBuffer()[0], size - chunksize); if (bOk) SkipBytes(size); } return bOk; }
SDIFresult SDIF_BeginRead(FILE *input) { SDIF_GlobalHeader sgh; SDIFresult r; /* make sure the header is OK. */ if ((r = SDIF_Read1(sgh.SDIF, 4, input))!=ESDIF_SUCCESS) return r; if (!SDIF_Char4Eq(sgh.SDIF, "SDIF")) return ESDIF_BAD_SDIF_HEADER; if ((r = SDIF_Read4(&sgh.size, 1, input))!=ESDIF_SUCCESS) return r; if (sgh.size % 8 != 0) return ESDIF_BAD_SDIF_HEADER; if (sgh.size < 8) return ESDIF_BAD_SDIF_HEADER; if ((r = SDIF_Read4(&sgh.SDIFversion, 1, input))!=ESDIF_SUCCESS) return r; if ((r = SDIF_Read4(&sgh.SDIFStandardTypesVersion, 1, input))!=ESDIF_SUCCESS) return r; if (sgh.SDIFversion != 3) { /*RWD was < 3 */ return ESDIF_OBSOLETE_FILE_VERSION; } if (sgh.SDIFStandardTypesVersion < 1) { return ESDIF_OBSOLETE_TYPES_VERSION; } /* skip size-8 bytes. (We already read the first two version numbers, but maybe there's more data in the header frame.) */ if (sgh.size == 8) { return ESDIF_SUCCESS; } if (SkipBytes(input, sgh.size-8)!=ESDIF_SUCCESS) { return ESDIF_BAD_SDIF_HEADER; } return ESDIF_SUCCESS; }
/// SimpleDPX::ParseHeader // Parse the file header of a DPX file void SimpleDPX::ParseHeader(FILE *file,struct ImgSpecs &specs) { ULONG hdr; char version[9]; ULONG encryption; UWORD orientation; UWORD depth,alpha; ULONG width,height; UWORD i; struct ComponentLayout *cl; m_bLittleEndian = false; hdr = GetLong(file); if (hdr == MakeID('S','D','P','X')) { // This is big-endian. m_bLittleEndian = false; } else if (hdr == MakeID('X','P','D','S')) { m_bLittleEndian = true; } else { PostError("input file %s is not a valid DPX file",m_pcFileName); } m_ulDataOffset = GetLong(file); version[8] = 0; GetString(file,version,8); if (strcmp(version,"V1.0") && strcmp(version,"V2.0")) PostError("unsupported DPX version detected, only V1.0 and V2.0 are supported"); SkipBytes(file,8); // file size and ditto key are not really needed. // // Read sizes of data structures. m_ulGenericSize = GetLong(file); m_ulIndustrySize = GetLong(file); m_ulUserSize = GetLong(file); // // Skip over the bytes we do not care about. SkipBytes(file,100+24+100+200+200); // // Read the encyrption key. encryption = GetLong(file); if (encryption != ULONG(~0UL)) fprintf(stderr,"Warning! - DPX file %s signals encryption, output may be wrong.\n",m_pcFileName); // // Skip over the rest of the header. not needed. SkipBytes(file,104); // // Read the image orientation orientation = GetWord(file); if (orientation >= 8) PostError("unknown orientation specified in DPX file %s, must be between 0 and 7",m_pcFileName); m_bFlipX = (orientation & 1)?true:false; m_bFlipY = (orientation & 2)?true:false; m_bFlipXY = (orientation & 4)?true:false; m_usElements = GetWord(file); if (m_usElements == 0 || m_usElements > 8) PostError("number of image elements must be between 1 and 8 in DPX file %s",m_pcFileName); width = GetLong(file); height = GetLong(file); if (m_bFlipXY) { m_ulHeight = width; m_ulWidth = height; } else { m_ulWidth = width; m_ulHeight = height; } specs.ASCII = ImgSpecs::No; specs.Interleaved = (m_usElements == 1)?(ImgSpecs::Yes):(ImgSpecs::No); specs.YUVEncoded = ImgSpecs::No; // changed possibly to Yes later on. specs.Palettized = ImgSpecs::No; specs.LittleEndian = (m_bLittleEndian)?(ImgSpecs::Yes):(ImgSpecs::No); // // Image elements. All eight are always present, though only the first m_usElements contain // valid data. for(i = 0;i < 8;i++) { if (i < m_usElements) { m_Elements[i].m_ulWidth = width; m_Elements[i].m_ulHeight = height; if (ParseElementHeader(file,m_Elements + i)) specs.YUVEncoded = ImgSpecs::Yes; } else { // Skip over elements we do not need SkipBytes(file,4*5 + 1*4 + 2*2 + 4*3 + 32); } } // // The rest is junk we do not need. // // Now compute the depth of the image. depth = 0; alpha = 0; for (i = 0;i < m_usElements;i++) { depth += m_Elements[i].m_ucDepth; alpha += m_Elements[i].m_ucAlphaDepth; } CreateComponents(m_ulWidth,m_ulHeight,depth + alpha); // // Now create the planes and allocate memory. cl = m_pComponent; for(i = 0;i < m_usElements;i++) { struct ImageElement *el = m_Elements + i; struct ScanElement *sl = el->m_pScanPattern; while(sl) { struct ComponentLayout *cll; UBYTE bytesperpixel = (el->m_ucBitDepth + 7) >> 3; UBYTE subx = el->m_ucSubX; UBYTE suby = el->m_ucSubY; UWORD k = sl->m_usTargetChannel; // // If flipXY is set, then X and Y change their role, so flip them now. if (m_bFlipXY) { subx = el->m_ucSubY; suby = el->m_ucSubX; } // // LUMA and alpha is always encoded without subsampling. if (k == 0 || k == 3) { subx = suby = 1; } // // Is this an alpha component or not? if (k == MAX_UWORD) { cll = cl + el->m_ucDepth; k = el->m_ucDepth; } else { cll = cl + k; } cll->m_ucBits = m_Elements[i].m_ucBitDepth; cll->m_bSigned = m_Elements[i].m_bSigned; cll->m_bFloat = m_Elements[i].m_bFloat; cll->m_ucSubX = subx; cll->m_ucSubY = suby; cll->m_ulWidth = (m_ulWidth + subx - 1) / subx; cll->m_ulHeight = (m_ulHeight + suby - 1) / suby; cll->m_ulBytesPerPixel = bytesperpixel; cll->m_ulBytesPerRow = cll->m_ulWidth * bytesperpixel; // Check whether we have already data for this channel. If not, allocate now. // As a channel may appear multiple times in one scan pattern, make sure to // allocate only once. if (el->m_pData[k] == NULL) { el->m_pData[k] = new UBYTE[cll->m_ulWidth * bytesperpixel * cll->m_ulHeight]; cll->m_pPtr = el->m_pData[k]; sl->m_bFirst = true; } sl->m_pData = cll->m_pPtr; sl->m_pComponent = cll; sl = sl->m_pNext; } // Adjust the components. cl += el->m_ucDepth + el->m_ucAlphaDepth; } }
/// SimpleDPX::ParseElementHeader // Parse a single element header from the given file. bool SimpleDPX::ParseElementHeader(FILE *file,struct ImageElement *el) { ULONG sign; UBYTE xfer,color; UWORD packing,encoding; bool yuv = false; // // Read an element. sign = GetLong(file); switch(sign) { case 0: el->m_bSigned = false; break; case 1: el->m_bSigned = true; break; default: PostError("found invalid signedness indicator in DPX file %s, must be either 1 or 0",m_pcFileName); break; } // Next four are luma scaling attributes we do not need to support. SkipBytes(file,4+4+4+4); // el->m_ucDescriptor = GetByte(file); // // Read the transfer characteristics. Not that we do anything about it. xfer = GetByte(file); if (xfer > 12) PostError("found unspecified DPX transfer characteristics in file %s",m_pcFileName); // // Read the colorimetric specification. Nothing we can make use of. color = GetByte(file); if (color > 10) PostError("found invalid colorimetric specification in DPX file %s",m_pcFileName); // el->m_ucBitDepth = GetByte(file); // Get the packing information. 0 is full packing, // 1 is with packing bits at the LSB side, 2 is with packing bits at // the MSB side. packing = GetWord(file); if (packing > 2) PostError("found invalid DPX padding specification in file %s",m_pcFileName); // switch(el->m_ucBitDepth) { case 8: case 16: // These are all integer bit depths DPX allows. No padding, no packing. break; case 1: // 11 bit elements are packed to 32 bit LONGs // No padding bits. el->m_ucPackElements = 32; break; case 10: // 10 bit elements are packed to 32 bit LONGs // Padding is possible. switch(packing) { case 1: el->m_ucLSBPaddingBits = 2; break; case 2: el->m_ucMSBPaddingBits = 2; break; } el->m_ucPackElements = 3; break; case 12: // 12 bit elements are packed to 32 bit LONGs. // Three elements are packed into one 32 bit word. switch(packing) { case 1: el->m_ucLSBPaddingBits = 4; break; case 2: el->m_ucMSBPaddingBits = 4; break; } el->m_ucPackElements = 1; break; case 32: case 64: el->m_bFloat = true; break; default: PostError("found invalid DPX bit depth in file %s",m_pcFileName); break; } // yuv = BuildScanPattern(el); // // Get the encoding information. encoding = GetWord(file); switch(encoding) { case 0: // no encoding. break; case 1: // RLE encoding. el->m_bRLE = true; // No idea what RLE and FLOAT is supposed to mean. How is the run length // encoded? if (el->m_bFloat) PostError("RLE encoding and floating point samples as found in file %s " "are undocumented in the DPX specs and not supported",m_pcFileName); break; default: PostError("found invalid DPX encoding specification in file %s",m_pcFileName); break; } // // Get the offset to the data. el->m_ulOffset = GetLong(file); // // Read end of line/end of frame padding. el->m_ulEndOfLinePadding = GetLong(file); // Read end of frame padding. el->m_ulEndOfFramePadding = GetLong(file); // // Skip the 32 bytes description. SkipBytes(file,32); // return yuv; }
HRESULT DataTargetReader::Skip64() { Align(8); return SkipBytes(sizeof(ULONG64)); }
HRESULT DataTargetReader::Skip32() { Align(4); return SkipBytes(sizeof(ULONG32)); }
HRESULT DataTargetReader::Skip8() { return SkipBytes(1); }
bool AtomMP4A::ReadData() { //qtff.pdf: General StructureofaSampleDescription (76/304) //TODO: there seems to be 2 kinds of DISTINCT mp4a atoms. If the size // of the atom is 0x0c (size+'mp4a'+4 zeros) we should ignore it for now... if (_size == 0x0c) { WARN("Another strange mp4a atom...."); return true; } //1. Skip reserved 6 bytes. Actually, slip the next 2, because the prev 4 //are already skipped by the versioned atom if (!SkipBytes(2)) { FATAL("Unable to skip 2 bytes"); return false; } if (!ReadUInt16(_dataReferenceIndex)) { FATAL("Unable to read count"); return false; } if (!ReadUInt16(_innerVersion)) { FATAL("Unable to read count"); return false; } if (!ReadUInt16(_revisionLevel)) { FATAL("Unable to read count"); return false; } if (!ReadUInt32(_vendor)) { FATAL("Unable to read count"); return false; } if (!ReadUInt16(_numberOfChannels)) { FATAL("Unable to read count"); return false; } if (!ReadUInt16(_sampleSizeInBits)) { FATAL("Unable to read count"); return false; } if (!ReadInt16(_compressionId)) { FATAL("Unable to read count"); return false; } if (!ReadUInt16(_packetSize)) { FATAL("Unable to read count"); return false; } if (!ReadUInt32(_sampleRate)) { FATAL("Unable to read count"); return false; } if (_innerVersion == 0) { return true; } if (!ReadUInt32(_samplesPerPacket)) { FATAL("Unable to read count"); return false; } if (!ReadUInt32(_bytesPerPacket)) { FATAL("Unable to read count"); return false; } if (!ReadUInt32(_bytesPerFrame)) { FATAL("Unable to read count"); return false; } if (!ReadUInt32(_bytesPerSample)) { FATAL("Unable to read count"); return false; } return true; }