private void WritePPMImage(CgData cg, string path) { if (File.Exists(path)) { File.Delete(path); } using (FileStream fs = File.Create(path)) { WriteText(fs, "P3\n"); WriteText(fs, cg.width + " " + cg.height + "\n"); WriteText(fs, "255\n"); for (int j = 0; j < cg.height; ++j) { for (int i = 0; i < cg.width; ++i) { int pixel = cg.data[j * cg.width + i]; if (i != 0) WriteText(fs, " "); WriteText(fs, cg.pallet.red[pixel] + " "); WriteText(fs, cg.pallet.green[pixel] + " "); WriteText(fs, cg.pallet.blue[pixel] + ""); } WriteText(fs, "\n"); } } }
public static CgData Extract(DriObject dri) { CgData cg = new CgData(); VspHeader header = ExtractHeader(dri); // プレーン型のデータは 1 byte で 8 pixels を表現 cg.type = CgType.VSP; cg.pallet = GetPallet(dri, header); cg.data = ExtractImageData(dri, header); cg.x = header.x0 * 8; cg.y = header.y0; cg.width = header.width * 8; cg.height = header.height; cg.palletBank = header.palletBank; return cg; }
public CgData LoadCg(DriObject dri) { CgType type = this.CheckCgFormat(dri); CgData data; switch(type) { case CgType.VSP: data = VspFormat.Extract(dri); break; default: // dummy data = new CgData(); data.type = type; data.x = 10; data.y = 10; break; } return data; }