% Written by: Holguer A Becerra %image to mif A = imread('pasto2.bmp'); [h,w,channels]= size(A); nombre_modulo='pasto2' fID = fopen('pasto2.v','w'); transparent='12''h77f';% color que se desea transparente dir=0; b=A/17; color_table=[]; color_table_order=[]; color_num=1; for y = 1:(h) for x = 1:(w) % R G B pixel=uint16(b(y,x,1))*256+uint16(b(y,x,2))*16+uint16(b(y,x,3)); encontro=0; for i=1:length(color_table) if(color_table(i)==pixel) encontro=1; end end if(encontro==0) color_table(color_num)=pixel; color_table_order(color_num)=color_num; color_num=color_num+1; end end end disp('numero de colores de la imagen:') disp(color_num-1); fprintf(fID,'module %s(input clk,input [3:0]scale,input flip_on,input on_off,input [10:0]x_video,input [10:0]y_video,input [10:0]x_pos,input [10:0]y_pos,output image_on,output [11:0]color);\n\n',nombre_modulo); fprintf(fID,'\nwire [10:0]real_x=(x_video[10:0]>>scale[3:0])-(x_pos[10:0]>>scale[3:0]);\nwire [10:0]real_y=(y_video[10:0]>>scale[3:0])-(y_pos[10:0]>>scale[3:0]);\n'); m=(ceil(log(color_num-1)/log(2))); fprintf(fID,'\nwire [%d:0]image_line;',m-1); fprintf(fID,'\nwire [10:0]bit_posx=flip_on? ((11''d%d)*%d-real_x[%d:0]*%d):real_x[%d:0]*%d;',w-1,m,ceil(log(w)/log(2)),m,ceil(log(w)/log(2)),m); fprintf(fID,'\nreg [0:%d]datos;\n',(w)*(ceil(log(color_num-1)/log(2)))-1); for i=1:m fprintf(fID,'assign image_line[%d]=datos[bit_posx[10:0]+%d];\n',i-1,m-i); end fprintf(fID,'assign image_on= (color[11:0]!=%s) & on_off & (real_x[10:0]>=11''d0) & (real_x[10:0]<11''d%d)& (real_y[10:0]>=11''d0) & (real_y[10:0]<11''d%d);\n\n',transparent,w,h); fprintf(fID,'always@(posedge clk)\nbegin\n case(real_y[10:0])\n'); for y = 1:(h) fprintf(fID,'\n %d:datos[0:%d]<=%d''b',dir,(w)*(ceil(log(color_num-1)/log(2)))-1,(w)*(ceil(log(color_num-1)/log(2)))); dir=dir+1; for x = 1:(w) % R G B pixel=uint16(b(y,x,1))*256+uint16(b(y,x,2))*16+uint16(b(y,x,3)); for i=1:length(color_table) if(color_table(i)==pixel) fprintf(fID,'%s',dec2bin(color_table_order(i),ceil(log(color_num-1)/log(2)))); end end end fprintf(fID,';'); end fprintf(fID,'\n default: datos[0:%d]<=%d''d0;\n',(w)*(ceil(log(color_num-1)/log(2)))-1,(w)*(ceil(log(color_num-1)/log(2)))); fprintf(fID,'\n endcase\n'); fprintf(fID,'end\n'); fprintf(fID,'\n//Map Color\nassign color[11:0]='); for i=1:length(color_table) fprintf(fID, ' (image_line[%d:0]==%d)?12''d%d:\n',m-1,i,color_table(i)); end fprintf(fID, ' 12''d0;\n\n'); fprintf(fID,'\nendmodule\n'); fclose(fID);