// ------------------------------------------------------- // -------- WGDownloadOptionsDlg // ------------------------------------------------------- WGDownloadOptionsDlg::WGDownloadOptionsDlg( QWidget* parent, const char* name, bool modal, WFlags fl ): WGDownloadOptionsDlgBase( parent, name, modal, fl ) { QIconSet image_open( QPixmap((const char**)image_open_data) ); image_open.setPixmap( QPixmap((const char**)image_open_d_data), QIconSet::Automatic, QIconSet::Disabled ); DirectoryB->setIconSet( image_open ); LogDirectoryB->setIconSet( image_open ); RetriesNumberLE->setValidator( new WGIntValidator( RetriesNumberLE ) ); RetriesWaitLE->setValidator( new WGIntValidator( RetriesWaitLE ) ); connect( OkB , SIGNAL(clicked()) , this, SLOT(slot_ok()) ); connect( CancelB , SIGNAL(clicked()) , this, SLOT(slot_cancel()) ); connect( DirectoryB , SIGNAL(clicked()) , this, SLOT(slot_directory()) ); connect( RestartCB , SIGNAL(clicked()) , this, SLOT(slot_restart()) ); connect( PasswordCB , SIGNAL(clicked()) , this, SLOT(slot_password()) ); connect( LogCB , SIGNAL(clicked()) , this, SLOT(slot_log()) ); connect( LogDirectoryB , SIGNAL(clicked()) , this, SLOT(slot_log_directory()) ); connect( URLLE , SIGNAL(returnPressed()), this, SLOT(slot_ok()) ); connect( PasswordUsrLE , SIGNAL(returnPressed()), this, SLOT(slot_ok()) ); connect( PasswordPassLE , SIGNAL(returnPressed()), this, SLOT(slot_ok()) ); connect( RetriesNumberLE, SIGNAL(returnPressed()), this, SLOT(slot_ok()) ); connect( RetriesWaitLE , SIGNAL(returnPressed()), this, SLOT(slot_ok()) ); updateControls(); URLLE->setFocus(); }
static void handle_image_open(int wfd, void *params) { Slave_Msg_Image_Open *p; Slave_Msg_Image_Opened result; Error_Type err; const char *loader = NULL, *file, *key, *ptr; char *resp; size_t resp_size; p = params; file = (const char *)(p + sizeof(Slave_Msg_Image_Open)); key = file + strlen(file) + 1; ptr = key + strlen(key) + 1; if (p->has_loader_data) loader = ptr; memset(&result, 0, sizeof(result)); if ((err = image_open(file, key, &result, &loader)) != CSERVE2_NONE) { printf("OPEN failed at %s:%d\n", __FUNCTION__, __LINE__); error_send(wfd, err); return; } result.has_loader_data = EINA_TRUE; resp_size = sizeof(Slave_Msg_Image_Opened) + sizeof(int) + strlen(loader) + 1; resp = alloca(resp_size); memcpy(resp, &result, sizeof(Slave_Msg_Image_Opened)); memcpy(resp + sizeof(Slave_Msg_Image_Opened), loader, strlen(loader) + 1); response_send(wfd, IMAGE_OPEN, resp, resp_size); }
// init an Image object, passing params to image_open // note that class of arg1, if array, will override requests for 'single' image VALUE initialize_disk_image(int argc, VALUE *args, VALUE self){ VALUE filename; VALUE rest; VALUE parsed_opts; VALUE flag; struct tsk4r_img_wrapper * ptr; rb_scan_args(argc, args, "11", &filename, &rest); if (NIL_P(rest)) rest = rb_hash_new(); parsed_opts = rb_funcall(self, rb_intern("parse_opts"), 1, rest); flag = rb_hash_aref(parsed_opts, ID2SYM(rb_intern("type_flag"))); if (! rb_obj_is_kind_of(flag, rb_cFixnum)) { flag = INT2NUM(0); } TSK_IMG_TYPE_ENUM * flag_num = get_img_flag(flag); if ( (! NIL_P(filename)) && (flag_num > 0) ) { rb_iv_set(self, "@auto_detect", Qfalse); } else if ( ! NIL_P(filename)) { flag = INT2FIX((TSK_IMG_TYPE_ENUM)0); // auto-detect rb_iv_set(self, "@auto_detect", Qtrue); } else { rb_raise (rb_eRuntimeError, "invalid arguments"); } if( ! NIL_P(filename)) { // string for single image, array for split images rb_iv_set(self, "@path", filename); if (rb_obj_is_kind_of(filename, rb_cString)) { image_open(self, filename, flag); // passing flag (disk_type) as ruby FIXNUM } else if (rb_obj_is_kind_of(filename, rb_cArray)) { image_open(self, filename, flag); } else { rb_raise(rb_eTypeError, "arg1 must be String or Array"); } } else { rb_raise(rb_eArgError, "Arg1 must be filename (string)"); } Data_Get_Struct(self, struct tsk4r_img_wrapper, ptr); if ( ptr->image != NULL ) { return self; } else { return Qnil; } }
image& image::set_clamped( bl clamped ) { image_open(); this->clamped = clamped; s32 clamping_parameters = get_clamping_params( this->clamped ); glTexParameteri( TEXTURE_2D, TEXTURE_WRAP_S, clamping_parameters ); glTexParameteri( TEXTURE_2D, TEXTURE_WRAP_T, clamping_parameters ); image_close(); RETHIS; }
image& image::set_mipmapped( bl mipmapped ) { image_open(); this->mipmapped = mipmapped; s32 filter_parameters = get_filter_params( filtered, this->mipmapped ); glTexParameteri( TEXTURE_2D, TEXTURE_MIN_FILTER, filter_parameters ); glTexParameteri( TEXTURE_2D, TEXTURE_MAG_FILTER, filter_parameters ); image_close(); RETHIS; }
static void get_window() { if (!host.inited) { host.tw = image_new(NULL, NULL); /* create and add to list */ if (host.tw) { image_open(host.tw); UpdateWindow(host.tw->hwnd); } host.hdc = NULL; host.count_GetDC = 0; host.window_height = 100; host.line_width = 1; host.color = 0; host.inited = true; } }
static int loadDriver(struct ecosflash_flash_bank *info) { size_t buf_cnt; size_t image_size; struct image image; image.base_address_set = 0; image.start_address_set = 0; struct target *target = info->target; int retval; if ((retval = image_open(&image, info->driverPath, NULL)) != ERROR_OK) { return retval; } info->start_address = image.start_address; image_size = 0x0; int i; for (i = 0; i < image.num_sections; i++) { void *buffer = malloc(image.sections[i].size); if ((retval = image_read_section(&image, i, 0x0, image.sections[i].size, buffer, &buf_cnt)) != ERROR_OK) { free(buffer); image_close(&image); return retval; } target_write_buffer(target, image.sections[i].base_address, buf_cnt, buffer); image_size += buf_cnt; LOG_DEBUG("%zu bytes written at address 0x%8.8" PRIx32 "", buf_cnt, image.sections[i].base_address); free(buffer); } image_close(&image); return ERROR_OK; }
/** * Take the input stream as an image and create a layout part containing * an image, as if it was taken from an img-tag in an HTML page. * * @param fd File descriptor of input stream. * * @return non-zero value if an error occurred. */ int parse_image(int fd) { struct layout_part *partp; struct image_data *picture; if(!user_interface.ui_support.image) return 1; /* Initialize the state struct used throughout the whole parsing. */ parse_state_delete_all(); parse_state_init(); partp = layout_init_part(LAYOUT_PART_GRAPHICS); if(partp == NULL) { return 1; } picture = image_open(fd, -1, -1); if(picture == NULL) return 1; /* We should really allocate a new area, copy the image and free the * image data. This is too much work for us, so for the time being, we * will only free the image data struct, and not the data itself. This * will however be freed by the function which destroys the layout parts. * So, do not worry about memory leaks, I have it all under control. */ partp->data.graphics.data = picture->data; partp->data.graphics.size = picture->size; partp->data.graphics.type = LAYOUT_PART_GRAPHICS_RAW; partp->data.graphics.alt_text = NULL; partp->geometry.width = picture->width; partp->geometry.height = picture->height; free(picture); layout_add_part(partp); /* Delete the states when we are done with them. */ parse_state_delete_all(); return 0; }
static int operate_on_image(char *path) { void *image; unsigned char *luma; float *out, **emap, da_ratio, blur_extent; int n, w, h; image = image_open(path, LUMA_COLORSPACE); if(image == NULL) return 1; luma = image_luma(image); w = image_width(image); h = image_height(image); n = w*h; out = malloc(sizeof(float)*n); assert(out != NULL); for(int i = 0; i < n; i++) out[i] = luma[i]/255.0; haar_transform(out, w, h); emap = malloc(sizeof(float*)*(LEVELS+1)); memset(emap, 0, sizeof(float*)*(LEVELS+1)); for(int i = 1; i <= LEVELS; i++) emap[i] = malloc(sizeof(float)*((w>>i)*(h>>i))); construct_edge_map(out, emap, w, h); /* Note: we don't perform non-maxima suppression at this * point, because it seems to yield worse results compared to * simply adjusting the threshold. */ detect_blur(emap, w, h, threshold, &da_ratio, &blur_extent); printf("%s -- da_ratio: %f blur_extent: %f\n", (da_ratio > min_zero) ? "sharp":"blurred", da_ratio, blur_extent); for(int i = 1; i <= LEVELS; i++) free(emap[i]); free(emap); free(out); return 0; }
EXPORT #endif int image_unpack(const char* imagefile,const char *outpath) { int ret = 0; unsigned int itemCountTotal = 0; unsigned int nItem = 0; unsigned int write_bytes = 0; char main_type[32] = {0}; char sub_type[32] = {0}; char outfile[512] = {0}; char cfgfile[128] = {0}; char buff[256] = {0}; #ifdef BUILD_DLL if(ImageDecoder->AmlFirmwareImg == NULL){ ImageDecoder->AmlFirmwareImg = (AmlFirmwareImg_t*)malloc(sizeof(AmlFirmwareImg_t)); if(ImageDecoder->AmlFirmwareImg == NULL){ fprintf(stderr,"not enough memory\n"); return -1; } } #endif if(outpath){ strcpy(outfile,outpath); strcat(outfile,"\\"); strcpy(cfgfile,outfile); } strcat(cfgfile,"image.cfg"); HIMAGE hImage = image_open(imagefile); if(image_check(hImage) < 0){ fprintf(stderr,"the image check fail!!\n"); return -1; }else{ printf("the image check ok!\n"); } itemCountTotal = image_get_item_count(hImage,NULL); const unsigned itemCountVerify = image_get_item_count(hImage, "VERIFY"); const unsigned itemCountNormal = itemCountTotal - itemCountVerify * 2; debugP("item cnt:total[%u], normal[%u], verify[%u]\n", itemCountTotal, itemCountNormal, itemCountVerify); char *unPackBuf = (char*)malloc(RW_MAX_SIZE); if(unPackBuf==NULL){ fprintf(stderr,"allocate memccpy failed at %s %d \n", __FILE__,__LINE__); return __LINE__; } FILE *fp_cfg = fopen(cfgfile,"wb+"); if(fp_cfg==NULL){ fprintf(stderr,"create image.cfg failed ! [%s] \n",strerror(errno)); return __LINE__; } fwrite(TAG_NORMALLIST,1,strlen(TAG_NORMALLIST), fp_cfg); fwrite("\r\n", 1, 2, fp_cfg); for(nItem = 0; nItem < itemCountTotal; ++nItem) { if(image_get_next_item(hImage,nItem,main_type,sub_type) < 0){ ret = -1; break; } if(!strcmp("VERIFY", main_type)) { continue;//skip verify item } if(nItem == itemCountNormal)//[List_normal]ends, [List_verify] starts { fwrite("\r\n", 1, 2, fp_cfg); fwrite(TAG_VERIFYLIST,1,strlen(TAG_VERIFYLIST), fp_cfg); fwrite("\r\n", 1, 2, fp_cfg); } memset(outfile,0,64); if(outpath){ strcpy(outfile,outpath); strcat(outfile,"/"); } strcat(outfile,sub_type); strcat(outfile,"."); strcat(outfile,main_type); debugP("out file: %s \n",outfile);//sub_type.main_type HIMAGEITEM hItem = image_open_item(hImage,main_type,sub_type); if(hItem == NULL){ fprintf(stderr,"open item[%s, %s] failed!\n", main_type, sub_type); ret = -1; break; } int backUpItemId = 0; int itemIsBacked = is_item_backup_for_other_item(hItem, &backUpItemId); if(itemIsBacked < 0){ errorP("Fail to in test is_item_backup_for_other_item\n"); ret = __LINE__; break; } if(itemIsBacked)//item is back item { char* CfgLine = (char*)unPackBuf; char srcBackItemMainType[32]; char srcBackItemSubType[32]; if(image_get_next_item(hImage, backUpItemId, srcBackItemMainType, srcBackItemSubType)){ errorP("Fail to get the backui item head\n"); ret = __LINE__; break; } sprintf(CfgLine, IMG_CFG_LINE, srcBackItemSubType, srcBackItemMainType, main_type, sub_type); fwrite(CfgLine,1,strlen(CfgLine), fp_cfg); continue; } FILE *fp_out = fopen(outfile,"wb+"); if(fp_out == NULL){ fprintf(stderr,"failed to create out file : %s \n",outfile); ret = -1; break; } while((write_bytes = image_read_item_data(hImage, hItem, unPackBuf, RW_MAX_SIZE))>0) { if(fwrite(unPackBuf,1,write_bytes,fp_out)!=write_bytes){ fprintf(stderr,"write to image file fail! [%s] \n",strerror(errno)); ret = -1; break; } } fclose(fp_out); image_close_item(hItem); char* CfgLine = (char*)unPackBuf; sprintf(CfgLine, IMG_CFG_LINE, sub_type, main_type, main_type, sub_type); fwrite(CfgLine,1,strlen(CfgLine), fp_cfg); } free(unPackBuf); fclose(fp_cfg); fp_cfg = NULL; #ifdef BUILD_DLL if(ImageDecoder->AmlFirmwareImg){ free(ImageDecoder->AmlFirmwareImg); ImageDecoder->AmlFirmwareImg = NULL; } #endif return ret; }
static int load_usb_blaster_firmware(struct jtag_libusb_device_handle *libusb_dev, struct ublast_lowlevel *low) { struct image ublast2_firmware_image; if (!low->firmware_path) { LOG_ERROR("No firmware path specified"); return ERROR_FAIL; } ublast2_firmware_image.base_address = 0; ublast2_firmware_image.base_address_set = 0; int ret = image_open(&ublast2_firmware_image, low->firmware_path, "ihex"); if (ret != ERROR_OK) { LOG_ERROR("Could not load firmware image"); return ret; } /** A host loader program must write 0x01 to the CPUCS register * to put the CPU into RESET, load all or part of the EZUSB * RAM with firmware, then reload the CPUCS register * with ‘0’ to take the CPU out of RESET. The CPUCS register * (at 0xE600) is the only EZ-USB register that can be written * using the Firmware Download command. */ char value = CPU_RESET; jtag_libusb_control_transfer(libusb_dev, LIBUSB_REQUEST_TYPE_VENDOR | \ LIBUSB_ENDPOINT_OUT, USBBLASTER_CTRL_LOAD_FIRM, EZUSB_CPUCS, 0, &value, 1, 100); /* Download all sections in the image to ULINK */ for (int i = 0; i < ublast2_firmware_image.num_sections; i++) { ret = ublast2_write_firmware_section(libusb_dev, &ublast2_firmware_image, i); if (ret != ERROR_OK) { LOG_ERROR("Error while downloading the firmware"); return ret; } } value = !CPU_RESET; jtag_libusb_control_transfer(libusb_dev, LIBUSB_REQUEST_TYPE_VENDOR | \ LIBUSB_ENDPOINT_OUT, USBBLASTER_CTRL_LOAD_FIRM, EZUSB_CPUCS, 0, &value, 1, 100); image_close(&ublast2_firmware_image); return ERROR_OK; }
int optimus_burn_with_cfg_file(const char* cfgFile) { extern ConfigPara_t g_sdcBurnPara ; int ret = 0; HIMAGE hImg = NULL; ConfigPara_t* pSdcCfgPara = &g_sdcBurnPara; const char* pkgPath = pSdcCfgPara->burnEx.pkgPath; __hdle hUiProgress = NULL; ret = parse_ini_cfg_file(cfgFile); if (ret) { DWN_ERR("Fail to parse file %s\n", cfgFile); ret = __LINE__; goto _finish; } if (pSdcCfgPara->custom.eraseBootloader && strcmp("1", getenv("usb_update"))) { if (is_bootloader_old()) { DWN_MSG("To erase OLD bootloader !\n"); ret = optimus_erase_bootloader("sdc"); if (ret) { DWN_ERR("Fail to erase bootloader\n"); ret = __LINE__; goto _finish; } #if defined(CONFIG_VIDEO_AMLLCD) //axp to low power off LCD, no-charging DWN_MSG("To close LCD\n"); ret = run_command("video dev disable", 0); if (ret) { printf("Fail to close back light\n"); /*return __LINE__;*/ } #endif// #if defined(CONFIG_VIDEO_AMLLCD) DWN_MSG("Reset to load NEW uboot from ext-mmc!\n"); optimus_reset(OPTIMUS_BURN_COMPLETE__REBOOT_SDC_BURN); return __LINE__;//should never reach here!! } } if (OPTIMUS_WORK_MODE_SDC_PRODUCE == optimus_work_mode_get()) //led not depend on image res, can init early { if (optimus_led_open(LED_TYPE_PWM)) { DWN_ERR("Fail to open led for sdc_produce\n"); return __LINE__; } optimus_led_show_in_process_of_burning(); } hImg = image_open("mmc", "0", "1", pkgPath); if (!hImg) { DWN_ERR("Fail to open image %s\n", pkgPath); ret = __LINE__; goto _finish; } //update dtb for burning drivers ret = optimus_sdc_burn_dtb_load(hImg); if (ITEM_NOT_EXIST != ret && ret) { DWN_ERR("Fail in load dtb for sdc_burn\n"); ret = __LINE__; goto _finish; } if (video_res_prepare_for_upgrade(hImg)) { DWN_ERR("Fail when prepare bm res or init video for upgrade\n"); image_close(hImg); return __LINE__; } show_logo_to_report_burning(); hUiProgress = optimus_progress_ui_request_for_sdc_burn(); if (!hUiProgress) { DWN_ERR("request progress handle failed!\n"); ret = __LINE__; goto _finish; } optimus_progress_ui_direct_update_progress(hUiProgress, UPGRADE_STEPS_AFTER_IMAGE_OPEN_OK); int hasBootloader = 0; u64 datapartsSz = optimus_img_decoder_get_data_parts_size(hImg, &hasBootloader); int eraseFlag = pSdcCfgPara->custom.eraseFlash; if (!datapartsSz) { eraseFlag = 0; DWN_MSG("Disable erase as data parts size is 0\n"); } ret = optimus_storage_init(eraseFlag); if (ret) { DWN_ERR("Fail to init stoarge for sdc burn\n"); return __LINE__; } optimus_progress_ui_direct_update_progress(hUiProgress, UPGRADE_STEPS_AFTER_DISK_INIT_OK); if (datapartsSz) { ret = optimus_progress_ui_set_smart_mode(hUiProgress, datapartsSz, UPGRADE_STEPS_FOR_BURN_DATA_PARTS_IN_PKG(!pSdcCfgPara->burnEx.bitsMap.mediaPath)); if (ret) { DWN_ERR("Fail to set smart mode\n"); ret = __LINE__; goto _finish; } ret = optimus_sdc_burn_partitions(pSdcCfgPara, hImg, hUiProgress, 1); if (ret) { DWN_ERR("Fail when burn partitions\n"); ret = __LINE__; goto _finish; } } if (pSdcCfgPara->burnEx.bitsMap.mediaPath) //burn media image { const char* mediaPath = pSdcCfgPara->burnEx.mediaPath; ret = optimus_sdc_burn_media_partition(mediaPath, NULL);//no progress bar info if have partition image not in package if (ret) { DWN_ERR("Fail to burn media partition with image %s\n", mediaPath); optimus_storage_exit(); ret = __LINE__;goto _finish; } } optimus_progress_ui_direct_update_progress(hUiProgress, UPGRADE_STPES_AFTER_BURN_DATA_PARTS_OK); //TO burn nandkey/securekey/efusekey ret = sdc_burn_aml_keys(hImg, pSdcCfgPara->custom.keyOverwrite); if (ret) { DWN_ERR("Fail in sdc_burn_aml_keys\n"); ret = __LINE__;goto _finish; } #if 1 if (hasBootloader) {//burn bootloader ret = optimus_burn_bootlader(hImg); if (ret) { DWN_ERR("Fail in burn bootloader\n"); goto _finish; } else {//update bootloader ENV only when bootloader image is burned ret = optimus_set_burn_complete_flag(); if (ret) { DWN_ERR("Fail in set_burn_complete_flag\n"); ret = __LINE__; goto _finish; } } } #endif optimus_progress_ui_direct_update_progress(hUiProgress, UPGRADE_STEPS_AFTER_BURN_BOOTLOADER_OK); _finish: image_close(hImg); optimus_progress_ui_report_upgrade_stat(hUiProgress, !ret); optimus_report_burn_complete_sta(ret, pSdcCfgPara->custom.rebootAfterBurn); optimus_progress_ui_release(hUiProgress); //optimus_storage_exit();//temporary not exit storage driver when failed as may continue burning after burn return ret; }