FX_BOOL CCodec_JpegDecoder::v_Rewind() { if (m_pExtProvider) { return m_pExtProvider->Rewind(m_pExtContext); } if (m_bStarted) { jpeg_destroy_decompress(&cinfo); if (!InitDecode()) { return FALSE; } } if (setjmp(m_JmpBuf) == -1) { return FALSE; } cinfo.scale_denom = m_nDefaultScaleDenom * m_DownScale; m_OutputWidth = (m_OrigWidth + m_DownScale - 1) / m_DownScale; m_OutputHeight = (m_OrigHeight + m_DownScale - 1) / m_DownScale; if (!jpeg_start_decompress(&cinfo)) { jpeg_destroy_decompress(&cinfo); return FALSE; } if ((int)cinfo.output_width > m_OrigWidth) { FXSYS_assert(FALSE); return FALSE; } m_bStarted = TRUE; return TRUE; }
BOOL CNITTable::Decode( BYTE* data, DWORD dataSize, DWORD* decodeReadSize ) { if( InitDecode(data, dataSize, decodeReadSize, TRUE) == FALSE ){ return FALSE; } Clear(); if( section_syntax_indicator != 1 ){ //固定値がおかしい _OutputDebugString( L"++CNITTable:: section_syntax err" ); return FALSE; } if( table_id != 0x40 && table_id != 0x41 ){ //table_idがおかしい _OutputDebugString( L"++CNITTable:: table_id err 0x%02X", table_id ); return FALSE; } if( section_length - 4 > 8 ){ network_id = ((WORD)data[readSize])<<8 | data[readSize+1]; version_number = (data[readSize+2]&0x3E)>>1; current_next_indicator = data[readSize+2]&0x01; section_number = data[readSize+3]; last_section_number = data[readSize+4]; network_descriptors_length = ((WORD)data[readSize+5]&0x0F)<<8 | data[readSize+6]; readSize += 7; if( readSize+network_descriptors_length <= (DWORD)section_length+3-4 && network_descriptors_length > 0){ if( network_id == 0x0001 || network_id == 0x0003 ){ SDDecode( data+readSize, network_descriptors_length, &descriptorList, NULL ); }else{ if( AribDescriptor::CreateDescriptors( data+readSize, network_descriptors_length, &descriptorList, NULL ) == FALSE ){ _OutputDebugString( L"++CNITTable:: descriptor err" ); return FALSE; } } readSize+=network_descriptors_length; } transport_stream_loop_length = ((WORD)data[readSize]&0x0F)<<8 | data[readSize+1]; readSize += 2; WORD tsLoopReadSize = 0; while( readSize+5 < (DWORD)section_length+3-4 && tsLoopReadSize < transport_stream_loop_length){ TS_INFO_DATA* item = new TS_INFO_DATA; item->transport_stream_id = ((WORD)data[readSize])<<8 | data[readSize+1]; item->original_network_id = ((WORD)data[readSize+2])<<8 | data[readSize+3]; item->transport_descriptors_length = ((WORD)data[readSize+4]&0x0F)<<8 | data[readSize+5]; readSize += 6; if( readSize+item->transport_descriptors_length <= (DWORD)section_length+3-4 && item->transport_descriptors_length > 0){ if( AribDescriptor::CreateDescriptors( data+readSize, item->transport_descriptors_length, &(item->descriptorList), NULL ) == FALSE ){ _OutputDebugString( L"++CNITTable:: descriptor2 err" ); SAFE_DELETE(item); return FALSE; } } readSize+=item->transport_descriptors_length; tsLoopReadSize += 6 + item->transport_descriptors_length; TSInfoList.push_back(item); } }else{
FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, FX_DWORD src_size, int width, int height, int nComps, FX_BOOL ColorTransform, IFX_JpegProvider* pJP) { if (pJP) { m_pExtProvider = pJP; m_pExtContext = m_pExtProvider->CreateDecoder( src_buf, src_size, width, height, nComps, ColorTransform); return m_pExtContext != NULL; } _JpegScanSOI(src_buf, src_size); m_SrcBuf = src_buf; m_SrcSize = src_size; jerr.error_exit = _error_fatal; jerr.emit_message = _error_do_nothing1; jerr.output_message = _error_do_nothing; jerr.format_message = _error_do_nothing2; jerr.reset_error_mgr = _error_do_nothing; src.init_source = _src_do_nothing; src.term_source = _src_do_nothing; src.skip_input_data = _src_skip_data; src.fill_input_buffer = _src_fill_buffer; src.resync_to_restart = _src_resync; m_bJpegTransform = ColorTransform; if (src_size > 1 && FXSYS_memcmp(src_buf + src_size - 2, "\xFF\xD9", 2) != 0) { ((uint8_t*)src_buf)[src_size - 2] = 0xFF; ((uint8_t*)src_buf)[src_size - 1] = 0xD9; } m_OutputWidth = m_OrigWidth = width; m_OutputHeight = m_OrigHeight = height; if (!InitDecode()) { return FALSE; } if (cinfo.num_components < nComps) { return FALSE; } if ((int)cinfo.image_width < width) { return FALSE; } m_Pitch = (cinfo.image_width * cinfo.num_components + 3) / 4 * 4; m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); m_nComps = cinfo.num_components; m_bpc = 8; m_bColorTransformed = FALSE; m_bStarted = FALSE; return TRUE; }
FX_BOOL CCodec_JpegDecoder::Create(const uint8_t* src_buf, uint32_t src_size, int width, int height, int nComps, FX_BOOL ColorTransform) { JpegScanSOI(&src_buf, &src_size); m_SrcBuf = src_buf; m_SrcSize = src_size; jerr.error_exit = _error_fatal; jerr.emit_message = _error_do_nothing1; jerr.output_message = _error_do_nothing; jerr.format_message = _error_do_nothing2; jerr.reset_error_mgr = _error_do_nothing; src.init_source = _src_do_nothing; src.term_source = _src_do_nothing; src.skip_input_data = _src_skip_data; src.fill_input_buffer = _src_fill_buffer; src.resync_to_restart = _src_resync; m_bJpegTransform = ColorTransform; if (src_size > 1 && FXSYS_memcmp(src_buf + src_size - 2, "\xFF\xD9", 2) != 0) { ((uint8_t*)src_buf)[src_size - 2] = 0xFF; ((uint8_t*)src_buf)[src_size - 1] = 0xD9; } m_OutputWidth = m_OrigWidth = width; m_OutputHeight = m_OrigHeight = height; if (!InitDecode()) return FALSE; if (cinfo.num_components < nComps) return FALSE; if ((int)cinfo.image_width < width) return FALSE; m_Pitch = (static_cast<uint32_t>(cinfo.image_width) * cinfo.num_components + 3) / 4 * 4; m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); m_nComps = cinfo.num_components; m_bpc = 8; m_bStarted = FALSE; return TRUE; }
FX_BOOL CCodec_JpegDecoder::v_Rewind() { if (m_bStarted) { jpeg_destroy_decompress(&cinfo); if (!InitDecode()) { return FALSE; } } if (setjmp(m_JmpBuf) == -1) { return FALSE; } cinfo.scale_denom = m_nDefaultScaleDenom; m_OutputWidth = m_OrigWidth; m_OutputHeight = m_OrigHeight; if (!jpeg_start_decompress(&cinfo)) { jpeg_destroy_decompress(&cinfo); return FALSE; } if ((int)cinfo.output_width > m_OrigWidth) { ASSERT(FALSE); return FALSE; } m_bStarted = TRUE; return TRUE; }
BOOL CEITTable_SD2::Decode( BYTE* data, DWORD dataSize, DWORD* decodeReadSize ) { if( InitDecode(data, dataSize, decodeReadSize, TRUE) == FALSE ) { return FALSE; } Clear(); if( section_syntax_indicator != 1 ) { //固定値がおかしい _OutputDebugString( L"++CEITTable_SD2:: section_syntax err" ); return FALSE; } if( table_id != 0xA3 && table_id != 0xA2 ) { //table_idがおかしい _OutputDebugString( L"++CEITTable_SD2:: table_id err 0x%02X", table_id ); return FALSE; } if( section_length - 4 > 18 ) { service_id = ((WORD)data[readSize])<<8 | data[readSize+1]; version_number = (data[readSize+2]&0x3E)>>1; current_next_indicator = data[readSize+2]&0x01; section_number = data[readSize+3]; last_section_number = data[readSize+4]; service_id2 = ((WORD)data[readSize+5])<<8 | data[readSize+6]; original_network_id = ((WORD)data[readSize+7])<<8 | data[readSize+8]; readSize += 9; DWORD mjd = ((DWORD)data[readSize])<<8 | data[readSize+1]; _MJDtoSYSTEMTIME(mjd, &start_time); start_time.wHour = (WORD)_BCDtoDWORD(data+readSize+2, 1, 2); start_time.wMinute = (WORD)_BCDtoDWORD(data+readSize+3, 1, 2); start_time.wSecond = (WORD)_BCDtoDWORD(data+readSize+4, 1, 2); readSize += 5; mjd = ((DWORD)data[readSize])<<8 | data[readSize+1]; _MJDtoSYSTEMTIME(mjd, &end_time); end_time.wHour = (WORD)_BCDtoDWORD(data+readSize+2, 1, 2); end_time.wMinute = (WORD)_BCDtoDWORD(data+readSize+3, 1, 2); end_time.wSecond = (WORD)_BCDtoDWORD(data+readSize+4, 1, 2); readSize += 5; while( readSize+3 < (DWORD)section_length+3-4 ) { EVENT_MAP_INFO* item = new EVENT_MAP_INFO; item->descriptor_length = ((WORD)data[readSize]&0x03)<<8 | data[readSize+1]; mjd = ((DWORD)data[readSize+2])<<8 | data[readSize+3]; _MJDtoSYSTEMTIME(mjd, &item->start_day); DWORD readDesc = 4; DWORD max = item->descriptor_length; max+=2; while( readSize+readDesc+6 < (DWORD)section_length+3-4 && readDesc < max ) { EVENT_MAP_DATA dataInfo; dataInfo.event_id = ((WORD)data[readSize+readDesc])<<8 | data[readSize+readDesc+1]; dataInfo.hour = data[readSize+readDesc+2]>>3; dataInfo.minute = (data[readSize+readDesc+2]&0x07)*10; dataInfo.minute += data[readSize+readDesc+3]>>4; BYTE length = data[readSize+readDesc+3]&0x0F; dataInfo.a4table_eventID = ((WORD)data[readSize+readDesc+5])<<8 | data[readSize+readDesc+6]; if( readSize+readDesc+10 < (DWORD)section_length+3-4 && length == 7 ) { dataInfo.duration = _BCDtoDWORD(data+readSize+readDesc+8, 1, 2)*60*60; dataInfo.duration += _BCDtoDWORD(data+readSize+readDesc+9, 1, 2)*60; dataInfo.duration += _BCDtoDWORD(data+readSize+readDesc+10, 1, 2); } else { dataInfo.duration = 0; } readDesc+=4+length; item->eventList.push_back(dataInfo); } eventMapList.push_back(item); readSize+=item->descriptor_length+2; } } else {
BOOL CEITTable::Decode( BYTE* data, DWORD dataSize, DWORD* decodeReadSize ) { if( InitDecode(data, dataSize, decodeReadSize, TRUE) == FALSE ){ return FALSE; } Clear(); if( section_syntax_indicator != 1 ){ //固定値がおかしい _OutputDebugString( L"++CEITTable:: section_syntax err" ); return FALSE; } if( table_id < 0x4E || table_id > 0x6F ){ //table_idがおかしい _OutputDebugString( L"++CEITTable:: table_id err 0x%02X", table_id ); return FALSE; } if( section_length - 4 > 10 ){ service_id = ((WORD)data[readSize])<<8 | data[readSize+1]; version_number = (data[readSize+2]&0x3E)>>1; current_next_indicator = data[readSize+2]&0x01; section_number = data[readSize+3]; last_section_number = data[readSize+4]; transport_stream_id = ((WORD)data[readSize+5])<<8 | data[readSize+6]; original_network_id = ((WORD)data[readSize+7])<<8 | data[readSize+8]; segment_last_section_number = data[readSize+9]; last_table_id = data[readSize+10]; readSize += 11; while( readSize+11 < (DWORD)section_length+3-4 ){ EVENT_INFO_DATA* item = new EVENT_INFO_DATA; item->event_id = ((WORD)data[readSize])<<8 | data[readSize+1]; if( data[readSize+2] == 0xFF && data[readSize+3] == 0xFF && data[readSize+4] == 0xFF && data[readSize+5] == 0xFF && data[readSize+6] == 0xFF ) { item->StartTimeFlag = FALSE; }else{ item->StartTimeFlag = TRUE; DWORD mjd = ((DWORD)data[readSize+2])<<8 | data[readSize+3]; _MJDtoSYSTEMTIME(mjd, &(item->start_time)); item->start_time.wHour = (WORD)_BCDtoDWORD(data+readSize+4, 1, 2); item->start_time.wMinute = (WORD)_BCDtoDWORD(data+readSize+5, 1, 2); item->start_time.wSecond = (WORD)_BCDtoDWORD(data+readSize+6, 1, 2); } readSize+=7; if( data[readSize] == 0xFF && data[readSize+1] == 0xFF && data[readSize+2] == 0xFF) { item->DurationFlag = FALSE; }else{ item->DurationFlag = TRUE; item->durationHH = (WORD)_BCDtoDWORD(data+readSize, 1, 2); item->durationMM = (WORD)_BCDtoDWORD(data+readSize+1, 1, 2); item->durationSS = (WORD)_BCDtoDWORD(data+readSize+2, 1, 2); } readSize+=3; item->running_status = (data[readSize]&0xE0)>>5; item->free_CA_mode = (data[readSize]&0x10)>>4; item->descriptors_loop_length = ((WORD)data[readSize]&0x0F)<<8 | data[readSize+1]; readSize += 2; if( readSize+item->descriptors_loop_length <= (DWORD)section_length+3-4 && item->descriptors_loop_length > 0){ if( original_network_id == 0x0001 || original_network_id == 0x0003 ){ SDDecode( data+readSize, item->descriptors_loop_length, &(item->descriptorList), NULL ); }else{ if( AribDescriptor::CreateDescriptors( data+readSize, item->descriptors_loop_length, &(item->descriptorList), NULL ) == FALSE ){ _OutputDebugString( L"++CEITTable:: descriptor2 err" ); SAFE_DELETE(item); return FALSE; } } } readSize+=item->descriptors_loop_length; eventInfoList.push_back(item); } }else{