test_numeric.py :  » GUI » PyQwt » PyQwt-5.2.0 » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » PyQwt 
PyQwt » PyQwt 5.2.0 » test » test_numeric.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
import Numeric as np
from PyQt4.Qt import *
from PyQt4.Qwt5 import *


class TestImageConversionFunctions(unittest.TestCase):

    def testHorizontalLinesARGB32(self):
        colors = (Qt.red, Qt.green, Qt.blue, Qt.white, Qt.black)
        alpha = 0xff000000
        red   = 0x00ff0000
        green = 0x0000ff00
        blue  = 0x000000ff
        white = 0x00ffffff
        black = 0x00000000

        image = QImage(3, len(colors), QImage.Format_ARGB32)
        painter = QPainter(image)
        for i, color in enumerate(colors):
            painter.setPen(color)
            painter.drawLine(0, i, image.width(), i)
        del painter

        array = np.zeros((image.height(), image.width()), np.UInt32)
        array[0,:] = alpha|red
        array[1,:] = alpha|green
        array[2,:] = alpha|blue
        array[3,:] = alpha|white
        array[4,:] = alpha|black

        self.assertEqual(array == toNumpy(image), True)
        self.assertEqual(image == toQImage(array), True)

    # testHorizontalLinesARGB32()

    def testVerticalLinesARGB32(self):
        colors = (Qt.red, Qt.green, Qt.blue)
        alpha = 0xff000000
        red   = 0x00ff0000
        green = 0x0000ff00
        blue  = 0x000000ff

        image = QImage(len(colors), 5, QImage.Format_ARGB32)
        painter = QPainter(image)
        for i, color in enumerate(colors):
            painter.setPen(color)
            painter.drawLine(i, 0, i, image.height())
        del painter
        
        array = np.zeros((image.height(), image.width()), np.UInt32)
        array[:,0] = alpha|red
        array[:,1] = alpha|green
        array[:,2] = alpha|blue

        self.assertEqual(array == toNumpy(image), True)
        self.assertEqual(image == toQImage(array), True)

    # testVerticalLinesARGB32()

    def testHorizontalLinesIndexed8(self):
        image = QImage(3, 5, QImage.Format_Indexed8)
        image.setColorTable([qRgb(i, i, i) for i in range(256)])

        for i in range(image.height()):
            for j in range(image.width()):
                image.setPixel(j, i, i)

        array = np.zeros((image.height(), image.width()), np.UInt8)
        for i in range(image.height()):
            array[i,:] = i

        self.assertEqual(array == toNumpy(image), True)
        self.assertEqual(image == toQImage(array), True)

    # testHorizontalLinesIndexed8()

    def testVerticalLinesIndexed8(self):
        image = QImage(5, 3, QImage.Format_Indexed8)
        image.setColorTable([qRgb(i, i, i) for i in range(256)])

        for i in range(image.width()):
            for j in range(image.height()):
                image.setPixel(i, j, i)

        array = np.zeros((image.height(), image.width()), np.UInt8)
        for i in range(image.width()):
            array[:,i] = i

        self.assertEqual(array == toNumpy(image), True)
        self.assertEqual(image == toQImage(array), True)

    # testVerticalLinesIndexed8()
    
# class TestImageConversionFunctions


if __name__ == '__main__':
    unittest.main()

# Local Variables: ***
# mode: python ***
# End: ***
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.