⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.cpp

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 CPP
字号:
/***************************************************************************        image.cpp  -  Shows an image                           -------------------   begin                :  2003   authors              :  Linus Gasser   emails               :  linus.gasser@epfl.ch***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 03-09-30 - ineiti - begin  **************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************//** * @short Holds the definition of a block */#include <iostream>#include <qimage.h>#include <qpixmap.h>#include <qbitmap.h>#include <stdlib.h>#include "image.h"// this is the standard C++-way of using cout <<using namespace std;Image::Image( QWidget *p, FifoCmd *c, int m_id, int id ) :  QCanvasView( p ), parent( p ), radio( c ), module_id( m_id ), stats_id( id ) {    // Get the image parameters  QStringList args( QStringList::split( ",", radio->getStats( m_id )[ stats_id ] ) );  img_w = args[3].toInt();  img_h = args[4].toInt();  bpp = args[5].toInt();  //  cout << img_w << " " << img_h << endl;  // Allocate a grayscale table  color_num = 1 << bpp;  color_t = (QRgb*)malloc( color_num * sizeof( QRgb ) );  for ( int i = 0; i < color_num; i++ ){    int v = 255 * i / ( color_num - 1 );    color_t[i] = qRgb( v, v, v );  }  // Generate a timer to show the image every n ms.  updateTimer = new QTimer();  QObject::connect( updateTimer, SIGNAL( timeout() ), 		    this, SLOT( tick() ) );  updateTimer->start( 200, FALSE );  setCanvas( new QCanvas() );  pixmap_array = new QCanvasPixmapArray();  sprite = new QCanvasSprite( pixmap_array, canvas() );  setVScrollBarMode( AlwaysOff );  setHScrollBarMode( AlwaysOff );}void Image::tick(){#if 1  QByteArray image_raw = radio->getImage( module_id, stats_id );  uchar *d_img = (uchar*)image_raw.data();#else  img_w = img_h = 127;  int size_bytes = img_w * img_h / 8;  int size = img_w;  uchar *d_img = (uchar*)calloc( 1, size_bytes );  // Draw a vertical line  for ( int y=0; y<size; y++ ){    int index_pic = y * size + y;    d_img[ index_pic / 8 ] |= 1 << ( index_pic % 8 );  }#endif  // Convert from packed to QImage data  int w_align = ( ( img_w + 31 ) / 32 ) * 32;  uchar *d_pix = (uchar*)calloc( 1, w_align * img_h / 8 );  for ( int y=0; y<img_h; y++ ){    for ( int x=0; x < img_w; x++ ){      int pos_img = y * img_w + x;      if ( d_img[ pos_img / 8 ] & ( 1 << ( pos_img % 8 ) ) ){	int pos_pix = y * w_align + x;	d_pix[pos_pix / 8] |= 1 << ( pos_pix % 8 );      }    }  }  QPixmap pix;  QImage img( d_pix, img_w, img_h, bpp,	      color_t, color_num, QImage::LittleEndian );#if 1  QImage img_scaled = img.smoothScale( width(), height() );  pixmap_array->setImage( 0, new QCanvasPixmap( img_scaled ) );  sprite->hide();  sprite->show();  canvas()->resize( width(), height() );  canvas()->update();#else  // Keep colors, if not Qt tries to convert it to a monochrome bitmap,  // but mixes the two colors.  pix.convertFromImage( img, QPixmap::Color );  setUpdatesEnabled( false );  setPixmap( pix );  setUpdatesEnabled( true );  repaint();#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -