Shop OBEX P1 Docs P2 Docs Learn Events
image->.mif file conversion — Parallax Forums

image->.mif file conversion

rjo__rjo__ Posts: 2,114
edited 2015-03-26 19:19 in Propeller 1
Howdy,

I've been banging my head against m9k blocks for a while now and I am about to yelp for help... few more things to try.

In the mean time, I have something that does work. I am creating a frame buffer in m9k on a de2-115, and I wanted to initialize the frame buffer with a 640x480 gray scale image converted to a .mif file ( while creating the ram in the megafunction). I wanted to create a .mif. I looked around and the only thing I could find was "bmp2mif.exe" from the University of Toronto. It works, but it requires a bit map and requires a fixed sized image 160x120. I wanted something more flexible.

The code below is what I ended up writing. It is a macro for ImageJ (free, cross-platformed, and open source from NIH).

To use it, you can copy the text into a window in ImageJ and then select Run Macro or you can open the attachment and copy the files to your ImageJ folder and run the imagetoMif.txt macro from there. Right now the macro will open just about any type of image, convert it to 8-Bit and then create and save a .mif file in the original image's source directory.

You can confirm the conversion in Quartus by file->open and then choosing the .mif file. After a few minutes, the memory manager displays the memory map of the image.
print("hello");    //make sure log window is open
selectWindow("Log");
print("\\Clear");
run("Open...");    //get image
run("8-bit");    //convert to 8 bit grey scale
name = getTitle;  //extract image title

dotIndex = indexOf(name, "."); 
title = substring(name, 0, dotIndex); 

dir=getDirectory("image");  //get directory of current image
saveAs("Jpeg",dir+title+"8bit.jpeg")
width=getWidth();
height=getHeight();
imagesize=width*height;

// create .mif file in log window
print("DEPTH="+imagesize+";");
print("WIDTH=8;");
print("ADDRESS_RADIX=DEC;");
print("DATA_RADIX=DEC;");
print("CONTENT BEGIN");
i=0;
for(y=0;y<height;y++){
for ( x=0;x< width;x++){
myval=getPixel(x,y);
print("        "+i+"    "+":    "+myval+";");
i++;
}
}
print("END;");
name = getTitle;
 dotIndex = indexOf(name, "."); 
 title = substring(name, 0, dotIndex); 

// create new file to contain mif file in same directory as original image
       f = File.open(dir+title+".mif"); 
      //Select log window 
        selectWindow("Log"); 

        //Get content from Log Window + Print to file 
        content = getInfo(); 
        print(f,content); 

        //Close file 
  File.close(f);   // close the .mif file

Comments

  • pik33pik33 Posts: 2,366
    edited 2015-03-26 06:15
    From my retromachine hub.v
    initial
    begin
    
    	$readmemh ("unscrambledrom.hex", rom_high);
    	$readmemh ("test4.hex", ram3);	
       $readmemh ("test3.hex", ram2);
       $readmemh ("test2.hex", ram1);	
       $readmemh ("test1.hex", ram0);
    	
    end
    

    This initializes hub ram with Propeller program so the retromachine starts with it after power on. I wrote a simple tool which converts .eeprom file to 4 .hex files needed to initialize 4 quarters of hub ram. These are simply text mode hex files, one byte in one line. So you can use the same method for initializing your framebuffer.
  • rjo__rjo__ Posts: 2,114
    edited 2015-03-26 09:03
    thank you... again:)

    I finally got VGA(24bit-60 fps 640x480) frame buffer working using m9k memory blocks on DE2-115, and I will post it after I play with it a little more. Of course there isn't enough room for a full frame buffer at this size so I am using gray scale at the moment and I am not yet putting characters on the screen... for which I know of a very nice example:).

    I was initializing the memory with an image just to make sure that everything works the way I think it does... it doesn''t:). In terms of memory, I now have SRAM working and full dual ported RAM working. The next step is to use some of the remaining memory bits (3,389,000) I still have available and to implement SDRAM. I am currently avoiding SDRAM because of problems I ran into implementing the m9k dpr.

    I guess this is as good a time as any to talk about it a little. I initially spent many fruitless hours, because I generated the RAM using the Quartus full dual ported ram megafunction, generating a bsf file as well as others for verilog. I was then completely unable to get anything working. So... because of this, when I consider your SDRAM implementation, I'm quite sure I'm going to run into the same issue... which I haven't resolved.

    The way that I finally did get the dual ported m9k to work was to not generate the bsf file. Instead, I ended up instantiating the dpr memory in my sram module, using examples I found on the web. I want a complete memory controller, with connections evident in a diagram... such as your SDRAM module... but am retarded at the moment by this issue. When I look at the diagram of my SRAM module... it doesn't hint at the presence of the dpr:)

    regards

    ps

    I know this sounds like gobledegoop... will post the code as soon as it is practical.
  • pik33pik33 Posts: 2,366
    edited 2015-03-26 12:05
    Making a dual port ram inside fpga is simple but you have to obey some rules or the Quartus will ty to make it with LEs instead of M9K. All read and write operations have to be synchronous and without any conditional instructions.
    I have to look at the code but I think (I am not sure now - I simply forgot :) ) the retromachine's audio buffer at $84000 is a dual port memory example.

    I didn't write the SDRAM controller used in the retromachine. It was ready to use on DE2-115 CD ROM. It has some bugs in it: CS line is not connected to anything inside the SDRAM controller so I had to add chipselect circuit outside it.

    Try to use a less-than-24 bit color mode and pallette registers when you haven't enough RAM. I had to do this because SRAM is simply too slow to do it @ 1920x1200. But if you are signalling 640x480 with 25 MHz pixel clock instead of 152 MHz used in my machine, you have enough time to make a 24 bit per pixel SRAM framebuffer without any problem.
  • rjo__rjo__ Posts: 2,114
    edited 2015-03-26 19:19
    Well... I did have it working:)... then I noticed that my image was being cropped by about 20 pixels on the right side, and the display was incredibly sensitive to just about any noodling on my part... and now everything seems to have blown up.

    I am going to need multiple frame buffers... and will probably end up using everything I can get my head into:)

    Up to now I have just been fiddling to learn enough to do something constructive... I think I am close to making this an actual project.

    Thanks again,

    Rich
Sign In or Register to comment.