Back to index

salome-gui  6.5.0
Functions
GLViewer_Widget.cxx File Reference
#include "GLViewer_Widget.h"
#include "GLViewer_ViewPort2d.h"
#include "GLViewer_Viewer2d.h"
#include "GLViewer_Grid.h"
#include "GLViewer_CoordSystem.h"
#include "GLViewer_ViewFrame.h"
#include <cmath>
#include <QEvent>
#include <QPaintEvent>
#include <QRect>
#include <QFile>
#include <QImage>
#include <QApplication>
#include <QToolTip>

Go to the source code of this file.

Functions

char hex (uchar c)
void AddImagePart (QFile &hFile, QImage &image, int w1, int w2, int h1, int h2, GLViewer_CoordSystem *aViewerCS, GLViewer_CoordSystem *aPSCS, double a, double b, double c, double d, double dw, double dh)
 Translates part of image inside rectangle from w1 to w2 and from h2 to h1 to PS format.
void DecodeScanLine (int width, uchar *dest, int dest_depth, uchar *source, int source_depth)
 Translates image line with one color depth to line with other depth.

Function Documentation

void AddImagePart ( QFile &  hFile,
QImage &  image,
int  w1,
int  w2,
int  h1,
int  h2,
GLViewer_CoordSystem aViewerCS,
GLViewer_CoordSystem aPSCS,
double  a,
double  b,
double  c,
double  d,
double  dw,
double  dh 
)

Translates part of image inside rectangle from w1 to w2 and from h2 to h1 to PS format.

Parameters:
hFile- PostScript file
image- image to be tarnslated
w1- x start position
w2- x end position
h1- y start position
h2- y end position
aViewerCS- viewer co-ordinate system
aPSCS- paper co-ordinate system
a
b
c
d
dw
dh

Definition at line 461 of file GLViewer_Widget.cxx.

{
  if( aViewerCS && aPSCS )
  {       
    double width = w2-w1+1, height = h2-h1+1;
    QString aBuffer = "", temp = "%1 %2 8 [ %3 %4 %5 %6 %7 %8 ]\n";
    aBuffer += temp.arg( width ).arg( height ).
                        arg( a ).arg( b ).arg( c ).arg( d ).
                        arg( dw ).arg( dh );
    aBuffer += "<\n";   
    
    char line[81]; line[80] = '\0'; int cur_index = 0;
    int full = 0;
    for( int i=h2; i>=h1; i-- )
    {           
      uchar* theCurLine = image.scanLine( i ), cur;
      for( int j=w1; j<=w2; j++ )
        for( int k=0; k<3; k++ )
        {
          cur = *(theCurLine+4*j+2-k);
          *(line+cur_index) = hex( cur/16 ); //HI
          *(line+cur_index+1) = hex( cur%16 ); //LO
          full++;
          cur_index+=2;
          if( cur_index>=80 )
          {
            aBuffer += line;
            aBuffer += "\n";
            cur_index = 0;
          }
        }           
    }
    
    aBuffer += "> false 3 colorimage\n\n";

    hFile.write( aBuffer.toAscii() );
  }
}

Here is the call graph for this function:

void DecodeScanLine ( int  width,
uchar *  dest,
int  dest_depth,
uchar *  source,
int  source_depth 
)

Translates image line with one color depth to line with other depth.

Definition at line 566 of file GLViewer_Widget.cxx.

{
#ifndef WIN32
typedef unsigned int WORD;
#endif

    int aSize = width*dest_depth,
        dw = aSize % 8;

    if( dw )
        aSize+=dw;

    if( dest_depth==source_depth )
        memcpy( dest, source, aSize/8 );
    else
    {
        double r, g, b; WORD color;
        for( int i=0; i<width; i++ )
        {
            color = 0;
            switch( source_depth )
            {
                case 16:
                    memcpy( &color, source + 2*i, 2 );
                    b = double( color & 0x001F ) / 31.0;
                    g = double( ( color & 0x07E0 ) >> 5 ) / 63.0;
                    r = double( ( color & 0xF800 ) >> 11 ) / 31.0;
                    break;
                case 24: 
                    b = double( *(source + 3*i) ) / 255.0;
                    g = double( *(source + 3*i+1) ) / 255.0;
                    r = double( *(source + 3*i+2) ) / 255.0;
                    break;
                case 32:
                    b = double( *(source + 4*i) ) / 255.0;
                    g = double( *(source + 4*i+1) ) / 255.0;
                    r = double( *(source + 4*i+2) ) / 255.0;
                    break;
            }
            switch( dest_depth )
            {
                case 16:
                    color = WORD(b*31.0);
                    color += (WORD(g*63.0)<<5);
                    color += (WORD(r*31.0)<<11);
                    memcpy( dest + 2*i, &color, 2 );
                    break;
                case 24:
                    *( dest + 3*i ) = (uchar)(255*b);
                    *( dest + 3*i+1 ) = (uchar)(255*g);
                    *( dest + 3*i+2 ) = (uchar)(255*r);
                    break;
                case 32:
                    *( dest + 4*i ) = (uchar)(255*b);
                    *( dest + 4*i+1 ) = (uchar)(255*g);
                    *( dest + 4*i+2 ) = (uchar)(255*r);
                    *( dest + 4*i+3 ) = 0;
                    break;
            }
        }
    }
}
char hex ( uchar  c) [inline]
Returns:
the hex code of digit < 16
Parameters:
c- digit

Definition at line 434 of file GLViewer_Widget.cxx.

{
  if( c<=9 )
    return '0'+c;
  else if( c < 16 )
    return 'a' + c - 10;

  return ' ';
}

Here is the caller graph for this function: