Changeset 4630:f88478f15c02 in orange


Ignore:
Timestamp:
05/09/08 02:21:23 (6 years ago)
Author:
Mitar <Mitar@…>
Branch:
default
Convert:
70f980908646a81e7143e71fd837ba942424171b
Message:

Hopefully corrected problems with colors and palettes.

Location:
orange/OrangeWidgets
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Associate/OWDistanceMap.py

    r4543 r4630  
    235235    def qrgbToQColor(self, color): 
    236236        # we could also use QColor(positiveColor(rgb), 0xFFFFFFFF) 
    237         return QColor(qRed(positiveColor(color)), qGreen(positiveColor(color)), qBlue(positiveColor(color))) # on Mac color can not be negative number in this case so we convert it manually 
     237        return QColor(qRed(positiveColor(color)), qGreen(positiveColor(color)), qBlue(positiveColor(color))) # if color cannot be negative number we convert it manually 
    238238 
    239239    def getItemFromPos(self, i): 
     
    637637    def __init__(self, bitmap, canvas, width, height, palette, depth=8, numColors=256, x=0, y=0, z=0): 
    638638        QCanvasRectangle.__init__(self, canvas) 
    639     self.image = QImage(bitmap, width, height, depth, signedPalette(palette), numColors, QImage.LittleEndian) # palette should be 32 bit, what is not so on some platforms (Mac) so we force it 
     639    self.image = QImage(bitmap, width, height, depth, signedPalette(palette), numColors, QImage.LittleEndian) # we take care palette has proper values with proper types 
    640640        self.image.bitmap = bitmap # this is tricky: bitmap should not be freed, else we get mess. hence, we store it in the object 
    641641        self.canvas = canvas 
  • orange/OrangeWidgets/ColorPalette.py

    r4158 r4630  
    3535except: 
    3636    wantsPositiveColor = True 
     37     
     38try: 
     39    QImage(chr(0), 1, 1, 1, [0,0xFFFFFFFF], 2, QImage.LittleEndian) 
     40    wantsIntPalette = False 
     41except: 
     42    wantsIntPalette = True 
     43 
     44try: 
     45    QImage(chr(0), 1, 1, 1, [0,-1], 2, QImage.LittleEndian) 
     46    wantsPositivePalette = False 
     47except: 
     48    wantsPositivePalette = True 
    3749 
    3850def signedColor(long): 
     51    # Maybe wantsIntPalette is true but we cannot do anything here than just try to convert it to positive color 
     52    # (colors with alpha cannot be represented with signed int and just positive values allowed) 
     53    if wantsPositivePalette and long < 0: 
     54        return int(-(((long & 0xFFFFFFFF) ^ 0xFFFFFFFF) + 1)) 
     55     
     56    # It is stored as int so we do not need to do anything 
    3957    if type(long) == int: 
    4058        return long 
    41      
    42     long &= 0xFFFFFFFF 
    43      
    44     if long & 0x80000000: 
    45         return int(-((long ^ 0xFFFFFFFF) + 1)) 
     59    elif wantsIntPalette and not wantsPositivePalette: 
     60        long &= 0xFFFFFFFF 
     61         
     62        if long & 0x80000000: 
     63            return int(-((long ^ 0xFFFFFFFF) + 1)) 
     64        else: 
     65            return int(long) 
     66    # Cannot do anythin and probably should not do anything 
    4667    else: 
    47         return int(long) 
     68        return long 
    4869 
    4970def positiveColor(color): 
     
    235256        # why this was not used before so I am leaving it as it is 
    236257         
    237         return QColor(qRed(positiveColor(rgb)), qGreen(positiveColor(rgb)), qBlue(positiveColor(rgb))) # on Mac color cannot be negative number in this case so we convert it manually 
     258        return QColor(qRed(positiveColor(rgb)), qGreen(positiveColor(rgb)), qBlue(positiveColor(rgb))) # if color cannot be negative number we convert it manually 
    238259 
    239260    def qRgbFromQColor(self, qcolor): 
     
    326347        dx = 140; dy = colorButtonSize 
    327348        bmp = chr(252)*dx*2 + reduce(lambda x,y:x+y, [chr(i*250/dx) for i in range(dx)] * (dy-4)) + chr(252)*dx*2  
    328         image = QImage(bmp, dx, dy, 8, signedPalette(palette), 256, QImage.LittleEndian) # palette should be 32 bit, what is not so on some platforms (Mac) so we force it 
     349        image = QImage(bmp, dx, dy, 8, signedPalette(palette), 256, QImage.LittleEndian) # we take care palette has proper values with proper types 
    329350        pm = QPixmap() 
    330351        pm.convertFromImage(image, QPixmap.Color); 
  • orange/OrangeWidgets/OWDlgs.py

    r4571 r4630  
    539539        # why this was not used before so I am leaving it as it is 
    540540 
    541         return QColor(qRed(positiveColor(rgb)), qGreen(positiveColor(rgb)), qBlue(positiveColor(rgb))) # on Mac color cannot be negative number in this case so we convert it manually 
     541        return QColor(qRed(positiveColor(rgb)), qGreen(positiveColor(rgb)), qBlue(positiveColor(rgb))) # if color cannot be negative number we convert it manually 
    542542 
    543543    def qRgbFromQColor(self, qcolor): 
  • orange/OrangeWidgets/Prototypes/OWScatterPlotGraphXp.py

    r4008 r4630  
    643643                palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))]) 
    644644 
    645             image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # palette should be 32 bit, what is not so on some platforms (Mac) so we force it 
     645            image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # we take care palette has proper values with proper types 
    646646            self.potentialsBmp = QPixmap() 
    647647            self.potentialsBmp.convertFromImage(image) 
  • orange/OrangeWidgets/Visualize/OWLinProjGraph.py

    r4581 r4630  
    871871                for cls in self.potentialsClassifier.classVar.values: 
    872872                    color = colors[sortedClasses.index(cls)].light(150).rgb() 
    873                     color = [f(ColorPalette.positiveColor(color)) for f in [qRed, qGreen, qBlue]] # on Mac color cannot be negative number in this case so we convert it manually 
     873                    color = [f(ColorPalette.positiveColor(color)) for f in [qRed, qGreen, qBlue]] # if color cannot be negative number we convert it manually 
    874874                    towhite = [255-c for c in color] 
    875875                    for s in range(nShades): 
     
    878878                palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))]) 
    879879 
    880 #            image = QImage(imagebmp, (2*rx + 3) & ~3, 2*ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # palette should be 32 bit, what is not so on some platforms (Mac) so we force it 
    881             image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # palette should be 32 bit, what is not so on some platforms (Mac) so we force it 
     880#            image = QImage(imagebmp, (2*rx + 3) & ~3, 2*ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # we take care palette has proper values with proper types 
     881            image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # we take care palette has proper values with proper types 
    882882            self.potentialsBmp = QPixmap() 
    883883            self.potentialsBmp.convertFromImage(image) 
  • orange/OrangeWidgets/Visualize/OWScatterPlotGraph.py

    r4140 r4630  
    553553                palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))]) 
    554554 
    555             image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) 
     555            image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # we take care palette has proper values with proper types 
    556556            self.potentialsBmp = QPixmap() 
    557557            self.potentialsBmp.convertFromImage(image) 
Note: See TracChangeset for help on using the changeset viewer.