# Image file read

**URL:** <https://verificationacademy.com/forums/t/image-file-read/29828>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [August 19, 2014, 1:48pm UTC](https://verificationacademy.com/forums/t/image-file-read/29828 "2014-08-19T13:48:27Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![rockgarden333](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a4c791/32.png) [@rockgarden333](https://verificationacademy.com/forums/u/rockgarden333)\
**Post date:** [August 27, 2014, 11:52am UTC](https://verificationacademy.com/forums/t/image-file-read/29828/9 "2014-08-27T11:52:00Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/image-file-read/29828/8):_

Dave,

My requirement is to **read** from a ASCII formatted input image file and **write** the data to another ASCII formatted output image file.  
I used a 800\*600 \*.raw(RGB formatted ASCII) file. I used IrfanView tool to generate \*.raw(RGB) from \*.JPG.

here is my full code. If wanted i can send the input image file as attachment.  
I don’t see an option to attach files here in this forum how?

```verilog
class input_video_IF;
    int data;
    int count;
    integer input_file, file_status,output_file,read_char;
	reg [7:0]data_byte;
	
    function new ();
	
	 	input_file = $fopen("test_800.raw","r");
		
		if(input_file)
		begin
		   $display("File OPENED");
		end
		else
		begin
		   $display("File error");
		end
	    endfunction:new 
	

	
	function void image_file_read();
            count = 0;
            while ((data = $fgetc(input_file)) != -1) // raw binary
				$display("fgetc:%0d %h %d",data, data , count);
            $fclose(file_status);
           /* file_status = $fopen("input_file","r");
            while ($fscanf(file_status,"%h",data) != -1) // hex formatted
	            $display("fscanf: %h",data);
            $fclose(file_status); */
    endfunction : image_file_read

		
	endclass

program Image_read_test;
int input_file;
input_video_IF In_IF = new();
initial
    In_IF.image_file_read();

endprogram

```

Thanks!

---

_[View the full topic](https://verificationacademy.com/forums/t/image-file-read/29828)._
