示例#1
0
文件: mybmp.c 项目: VVillwin/minigui
int GUIAPI LoadMyBitmapEx (PMYBITMAP my_bmp, RGB* pal, MG_RWops* area, const char* ext)
{
    int type, ret;
    void* init_info;

    if ((type = get_image_type(ext)) < 0)
        return ERR_BMP_UNKNOWN_TYPE;

    my_bmp->flags = MYBMP_LOAD_NONE;
    my_bmp->bits = NULL;
    my_bmp->frames = 1;
    my_bmp->depth = GetGDCapability (HDC_SCREEN, GDCAP_DEPTH);

    if (my_bmp->depth <= 8)
        GetPalette (HDC_SCREEN, 0, 256, (GAL_Color*)pal);

#ifdef _GRAY_SCREEN
    my_bmp->flags |= MYBMP_LOAD_GRAYSCALE;
#endif

    init_info = bitmap_types [type].init (area, my_bmp, pal);
    if (init_info == NULL)
        return ERR_BMP_CANT_READ;

    my_bmp->bits = malloc (my_bmp->pitch * my_bmp->h);

    if (my_bmp->bits)
        ret = bitmap_types [type].load (area, init_info, my_bmp, NULL, NULL);
    else
        ret = ERR_BMP_MEM;

    bitmap_types [type].cleanup (init_info);

    return ret;
}
示例#2
0
文件: mybmp.c 项目: VVillwin/minigui
int GUIAPI SaveMyBitmapToFile (PMYBITMAP my_bmp, RGB* pal, const char* spFileName)
{
    MG_RWops* fp;
    const char* ext;
    int type;
    int save_ret;

    if ((ext = get_extension (spFileName)) == NULL)
        return ERR_BMP_UNKNOWN_TYPE;

    if ( (type = get_image_type(ext)) < 0 )
        return ERR_BMP_UNKNOWN_TYPE;

    if (bitmap_types[type].save == NULL)
        return ERR_BMP_CANT_SAVE;

    if (!(fp = MGUI_RWFromFile (spFileName, "wb+"))) {
#ifdef _DEBUG
        fprintf (stderr, "Saving BMP file: fopen error.\n");
#endif
        return ERR_BMP_FILEIO;
    }

    save_ret = bitmap_types[type].save (fp, my_bmp, pal);

    MGUI_RWclose (fp);

    return save_ret;
}
示例#3
0
文件: mybmp.c 项目: VVillwin/minigui
void* GUIAPI InitMyBitmapSL (MG_RWops* area, const char* ext, MYBITMAP* my_bmp, RGB* pal)
{
    int type;
    LOAD_MYBITMAP_INFO* load_info;

    load_info = calloc (1, sizeof (LOAD_MYBITMAP_INFO));
    if (load_info == NULL)
        return NULL;

    if ((type = get_image_type(ext)) < 0)
    {
        free (load_info);
        return NULL;
    }

    load_info->type_info = bitmap_types + type;

    my_bmp->flags = MYBMP_LOAD_ALLOCATE_ONE;
    my_bmp->bits = NULL;
    my_bmp->frames = 1;
    my_bmp->depth = GetGDCapability (HDC_SCREEN, GDCAP_DEPTH);

    if (my_bmp->depth <= 8)
        GetPalette (HDC_SCREEN, 0, 256, (GAL_Color*)pal);

#ifdef _GRAY_SCREEN
    my_bmp->flags |= MYBMP_LOAD_GRAYSCALE;
#endif

    load_info->init_info = load_info->type_info->init (area, my_bmp, pal);
    if (load_info->init_info == NULL)
        goto fail;

    my_bmp->bits = malloc (my_bmp->pitch);
    if (my_bmp->bits == NULL)
        goto fail;

    return load_info;

fail:
    if (my_bmp->bits != NULL)
        free (my_bmp->bits);
    free (load_info);
    return NULL;
}
示例#4
0
static PyObject *
im_SetImageType(PyObject *self, PyObject *args) {

	void *magick_pointer;
	MagickWand *magick_wand;
	char *img_type = NULL;

	if (!PyArg_ParseTuple(args, "Os", &magick_pointer, &img_type)){
		Py_INCREF(Py_None);
		return Py_None;
	}

	magick_wand = (MagickWand *) PyCObject_AsVoidPtr(magick_pointer);
	MagickSetImageType(magick_wand, get_image_type(img_type));

	Py_INCREF(Py_None);
	return Py_None;
}
BOOL write_to_nand(u8* data, u32 length, u32 img_total_len)
{
	static u64 partition_size = 0;
	int next_flip = 0;
	u32 index;
	static int img_type = UNKOWN_IMG;
	s8* p_type;
	u32 w_length =0;
	//u32 pre_chksum = 0;
	//u32 post_chksum = 0;
	int r;

	if(sto_info.first_run)
	{
		r = get_partition_name(data, length, sto_info.partition_name);
		if(r < 0)
		{
			display_info("\nGet_partition_name() Fail");
			return FALSE;
		}

		index = partition_get_index(sto_info.partition_name);  //
		if(index == -1)
		{
			display_info("\nBrick phone??");
			return FALSE;
		}

		if(!is_support_flash(index))
		{
			display_info("\nDont support partition.");
			return FALSE;
		}

		partition_size = partition_get_size(index);
		dprintf(DBG_LV, "[index:%d]-[partitionSize:%lld]-[downSize:%d]\n", index, partition_size, sto_info.to_write_data_len);

		if (ROUND_TO_PAGE(sto_info.to_write_data_len,511) > partition_size)
		{
			display_info("size too large, space small.");
			dprintf(DBG_LV, "size too large, space small.");
			return FALSE;
		}

		{
			char i_type[20] = {0};
			get_image_type(data,length,(char *)i_type);
					
			partition_get_type(index,&p_type);
			
			if(strcmp(i_type,p_type)){
					display_info("[warning]image type is not match with partition type\n");
					dprintf(DBG_LV, "[warning]image type'%s' is not match with partition type'%s'",i_type,p_type);
			}
			printf("image type %s\n",i_type);

			if(!strcmp(i_type,"raw data")){
				img_type = RAW_DATA_IMG;	
			}else if(!strcmp(i_type,"yaffs2")){
				img_type = YFFS2_IMG;	
			}else if(!strcmp(i_type,"ubifs")){
				img_type = UBIFS_IMG;	
			}else{
					dprintf(DBG_LV, "image type '%s' unkown\n",i_type);
					display_info("\nimage type unkown");
					return FALSE;
			}
		}		
		sto_info.image_base_addr = partition_get_offset(index);

		//NAND has no sparse image.
		//sto_info.unsparse_status.image_base_addr = sto_info.image_base_addr;
		//sto_info.is_sparse_image = is_sparse_image(data, length);
		sto_info.first_run = 0;
	}
#if defined(MTK_MLC_NAND_SUPPORT)
	if (0 != nand_write_img_ex((u64)(sto_info.image_base_addr+sto_info.bulk_image_offset), (void*)data, length,img_total_len?(u64)(img_total_len):(u64)(sto_info.to_write_data_len), &w_length, (u64)(sto_info.image_base_addr),(u64)partition_size, img_type))
#else
	if (0 != nand_write_img_ex((u32)(sto_info.image_base_addr+sto_info.bulk_image_offset), (void*)data, length,img_total_len?(u32)(img_total_len):(u32)(sto_info.to_write_data_len), &w_length, (u32)(sto_info.image_base_addr),(u32)partition_size, img_type))
#endif
	{
		dprintf(DBG_LV, "nand_write_img() Failed.\n");
		display_info("Error in write bulk in NAND.");
		return FALSE;
	}
	if(sto_info.checksum_enabled)
	{
		//NAND do not support read() now.
	}

	sto_info.bulk_image_offset += w_length;

	return TRUE;
}
BOOL cmd_flash_nand_img(const char *arg, void *data, unsigned sz)
{
	int index;
	u64 offset,size;
	int img_type;
	char *p_type;
	char msg[256];

    index = partition_get_index(arg);
    if(index == -1){
        fastboot_fail_wrapper("partition get index fail");
        return FALSE;
    }
    if(!is_support_flash(index)){
        sprintf(msg,"partition '%s' not support flash\n",arg);
        fastboot_fail_wrapper(msg);
        return FALSE;
    }

    offset = partition_get_offset(index);
    if(offset == (u64)(-1)){
        fastboot_fail_wrapper("partition get offset fail");
        return FALSE;
    }else{
        printf("get offset: 0x%llx\n",offset);
    }
    size = partition_get_size(index);
    if(size == (u64)(-1)){
        fastboot_fail_wrapper("partition get size fail");
        return FALSE;
    }else{
        printf("get size: 0x%llx\n",size);
    }

    if (!strcmp(arg, "boot") || !strcmp(arg, "recovery"))
    {
        if (memcmp((void *)data, BOOT_MAGIC, strlen(BOOT_MAGIC)))
        {
            fastboot_fail_wrapper("image is not a boot image");
            return FALSE;
        }
    }
    {
			char i_type[20] = {0};
			
			get_image_type(data,sz,(char *)i_type);
					
			partition_get_type(index,&p_type);
			
			if(strcmp(i_type,p_type)){
					display_info("[warning]image type is not match with partition type\n");
					dprintf(DBG_LV, "[warning]image type'%s' is not match with partition type'%s'",i_type,p_type);
			}
			if(!strcmp(i_type,"raw data")){
				img_type = RAW_DATA_IMG;	
			}else if(!strcmp(i_type,"yaffs2")){
				img_type = YFFS2_IMG;	
			}else if(!strcmp(i_type,"ubifs")){
				img_type = UBIFS_IMG;	
			}else{
					dprintf(DBG_LV, "image type '%s' unkown\n",i_type);
					display_info("\nimage type unkown");
					return FALSE;
			}
		}
    TIME_START;
    display_info("write flash ....");
    printf("writing %d bytes to '%s' img_type %d\n", sz, arg,img_type);
#if defined(MTK_MLC_NAND_SUPPORT)
    if (nand_write_img((u64)offset, (char*)data, sz,(u64)size,img_type)) {
#else
    if (nand_write_img((u32)offset, (char*)data, sz,(u32)size,img_type)) {
#endif
        fastboot_fail_wrapper("nand  write image failure");
        return FALSE;
    }
    printf("partition '%s' updated\n", arg);
    fastboot_ok_wrapper("write flash sucess",sz);

    return TRUE;
}


void cmd_flash_nand(const char *arg, void *data, unsigned sz)
{
	char msg[128] = {0};

	if(sz  == 0)
	{
		fastboot_okay("");
		return;
	}
	
#ifdef MTK_SECURITY_SW_SUPPORT    
    //Please DO NOT get any data for reference if security check is not passed
    if(!security_check((u8**)&data, &sz, 0, arg))
    {
        sprintf(msg, "\nSecurity deny - Err:0x%x \n", sec_error());
    	dprintf(DBG_LV, msg);
    	fastboot_fail_wrapper(msg);
        return;
    }
#endif

	dprintf(DBG_LV, "cmd_flash_nand, data:0x%x\n",*(int*)data);

    if(cmd_flash_nand_img(arg,data,sz))
    {
        //[Security] Notify security check that is the end.
        sz = 0;
    #ifdef MTK_SECURITY_SW_SUPPORT    
        security_check((u8**)&data, &sz, IMAGE_TRUNK_SIZE, arg); 
    #endif
    }
}
BOOL cmd_flash_nand_img(const char *arg, void *data, unsigned sz)
{
	int index;
	u64 offset,size;
	int img_type;
	char *p_type;
	char msg[256];

    index = partition_get_index(arg);
    if(index == -1){
        fastboot_fail_wrapper("partition get index fail");
        return FALSE;
    }
    if(!is_support_flash(index)){
        sprintf(msg,"partition '%s' not support flash\n",arg);
        fastboot_fail_wrapper(msg);
        return FALSE;
    }

    offset = partition_get_offset(index);
    if(offset == -1){
        fastboot_fail_wrapper("partition get offset fail");
        return FALSE;
    }else{
        printf("get offset: 0x%llx\n",offset);
    }
    size = partition_get_size(index);
    if(size == -1){
        fastboot_fail_wrapper("partition get size fail");
        return FALSE;
    }else{
        printf("get size: 0x%llx\n",size);
    }

    if (!strcmp(arg, "boot") || !strcmp(arg, "recovery"))
    {
        if (memcmp((void *)data, BOOT_MAGIC, strlen(BOOT_MAGIC)))
        {
            fastboot_fail_wrapper("image is not a boot image");
            return FALSE;
        }
    }
    {
			char i_type[20] = {0};
			
			get_image_type(data,sz,(char *)i_type);
					
			partition_get_type(index,&p_type);
			
			if(strcmp(i_type,p_type)){
					display_info("[warning]image type is not match with partition type\n");
					dprintf(DBG_LV, "[warning]image type'%s' is not match with partition type'%s'",i_type,p_type);
			}
			if(!strcmp(i_type,"raw data")){
				img_type = RAW_DATA_IMG;	
			}else if(!strcmp(i_type,"yaffs2")){
				img_type = YFFS2_IMG;	
			}else if(!strcmp(i_type,"ubifs")){
				img_type = UBIFS_IMG;	
			}else{
					dprintf(DBG_LV, "image type '%s' unkown\n",i_type);
					display_info("\nimage type unkown");
					return FALSE;
			}
		}
    TIME_START;
    display_info("write flash ....");
    printf("writing %d bytes to '%s' img_type %d\n", sz, arg,img_type);
    if (nand_write_img((u32)offset, data, sz,(u32)size,img_type)) {
        fastboot_fail_wrapper("nand  write image failure");
        return FALSE;
    }
    printf("partition '%s' updated\n", arg);
    fastboot_ok_wrapper("write flash sucess",sz);

    return TRUE;
}
示例#8
0
void main(int argc, char **argv) {

	FILE *file, *fout, *mask_file; // arquivos de entrada e saída

	char line[MAX], header_type[MAX]; // strings

	int matrix_width, matrix_height, grayscale, weight, soma, mask_size; // colunas, linhas, escala de cinza, weight da máscara, soma dos elementos

	int i, j, w, z, x, y; // contadores e auxiliares

	int **array, **output, **mask; // matriz da imagem original, matriz da imagem de saída, matriz da mascara

	int c, r = 0; // colunas, linhas

	// verifica se os argumentos foram passados corretamente
	if (argc != 5 && argc != 4) {
		printf(
				"Os argumentos foram passados incorretamente. Por favor, consulte a documentação.");
		exit(EXIT_FAILURE);
	} else {
		if (!(file = fopen(argv[1], "r"))) {
			printf("Não foi possível abrir a imagem.");
			exit(EXIT_FAILURE);
		}

		if (!(fout = fopen(argv[argc - 1], "w+"))) {
			printf("Não foi possível abrir a imagem.");
			exit(EXIT_FAILURE);
		}
	}

	// se for utilizado o filtro de média, abre a imagem
	if (argc == 4) {
		if (!(mask_file = fopen(argv[2], "r"))) {
			printf("Não foi possível abrir a máscara.");
			exit(EXIT_FAILURE);
		}
	}

	// tipo da imagem: P5 ou P2
	get_image_type(file, &header_type);

	// tamanho da matrix: col lin
	get_matrix_size(file, &matrix_width, &matrix_height);

	// maior valor da escala de cinza
	get_grayscale(file, &grayscale);

	// verifica se o nível de cinza é o permitido
	if (grayscale > MAX_GRAYSCALE) {
		printf("O valor da escala de cinza é maior do que o permitido.");
		exit(EXIT_FAILURE);
	}

	// escreve o cabeçalho da imagem no arquivo
	write_image_header(fout, header_type, matrix_width, matrix_height,
			grayscale);

	// aloca memória para a imagem de saída
	output = (int **) (mallocc(sizeof(int *) * matrix_height));
	for (i = 0; i < matrix_height; i++) {
		output[i] = (int *) (mallocc(sizeof(int) * matrix_width));
	}

	// copia o corpo da imagem para a matriz
	array = read_matrix_elements(file, matrix_width, matrix_height);
	output = read_matrix_elements(file, matrix_width, matrix_height);

	// filtro da média
	mask_size = get_mask_size(mask_file);
	if(argc == 4){
		// aloca memória para a imagem de saída
		mask = (int **) (mallocc(sizeof(int *) * mask_size));
		for (i = 0; i < mask_size; i++) {
			mask[i] = (int *) (mallocc(sizeof(int) * mask_size));
		}

		// passa os elementos do arquivo para uma array
		mask = read_matrix_elements(mask_file, mask_size, mask_size);

		// verifica se o tamanho da mascara está correto
		if ((mask_size % 2 == 0) || mask_size < 3) {
			printf("Tamanho da máscara incorreto.");
			exit(EXIT_FAILURE);
		}

		// calcula o weight da máscara
		for (i = 0; i < mask_size; i++) {
			for (j = 0; j < mask_size; j++) {
				weight = weight + mask[i][j];
			}
		}

		// aplica o filtro
		media( matrix_height, matrix_width, mask_size, weight, array, output );
	} else
		mediana(matrix_height, matrix_width, mask_size, array, output);

	// grava imagem
	write_image_body(fout, matrix_width, matrix_height, output);

	// libera a memória alocada
	free(array);
	free(output);

	// fecha o buffer dos arquivos
	fclose(file);
	fclose(fout);

	return;
}
示例#9
0
void game_display::draw_hex(const map_location& loc)
{
	const bool on_map = get_map().on_board(loc);
	const bool is_shrouded = shrouded(loc);
	const bool is_fogged = fogged(loc);
	int xpos = get_location_x(loc);
	int ypos = get_location_y(loc);
	tblit blit(xpos, ypos);

	image::TYPE image_type = get_image_type(loc);

	display::draw_hex(loc);

	if(!is_shrouded) {
		typedef overlay_map::const_iterator Itor;
		std::pair<Itor,Itor> overlays = overlays_.equal_range(loc);
		for( ; overlays.first != overlays.second; ++overlays.first) {
			if ((overlays.first->second.team_name == "" ||
			overlays.first->second.team_name.find(teams_[playing_team()].team_name()) != std::string::npos)
			&& !(is_fogged && !overlays.first->second.visible_in_fog))
			{
				drawing_buffer_add(LAYER_TERRAIN_BG, loc, tblit(xpos, ypos,
					image::get_image(overlays.first->second.image,image_type)));
			}
		}
		// village-control flags.
		//drawing_buffer_add(LAYER_TERRAIN_BG, loc, tblit(xpos, ypos, get_flag(loc)));
		
		textureAtlasInfo tinfo = get_flag(loc);
		if (tinfo.mapId != 0)
		{
			drawing_buffer_add(LAYER_UNIT_FG, loc, tblit(xpos, ypos, tinfo));
		}
		
		
	}

	// Draw the time-of-day mask on top of the terrain in the hex.
	// tod may differ from tod if hex is illuminated.
	std::string tod_hex_mask = timeofday_at(status_,units_,loc,get_map()).image_mask;
	if(tod_hex_mask1 != NULL || tod_hex_mask2 != NULL) {
		drawing_buffer_add(LAYER_TERRAIN_FG, loc, tblit(xpos, ypos, tod_hex_mask1));
		drawing_buffer_add(LAYER_TERRAIN_FG, loc, tblit(xpos, ypos, tod_hex_mask2));
	} else if(tod_hex_mask != "") {
		drawing_buffer_add(LAYER_TERRAIN_FG, loc, tblit(xpos, ypos,
			image::get_image(tod_hex_mask,image::UNMASKED)));
	}

	// Draw reach_map information.
	// We remove the reachability mask of the unit
	// that we want to attack.
	if (!is_shrouded && !reach_map_.empty()
			&& reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) {
		textureAtlasInfo tinfo;
		if (getTextureAtlasInfo(game_config::unreachable_image, tinfo))
			drawing_buffer_add(LAYER_REACHMAP, loc, tblit(xpos, ypos,
														  //image::get_image(game_config::unreachable_image,image::UNMASKED)));
														  tinfo));
	}

	// Footsteps indicating a movement path
	drawing_buffer_add(LAYER_TERRAIN_TMP_BG, loc, tblit(xpos, ypos, footsteps_images(loc)));
	// Draw cross images for debug highlights
	if(game_config::debug && debugHighlights_.count(loc)) {
		drawing_buffer_add(LAYER_TERRAIN_TMP_BG, loc, tblit(xpos, ypos,
			image::get_image(game_config::cross_image, image::UNMASKED)));
	}
	// Draw the attack direction indicator
	if(on_map && loc == attack_indicator_src_) {
		textureAtlasInfo tinfo;
		getTextureAtlasInfo("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", tinfo);
		drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, tblit(xpos, ypos,
			//image::get_image("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::UNMASKED)));
		  tinfo));
	} else if (on_map && loc == attack_indicator_dst_) {
		textureAtlasInfo tinfo;
		getTextureAtlasInfo("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", tinfo);
		drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, tblit(xpos, ypos,
			//image::get_image("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::UNMASKED)));
		  tinfo));
	}

	// Linger overlay unconditionally otherwise it might give glitches
	// so it's drawn over the shroud and fog.
	if(game_mode_ != RUNNING) {
		blit.surf.push_back(image::get_image(game_config::linger_image, image::SCALED_TO_HEX));
		drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, blit);
		blit.surf.clear();
	}

	// Show def% and turn to reach infos
	if(!is_shrouded && on_map) {
		draw_movement_info(loc);
	}
	//simulate_delay += 1;
}
示例#10
0
void game_display::draw_hex(const map_location& loc)
{
	const bool on_map = get_map().on_board(loc);
	const bool is_shrouded = shrouded(loc);
	const bool is_fogged = fogged(loc);
	const int xpos = get_location_x(loc);
	const int ypos = get_location_y(loc);

	image::TYPE image_type = get_image_type(loc);

	display::draw_hex(loc);

	if(on_map && loc == mouseoverHex_) {
		tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM;
		if( get_visible_unit(loc, (*teams_)[viewing_team()] ) != NULL ) {
			hex_top_layer = LAYER_MOUSEOVER_TOP;
		}
		drawing_buffer_add( hex_top_layer,
						   loc, xpos, ypos, image::get_image("misc/hover-hex-top.png", image::SCALED_TO_HEX));
		drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM,
						   loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png", image::SCALED_TO_HEX));
	}

	if(!is_shrouded) {
		typedef overlay_map::const_iterator Itor;
		std::pair<Itor,Itor> overlays = overlays_.equal_range(loc);
		for( ; overlays.first != overlays.second; ++overlays.first) {
			if ((overlays.first->second.team_name == "" ||
			overlays.first->second.team_name.find((*teams_)[playing_team()].team_name()) != std::string::npos)
			&& !(is_fogged && !overlays.first->second.visible_in_fog))
			{
				drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos,
					image::get_image(overlays.first->second.image,image_type));
			}
		}
		// village-control flags.
		drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, get_flag(loc));
	}

	// Draw reach_map information.
	// We remove the reachability mask of the unit
	// that we want to attack.
	if (!is_shrouded && !reach_map_.empty()
			&& reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) {
		static const image::locator unreachable(game_config::images::unreachable);
		drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos,
				image::get_image(unreachable,image::SCALED_TO_HEX));
	}

	resources::whiteboard->draw_hex(loc);

	if (!(resources::whiteboard->is_active() && resources::whiteboard->has_temp_move()))
	{
		// Footsteps indicating a movement path
		const std::vector<surface>& footstepImages = footsteps_images(loc);
		if (footstepImages.size() != 0) {
			drawing_buffer_add(LAYER_FOOTSTEPS, loc, xpos, ypos, footstepImages);
		}
	}
	// Draw the attack direction indicator
	if(on_map && loc == attack_indicator_src_) {
		drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos,
			image::get_image("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
	} else if (on_map && loc == attack_indicator_dst_) {
		drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos,
			image::get_image("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
	}

	// Linger overlay unconditionally otherwise it might give glitches
	// so it's drawn over the shroud and fog.
	if(game_mode_ != RUNNING) {
		static const image::locator linger(game_config::images::linger);
		drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, xpos, ypos,
			image::get_image(linger, image::TOD_COLORED));
	}

	if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) {
		static const image::locator selected(game_config::images::selected);
		drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
				image::get_image(selected, image::SCALED_TO_HEX));
	}

	// Show def% and turn to reach info
	if(!is_shrouded && on_map) {
		draw_movement_info(loc);
	}

	if(game_config::debug) {
		int debugH = debugHighlights_[loc];
		if (debugH) {
			std::string txt = lexical_cast<std::string>(debugH);
			draw_text_in_hex(loc, LAYER_MOVE_INFO, txt, 18, font::BAD_COLOR);
		}
	}
	//simulate_delay += 1;
}
示例#11
0
文件: i2u.c 项目: jszigetvari/i2u
int main(int argc, char **argv, char **env) {
/*=========== GENERIC VARIABLES ===========*/
	FILE *f_output = NULL, *f_input = NULL;
	int c, i;
	char *end;
	
/*=========== GETOPT VARIABLES ===========*/
	char const *const optstr = "hi:o:f:c:w:b:n:t:";
#ifdef _GNU_SOURCE
	static struct option long_opts[] = {
		{"help", 0, NULL, 'h'},
		{"infile", 1, NULL, 'i'},
		{"outfile", 1, NULL, 'o'},
		{"format", 1, NULL, 'f'},
		{"colors", 1, NULL, 'c'},
		{"width", 1, NULL, 'w'},
		{"bgcolor", 1, NULL, 'b'},
		{"newcolor", 1, NULL, 'n'},
		{"color-tolerance", 1, NULL, 't'},
		{NULL, 0, NULL, 0},
	};
#endif

/*=========== IMAGE-RELATED VARIABLES ===========*/
	int x, y;
	int color_idx = 0;
	int img_orig_h = 0, img_orig_w = 0;
	int img_targ_h = 0, img_targ_w = 0;
	int top = -1, bottom = -1, top_prev = -1, bottom_prev = -1;
	int color = -1, color_prev = -1;
	gdImagePtr image_data = NULL;
	gdImagePtr image_resized = NULL;
	gdImageCreateFunction image_openers[] = {
		NULL,
		(gdImageCreateFunction) gdImageCreateFromJpeg,
		(gdImageCreateFunction) gdImageCreateFromPng,
		(gdImageCreateFunction) gdImageCreateFromGif,
		(gdImageCreateFunction) gdImageCreateFromWBMP,
		(gdImageCreateFunction) gdImageCreateFromXpm	/* Accepts char * as first argument! */
	};

	
	while (true) {
#ifdef _GNU_SOURCE
		c = getopt_long(argc, argv, optstr, long_opts, NULL);
#else /* not _GNU_SOURCE */ 
		c = getopt(argc, argv, optstr);
#endif /* _GNU_SOURCE */
		if (c == -1) break;

		switch (c) {
			case 'h':
				help(stdout, EXEC_NAME);
				exit(ALL_OK);
				break;
			case 'i':
				i = strlen(optarg);
				if (i2u_conf.m_infile != NULL) free(i2u_conf.m_infile);
				if ((i2u_conf.m_infile = (char *) calloc(i+1, sizeof(char))) == NULL) {
					fprintf(stderr, "calloc() failed!\n");
					cleanup_main();
					exit(ERR_OUT_OF_MEMORY);
				}
				strncpy(i2u_conf.m_infile, optarg, i);
				break;
			case 'o':
				if (strncmp("-", optarg, 2) == 0) {
					if (i2u_conf.m_outfile != NULL) free(i2u_conf.m_outfile);
					i2u_conf.m_outfile = NULL;
					break;
				}
				else {
					i = strlen(optarg);
					if (i2u_conf.m_outfile != NULL) free(i2u_conf.m_outfile);
					if ((i2u_conf.m_outfile = (char *) calloc(i+1, sizeof(char))) == NULL) {
						fprintf(stderr, "calloc() failed!\n");
						cleanup_main();
						exit(ERR_OUT_OF_MEMORY);
					}
					strncpy(i2u_conf.m_outfile, optarg, i);
					break;
				}
			case 'f':
				i = (int) strtol(optarg, &end, 10);
				if (optarg != end) {
					i2u_conf.m_outformat = (i > 8) ? unicode : ansi;
				}
				else {	
					if (strncasecmp(optarg, "ansi", 5) == 0) i2u_conf.m_outformat = ansi;
					else {
						if (strncmp(optarg, "unicode", 8) == 0) i2u_conf.m_outformat = unicode;
						else fprintf(stderr, "Warning: invalid format specified. Defaulting to Unicode.\n"); 
					}
				}
				break;
			case 'c':
				i = (int) strtol(optarg, &end, 10);
				if (optarg != end) { 
					if (i < 9) i2u_conf.m_colors = low;
					else {
						if (i < 17) i2u_conf.m_colors = basic;
						else i2u_conf.m_colors = extended;
					}
				}
				else fprintf(stderr, "Warning: invalid color depth specified. Defaulting to 256.\n");
				break;
			case 'w':
				i = (int) strtol(optarg, &end, 10);
				if (optarg != end) i2u_conf.m_targ_width = i;
				else fprintf(stderr, "Warning: invalid width specified. Defaulting to 80.\n");
				break;
			case 't':
				i = (int) strtol(optarg, &end, 10);
				if (optarg != end) i2u_conf.m_toleranceradius = (i > 0) ? i : 0;
				else fprintf(stderr, "Warning: invalid color-tolerance radius specified. Defaulting to zero.\n");
				break;
			case 'b':
				i = strtol(optarg, &end, 16);
				if (optarg != end) i2u_conf.m_bgcolor = i;
				else fprintf(stderr, "Warning: invalid background color specified. No background-substitution will occur.\n");
				break;
			case 'n':
				i = strtol(optarg, &end, 16);
				if (optarg != end) i2u_conf.m_newcolor = i;
				else fprintf(stderr, "Warning: invalid substitution color specified. No background-substitution will occur.\n");
				break;
			case '?':
			default:
				help(stderr, EXEC_NAME);
				exit(ERR_INVALID_ARG);
		}
		if (c == 'x') break;
	}

		
		
	if (i2u_conf.m_infile == NULL) {
		fprintf(stderr, "Error: input file not set. Use option" 
#ifdef _GNU_SOURCE
			"s -i or --infile"
#else /* not _GNU_SOURCE */ 
			" -i"
#endif /* _GNU_SOURCE */
			" to specify one.\n");
		cleanup_main();
		exit(ERR_INVALID_ARG);
	}

/*=========== GD PART ==========*/
	
	i2u_conf.m_ftype = get_image_type(i2u_conf.m_infile);
	
	if (i2u_conf.m_ftype == UNKNOWN) {
		fprintf(stderr, "Error: unsupported input file type!\n" );
		cleanup_main();
		exit(ERR_UNSUPPORTED_FORMAT);
	}
	
	if (i2u_conf.m_ftype != xpm) {
			if ((f_input = fopen(i2u_conf.m_infile, "r")) == NULL) {
				perror("fopen(): ");
				cleanup_main();
				exit(ERR_FOPEN_FAIL);
			}
		
			image_data = image_openers[i2u_conf.m_ftype](f_input);
			
			fclose(f_input);
	}
	else {
			if ((image_data = image_openers[i2u_conf.m_ftype](i2u_conf.m_infile)) == NULL) {
				fprintf(stderr, "gdImageCreateFromXpm(): Error occured while opening file \'%s\'\n", i2u_conf.m_infile);
				cleanup_main();
				exit(ERR_GD_XPMOPEN_FAIL);
			}
	}
	
	img_orig_w = image_data->sx;
	img_orig_h = image_data->sy;
	img_targ_w = i2u_conf.m_targ_width;
	img_targ_h = (int) round(((double) img_targ_w)/((double) img_orig_w)*((double) img_orig_h));
	/* if (i2u_conf.m_outformat == ansi) img_targ_w /= 2; */
	
	/* change background, if requested */
	if ((i2u_conf.m_bgcolor > -1) && (i2u_conf.m_newcolor > -1)) {
			int bg_r, bg_g, bg_b;
			int nc_r, nc_g, nc_b;
			int bgcolor, newcolor;
			int radius = i2u_conf.m_toleranceradius;
			bg_r = (i2u_conf.m_bgcolor & 0x00ff0000) >> 16;
			bg_g = (i2u_conf.m_bgcolor & 0x0000ff00) >> 8;
			bg_b = (i2u_conf.m_bgcolor & 0x000000ff);
			nc_r = (i2u_conf.m_newcolor & 0x00ff0000) >> 16;
			nc_g = (i2u_conf.m_newcolor & 0x0000ff00) >> 8;
			nc_b = (i2u_conf.m_newcolor & 0x000000ff);
			
			if ((bgcolor = gdImageColorExact(image_data, bg_r, bg_g, bg_b)) != -1) {
				color_idx = gdImageGetPixel(image_data, 0, 0);
				newcolor = gdImageColorResolve(image_data, nc_r, nc_g, nc_b);
				for (y=0; y<img_orig_h; y++) {
					for (x=0; x<img_orig_w; x++) {
					  color_idx = gdImageGetPixel(image_data, x, y);
				    if (get_color_distance(gdImageRed(image_data, color_idx), gdImageRed(image_data, bgcolor), gdImageGreen(image_data, color_idx), gdImageGreen(image_data, bgcolor), gdImageBlue(image_data, color_idx), gdImageBlue(image_data, bgcolor)) <= radius) gdImageSetPixel(image_data, x, y, newcolor);
					}
				}
			}	
	}