def reevaluate(self):
        
        #get pixbuf array
        pixBufArray = main.documents.active.layers.active.pixbuf.get_pixels_array()
                
        #get pixData
        pixData = main.documents.active.layers.active.pixData
                
        #for each k in range(len(pixel buffer array)) 
        for k in range(len(pixBufArray)):
            #for each j in range(len(k))
            for j in range(len(pixBufArray[k])):
                
                #initialize pixel values to be set to 0
                finalR = finalG = finalB = finalA = 0
                
                #handle for current column
                thisPixel = pixData[k][j]
                
                #initialize final values to that of the first element
                if(len(thisPixel) != 0):
                    finalR,finalG,finalB = convert.hex_rgb(self.palette[thisPixel[0][0]])
                    finalA = thisPixel[0][1]
                    
                
                #for i in range(len(j) - 1)
                for i in range(len(thisPixel) - 1):
                    
#                    #get RBG of next color entry from it's hex value
                    nextR,nextG,nextB = convert.hex_rgb(self.palette[thisPixel[i + 1][0]])
                    
                    #get alpha value of next entry
                    nextA = thisPixel[i + 1][1]
                    
                    #get master alpha value of next entry
                    nextAM = thisPixel[i + 1][2]
                    
                    
                    
                    #final R
                    finalR = self.compositeRGB(finalR,nextR,finalA,nextA,nextAM)
                    #final G
                    finalG = self.compositeRGB(finalG,nextG,finalA,nextA,nextAM)
                    #final B
                    finalB = self.compositeRGB(finalB,nextB,finalA,nextA,nextAM)
                    #final A
                    finalA = core.getOverAlpha(float(finalA),float(thisPixel[i + 1][1]))

                    
            
                    
                #insert into pixBuf Array               
                pixBufArray[k][j][0] = finalR
                pixBufArray[k][j][1] = finalG
                pixBufArray[k][j][2] = finalB
                pixBufArray[k][j][3] = finalA


        
        #new pixBuf from array
        main.documents.active.layers.active.pixbuf = gtk.gdk.pixbuf_new_from_array(pixBufArray, gtk.gdk.COLORSPACE_RGB, 8)
        
        #update pixbuf pointer
        main.documents.active.layers.active.update_pointer()
        
        #redraw expired area
        main.documents.active.canvas.redraw_all()
        main.documents.active.actions.end([0,0,699,699])
Exemple #2
0
    def updatePixData(self, mouseX, mouseY):
        
        #foreground xOffset
        xOff = mouseX
        
        #foreground yOffset
        yOff = mouseY
        
        #foreground xEnd (must be <= layer width)
        xEnd = xOff + self.size
        xEnd = xEnd if(xEnd < self.layer.width) else self.layer.width
        
        #foreground yEnd (must be <= layer height)
        yEnd = yOff + self.size
        yEnd = yEnd if(yEnd < self.layer.height) else self.layer.height

  
        #Actual Row Number
        rowNum = 0
        
        #get Color Index
        colorIndex = main.gui.colorDictionary.palette.index(main.color.hex)
        
        #iterate through relevant pixels
        for row in range(yOff,yEnd):
            #Actual Column Number
            columnNum = 0

            for column in range(xOff,xEnd):
                
                #retrieve pre-calculated opacity
                pixelSoftness = self.getPixelSoftness(rowNum,columnNum)
                
                #handle for this column
                thisColumn = self.layer.pixData[row][column]
                
                #handle for brush opacity
                brushOpacity = self.opacity
                
                              
                
                #only add if some opacity exists
                if(pixelSoftness != 0):
                    
                    #if column not empty and last element is the same color as current
                    if((len(thisColumn) != 0) and
                        (thisColumn[-1][0] == colorIndex)):
                            
                        #handle for this colorEntry
                        thisEntry = thisColumn[-1]

                        #combine opacity
                        combinedOpacity = core.getOverAlpha(float(pixelSoftness),float(thisEntry[1]))

                        #if their combined opacities == 255 --> remove the rest of the array and add
                        if(combinedOpacity == 255):
                            thisColumn = [[colorIndex, 255, brushOpacityy/100.0]]

                        #else update old opacity
                        else:
                            thisEntry[1] = combinedOpacity
                            thisEntry[2] = (thisColumn[-1][2] + brushOpacity/100.0)
                            if(thisEntry[2] > 1.0): thisEntry[2] = 1.0


                    #else just append
                    else:
                        thisColumn.append([colorIndex,pixelSoftness, brushOpacity/100.0])

                #increment column number
                columnNum = columnNum + 1
            
            #increment row number
            rowNum = rowNum + 1