Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to skip bmp header in vhdl

Status
Not open for further replies.

alvearal

Newbie level 2
Joined
Mar 3, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
hi
I want to read bmp files in vhdl. I need only data values,so I skip header by reading each character in the header. but there is a problem that we may encounter with a NL(new line) character. when it exist I must use readline to get new line. I do this and it works but problem is when I use it, it takes time for each character(for 8bbp,1078 ch for example)but I want to skip header in one clock cyle. do you have any idea how I can do this?

Thanks.
 

the problem is, there are different header formats, and then depending on the BPPs, it affects the colour table size too. But then, without knowing how long each line is (information from the header), you wont be able to work out how much padding each line has (as in the data section, if a line is not divisible by 4 bytes, it is padded).

So, the only way you are able to skip the header, is if you know you always have the same image size, and same header format.

Even simpler - get a microprocessor to convert it to raw data for you.
 

It's not really clear how characters in a bmp file are related to clock cycles...
 

hi
I want to read bmp files in vhdl. I need only data values,so I skip header by reading each character in the header. but there is a problem that we may encounter with a NL(new line) character. when it exist I must use readline to get new line. I do this and it works but problem is when I use it, it takes time for each character(for 8bbp,1078 ch for example)but I want to skip header in one clock cyle. do you have any idea how I can do this?

Thanks.

How are you opening the file? Post your file open command and the FILE declaration for the variable, that will make a difference for how the simulator interprets the file. What you want to get working first is the ability to read (and probably down the road 'write') binary files. Also, different simulators may still not handle the read/write of binary files in the same fashion. File I/O in VHDL has some holes open to interpretation that makes portability across platforms a potential problem...but if you can get it working for your simulator that might be all you need.

Kevin Jennings
 
Last edited:

in 8 bbp bmp header(1920*1080,my bmp size is fixed), there are 1078 character(it is fixed for my purpose). I use Modelsim. my purpose is to read pixel data values thus I need to skip header part in one clock. in a easy way, I can use


Code VHDL - [expand]
1
2
READLINE(F,L)
READ(L,header_string)  --header_string is 1 to 1078



but sometimes there are a NL(new line) characters in bmp header and when it is encountered modelsim give an error. I use such a code


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
file F:text
L:variable
character_value:character
not_end_of_line:boolean
 
--asynchronous reset
..
elsif rising_edge(clock) then
..
READLINE(F,L)                                  
READ(L,character_value,not_end_of_line)   --first character read only once.
....
if counter< 1077 then
counter<=counter+1
if not_end_of_line then
READ(L,character_value,not_end_of_line) 
else
READLINE(F,L)
READ(L,character_value,not_end_of_line) 
end if
end if



but when I do this, it takes 1078 clock cyle. would you suggest a way to solve this problem? I think I should read text not by charcter and by other things, for example binary numbers!! maybe it might be a solution but I dont know how to do that.
 
Last edited by a moderator:

First of all: why are you reading a bitmap file as text? its not a text file, so I would not recommend using the text file type.
Second: Why are you clocking it? why not just write a function to strip out the entire header?

If you are using modelsim, you can use a workaround to read the bitmap as a binary file by reading single chars (bytes), and you can do what you want with a file header.

Code:
type data_file_t is file of character;         
type int_array_t is array(natural range <>) of integer;

function get_data return int_array_t is

  file f : data_file_t open read_mode is some_file_name;

  variable c_buf : character;
  variable ret : int_array_t(0 to 9);
begin

  for i in ret'range loop
    read(f, c_buf);
    ret := character'pos( c_buf );  --get the byte value
  end loop;

  return ret;
end function get_data;

The great thing about bitmaps is the header contains all the size information, so you can create the arrays (or pointers if you like) before you read the data.
 
Any reason to do the skip operation in the periodically scheduled action? I think it rather belongs to the initial actions (not shown in your code snippet) and should be performed in a loop after opening the file.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top