int					convert_to_bytecode(t_function *functions, char *filename)
{
	if (!(merge_first_two_functions(&functions)))
		return (0);
	convert_to_binary(functions, filename);
	return (0);
}
Exemple #2
0
int main()
{
    int a;
    while (1) {
        printf("please input your integer (any negative integer to quit):");
        scanf("%d",&a);
        if(a < 0) break;
        convert_to_binary(a);
    }
    return 0;
}
Exemple #3
0
/*
	This mapping is an intermediate process
	between the input and subkey passed
	to the fk function
*/
void F_mapping(char *output, char *subkey)
{
	char binary[3];
	int s0;
	int s1;
	char output_sbox[5];

	divide_block(output);
	expansion_permutation(r);
	xor(output, subkey);

	s0 = sbox_s(output, 0);
	convert_to_binary(s0, binary);
	strcpy(output_sbox, binary);

	s1 = sbox_s(output, 1);
	convert_to_binary(s1, binary);
	strcat(output_sbox, binary);

	p4_permutation(output_sbox);
}
int main(){
	printf("This program will generate 4 bit grey code\n");
	int i=0;
	int m=0;
	for(i=0;i<16;i++){
		convert_to_binary(gray_array[i]);
		printf("%d:",gray_array[i]);
		for(m=3;m>=0;m--)
			printf("%d",output[m]);
		printf("\n");
	}

}
Exemple #5
0
bool builder::resample() {
    memory_limit_ = calculate_memory_limit();

    auto input_file = fs::canonical(fs::path(desc_.input_file));
    const std::string input_file_type = input_file.extension().string();

    uint16_t start_stage = 0;
    if (input_file_type == ".xyz" || 
        input_file_type == ".ply" || 
        input_file_type == ".bin" ||
        input_file_type == ".xyz" || 
        input_file_type == ".xyz_all" || 
        input_file_type == ".ply")
        start_stage = 0;
    else if (input_file_type == ".bin" || input_file_type == ".bin_all")
        start_stage = 1;
    else {
        LOGGER_ERROR("Unknown input file format");
        return false;
    }

    // convert to binary file
    if (0 >= start_stage) {
        input_file = convert_to_binary(input_file_type);
        if(input_file.empty()) return false;
    }

    // downsweep (create bvh)
    if (3 >= start_stage) {
        input_file = downsweep(input_file, start_stage);
        if(input_file.empty()) return false;
    }

    // resample (create new xzy)
   bool resample_success = resample_surfels(input_file);
   return resample_success;
}
Exemple #6
0
bool builder::
construct()
{
    memory_limit_ = calculate_memory_limit();

    uint16_t start_stage = 0;
    uint16_t final_stage = desc_.final_stage;

    auto input_file = fs::canonical(fs::path(desc_.input_file));
    const std::string input_file_type = input_file.extension().string();

    if (input_file_type == ".xyz" || 
        input_file_type == ".ply" || 
        input_file_type == ".bin")
        desc_.compute_normals_and_radii = true;

    if (input_file_type == ".xyz" || 
        input_file_type == ".xyz_all" || 
        input_file_type == ".ply")
        start_stage = 0;
    else if (input_file_type == ".bin" || input_file_type == ".bin_all")
        start_stage = 1;
    else if (input_file_type == ".bin_wo_outlier")
        start_stage = 3;
    else if (input_file_type == ".bvhd")
        start_stage = 4;
    else if (input_file_type == ".bvhu")
        start_stage = 5;
    else {
        LOGGER_ERROR("Unknown input file format");
        return false;
    }

    // init algorithms
    std::unique_ptr<reduction_strategy> reduction_strategy{get_reduction_strategy(desc_.reduction_algo)};
    std::unique_ptr<normal_computation_strategy> normal_comp_strategy{get_normal_strategy(desc_.normal_computation_algo)};
    std::unique_ptr<radius_computation_strategy> radius_comp_strategy{get_radius_strategy(desc_.radius_computation_algo)};

    // convert to binary file
    if ((0 >= start_stage) && (0 <= final_stage)) {
        input_file = convert_to_binary(input_file_type);
        if(input_file.empty()) return false;
    }

    // downsweep (create bvh)
    if ((3 >= start_stage) && (3 <= final_stage)) {
        input_file = downsweep(input_file, start_stage);
        if(input_file.empty()) return false;
    }

    // upsweep (create LOD)
    if ((4 >= start_stage) && (4 <= final_stage)) {
       input_file = upsweep(input_file, start_stage, reduction_strategy.get(), normal_comp_strategy.get(), radius_comp_strategy.get());
       if(input_file.empty()) return false;
    }

    // serialize to file
    if ((5 >= start_stage) && (5 <= final_stage)) {
        bool reserialize_success = reserialize(input_file, start_stage);
        if(!reserialize_success) return false;
    }
    return true;
}
void ProcessGif::read_image(char file_name[], cv::Mat **image)
{
	GifFileType *gif_image = NULL;
	GifRowType *ScreenBuffer = NULL;
	int size_of_each_row = 0, BackGround = 0, i, j, Row = 0, Col = 0, Width = 0, Height = 0,
			ImageNum = 0, ExtCode, Count, img_width = 0, img_height = 0,
			InterlacedOffset[] = { 0, 4, 2, 1 }, /* The way Interlaced image should. */
		    InterlacedJumps[] = { 8, 8, 4, 2 };    /* be read - offsets and jumps... */;
	ColorMapObject *ColorMap;
	GifRowType GifRow;
	static GifColorType *ColorMapEntry;
	GifRecordType RecordType;
	GifByteType *Extension;
	unsigned char *BufferP, *image_buffer;

	gif_image = DGifOpenFileName(file_name);

	img_height = gif_image->SHeight;
	img_width = gif_image->SWidth;

	image_buffer = new unsigned char[img_height * img_width * 3];

	if ((ScreenBuffer = (GifRowType *) malloc(img_height * sizeof(GifRowType *))) == NULL)
		GIF_EXIT("Failed to allocate memory required, aborted.");

	size_of_each_row = img_width * sizeof(GifPixelType);/* Size in bytes one row.*/
	if ((ScreenBuffer[0] = (GifRowType) malloc(size_of_each_row)) == NULL) /* First row. */
		GIF_EXIT("Failed to allocate memory required, aborted.");

	for (i = 0; i < gif_image->SWidth; i++)  /* Set first row's color to BackGround. */
		ScreenBuffer[0][i] = gif_image->SBackGroundColor;

	for (i = 1; i < img_height; i++)
	{
		/* Allocate the other rows, and set their color to background too: */
		if ((ScreenBuffer[i] = (GifRowType) malloc(size_of_each_row)) == NULL)
			GIF_EXIT("Failed to allocate memory required, aborted.");

		memcpy(ScreenBuffer[i], ScreenBuffer[0], size_of_each_row);
	}

	/* Scan the content of the GIF file and load the image(s) in: */
	do {
		if (DGifGetRecordType(gif_image, &RecordType) == GIF_ERROR)
		{
			PrintGifError();
			exit(EXIT_FAILURE);
		}
		switch (RecordType) {
		case IMAGE_DESC_RECORD_TYPE:
			if (DGifGetImageDesc(gif_image) == GIF_ERROR)
			{
				PrintGifError();
				exit(EXIT_FAILURE);
			}

			Row = gif_image->Image.Top; /* Image Position relative to Screen. */
			Col = gif_image->Image.Left;
			Width = gif_image->Image.Width;
			Height = gif_image->Image.Height;

			if (gif_image->Image.Left + gif_image->Image.Width > gif_image->SWidth ||
					gif_image->Image.Top + gif_image->Image.Height > gif_image->SHeight)
			{
				fprintf(stderr, "Image %d is not confined to screen dimension, aborted.\n",ImageNum);
				exit(EXIT_FAILURE);
			}
			if (gif_image->Image.Interlace) {
				/* Need to perform 4 passes on the images: */
				for (Count = i = 0; i < 4; i++)
					for (j = Row + InterlacedOffset[i]; j < Row + Height; j += InterlacedJumps[i])
					{
						if (DGifGetLine(gif_image, &ScreenBuffer[j][Col], Width) == GIF_ERROR)
						{
							PrintGifError();
							exit(EXIT_FAILURE);
						}
					}
			}
			else {
				for (i = 0; i < Height; i++) {
					if (DGifGetLine(gif_image, &ScreenBuffer[Row++][Col], Width) == GIF_ERROR)
					{
						PrintGifError();
						exit(EXIT_FAILURE);
					}
				}
			}
			break;
		case EXTENSION_RECORD_TYPE:
			/* Skip any extension blocks in file: */
			if (DGifGetExtension(gif_image, &ExtCode, &Extension) == GIF_ERROR)
			{
				PrintGifError();
				exit(EXIT_FAILURE);
			}
			while (Extension != NULL) {
				if (DGifGetExtensionNext(gif_image, &Extension) == GIF_ERROR)
				{
					PrintGifError();
					exit(EXIT_FAILURE);
				}
			}
			break;
		case TERMINATE_RECORD_TYPE:
			break;
		default:		    /* Should be traps by DGifGetRecordType. */
			break;
		}
	} while (RecordType != TERMINATE_RECORD_TYPE);

	BackGround = gif_image->SBackGroundColor;
	ColorMap = (gif_image->Image.ColorMap
			? gif_image->Image.ColorMap
					: gif_image->SColorMap);
	if (ColorMap == NULL)
	{
		fprintf(stderr, "Gif Image does not have a colormap\n");
		exit(EXIT_FAILURE);
	}

	for (i = 0, BufferP = image_buffer; i < img_height; i++)
	{
		GifRow = ScreenBuffer[i];

		for (j = 0; j < img_width; j++) {
			ColorMapEntry = &ColorMap->Colors[GifRow[j]];
			*BufferP++ = ColorMapEntry->Red;
			*BufferP++ = ColorMapEntry->Green;
			*BufferP++ = ColorMapEntry->Blue;
		}

		free(ScreenBuffer[i]);
	}

	free(ScreenBuffer);

	DGifCloseFile(gif_image);

	(*image) = new cv::Mat(cv::Size(img_width, img_height), CV_8UC3, image_buffer);

	convert_to_binary(image);
}