📄 mainwzpixmaptest.html
字号:
<TITLE>WZ 1.1: Reading pixmaps</TITLE><H1>Reading Pixmaps</H1><PRE>#include "wzoutput.hxx"#include "wzpixmap.hxx"</PRE><H2>class wzTrueColorPixmap</H2>The class <B>wzTrueColorPixmap</B> should be able to read true colorpictures in many formats. At the current time, it allows to read onlythe simplest pixmap format - <B>PPM</B>. Thus, you have to transferpictures from other formats into PPM using other programs. I use<B>xv</B> for this purpose.<PRE>void main(){ wzTrueColorPixmap tmap("cog/pixmapinput.ppm"); tmap.save("test.ppm"); // compare if they are identical</PRE><H2>class wzColorTablePixmap</H2>ls This class has a color table and indices into this color table. Themaximal length of the color table is 256. With lower number of<B>maxcolors</B> the algorithm to identify similar colors in a truecolor picture becomes faster. Instead of creating a<B>wzColorTablePixmap</B> explicit from a <B>wzTrueColorPixmap</B> by<PRE> int maxcolors=20; wzColorTablePixmap map(tmap,maxcolors); map.save("test2.ppm"); // compare if they are identical</PRE>you can immediately create it from a file, in this case the true colorpixmap is allocated only temporary<PRE>// wzColorTablePixmap map("pixmap.ppm",maxcolors);</PRE>How to use the resulting color table can be seen here:<PRE> wzOutputDefault("<>") << "Pixmap [" << map.lx() << ","<< map.ly()<<"] with " << map.colors() << " colors\n"; for(int i=1;i<=map.colors();i++){ wzOutputDefault("<>") << i << ": "<< map.color(i) << "\n"; }</PRE>A loop over the whole picture has to be organized in this way:<PRE>/* int ix,iy,index; wzColor color; for(ix=0;ix<map.lx();ix++){ for(iy=0;iy<map.ly();iy++){ index = map(ix,iy); color = map.color(index); } }*/</PRE><A NAME="End"> <hr></A><PRE> fine();}</PRE> <P>If you have a test file <I>wzpixmaptest.ppm</I>, you can test thiscode with: <BR> <BR><B>>cog main wzpixmap</B> <BR> <BR>The output should be something like <BR>Pixmap [250,248] with 5 colors <BR>1: #000000000 <BR>2: #f00800800 <BR>3: #800800f00 <BR>4: #800f00f00 <BR>5: #800f00800 <BR>success <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -