/* * This file is part of libcxxsupport. * * libcxxsupport is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * libcxxsupport is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with libcxxsupport; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt * (DLR). */ /* * Classes for creation and output of image files * * Copyright (C) 2003 Max-Planck-Society * Author: Martin Reinecke */ #include #include #include "ls_image.h" #include "bstream.h" #include "font_data.inc" using namespace std; const Font medium_bold_font = { 0, 128, 7, 13, medium_bold_font_data }; const Font giant_font = { 0, 128, 9, 15, giant_font_data }; void Palette::setPredefined (int num) { fv.clear(); cv.clear(); switch(num) { case 0: add(0,Colour(0,0,0)); add(1,Colour(1,1,1)); break; case 1: add(0,Colour(0,0,0)); add(0.4f,Colour(0,0,0.5f)); add(0.75f,Colour(0,0.6f,1)); add(1,Colour(1,1,1)); break; case 4: add(0,Colour(0,0,.5f)); add(0.15f,Colour(0,0,1)); add(0.4f,Colour(0,1,1)); add(0.7f,Colour(1,1,0)); add(0.9f,Colour(1,.33f,0)); add(1,Colour(.5f,0,0)); break; default: planck_fail("Palette #"+dataToString(num)+" not yet supported."); } } void LS_Image::write_char (int xpos, int ypos, const Colour &col, char c, int scale) { planck_assert ((c>=font.offset) && (c &px, tsize begin, tsize end, bostream &file) { chunkMaker cm (end-begin,128); uint64 cbeg, csz; while (cm.getNext(cbeg,csz)) { file << uint8(csz-1+128); file << px[begin].b << px[begin].g << px[begin].r; } } void write_unequal_range (const arr &px, tsize begin, tsize end, bostream &file) { chunkMaker cm (end-begin,128); uint64 cbeg, csz; while (cm.getNext(cbeg,csz)) { file << uint8(csz-1); for (tsize cnt=begin+cbeg; cnt< begin+cbeg+csz; ++cnt) file << px[cnt].b << px[cnt].g << px[cnt].r; } } } // unnamed namespace void LS_Image::write_TGA_rle(const string &file) const { ofstream out(file.c_str(), ios_base::out | ios_base::binary); planck_assert(out, "could not create file '" + file + "'"); tsize xres=pixel.size1(), yres=pixel.size2(); bostream bo(out); const uint8 header[18] = { 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, xres%256, xres/256, yres%256, yres/256, 24, 32 }; bo.put(header,18); for (tsize y=0; y px(xres); for (tsize x=0; x