/* * mp3plot - Bitrate analysis tool * * Copyright (C) 2007 Toni Corvera * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // $Id: mp3_image_plotter.cc 755 2007-05-26 15:02:28Z $ #include #include #include #include #include "config.h" // Defines HAVE_MAGICK #ifdef HAVE_MAGICK #include #define HEIGHT 300 #define WIDTH 600 #endif #include "mp3_common.h" #include "mp3_frame.h" #include "mp3_image_plotter.h" #include "str_utils.h" #include "spinner.h" namespace net_outlyer { namespace mp3 { namespace str = str_utils; // static void image_plotter::register_me() { boost::shared_ptr p(new image_plotter()); bitrate_plotter::register_plotter( bitrate_plotter::IMAGE, p ); } void image_plotter::plot(const mp3file & file) const { #ifndef HAVE_MAGICK throw e_error("Image output is disabled in this build!", EX_SOFTWARE); #else const frame_vector_t & frames = file.get_frames(); const bitrate_distribution & dist = file.get_br_distribution(); using namespace Magick; std::map colormap; // FIXME: Cleanup const uint16_t num_bitrates = BITRATE_TABLE_LEN; const float dec = 1.0 / num_bitrates; float r = 1.0, g = .33, b = .44; for (bitrate_distribution::const_iterator it = dist.begin(); it != dist.end(); ++it) { colormap[ it->first ] = ColorRGB(r, g, b); r -= dec; assert( r >= 0 ); } const std::string & geometry = str::to_string(frames.size()) + "x" + str::to_string(HEIGHT); Image output(Geometry(geometry.c_str()), ColorRGB(1,1,1)); numframes_t offset=0; spinner s; s.start(); for (frame_vector_constit_t it = frames.begin(); it != frames.end(); ++it, ++offset) { s.step(); //output.strokeColor( colormap[it->bitrate] ); output.strokeWidth(0); output.fillColor( colormap[it->bitrate] ); //output.draw( DrawableLine(offset, 0, offset+1, HEIGHT/2) ); output.draw( DrawableRectangle(offset, 0, offset+1, HEIGHT/2) ); } s.stop(); const int boxsize = frames.size() / colormap.size(); offset = 0; for (std::map::const_iterator it = colormap.begin(); it != colormap.end(); ++it) { output.strokeColor("black"); output.strokeWidth(1); output.fillColor( it->second ); output.draw( DrawableRectangle(offset, HEIGHT/3*2 + 20, offset+20, HEIGHT/3*2 + 40) ); output.strokeColor( it->second ); output.draw( DrawableText(offset, HEIGHT/3*2, str::to_string(it->first)) ); offset += boxsize; } //output.scale(Geometry("600x300")); output.write( file.name() + ".png" ); #endif } // image_plotter::plot() } // namespace mp3 } // namespace net_outlyer /* vim:set ts=4 et ai: */