| 1 |
- import{_ as t,a as s,z as a,A as e,s as i,e as l,w as c,i as h,o as n,g as o,h as r,u as d,t as x,l as f,p as m,m as u}from"./index-BiysCLwd.js";const g=t({data:()=>({canvasWidth:300,canvasHeight:300,scale:1,minScale:.1,maxScale:5,scaleStep:.1,ctx:null,pgmData:null}),mounted(){this.initCanvas()},methods:{initCanvas(){const t=s("pgmCanvas",this);this.ctx=t,this.drawPlaceholder()},drawPlaceholder(){if(this.ctx){this.ctx.setFillStyle("#f0f0f0"),this.ctx.fillRect(0,0,this.canvasWidth,this.canvasHeight),this.ctx.setStrokeStyle("#ddd"),this.ctx.setLineWidth(1);for(let t=0;t<=this.canvasWidth;t+=20)this.ctx.beginPath(),this.ctx.moveTo(t,0),this.ctx.lineTo(t,this.canvasHeight),this.ctx.stroke();for(let t=0;t<=this.canvasHeight;t+=20)this.ctx.beginPath(),this.ctx.moveTo(0,t),this.ctx.lineTo(this.canvasWidth,t),this.ctx.stroke();this.ctx.setFillStyle("#999"),this.ctx.setFontSize(16),this.ctx.setTextAlign("center"),this.ctx.fillText("请加载PGM文件",this.canvasWidth/2,this.canvasHeight/2),this.ctx.draw()}},loadPGMFile(){a({title:"加载中..."}),setTimeout((()=>{try{const t=this.generateMockPGMData();this.pgmData=t,this.canvasWidth=t.width,this.canvasHeight=t.height,this.drawPGM(),e(),i({title:"加载成功",icon:"success"})}catch(t){console.error("PGM文件解析失败:",t),e(),i({title:"文件解析失败",icon:"none"})}}),1500)},generateMockPGMData(){const t=300,s=300,a=new Uint8Array(9e4),e=Math.min(t,s)/2;for(let i=0;i<s;i++)for(let s=0;s<t;s++){const l=i*t+s,c=Math.sqrt(Math.pow(s-150,2)+Math.pow(i-150,2)),h=Math.max(0,Math.min(255,255*(1-c/e)));a[l]=h}return{width:t,height:s,maxValue:255,data:a}},drawPGM(){if(!this.ctx||!this.pgmData)return;const{width:t,height:s,data:a,maxValue:e}=this.pgmData;this.ctx.clearRect(0,0,t,s);const i=new Uint8ClampedArray(t*s*4);for(let l=0;l<a.length;l++){const t=Math.floor(a[l]/e*255),s=4*l;i[s]=t,i[s+1]=t,i[s+2]=t,i[s+3]=255}this.ctx.setFillStyle("#000000"),this.ctx.fillRect(0,0,t,s);for(let l=0;l<s;l+=10)for(let i=0;i<t;i+=10){const c=l*t+i,h=Math.floor(a[c]/e*255);this.ctx.setFillStyle(`rgb(${h}, ${h}, ${h})`);const n=Math.min(10,t-i),o=Math.min(10,s-l);this.ctx.fillRect(i,l,n,o)}this.ctx.draw()},zoomIn(){this.scale<this.maxScale&&(this.scale+=this.scaleStep)},zoomOut(){this.scale>this.minScale&&(this.scale-=this.scaleStep)},resetScale(){this.scale=1}}},[["render",function(t,s,a,e,i,g){const v=f,M=h,p=m,_=u;return n(),l(M,{class:"container"},{default:c((()=>[o(M,{class:"header"},{default:c((()=>[o(v,{class:"title"},{default:c((()=>[r("PGM图像查看器")])),_:1})])),_:1}),o(M,{class:"canvas-container"},{default:c((()=>[o(p,{"canvas-id":"pgmCanvas",id:"pgmCanvas",class:"pgm-canvas",style:d({width:i.canvasWidth+"px",height:i.canvasHeight+"px",transform:`scale(${i.scale})`,transformOrigin:"top left"})},null,8,["style"])])),_:1}),o(M,{class:"controls"},{default:c((()=>[o(M,{class:"zoom-controls"},{default:c((()=>[o(_,{class:"control-btn",onClick:g.zoomOut},{default:c((()=>[o(v,{class:"btn-text"},{default:c((()=>[r("-")])),_:1})])),_:1},8,["onClick"]),o(v,{class:"scale-text"},{default:c((()=>[r(x(Math.round(100*i.scale))+"%",1)])),_:1}),o(_,{class:"control-btn",onClick:g.zoomIn},{default:c((()=>[o(v,{class:"btn-text"},{default:c((()=>[r("+")])),_:1})])),_:1},8,["onClick"])])),_:1}),o(_,{class:"reset-btn",onClick:g.resetScale},{default:c((()=>[r(" 重置缩放 ")])),_:1},8,["onClick"])])),_:1}),o(M,{class:"file-input"},{default:c((()=>[o(_,{onClick:g.loadPGMFile},{default:c((()=>[r("加载PGM文件")])),_:1},8,["onClick"])])),_:1})])),_:1})}],["__scopeId","data-v-22fd1586"]]);export{g as default};
|