ico_image_t * ico_image_read(ico_reader_t *file, int index, int *error) { io_glue *ig = file->ig; ico_reader_image_entry *im; long bi_size, width, height, planes, bit_count; ico_image_t *result; if (index < 0 || index >= file->count) { *error = ICOERR_Bad_Image_Index; return NULL; } im = file->images + index; if (i_io_seek(ig, im->offset, SEEK_SET) != im->offset) { *error = ICOERR_File_Error; return NULL; } if (!read_packed(ig, "dddww xxxx xxxx xxxx xxxx xxxx xxxx", &bi_size, &width, &height, &planes, &bit_count)) { *error = ICOERR_Short_File; return NULL; } /* the bitmapinfoheader height includes the height of the and and xor masks */ if (bi_size != 40 || width != im->width || height != im->height * 2 || planes != 1) { /* don't know how to handle planes != 1 */ *error = ICOERR_Invalid_File; return NULL; } if (bit_count != 1 && bit_count != 4 && bit_count != 8 && bit_count != 32) { *error = ICOERR_Unknown_Bits; return 0; } result = malloc(sizeof(ico_image_t)); if (!result) { *error = ICOERR_Out_Of_Memory; return NULL; } result->width = width; result->height = im->height; result->direct = bit_count > 8; result->bit_count = bit_count; result->palette = NULL; result->image_data = NULL; result->mask_data = NULL; result->hotspot_x = im->hotspot_x; result->hotspot_y = im->hotspot_y; if (bit_count == 32) { result->palette_size = 0; result->image_data = malloc(result->width * result->height * sizeof(ico_color_t)); if (!result->image_data) { free(result); *error = ICOERR_Out_Of_Memory; return NULL; } if (!read_32bit_data(file, result, error)) { free(result->image_data); free(result); return NULL; } } else { int read_result; result->palette_size = 1 << bit_count; result->palette = malloc(sizeof(ico_color_t) * result->palette_size); if (!result->palette) { free(result); *error = ICOERR_Out_Of_Memory; return NULL; } result->image_data = malloc(result->width * result->height); if (!result->image_data) { *error = ICOERR_Out_Of_Memory; free(result->palette); free(result); return 0; } if (!read_palette(file, result, error)) { free(result->palette); free(result->image_data); free(result); return 0; } switch (bit_count) { case 1: read_result = read_1bit_data(file, result, error); break; case 4: read_result = read_4bit_data(file, result, error); break; case 8: read_result = read_8bit_data(file, result, error); break; default: assert(0); /* this can't happen in theory */ read_result = 0; break; } if (!read_result) { free(result->palette); free(result->image_data); free(result); return 0; } } result->mask_data = malloc(result->width * result->height); if (!result->mask_data) { *error = ICOERR_Out_Of_Memory; free(result->palette); free(result->image_data); free(result); return 0; } if (!read_mask(file, result, error)) { free(result->mask_data); free(result->palette); free(result->image_data); free(result); return 0; } return result; }
int main() { uint8_t i; Init(); if (service_mode_rx) ServiceMode(); //enter service mode //Hop to first frequency from Carrier #ifdef FREQUENCY_HOPPING Hopping(); #endif RF_Mode = Receive; Red_LED_OFF; time = millis(); last_pack_time = time; // reset the last pack receiving time for first usage last_hopping_time = time; // reset hopping timer // quality_check_time = time; //-------------- MAIN LOOP ------------------------------------------------------------------------------------------- while(1) { time = millis(); if (_spi_read(0x0C)==0) // detect the locked module and reboot { RF22B_init_parameter(); to_rx_mode(); } SignalLostProcedure(); if(RF_Mode == Received) // RFM22B INT pin Enabled by received Data { last_pack_time = time; // record last package time Red_LED_OFF; Green_LED_ON; send_read_address(0x7f); // Send the package read command //read all buffer for(i = 0; i<DATA_PACKAGE_SIZE; i++) RF_Rx_Buffer[i] = read_8bit_data(); rx_reset(); if (RF_Rx_Buffer[0] == 'S') // servo control data { for(i = 0; i<8; i++) //Write into the Servo Buffer { temp_int = (256*RF_Rx_Buffer[1+(2*i)]) + RF_Rx_Buffer[2+(2*i)]; if ((temp_int>1500) && (temp_int<4500)) Servo_Position[i] = temp_int; } } // sum_rssi += _spi_read(0x26); // Read the RSSI value //binding mode if (bind) if (Bind()) break; #ifdef FREQUENCY_HOPPING ChannelHopping(1); #endif last_ok_channel = hopping_channel; last_hopping_time = time; RF_Mode = Receive; } else Green_LED_OFF; } //---------------------------------------------------------------------------------------------------------------------- if (bind) //binding finished, now you have to restart RX { Red_LED_ON; Green_LED_ON; while(1); } }