fsm_env::fsm_env(xcs_config_mgr2& xcs_config) { if (!fsm_env::init) { if (!xcs_config.exist(tag_name())) { xcs_utility::error(class_name(), "constructor", "section <" + tag_name() + "> not found", 1); } try { state_bits = (long) xcs_config.Value(tag_name(), "number of bits"); states_number = (long) xcs_config.Value(tag_name(), "number of states"); } catch (const char *attribute) { string msg = "attribute \'" + string(attribute) + "\' not found in <" + tag_name() + ">"; xcs_utility::error(class_name(), "constructor", msg, 1); } //! look for the init section in the configuration file string input_configuration; if ((states_number%2) == 0) xcs_utility::error(class_name(),"class constructor", "Number of states must be even", 1); current_state = 0; final_state = (states_number-1)/2; set_state(); } fsm_env::init = true; }
static int temp_update(channel_tag temp_ch) { int ret; int analog; double celsius; int idx = 0; idx = temp_index_lookup(temp_ch); if (idx < 0) { return -1; } temp_t *p = &temps[idx]; ret = analog_get_input(p->analog_input, &analog); if (ret < 0) { fprintf(stderr, "Get analog input failed\n"); } if (p->convert) { ret = p->convert(analog, &celsius); if (ret) { fprintf(stderr, "failed to convert %s\n", temp_ch); } else { p->value = celsius; } } else { fprintf(stderr, "convert func not registered\n"); } if (DBG(D_TEMP)) { printf("analog %d, celsius %f\n", analog, celsius); } if (p->rang_low <= celsius && celsius <= p->rang_high) { if (p->out_of_range > 0) { p->out_of_range--; if (p->out_of_range == 0) { //if (DBG(D_TEMP)) { printf("temperature for %s has stabilized!\n", tag_name(temp_ch)); //} } } } else { if (p->out_of_range == 0) { //if (DBG(D_TEMP)) { printf("temperature for %s is out of range!\n", tag_name(temp_ch)); //} } p->out_of_range = p->in_range_time; } return 0; }
/** * Handle portions of messages containing custom stanza extensions. */ bool XmppClient::handleIq(const glooxwrapper::IQ& iq) { DbgXMPP("handleIq [" << tag_xml(iq) << "]"); if(iq.subtype() == gloox::IQ::Result) { const GameListQuery* gq = iq.findExtension<GameListQuery>( ExtGameListQuery ); const BoardListQuery* bq = iq.findExtension<BoardListQuery>( ExtBoardListQuery ); if(gq) { for(std::vector<const glooxwrapper::Tag*>::const_iterator it = m_GameList.begin(); it != m_GameList.end(); ++it ) glooxwrapper::Tag::free(*it); m_GameList.clear(); for(std::vector<const glooxwrapper::Tag*>::const_iterator it = gq->m_GameList.begin(); it != gq->m_GameList.end(); ++it) m_GameList.push_back( (*it)->clone() ); CreateSimpleMessage("system", "gamelist updated", "internal"); } if(bq) { if (bq->m_Command == "boardlist") { for(std::vector<const glooxwrapper::Tag*>::const_iterator it = m_BoardList.begin(); it != m_BoardList.end(); ++it ) glooxwrapper::Tag::free(*it); m_BoardList.clear(); for(std::vector<const glooxwrapper::Tag*>::const_iterator it = bq->m_StanzaBoardList.begin(); it != bq->m_StanzaBoardList.end(); ++it) m_BoardList.push_back((*it)->clone()); CreateSimpleMessage("system", "boardlist updated", "internal"); } else if (bq->m_Command == "ratinglist") { for(std::vector<const glooxwrapper::Tag*>::const_iterator it = bq->m_StanzaBoardList.begin(); it != bq->m_StanzaBoardList.end(); ++it) { std::string name = (*it)->findAttribute("name").to_string(); if (m_PlayerMap.find(name) != m_PlayerMap.end()) m_PlayerMap[name][1] = (*it)->findAttribute("rating").to_string(); } CreateSimpleMessage("system", "ratinglist updated", "internal"); } } } else if(iq.subtype() == gloox::IQ::Error) { gloox::StanzaError err = iq.error_error(); std::string msg = StanzaErrorToString(err); CreateSimpleMessage("system", msg, "error"); } else { CreateSimpleMessage("system", std::string("unknown subtype : ") + tag_name(iq), "error"); } return true; }
static int pwm_index_lookup( channel_tag pwm_channel) { for (int ix = 0 ; ix < num_pwm_channels ; ++ix) { if (pwm_channels[ ix].id == pwm_channel) { return ix; } } if (debug_flags & DEBUG_PWM) { fprintf( stderr, "pwm_index_lookup failed for '%s'\n", tag_name( pwm_channel)); } return -1; }
channel_tag analog_lookup_by_name(const char *name) { int idx; for (idx = 0; idx < nr_analogs; idx++) { channel_tag tag = analogs[idx].id; if (strcmp(tag_name(tag), name) == 0) { return tag; } } return NULL; }
static int analog_index_lookup(channel_tag analog_ch) { int idx; for (idx = 0; idx < nr_analogs; idx++) { if (analogs[idx].id == analog_ch) { return idx; } } if (DBG(D_ANALOG)) { fprintf(stderr, "analog_index_lookup failed for '%s'\n", tag_name(analog_ch)); } return -1; }
static int temp_index_lookup(channel_tag temp_ch) { int idx; for (idx = 0; idx < nr_temps; idx++) { if (temps[idx].id == temp_ch) { return idx; } } if DBG(D_TEMP) { fprintf(stderr, "temp_index_lookup failed for '%s'\n", tag_name(temp_ch)); } return -1; }
int unicorn_test(void) { int i = 0; int idx = 0; int num_fans = 0; double celsius = 0.0; channel_tag heater, fan, pwm; if (bbp_board_type == BOARD_BBP1S) { num_fans = 6; } else if (bbp_board_type == BOARD_BBP1) { num_fans = 5; } #if 0 start_test_thread(); int count = 10; while (1) { printf("wait evtout count=%d\n", count); prussdrv_pru_wait_event(PRU_EVTOUT_1); prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT); if(count-- == 0){ return; } } #endif printf("Test 1: Fan testing...\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 1: Fan testing...\n"); printf(" Please watch the led lights and leds on board\n"); printf(" 1.1 close all fans\n"); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_disable(fan); } } printf(" 1.2 open each fan for 1s then close one by one\n"); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { printf(" Open %s\n", tag_name(fan)); fan_enable(fan); fan_set_level(fan, 80); sleep(1); printf(" Close %s\n", tag_name(fan)); fan_set_level(fan, 0); fan_disable(fan); } } printf(" 1.3 turn on all fans for 1s, then turn off, repeat 3 times\n"); for (i = 0; i < 2; i++) { for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_enable(fan); fan_set_level(fan, 80); } } sleep(1); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_disable(fan); } } sleep(1); } printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 2: LMSW testing...\n"); printf(" 2.1 Please press min x: \n"); wait_lmsw_min_test(X_AXIS); printf(" min_x ok\n"); printf(" 2.2 Please press min y: \n"); wait_lmsw_min_test(Y_AXIS); printf(" min_y ok\n"); printf(" 2.3 Please press min z: \n"); wait_lmsw_min_test(Z_AXIS); printf(" min_z ok\n"); printf(" 2.4 Please press max x: \n"); wait_lmsw_max(X_AXIS); printf(" max_x ok\n"); printf(" 2.5 Please press max y: \n"); wait_lmsw_max(Y_AXIS); printf(" max_y ok\n"); printf(" 2.6 Please press max z: \n"); wait_lmsw_max(Z_AXIS); printf(" max_z ok\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 3: Heater testing...\n"); printf(" open each heater for 1s then close\n"); printf(" Please watch the led beside the heater interface!\n"); if (bbp_board_type == BOARD_BBP1S) { pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); for (i = 0; i < 2; i++) { pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 80); } pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 80); } pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 80); } sleep(4); pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 0); } pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 0); } pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 0); } sleep(2); } } if (bbp_board_type == BOARD_BBP1) { for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { printf(" Open %s\n", tag_name(heater)); heater_enable(heater); heater_set_raw_pwm(heater, 40); sleep(5); printf(" Close %s\n", tag_name(heater)); heater_set_raw_pwm(heater, 0); heater_disable(heater); } } } printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 4: Stepper testing...\n"); printf(" 4.1 Turn on all stepper\n"); stepper_test(); printf(" 4.2 Stop Stepper\n"); printf(" Please press min x to stop stepper\n"); wait_lmsw_min(X_AXIS); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 5: USB Host testing...\n"); printf(" 5.1 please insert U mass storage\n"); if(unicorn_test_usb_storage() == -1){ halt_test("Usb mass storage is BAD!!!!!!!!!!!!!!!\n"); } printf("Usb mass storage is OK\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 6: Internal emmc testing...\n"); if(unicorn_test_emmc() == -1){ halt_test("Internal emmc is BAD!!!!!!!!!!!!!!\n"); } printf("Internal emmc is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 7: eeprom testing...\n"); if(unicorn_test_eeprom() == -1){ halt_test("eeprom is BAD!!!!!!!!!!!!\n"); } printf("eeprom is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 8: rtc testing...\n"); if(unicorn_test_rtc() == -1) { halt_test("rtc is BAD!!!!!!!!!!!!\n"); } printf("rtc is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 9: Network testing...\n"); printf(" Start to ping the router..\n"); if(unicorn_test_network() == -1) { halt_test("network is BAD!!!!!!!!!!!!\n"); } printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("Test 10: USB OTG testing...\n"); printf(" 11.1 Please connect usb otg line to PC\n"); printf(" 11.2 Could you see the boot partion? If yes, Please press min_x..\n"); wait_lmsw_min_test(X_AXIS); printf("done.\n"); printf("-------------------------------------------------------------\n"); if (bbp_board_type == BOARD_BBP1S) { printf("Test 11: Test max6675 temperature...\n"); printf("long press min y key to exit\n"); if(unicorn_test_max6675() == -1) { halt_test("max6675 is BAD!!!!!!!!!!!!\n"); } printf("\n-------------------------------------------------------------\n"); } #if 0 if (bbp_board_type == BOARD_BBP1S) { #ifdef SERVO printf("Test 12: Test servo...\n"); if (unicorn_test_servo()) { halt_test("servo is BAD!!!!!!!!!!!!\n"); } printf("\n-------------------------------------------------------------\n"); #endif } #endif printf("\n-------------------------------------------------------------\n"); printf("Test 12: Temp adc testing...\n"); heater_start(); if (bbp_board_type == BOARD_BBP1S) { char *heater_array_bbp1s[] = {"heater_ext", "heater_ext2", "heater_bed"}; for (idx = 0; idx < sizeof(heater_array_bbp1s)/sizeof(heater_array_bbp1s[0]); idx++) { heater = heater_lookup_by_name(heater_array_bbp1s[idx]); if (heater) { heater_enable(heater); heater_set_setpoint(heater, TARGET_TEMP); } } for (i = 0; i < 80 && stepper_check_lmsw(X_AXIS) == 0; i++) { for (idx = 0; idx < sizeof(heater_array_bbp1s)/sizeof(heater_array_bbp1s[0]); idx++) { heater = heater_lookup_by_name(heater_array_bbp1s[idx]); if (heater) { celsius = 0.0; heater_get_celsius(heater, &celsius); printf("%s -> %f\n", tag_name(heater), celsius); sleep(1); } } } } else if (bbp_board_type == BOARD_BBP1) { for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { heater_enable(heater); heater_set_setpoint(heater, TARGET_TEMP); } } printf("long press min x key to exit\n"); heater = heater_lookup_by_name("heater_bed"); for (i = 0; i < 80 && stepper_check_lmsw(X_AXIS) == 0; i++) { if (heater_temp_reached(heater)) { printf("ok\n"); break; } else { sleep(1); } for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { celsius = 0.0; heater_get_celsius(heater, &celsius); printf("%s -> %f\n", tag_name(heater), celsius); } } printf("\n"); } } heater_stop(); printf("done.\n"); printf("-------------------------------------------------------------\n"); halt_test("All is Good!\n"); return 0; }
uint64_t header_check_tiff_le(file_recovery_t *fr, const uint32_t tiff_diroff, const unsigned int depth, const unsigned int count) { unsigned char buffer[8192]; unsigned int i,n; int data_read; const uint32_t *tiff_next_diroff; uint64_t max_offset=0; uint64_t alphaoffset=0; uint64_t alphabytecount=0; uint64_t imageoffset=0; uint64_t imagebytecount=0; uint64_t jpegifoffset=0; uint64_t jpegifbytecount=0; uint64_t strip_offsets=0; uint64_t strip_bytecounts=0; uint64_t tile_offsets=0; uint64_t tile_bytecounts=0; unsigned int tdir_tag_old=0; unsigned int sorted_tag_error=0; const TIFFDirEntry *entry=(const TIFFDirEntry *)&buffer[2]; const TIFFDirEntry *entry_strip_offsets=NULL; const TIFFDirEntry *entry_strip_bytecounts=NULL; const TIFFDirEntry *entry_tile_offsets=NULL; const TIFFDirEntry *entry_tile_bytecounts=NULL; #ifdef DEBUG_TIFF log_info("header_check_tiff_le(fr, %lu, %u, %u)\n", (long unsigned)tiff_diroff, depth, count); #endif if(depth>4) return -1; if(count>16) return -1; if(tiff_diroff < sizeof(TIFFHeader)) return -1; if(fseek(fr->handle, tiff_diroff, SEEK_SET) < 0) return -1; data_read=fread(buffer, 1, sizeof(buffer), fr->handle); if(data_read<2) return -1; n=buffer[0]+(buffer[1]<<8); #ifdef DEBUG_TIFF log_info("header_check_tiff_le(fr, %lu, %u, %u) => %u entries\n", (long unsigned)tiff_diroff, depth, count, n); #endif //sizeof(TIFFDirEntry)=12; if(n > (unsigned)(data_read-2)/12) n=(data_read-2)/12; if(n==0) return -1; for(i=0;i<n;i++) { const unsigned int tdir_tag=le16(entry->tdir_tag); const uint64_t val=(uint64_t)le32(entry->tdir_count) * tiff_type2size(le16(entry->tdir_type)); #ifdef DEBUG_TIFF log_info("%u tag=%u(0x%x) %s type=%u count=%lu offset=%lu(0x%lx) val=%lu\n", i, tdir_tag, tdir_tag, tag_name(tdir_tag), le16(entry->tdir_type), (long unsigned)le32(entry->tdir_count), (long unsigned)le32(entry->tdir_offset), (long unsigned)le32(entry->tdir_offset), (long unsigned)val); #endif if(tdir_tag_old > tdir_tag) { /* Entries must be sorted by tag, some SR2 file doesn't respected this rule */ sorted_tag_error++; if(sorted_tag_error > 1 && strcmp(fr->extension,"sr2")!=0) return -1; } if(val>4) { const uint64_t new_offset=le32(entry->tdir_offset)+val; if(new_offset==0) return -1; if(max_offset < new_offset) max_offset=new_offset; } if(le32(entry->tdir_count)==1 && val<=4) { const unsigned int tmp=tiff_le_read(&entry->tdir_offset, le16(entry->tdir_type)); switch(tdir_tag) { case TIFFTAG_ALPHABYTECOUNT: alphabytecount=tmp; break; case TIFFTAG_ALPHAOFFSET: alphaoffset=tmp; break; case TIFFTAG_IMAGEBYTECOUNT: imagebytecount=tmp; break; case TIFFTAG_IMAGEOFFSET: imageoffset=tmp; break; case TIFFTAG_JPEGIFBYTECOUNT: jpegifbytecount=tmp; break; case TIFFTAG_JPEGIFOFFSET: jpegifoffset=tmp; break; case TIFFTAG_STRIPBYTECOUNTS: strip_bytecounts=tmp; break; case TIFFTAG_STRIPOFFSETS: strip_offsets=tmp; break; case TIFFTAG_TILEBYTECOUNTS: tile_bytecounts=tmp; break; case TIFFTAG_TILEOFFSETS: tile_offsets=tmp; break; case TIFFTAG_EXIFIFD: case TIFFTAG_KODAKIFD: { const uint64_t new_offset=header_check_tiff_le(fr, tmp, depth+1, 0); if(new_offset==-1) return -1; if(max_offset < new_offset) max_offset=new_offset; } break; case TIFFTAG_SUBIFD: if(fr->extension!=NULL && strcmp(fr->extension, "arw")==0) { /* DSLR-A100 is boggus, may be A100DataOffset */ if(max_offset < tmp) max_offset=tmp; } else { const uint64_t new_offset=header_check_tiff_le(fr, tmp, depth+1, 0); if(new_offset==-1) return -1; if(max_offset < new_offset) max_offset=new_offset; } break; #ifdef ENABLE_TIFF_MAKERNOTE case EXIFTAG_MAKERNOTE: { const uint64_t new_offset=tiff_le_makernote(fr->handle, tmp); if(new_offset==-1) return -1; if(max_offset < new_offset) max_offset=new_offset; } break; #endif } } else if(le32(entry->tdir_count) > 1) { switch(tdir_tag) { case TIFFTAG_EXIFIFD: case TIFFTAG_KODAKIFD: case TIFFTAG_SUBIFD: if(le16(entry->tdir_type)==4) { const unsigned int nbr=(le32(entry->tdir_count)<32?le32(entry->tdir_count):32); unsigned int j; uint32_t *subifd_offsetp; if(fseek(fr->handle, le32(entry->tdir_offset), SEEK_SET) < 0) { return -1; } subifd_offsetp=(uint32_t *)MALLOC(nbr*sizeof(*subifd_offsetp)); if(fread(subifd_offsetp, sizeof(*subifd_offsetp), nbr, fr->handle) != nbr) { free(subifd_offsetp); return -1; } for(j=0; j<nbr; j++) { const uint64_t new_offset=header_check_tiff_le(fr, le32(subifd_offsetp[j]), depth+1, 0); if(new_offset==-1) { free(subifd_offsetp); return -1; } if(max_offset < new_offset) max_offset = new_offset; } free(subifd_offsetp); } break; case TIFFTAG_STRIPOFFSETS: entry_strip_offsets=entry; break; case TIFFTAG_STRIPBYTECOUNTS: entry_strip_bytecounts=entry; break; case TIFFTAG_TILEBYTECOUNTS: entry_tile_bytecounts=entry; break; case TIFFTAG_TILEOFFSETS: entry_tile_offsets=entry; break; } } tdir_tag_old=tdir_tag; entry++; } if(alphabytecount > 0 && max_offset < alphaoffset + alphabytecount) max_offset = alphaoffset + alphabytecount; if(imagebytecount > 0 && max_offset < imageoffset + imagebytecount) max_offset = imageoffset + imagebytecount; if(jpegifbytecount > 0 && max_offset < jpegifoffset + jpegifbytecount) max_offset = jpegifoffset + jpegifbytecount; if(strip_bytecounts > 0 && strip_offsets!=0xffffffff && max_offset < strip_offsets + strip_bytecounts) max_offset = strip_offsets + strip_bytecounts; if(tile_bytecounts > 0 && tile_offsets!=0xffffffff && max_offset < tile_offsets + tile_bytecounts) max_offset = tile_offsets + tile_bytecounts; if(entry_strip_offsets != NULL && entry_strip_bytecounts != NULL) { const uint64_t tmp=parse_strip_le(fr->handle, entry_strip_offsets, entry_strip_bytecounts); if(tmp==-1) return -1; if(max_offset < tmp) max_offset=tmp; } if(entry_tile_offsets != NULL && entry_tile_bytecounts != NULL) { const uint64_t tmp=parse_strip_le(fr->handle, entry_tile_offsets, entry_tile_bytecounts); if(tmp==-1) return -1; if(max_offset < tmp) max_offset=tmp; } tiff_next_diroff=(const uint32_t *)entry; if(le32(*tiff_next_diroff) > 0) { const uint64_t new_offset=header_check_tiff_le(fr, le32(*tiff_next_diroff), depth+1, count+1); if(new_offset != -1 && max_offset < new_offset) max_offset=new_offset; } return max_offset; }
static uint64_t tiff_le_makernote(FILE *in, const uint32_t tiff_diroff) { const unsigned char sign_nikon1[7]={'N', 'i', 'k', 'o', 'n', 0x00, 0x01}; const unsigned char sign_nikon2[7]={'N', 'i', 'k', 'o', 'n', 0x00, 0x02}; const unsigned char sign_pentax[4]={'A', 'O', 'C', 0x00}; unsigned char buffer[8192]; unsigned int i,n; int data_read; uint64_t max_offset=0; uint64_t alphaoffset=0; uint64_t alphabytecount=0; uint64_t imageoffset=0; uint64_t imagebytecount=0; uint64_t jpegifoffset=0; uint64_t jpegifbytecount=0; uint64_t strip_offsets=0; uint64_t strip_bytecounts=0; uint64_t tile_offsets=0; uint64_t tile_bytecounts=0; const TIFFDirEntry *entry; if(tiff_diroff < sizeof(TIFFHeader)) return -1; if(fseek(in, tiff_diroff, SEEK_SET) < 0) return -1; data_read=fread(buffer, 1, sizeof(buffer), in); if(data_read<2) return -1; if( memcmp(buffer, sign_nikon1, sizeof(sign_nikon1))==0 || memcmp(buffer, sign_nikon2, sizeof(sign_nikon2))==0 || memcmp(buffer, sign_pentax, sizeof(sign_pentax))==0 ) return tiff_diroff; entry=(const TIFFDirEntry *)&buffer[2]; n=buffer[0]+(buffer[1]<<8); #ifdef DEBUG_TIFF log_info("tiff_le_makernote(%lu) => %u entries\n", (long unsigned)tiff_diroff, n); #endif //sizeof(TIFFDirEntry)=12; if(n > (unsigned)(data_read-2)/12) n=(data_read-2)/12; if(n==0) return -1; for(i=0;i<n;i++) { const uint64_t val=(uint64_t)le32(entry->tdir_count) * tiff_type2size(le16(entry->tdir_type)); #ifdef DEBUG_TIFF log_info("%u tag=%u(0x%x) %s type=%u count=%lu offset=%lu(0x%lx)\n", i, le16(entry->tdir_tag), le16(entry->tdir_tag), tag_name(le16(entry->tdir_tag)), le16(entry->tdir_type), (long unsigned)le32(entry->tdir_count), (long unsigned)le32(entry->tdir_offset), (long unsigned)le32(entry->tdir_offset)); #endif if(val>4) { const uint64_t new_offset=le32(entry->tdir_offset)+val; if(new_offset==0) return -1; if(max_offset < new_offset) max_offset=new_offset; } if(le32(entry->tdir_count)==1) { const unsigned int tmp=tiff_le_read(&entry->tdir_offset, le16(entry->tdir_type)); switch(le16(entry->tdir_tag)) { case TIFFTAG_JPEGIFOFFSET: jpegifoffset=tmp; break; case TIFFTAG_JPEGIFBYTECOUNT: jpegifbytecount=tmp; break; case TIFFTAG_ALPHAOFFSET: alphaoffset=tmp; break; case TIFFTAG_ALPHABYTECOUNT: alphabytecount=tmp; break; case TIFFTAG_IMAGEOFFSET: imageoffset=tmp; break; case TIFFTAG_IMAGEBYTECOUNT: imagebytecount=tmp; break; case TIFFTAG_STRIPOFFSETS: strip_offsets=tmp; break; case TIFFTAG_STRIPBYTECOUNTS: strip_bytecounts=tmp; break; case TIFFTAG_TILEBYTECOUNTS: tile_bytecounts=tmp; break; case TIFFTAG_TILEOFFSETS: tile_offsets=tmp; break; } } entry++; } if(alphabytecount > 0 && max_offset < alphaoffset + alphabytecount) max_offset = alphaoffset + alphabytecount; if(imagebytecount > 0 && max_offset < imageoffset + imagebytecount) max_offset = imageoffset + imagebytecount; if(jpegifbytecount > 0 && max_offset < jpegifoffset + jpegifbytecount) max_offset = jpegifoffset + jpegifbytecount; if(strip_bytecounts > 0 && strip_offsets!=0xffffffff && max_offset < strip_offsets + strip_bytecounts) max_offset = strip_offsets + strip_bytecounts; if(tile_bytecounts > 0 && tile_offsets!=0xffffffff && max_offset < tile_offsets + tile_bytecounts) max_offset = tile_offsets + tile_bytecounts; return max_offset; }