// Parse the marker in from the JP2 file. CNCSError CNCSJPCRGNMarker::Parse(CNCSJPC &JPC, CNCSJPCIOStream &Stream) { CNCSError Error; m_bHaveMarker = true; NCSJP2_CHECKIO_BEGIN(Error, Stream); NCSJP2_CHECKIO(ReadUINT16(m_nLength)); UINT8 t8; if(JPC.m_SIZ.m_nCsiz < 257) { NCSJP2_CHECKIO(ReadUINT8(t8)); m_nCrgn = t8; } else { NCSJP2_CHECKIO(ReadUINT16(m_nCrgn)); } NCSJP2_CHECKIO(ReadUINT8(t8)); if(t8 == 0x0) { m_eSrgn = IMPLICIT; NCSJP2_CHECKIO(ReadUINT8(m_nSPrgn)); } else { Error = NCS_FILEIO_ERROR; } if(Error == NCS_SUCCESS) { m_bValid = true; } NCSJP2_CHECKIO_END(); return(Error); }
// Parse the marker in from the JP2 file. CNCSError CNCSJPCSOPMarker::Parse(CNCSJPC &JPC, CNCSJPCIOStream &Stream) { CNCSError Error; Error = CNCSJPCMarker::Parse(JPC, Stream); if(Error == NCS_SUCCESS && m_eMarker == SOP) { m_bHaveMarker = true; NCSJP2_CHECKIO_BEGIN(Error, Stream); NCSJP2_CHECKIO(ReadUINT16(m_nLength)); NCSJP2_CHECKIO(ReadUINT16(m_nNsop)); m_bValid = true; NCSJP2_CHECKIO_END(); } return(NCS_SUCCESS); }
// Parse the marker in from the JP2 file. CNCSError CNCSJPCCRGMarker::Parse(CNCSJPC &JPC, CNCSJPCIOStream &Stream) { CNCSError Error; m_bHaveMarker = true; NCSJP2_CHECKIO_BEGIN(Error, Stream); NCSJP2_CHECKIO(ReadUINT16(m_nLength)); for(int i = 0; i < JPC.m_SIZ.m_nCsiz; i++) { Registration reg; NCSJP2_CHECKIO(ReadUINT16(reg.m_nXcrg)); NCSJP2_CHECKIO(ReadUINT16(reg.m_nYcrg)); m_Offsets.push_back(reg); } if(Error == NCS_SUCCESS) { m_bValid = true; } NCSJP2_CHECKIO_END(); return(Error); }
// Parse the box in from the stream. CNCSError CNCSJP2File::CNCSJP2UUIDInfoBox::CNCSJP2UUIDListBox::Parse(class CNCSJP2File &JP2File, CNCSJPCIOStream &Stream) { CNCSError Error; NCSJP2_CHECKIO_BEGIN(Error, Stream); // Get the fields in NCSJP2_CHECKIO(ReadUINT16(m_nEntries)); for(int e = 0; e < m_nEntries; e++) { NCSUUID uuid; NCSJP2_CHECKIO(Read(&uuid.m_UUID, sizeof(uuid.m_UUID))); m_UUIDs.push_back(uuid); } m_bValid = true; NCSJP2_CHECKIO_END(); return(Error); }
// Parse the marker in from the JP2 file. CNCSError CNCSJPCPPTMarker::Parse(CNCSJPC &JPC, CNCSJPCIOStream &Stream) { &JPC;//Keep compiler happy CNCSError Error; m_bHaveMarker = true; NCSJP2_CHECKIO_BEGIN(Error, Stream); NCSJP2_CHECKIO(ReadUINT16(m_nLength)); NCSJP2_CHECKIO(ReadUINT8(m_nZppt)); NCSJP2_CHECKIO(Seek(m_nLength - (sizeof(UINT16) + sizeof(UINT8)))); if(Error == NCS_SUCCESS) { m_bValid = true; } NCSJP2_CHECKIO_END(); return(Error); }
void vtkDCMParser::ReadElement(DCMDataElementStruct *des) { if(this->file_in) { PrevFilePos = ftell(file_in); PrevFileIOMessage = FileIOMessage; switch(TransferSyntax) { case TFS_IVRLE: case TFS_IVRBE: des->GroupCode = ReadUINT16(); des->ElementCode = ReadUINT16(); des->Length = ReadUINT32(); des->NextBlock = ftell(file_in); if(des->Length != 0xffffffff) des->NextBlock += des->Length; sprintf(des->VR, "??"); break; case TFS_EVRLE: case TFS_EVRBE: des->GroupCode = ReadUINT16(); des->ElementCode = ReadUINT16(); if((des->GroupCode) == 0xfffe) { if((des->ElementCode == 0xe000) || (des->ElementCode == 0xe00d) || (des->ElementCode == 0xe0dd)) { // must be implicit VR always des->Length = ReadUINT32(); des->NextBlock = ftell(file_in); if(des->Length != 0xffffffff) des->NextBlock += des->Length; sprintf(des->VR, "??"); return; } } ReadText(des->VR, 2); // getting VR if((strcmp(des->VR, "OB") == 0) || (strcmp(des->VR, "OW") == 0) || (strcmp(des->VR, "SQ") == 0) || (strcmp(des->VR, "UN") == 0) || (strcmp(des->VR, "UT") == 0) ) { des->Length = ReadUINT16(); // reserved field des->Length = ReadUINT32(); des->NextBlock = ftell(file_in); if(des->Length != 0xffffffff) des->NextBlock += des->Length; } else { des->Length = ReadUINT16(); des->NextBlock = ftell(file_in); if(des->Length != 0xffffffff) des->NextBlock += des->Length; } break; } } }
bool WavReader_R32::OpenWavFile(const char *pszFilePathName) { if (pszFilePathName == NULL) return false; if (strlen(pszFilePathName) <= 0) return false; if (m_fpSamples != NULL) delete[] m_fpSamples; if (m_pFileHandle != NULL) fclose(m_pFileHandle); m_fpSamples = NULL; m_pFileHandle = NULL; m_uiFrameCount = 0; m_uiSamplingRate = 0; m_uiChannels = 0; m_pFileHandle = fopen(pszFilePathName, "rb"); if (m_pFileHandle == NULL) return false; int8_t cCode[4]; if (!ReadFOURCC(cCode)) return false; if ((cCode[0] != 'R') || (cCode[1] != 'I') || (cCode[2] != 'F') || (cCode[3] != 'F')) return false; uint32_t uiRiffChunkDataSize = ReadUINT32(); if (uiRiffChunkDataSize == 0) return false; if (!ReadFOURCC(cCode)) return false; if ((cCode[0] != 'W') || (cCode[1] != 'A') || (cCode[2] != 'V') || (cCode[3] != 'E')) return false; cCode[0] = 'f'; cCode[1] = 'm'; cCode[2] = 't'; uint32_t nFormatLength = SeekToChunk(cCode, 3); if (nFormatLength < 16) return false; uint16_t nFormatTag = ReadUINT16(); if ((nFormatTag != 0x0001) && (nFormatTag != 0x0003)) return false; uint16_t uiChannels = ReadUINT16(); if ((uiChannels != 1) && (uiChannels != 2)) return false; uint32_t uiSampleRate = ReadUINT32(); ReadUINT32(); ReadUINT16(); uint16_t uiBitsPerSample = ReadUINT16(); if ((uiBitsPerSample != 8) && (uiBitsPerSample != 16) && (uiBitsPerSample != 24) && (uiBitsPerSample != 32)) return false; cCode[0] = 'd'; cCode[1] = 'a'; cCode[2] = 't'; cCode[3] = 'a'; uint32_t uiDataSize = SeekToChunk(cCode, 4); uint32_t uiFrameCount = uiDataSize / (uiBitsPerSample / 8) / uiChannels; if (uiFrameCount == 0) return false; if (nFormatTag == 0x0003) { m_fpSamples = new float[uiFrameCount * uiChannels]; if (m_fpSamples == NULL) return false; uint32_t nReadFrameCount = (uint32_t) fread(m_fpSamples, sizeof(float), uiFrameCount * uiChannels, m_pFileHandle); if (nReadFrameCount != uiFrameCount * uiChannels) { delete[] m_fpSamples; return false; } m_uiFrameCount = uiFrameCount; m_uiSamplingRate = uiSampleRate; m_uiChannels = uiChannels; return true; } else { uint32_t uiReadDataLength = uiFrameCount * uiChannels * (uiBitsPerSample / 8); uint8_t *ucFrameBuffer = new uint8_t[uiReadDataLength]; if (ucFrameBuffer == NULL) return false; uint32_t nReadFrameCount = (uint32_t) fread(ucFrameBuffer, sizeof(uint8_t), uiReadDataLength, m_pFileHandle); if (nReadFrameCount != uiReadDataLength) { delete[] ucFrameBuffer; return false; } m_fpSamples = new float[uiFrameCount * uiChannels]; if (m_fpSamples == NULL) { delete[] ucFrameBuffer; return false; } switch (uiBitsPerSample) { case 8: ConvertInt8ToFloat32(ucFrameBuffer, uiFrameCount, uiChannels, m_fpSamples); break; case 16: ConvertInt16ToFloat32((int16_t*) ucFrameBuffer, uiFrameCount, uiChannels, m_fpSamples); break; case 24: ConvertInt24ToFloat32(ucFrameBuffer, uiFrameCount, uiChannels, m_fpSamples); break; case 32: ConvertInt32ToFloat32((int32_t*) ucFrameBuffer, uiFrameCount, uiChannels, m_fpSamples); break; } delete[] ucFrameBuffer; m_uiFrameCount = uiFrameCount; m_uiSamplingRate = uiSampleRate; m_uiChannels = uiChannels; return true; } return false; }