Ejemplo n.º 1
0
 def onDraw(self, width, height):
     PLOG(PLOG_FRAME, "onDraw start")
     self.init()
     y = 0  #height/2.0-170.0
     x = 0  # width/2.0
     for t in self.thumbs:
         self.matrix.identity()
         self.matrix.viewport(width, height)
         self.matrix.translate(x, y)
         x += 0.1  # 260.0
         if x > (width / 2.0 - 260.0):
             x = 0  # -width/2.0
             y += 0.1  #170.0
         self.shader.draw(t, self.atlas, self.matrix)
     PLOG(PLOG_FRAME, "onDraw end")
Ejemplo n.º 2
0
 def onIdle(self):
     PLOG(PLOG_FRAME, "onIdle start")
     if not self._init:
         self.redisplay()
     raw = None
     while raw == None and len(self.files) > 0:
         nextfile = self.files.pop()
         try:
             raw = MlRaw.loadRAWorMLV(os.path.join(self.path, nextfile),
                                      preindex=False)
             if (raw != None):
                 PLOG(PLOG_FRAME, "opened raw file %s" % nextfile)
                 thumbData = raw.firstFrame.thumb()
                 PLOG(PLOG_FRAME, "add to atlas")
                 thumbIndex = self.atlas.atlasadd(thumbData.flatten(),
                                                  thumbData.shape[1],
                                                  thumbData.shape[0])
                 PLOG(PLOG_FRAME, "added to atlas")
                 uv = self.atlas.atlas[thumbIndex]
                 texture, vertices = self.shader.rectangle(
                     thumbData.shape[1],
                     thumbData.shape[0],
                     uv=uv,
                     solid=0.0,
                     tex=0.5,
                     tint=0.0)
                 svbobase = self.svbo.allocate(6 * 12 * 4)
                 vab = (self.svbo.vboOffset(svbobase),
                        self.svbo.vboOffset(svbobase + 16),
                        self.svbo.vboOffset(svbobase + 32),
                        len(vertices) / 12)
                 self.svbo.upload()
                 self.thumbs.append(vab)
                 print "Thumbnail added"
         except:
             pass
     self.redisplay()
     PLOG(PLOG_FRAME, "onIdle ends")
Ejemplo n.º 3
0
 def render(self, scene, matrix, opacity):
     # Now display the RGB image
     #self.rgbImage.addmipmap()
     # Scale
     PLOG(PLOG_GPU, "Display shader draw")
     #print scene.frames.raw.activeArea
     #print scene.frames.raw.cropOrigin
     #print scene.frames.raw.cropSize
     aa = scene.frames.raw.activeArea
     fw = scene.frames.raw.width()
     fh = scene.frames.raw.height()
     tlx, tly = aa[1], aa[0]
     aw = aa[3] - aa[1]
     ah = aa[2] - aa[0]
     if aw >= fw:
         aw = fw
         tlx = 0
     if ah >= fh:
         ah = fh
         tly = 0
     self.displayShader.draw(scene.size[0], scene.size[1], self.rgbImage,
                             (tlx, tly, aw, ah))
     PLOG(PLOG_GPU, "Display shader draw done")
Ejemplo n.º 4
0
 def render(self, scene, matrix, opacity):
     PLOG(PLOG_CPU, "Geometry render %d,%d" % self.pos)
     self.updateMatrix()
     m = self.matrix.copy()
     m.mult(matrix)
     finalopacity = self.opacity * opacity
     if finalopacity > 0.0:
         PLOG(PLOG_CPU, "Geometry render draw %d,%d" % self.pos)
         if self.clip:
             glEnable(GL_STENCIL_TEST)
             glStencilFunc(GL_ALWAYS, 1, 0xFF)
             glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
             glStencilMask(0xFF)
         self.shader.draw(m, 128, 128, self.texture, finalopacity)
         PLOG(PLOG_CPU, "Geometry render children %d,%d" % self.pos)
     if self.clip:
         glStencilFunc(GL_EQUAL, 1, 0xFF)
         glStencilMask(0x00)
     for c in self.children:
         c.render(scene, m, finalopacity)  # Relative to parent
     if self.clip:
         glDisable(GL_STENCIL_TEST)
         glStencilMask(0xFF)
     PLOG(PLOG_CPU, "Geometry render done %d,%d" % self.pos)
Ejemplo n.º 5
0
    def render(self,scene,matrix,opacity):
        lut = self.frames.currentLut3D()
        lutchanged = False
        if lut != self.lut:
            self.lut = lut
            lutchanged = True
            if self.luttex != None:
                self.luttex.free()
                self.luttex = None
        if self.luttex == None:
            l = self.lut
            if l != None:
                self.luttex = GLCompute.Texture3D(l.len(),l.lut().tostring())
        lut1d = self.frames.currentLut1D1()
        if lut1d != self.lut1d1:
            self.lut1d1 = lut1d
            lutchanged = True
            if self.lut1d1tex != None:
                self.lut1d1tex.free()
                self.lut1d1tex = None
        if self.lut1d1tex == None:
            l = self.lut1d1
            if l != None:
                self.lut1d1tex = GLCompute.Texture1D(l.len(),l.lut().tostring())
        lut1d2 = self.frames.currentLut1D2()
        if lut1d2 != self.lut1d2:
            self.lut1d2 = lut1d2
            lutchanged = True
            if self.lut1d2tex != None:
                self.lut1d2tex.free()
                self.lut1d2tex = None
        if self.lut1d2tex == None:
            l = self.lut1d2
            if l != None:
                self.lut1d2tex = GLCompute.Texture1D(l.len(),l.lut().tostring())
        #if self.lut1d1tex == None:
        #    l = LUT.LOG_1D_LUT
        #    self.lut1d1tex = GLCompute.Texture1D(l.len(),l.lut().tostring())
        frameData = self.frames.currentFrame()
        frameNumber = self.frames.currentFrameNumber()

        #r1 = 1.0
        #g1 = 0.5
        #b1 = 0.1
        #testrgb = np.array([r1,g1,b1])
        #testrgb2 = np.dot(camToLinearsRGB,testrgb)
        #print camToLinearsRGB,testrgb,testrgb2

        brightness = self.settings.brightness()
        rgb = self.settings.rgb()
        balance = (rgb[0], rgb[1], rgb[2], brightness)
        tone = self.settings.tonemap()
        different = (frameData != self.lastFrameData) or (brightness != self.lastBrightness) or (rgb != self.lastRgb) or (frameNumber != self.lastFrameNumber) or (tone != self.lastTone) or (lutchanged)
        # or (rgb[0] != frameData.rawwbal[0]) or (rgb[2] != frameData.rawwbal[2])
        if (frameData and different):
            if ((frameData.rgbimage!=None) or self.settings.highQuality() or self.settings.encoding()) and (frameData.canDemosaic):
                # Already rgb available, or else low/high quality decode for static view or encoding
                if not self.settings.setting_preprocess:
                    PLOG(PLOG_CPU,"CPU Demosaic started for frame %d"%frameNumber)
                    before = time.time()
                    frameData.demosaic()
                    PLOG(PLOG_CPU,"CPU Demosaic completed for frame %d"%frameNumber)
                    after = time.time()
                    self.encoder.demosaicDuration(after-before)
                    if (frameData != self.lastFrameData) or (self.rgbFrameUploaded != frameNumber):
                        PLOG(PLOG_GPU,"RGB texture upload called for frame %d"%frameNumber)
                        self.rgbUploadTex.update(frameData.rgbimage)
                        PLOG(PLOG_GPU,"RGB texture upload returned for frame %d"%frameNumber)
                        self.rgbFrameUploaded = frameNumber
                    self.shaderQuality.demosaicPass(self.rgbUploadTex,self.luttex,frameData.black,balance=balance,white=frameData.white,tonemap=tone,colourMatrix=self.settings.setting_colourMatrix,lut1d1=self.lut1d1tex,lut1d2=self.lut1d2tex)
                    #mydump = glReadPixels(0,0,scene.size[0],scene.size[1],GL_RGB,GL_UNSIGNED_SHORT)
                    #print frameNumber
                    #for i in range(10):
                    #    print "(%04x,%04x,%04x)"%tuple(mydump[0,i,:]),
                    #print
                    if self.settings.encoding():
                        self.rgb = glReadPixels(0,0,scene.size[0],scene.size[1],GL_RGB,GL_UNSIGNED_SHORT)
                        self.encoder.encode(frameNumber,self.rgb)
                else: # Preprocess AND CPU demosaic
                    if frameData != self.lastFrameData:
                        PLOG(PLOG_CPU,"Bayer 14-16 convert starts for frame %d"%frameNumber)
                        frameData.convert()
                        PLOG(PLOG_CPU,"Bayer 14-16 convert done for frame %d"%frameNumber)
                        self.rawUploadTex.update(frameData.rawimage)
                    PLOG(PLOG_GPU,"Demosaic shader draw for frame %d"%frameNumber)
                    # Do some preprocess passes to find horizontal/vertical stripes
                    if frameData.rgbimage == None:
                        self.horizontalPattern.bindfbo()
                        self.shaderPatternNoise.draw(scene.size[0],scene.size[1],self.rawUploadTex,0,frameData.black/65536.0,frameData.white/65536.0)
                        ssh = self.shaderPatternNoise.calcStripescaleH(scene.size[0],scene.size[1])
                        self.verticalPattern.bindfbo()
                        self.shaderPatternNoise.draw(scene.size[0],scene.size[1],self.rawUploadTex,1,frameData.black/65536.0,frameData.white/65536.0)
                        ssv = self.shaderPatternNoise.calcStripescaleV(scene.size[0],scene.size[1])
                        if self.lastPP == self.preprocessTex2:
                            self.preprocessTex1.bindfbo()
                            self.shaderPreprocess.draw(scene.size[0],scene.size[1],self.rawUploadTex,self.preprocessTex2,self.horizontalPattern,self.verticalPattern,ssh,ssv,frameData.black/65536.0,frameData.white/65536.0,balance,cfa=frameData.cfa)
                            self.lastPP = self.preprocessTex1
                        else:
                            self.preprocessTex2.bindfbo()
                            self.shaderPreprocess.draw(scene.size[0],scene.size[1],self.rawUploadTex,self.preprocessTex1,self.horizontalPattern,self.verticalPattern,ssh,ssv,frameData.black/65536.0,frameData.white/65536.0,balance,cfa=frameData.cfa)
                            self.lastPP = self.preprocessTex2
                        # Now, read out the results as a 16bit raw image and feed to cpu demosaicer
                        rawpreprocessed = glReadPixels(0,0,scene.size[0],scene.size[1],GL_RED,GL_UNSIGNED_SHORT)
                        frameData.rawimage = rawpreprocessed
                        frameData.rawwbal = balance[:3]
                        self.rgbImage.bindfbo()
                        PLOG(PLOG_CPU,"CPU Demosaic started for frame %d"%frameNumber)
                        before = time.time()
                        frameData.demosaic()
                        PLOG(PLOG_CPU,"CPU Demosaic completed for frame %d"%frameNumber)
                        after = time.time()
                        self.encoder.demosaicDuration(after-before)
                    if (frameData != self.lastFrameData) or (self.rgbFrameUploaded != frameNumber):
                        PLOG(PLOG_GPU,"RGB texture upload called for frame %d"%frameNumber)
                        self.rgbUploadTex.update(frameData.rgbimage)
                        PLOG(PLOG_GPU,"RGB texture upload returned for frame %d"%frameNumber)
                        self.rgbFrameUploaded = frameNumber
                    wbalred = frameData.rawwbal[0]
                    wbalblue = frameData.rawwbal[2]
                    if wbalred<0.01: wbalred=0.01 # Avoid divide by zero
                    if wbalblue<0.01: wbalblue=0.01
                    newrgb = (rgb[0]/wbalred,1.0,rgb[2]/wbalblue)
                    self.shaderQuality.demosaicPass(self.rgbUploadTex,self.luttex,frameData.black,balance=(newrgb[0],newrgb[1],newrgb[2],balance[3]),white=frameData.white,tonemap=tone,colourMatrix=self.settings.setting_colourMatrix,recover=0.0,lut1d1=self.lut1d1tex,lut1d2=self.lut1d2tex)
            else:
                # Fast decode for full speed viewing
                if frameData != self.lastFrameData:
                    PLOG(PLOG_CPU,"Bayer 14-16 convert starts for frame %d"%frameNumber)
                    frameData.convert()
                    PLOG(PLOG_CPU,"Bayer 14-16 convert done for frame %d"%frameNumber)
                    self.rawUploadTex.update(frameData.rawimage)
                PLOG(PLOG_GPU,"Demosaic shader draw for frame %d"%frameNumber)

                if self.settings.setting_preprocess:
                    # Do some preprocess passes to find horizontal/vertical stripes
                    self.horizontalPattern.bindfbo()
                    self.shaderPatternNoise.draw(scene.size[0],scene.size[1],self.rawUploadTex,0,frameData.black/65536.0,frameData.white/65536.0)
                    ssh = self.shaderPatternNoise.calcStripescaleH(scene.size[0],scene.size[1])
                    self.verticalPattern.bindfbo()
                    self.shaderPatternNoise.draw(scene.size[0],scene.size[1],self.rawUploadTex,1,frameData.black/65536.0,frameData.white/65536.0)
                    ssv = self.shaderPatternNoise.calcStripescaleV(scene.size[0],scene.size[1])
                    # Swap preprocess buffer - feed previous one to new call
                    if self.lastPP == self.preprocessTex2:
                        self.preprocessTex1.bindfbo()
                        self.shaderPreprocess.draw(scene.size[0],scene.size[1],self.rawUploadTex,self.preprocessTex2,self.horizontalPattern,self.verticalPattern,ssh,ssv,frameData.black/65536.0,frameData.white/65536.0,balance,cfa=frameData.cfa)
                        self.lastPP = self.preprocessTex1
                    else:
                        self.preprocessTex2.bindfbo()
                        self.shaderPreprocess.draw(scene.size[0],scene.size[1],self.rawUploadTex,self.preprocessTex1,self.horizontalPattern,self.verticalPattern,ssh,ssv,frameData.black/65536.0,frameData.white/65536.0,balance,cfa=frameData.cfa)
                        self.lastPP = self.preprocessTex2
                    self.rgbImage.bindfbo()
                    self.shaderNormal.demosaicPass(self.lastPP,self.luttex,frameData.black,balance=(1.0,1.0,1.0,balance[3]),white=frameData.white,tonemap=self.settings.tonemap(),colourMatrix=self.settings.setting_colourMatrix,recover=0.0,lut1d1=self.lut1d1tex,lut1d2=self.lut1d2tex,cfa=frameData.cfa)
                    #debug = glReadPixels(0,scene.size[1]-2,4,1,GL_RGBA,GL_FLOAT)
                    #print debug,scene.size
                else:
                    self.shaderNormal.demosaicPass(self.rawUploadTex,self.luttex,frameData.black,balance=balance,white=frameData.white,tonemap=self.settings.tonemap(),colourMatrix=self.settings.setting_colourMatrix,lut1d1=self.lut1d1tex,lut1d2=self.lut1d2tex,cfa=frameData.cfa)
                    #debug = glReadPixels(0,scene.size[1]-2,4,1,GL_RGBA,GL_FLOAT)
                    #print debug,scene.size
                PLOG(PLOG_GPU,"Demosaic shader draw done for frame %d"%frameNumber)
        #redframe = glReadPixels(0,10,scene.size[0],1,GL_RGB,GL_FLOAT)
        #histogram = np.histogram(redframe,bins=256)
        # Calculate histogram
        if self.frames.setting_histogram == 1:
            self.histogramTex.bindfbo()
            if self.shaderHistogram:
                self.shaderHistogram.draw(scene.size[0],scene.size[1],self.rgbImage)
            """
            for i in range(256):
                print histogram[i],
            #print
            """

        self.lastFrameData = frameData
        self.lastFrameNumber = frameNumber
        self.lastBrightness = brightness
        self.lastRgb = rgb
        self.lastTone = tone
Ejemplo n.º 6
0
 def use(self):
     if self.context.current_shader != self:
         PLOG(PLOG_CPU,"Changing shader")
         glUseProgram(self.program)
         self.context.current_shader = self