Esempio n. 1
0
File: Noise.c Progetto: PelinV/Elman
int getHeight(char *src){
	FILE * pFile;
	if((pFile = fopen(src, "rb")) == NULL){
		puts("Error: wrong source.\n");
		return 0;
	}

	BITMAPFILEHEADER header __attribute__((unused));
 
    header.bfType      = read_u16(pFile);
    header.bfSize      = read_u32(pFile);
    header.bfReserved1 = read_u16(pFile);
    header.bfReserved2 = read_u16(pFile);
    header.bfOffBits   = read_u32(pFile);

    // считываем заголовок изображения
    BITMAPINFOHEADER bmiHeader;

    bmiHeader.biSize          = read_u32(pFile);
    bmiHeader.biWidth         = read_s32(pFile);
    bmiHeader.biHeight        = read_s32(pFile);

    fclose(pFile);
    return bmiHeader.biHeight;
}
bool LLImageDimensionsInfo::getImageDimensionsPng()
{
	const S32 PNG_MAGIC_SIZE = 8;

	// Make sure the file is long enough.
	if (!checkFileLength(PNG_MAGIC_SIZE + 8 + sizeof(S32) * 2 /* width, height */))
	{
		LL_WARNS() << "Premature end of file" << LL_ENDL;
		return false;
	}

	// Read PNG signature.
	const U8 png_magic[PNG_MAGIC_SIZE] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
	U8 signature[PNG_MAGIC_SIZE];
	mInfile.read((void*)signature, PNG_MAGIC_SIZE);

	// Make sure it's a PNG file.
	if (memcmp(signature, png_magic, PNG_MAGIC_SIZE) != 0)
	{
		LL_WARNS() << "Not a PNG" << LL_ENDL;
		return false;
	}

	// Read image dimensions.
	mInfile.seek(APR_CUR, 8 /* chunk length + chunk type */);
	mWidth = read_s32();
	mHeight = read_s32();

	return true;
}
Esempio n. 3
0
File: Noise.c Progetto: PelinV/Elman
unsigned int* read_bmp(char* src){
	FILE * pFile;
	if((pFile = fopen(src, "rb")) == NULL){
		puts("Error: wrong source.\n");
		return 0;
	}

puts("read_bmp 1");

    // считываем заголовок файла
    BITMAPFILEHEADER header __attribute__((unused));
 
    header.bfType      = read_u16(pFile);
    header.bfSize      = read_u32(pFile);
    header.bfReserved1 = read_u16(pFile);
    header.bfReserved2 = read_u16(pFile);
    header.bfOffBits   = read_u32(pFile);

    // считываем заголовок изображения
    BITMAPINFOHEADER bmiHeader;

    bmiHeader.biSize          = read_u32(pFile);
    bmiHeader.biWidth         = read_s32(pFile);
    bmiHeader.biHeight        = read_s32(pFile);
    bmiHeader.biPlanes        = read_u16(pFile);
    bmiHeader.biBitCount      = read_u16(pFile);
    bmiHeader.biCompression   = read_u32(pFile);
    bmiHeader.biSizeImage     = read_u32(pFile);
    bmiHeader.biXPelsPerMeter = read_s32(pFile);
    bmiHeader.biYPelsPerMeter = read_s32(pFile);
    bmiHeader.biClrUsed       = read_u32(pFile);
    bmiHeader.biClrImportant  = read_u32(pFile);

	// unsigned int *img = new unsigned int[bmiHeader.biWidth*bmiHeader.biHeight];
	unsigned int *img = malloc(sizeof(unsigned int)*bmiHeader.biWidth*bmiHeader.biHeight);

puts("read_bmp 2");

    int i, j, k;

	for (i = 0; i < bmiHeader.biHeight; ++i)
	{
		for (j = 0; j < bmiHeader.biWidth; ++j)
		{
			for (k = 0; k < 3; ++k)
			{
				img[i*bmiHeader.biWidth + j] |= !getc(pFile) << (8*k);
			}
		}
		for (j = 0; j < bmiHeader.biWidth%4; ++j)
		{
			getc(pFile);
		}
	}
puts("read_bmp 3");
	fclose(pFile);
	return img;
}
bool LLImageDimensionsInfo::getImageDimensionsPng()
{
	const S32 PNG_FILE_MARKER_SIZE = 8;

	mInfile.seek(APR_CUR,PNG_FILE_MARKER_SIZE + 8/*header offset+chunk length+chunk type*/);
	mWidth = read_s32();
	mHeight = read_s32();

	return true;
}
Esempio n. 5
0
struct tableswitch *alloc_tableswitch(struct tableswitch_info *info,
				      struct compilation_unit *cu,
				      struct basic_block *bb,
				      unsigned long offset)
{
	struct tableswitch *table;

	table = malloc(sizeof(*table));
	if (!table)
		return NULL;

	table->src = bb;

	table->low = info->low;
	table->high = info->high;

	table->bb_lookup_table = malloc(sizeof(void *) * info->count);
	if (!table->bb_lookup_table) {
		free(table);
		return NULL;
	}

	for (unsigned int i = 0; i < info->count; i++) {
		int32_t target;

		target = read_s32(info->targets + i * 4);
		table->bb_lookup_table[i] = find_bb(cu, offset + target);
	}

	list_add(&table->list_node, &cu->tableswitch_list);

	return table;
}
Esempio n. 6
0
	u32					xbinary_reader::read(s32 & b)
	{
		if (_can_read(len_, cursor_, sizeof(b)))
		{
			xbyte const* ptr = buffer_ + cursor_;
			cursor_ += sizeof(b);
			b = read_s32(ptr);
			return sizeof(b);
		}
		return 0;
	}
Esempio n. 7
0
std::string BinaryReader::read_string(
    int max_length)
{
    auto length = bstone::Endian::le(read_s32());

    if (max_length >= 0 && length > max_length) {
        return {};
    }

    std::string string(length, '\0');

    if (length > 0) {
        if (!read(&string[0], length)) {
            string.clear();
        }
    }

    return string;
}
Esempio n. 8
0
File: Noise.c Progetto: PelinV/Elman
//Noise::
unsigned int delete_noise(char* src){
	FILE * pFile;
	if((pFile = fopen(src, "rb")) == NULL){
		puts("Error: wrong source.\n");
		return 0;
	}

    // считываем заголовок файла
    BITMAPFILEHEADER header __attribute__((unused));
 
    header.bfType      = read_u16(pFile);
    header.bfSize      = read_u32(pFile);
    header.bfReserved1 = read_u16(pFile);
    header.bfReserved2 = read_u16(pFile);
    header.bfOffBits   = read_u32(pFile);

    // считываем заголовок изображения
    BITMAPINFOHEADER bmiHeader;

    bmiHeader.biSize          = read_u32(pFile);
    bmiHeader.biWidth         = read_s32(pFile);
    bmiHeader.biHeight        = read_s32(pFile);
    bmiHeader.biPlanes        = read_u16(pFile);
    bmiHeader.biBitCount      = read_u16(pFile);
    bmiHeader.biCompression   = read_u32(pFile);
    bmiHeader.biSizeImage     = read_u32(pFile);
    bmiHeader.biXPelsPerMeter = read_s32(pFile);
    bmiHeader.biYPelsPerMeter = read_s32(pFile);
    bmiHeader.biClrUsed       = read_u32(pFile);
    bmiHeader.biClrImportant  = read_u32(pFile);

	// unsigned int *img = new unsigned int[bmiHeader.biWidth*bmiHeader.biHeight];
	unsigned int *img = malloc(sizeof(unsigned int)*bmiHeader.biWidth*bmiHeader.biHeight);

	int i, j, k;

	for (i = 0; i < bmiHeader.biHeight * bmiHeader.biWidth; ++i)
	{
		img[i] = 0;
	}

	for (i = 0; i < bmiHeader.biHeight; ++i)
	{
		for (j = 0; j < bmiHeader.biWidth; ++j)
		{
			for (k = 0; k < 3; ++k)
			{
				img[i*bmiHeader.biWidth + j] |= getc(pFile) << (8*k);
			}
		}
		for (j = 0; j < bmiHeader.biWidth%4; ++j)
		{
			getc(pFile);
		}
	}

	for (i = 0, j = 0; i < bmiHeader.biWidth * bmiHeader.biHeight; ++i)
	{
		img[i] = (img[i] == 0)?0xFFFFFF:0;
	}

	// unsigned int *col = new unsigned int[bmiHeader.biHeight];
	unsigned int *col = malloc(sizeof(unsigned int)*bmiHeader.biHeight);

	// unsigned int *row = new unsigned int[bmiHeader.biWidth];
	unsigned int *row = malloc(sizeof(unsigned int)*bmiHeader.biWidth);

	for (i = 0; i < bmiHeader.biWidth; ++i)
	{
		row[i] = 0;
	}

	for (i = 0; i < bmiHeader.biWidth; ++i)
	{
		for (j = 0; j < bmiHeader.biHeight; ++j)
		{
			row[i] |= img[i + j*bmiHeader.biWidth];
		}
	}

	int n = 0;

	for (i = 0; i < bmiHeader.biWidth - 1; ++i)
	{
		if(row[i + 1] != row[i])
			n++;
	}
	n = n/2;

	int length = 0, start_l = 0, l = 0;
	int vertical = 0, start_v = 0;

	for (k = 0; k < n; ++k)
	{	
		l = length + start_l;
		length = 0;
		for (; l < bmiHeader.biWidth - 1; ++l)
		{
			if(row[0] != 0)
				start_l = 0;
			if(row[l] == 0 && row[l + 1] != row[l])
				start_l = l + 1;
			if(row[l] != 0 && row[l + 1] == row[l])
				++length;
			if(row[l] != 0 && row[l + 1] != row[l]){
				++length;
				break;
			}
		}

//COL
		for (i = 0; i < bmiHeader.biHeight; ++i)
		{
			col[i] = 0;
		}

		for (i = 0; i < bmiHeader.biHeight; ++i)
		{
			for (j = 0; j < length; ++j)
			{
				col[i] |= img[j + start_l + i*bmiHeader.biWidth];
			}
		}

		vertical = 1;

		for (i = 0; i < bmiHeader.biHeight - 1; ++i)
		{
			if(col[i] == 0 && col[i + 1] != 0)
				start_v = i + 1;
			if(col[i] != 0)
				++vertical;
		}

		// unsigned int* p = new unsigned int[length * vertical];
		unsigned int* p = malloc(sizeof(unsigned int)*length * vertical);

		for(i = 0; i < length; ++i)
		{
			for (j = 0; j < vertical; ++j)
			{
				p[i + j*length] = (img[(i + start_l) + (j + start_v)*bmiHeader.biWidth])?0:0xFFFFFF;
			}
		}
		// char *name = new char[5];
		char *name = malloc(sizeof(char)*5);;
		name[0] = k + 0x31;
		name[1] = '.';
		name[2] = 'b';
		name[3] = 'm';
		name[4] = 'p';
		CreateBMP(name, p, length, vertical);
		// delete[] p;
		free(p);
	}



	// CreateBMP((char*)"result.bmp", img, bmiHeader.biWidth, bmiHeader.biHeight);
	fclose(pFile);

	// delete[] col;
	free(col);
	// delete[] row;
	free(row);
	// delete[] img;
	free(img);

	return n;
}
Esempio n. 9
0
int convert_tableswitch(struct parse_context *ctx)
{
	struct tableswitch_info info;
	struct tableswitch *table;
	struct basic_block *master_bb;
	struct basic_block *default_bb;
	struct basic_block *b1;
	struct basic_block *b2;

	get_tableswitch_info(ctx->code, ctx->offset, &info);
	ctx->buffer->pos += info.insn_size;

	default_bb = find_bb(ctx->cu, ctx->offset + info.default_target);
	if (!default_bb)
		goto fail_default_bb;

	master_bb = ctx->bb;

	b1 = bb_split(master_bb, master_bb->end);
	b2 = bb_split(b1, master_bb->end);

	assert(b1 && b2);

	master_bb->has_branch = true;
	b1->has_branch = true;
	b2->has_branch = true;

	bb_add_successor(master_bb, default_bb );
	bb_add_successor(master_bb, b1);

	bb_add_successor(b1, default_bb );
	bb_add_successor(b1, b2);

	for (unsigned int i = 0; i < info.count; i++) {
		struct basic_block *target_bb;
		int32_t target;

		target = read_s32(info.targets + i * 4);
		target_bb = find_bb(ctx->cu, ctx->offset + target);

		if (!bb_successors_contains(b2, target_bb))
			bb_add_successor(b2, target_bb);
	}

	table = alloc_tableswitch(&info, ctx->cu, b2, ctx->offset);
	if (!table)
		return -ENOMEM;

	struct statement *if_lesser_stmt;
	struct statement *if_greater_stmt;
	struct statement *stmt;
	struct expression *pure_index;

	pure_index = get_pure_expr(ctx, stack_pop(ctx->bb->mimic_stack));

	if_lesser_stmt =
		branch_if_lesser_stmt(default_bb, pure_index, info.low);
	if (!if_lesser_stmt)
		goto fail_lesser_stmt;

	expr_get(pure_index);
	if_greater_stmt =
		branch_if_greater_stmt(default_bb, pure_index, info.high);
	if (!if_greater_stmt)
		goto fail_greater_stmt;

	stmt = alloc_statement(STMT_TABLESWITCH);
	if (!stmt)
		goto fail_stmt;

	expr_get(pure_index);
	stmt->index = &pure_index->node;
	stmt->table = table;

	do_convert_statement(master_bb, if_lesser_stmt, ctx->offset);
	do_convert_statement(b1, if_greater_stmt, ctx->offset);
	do_convert_statement(b2, stmt, ctx->offset);
	return 0;

 fail_stmt:
	free_statement(if_greater_stmt);
 fail_greater_stmt:
	free_statement(if_lesser_stmt);
 fail_lesser_stmt:
	free_tableswitch(table);
 fail_default_bb:
	return -1;
}