Ejemplo n.º 1
0
def convertExr(
    filename='/s/prodanim/asterix2/_sandbox/duda/paintOver/s0180/p0100/s0180_p0100-base-light_prelight-left.0103.exr'
):
    listImages = [
        '/s/prodanim/asterix2/sequences/s0080/s0080_p0010/compo/compo_comp/publish/images/s0080_p0010-base-compo_comp-v026/left/s0080_p0010-base-compo_comp-left.0188.exr',
        '/s/prodanim/asterix2/sequences/s0080/s0080_p0020/compo/compo_comp/publish/images/s0080_p0020-base-compo_comp-v030/left/s0080_p0020-base-compo_comp-left.0101.exr',
        '/s/prodanim/asterix2/sequences/s0080/s0080_p0030/compo/compo_comp/publish/images/s0080_p0030-base-compo_comp-v015/left/s0080_p0030-base-compo_comp-left.0101.exr',
        '/s/prodanim/asterix2/sequences/s0080/s0080_p0040/compo/compo_comp/publish/images/s0080_p0040-base-compo_comp-v020/left/s0080_p0040-base-compo_comp-left.0101.exr',
        '/s/prodanim/asterix2/sequences/s0080/s0080_p0050/compo/compo_comp/publish/images/s0080_p0050-base-compo_comp-v012/left/s0080_p0050-base-compo_comp-left.0115.exr',
        '/s/prodanim/asterix2/sequences/s0080/s0080_p0060/compo/compo_comp/publish/images/s0080_p0060-base-compo_comp-v012/left/s0080_p0060-base-compo_comp-left.0101.exr'
    ]
    checkerImage = oiio.ImageBuf(
        '/s/prodanim/asterix2/_sandbox/duda/images/chekerCrop.jpg')
    widthChecker = checkerImage.spec().width
    heightChecker = checkerImage.spec().height
    outFilename = filename.replace('.exr', '.jpg')
    averageList = []
    print outFilename
    space = 80
    maxwidth = 2048
    maxheight = 858
    nrow = 5
    # calcul the number of column
    ncol = (len(listImages) / nrow)
    floatncol = (len(listImages) / 5.0)
    if floatncol - ncol > 0:
        ncol = ncol + 1
    ncol = 14
    # inFile = oiio.ImageBuf(filename)
    # inFileMono = oiio.ImageBuf()
    # inFilewidth = inFile.spec().width
    # inFileheight = inFile.spec().height
    offsetwidth = 0
    offsetheight = 0
    widthBufImage = (maxwidth * nrow) + (space * (nrow + 1))
    heightBufImage = (maxheight * ncol) + (space * (ncol + 1))
    buf = oiio.ImageBuf(
        oiio.ImageSpec(widthBufImage, heightBufImage, 4, oiio.FLOAT))
    text = oiio.ImageBuf(oiio.ImageSpec(maxwidth, maxheight, 4, oiio.FLOAT))
    oiio.ImageBufAlgo.render_text(text,
                                  100, (maxheight / 2) + 200,
                                  's0080',
                                  700,
                                  fontname='LiberationSans-Italic',
                                  textcolor=(1, 1, 1, 1))

    # if inFilewidth > maxwidth:
    #     offsetwidth = (inFilewidth - maxwidth)/2
    # if inFileheight > maxheight:
    #     offsetheight = (inFileheight-maxheight)/2
    # tmpInfile = oiio.ImageBuf(oiio.ImageSpec(maxwidth,maxheight,4,oiio.FLOAT))
    # oiio.ImageBufAlgo.crop(tmpInfile,inFile,oiio.ROI(offsetwidth,inFile.spec().width-offsetwidth,offsetheight,inFile.spec().height-offsetheight))

    imgh = 0
    nbimage = 0
    listImagesLen = len(listImages)
    a = 1

    for i in range(1, ncol + 1):
        if a == 0:
            break
        imgw = 0
        for j in range(1, nrow + 1):
            if nbimage < listImagesLen:
                fileFromList = oiio.ImageBuf(listImages[nbimage])
            else:
                #fileFromList = text
                a = 0
                break
            fileFromListWidth = fileFromList.spec().width
            fileFromListHeight = fileFromList.spec().height
            if fileFromListWidth > maxwidth or fileFromListHeight > maxheight:
                offsetwidth = (fileFromListWidth - maxwidth) / 2
                offsetheight = (fileFromListHeight - maxheight) / 2
            tmpInfile = oiio.ImageBuf(
                oiio.ImageSpec(maxwidth, maxheight, 4, oiio.FLOAT))
            oiio.ImageBufAlgo.crop(
                tmpInfile, fileFromList,
                oiio.ROI(offsetwidth, fileFromListWidth - offsetwidth,
                         offsetheight, fileFromListHeight - offsetheight))
            oiio.ImageBufAlgo.paste(buf, imgw + (j * space),
                                    imgh + (i * space), 0, 0, tmpInfile)
            stats = oiio.PixelStats()
            oiio.ImageBufAlgo.computePixelStats(tmpInfile, stats)
            averageList.append(stats.avg)
            imgw = imgw + maxwidth
            nbimage = nbimage + 1
        imgh = imgh + maxheight

    # create the master buffer
    masterBufwidth = widthBufImage + (578 * 2)
    #masterBufHeight = heightBufImage+240+(2*maxheight)
    masterBufHeight = int(masterBufwidth * 1.414)
    masterBuf = oiio.ImageBuf(
        oiio.ImageSpec(masterBufwidth, masterBufHeight, 4, oiio.FLOAT))

    #create the white border
    oiio.ImageBufAlgo.render_box(masterBuf, 518, 518, masterBufwidth - 518,
                                 masterBufHeight - 518, (1, 1, 1, 1), True)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, 578, masterBufwidth - 578,
                                 masterBufHeight - 578, (0, 0, 0, 1), True)

    # #create the bottom ant top band
    # oiio.ImageBufAlgo.render_box(masterBuf, 120, masterBufHeight-(120+ space+maxheight), masterBufwidth -120, masterBufHeight - 120, (0, 0, 0, 1), True)
    # oiio.ImageBufAlgo.render_box(masterBuf, 120, 120, masterBufwidth - 120, maxheight+ 120, (0, 0, 0, 1), True)
    #
    # #paste the contactsheet images
    oiio.ImageBufAlgo.paste(masterBuf, 578, 578 + (2 * maxheight), 0, 0, buf)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, (578 + (2 * maxheight)) - 60,
                                 masterBufwidth - 578, 578 + (2 * maxheight),
                                 (1, 1, 1, 1), True)
    # #paste the sequence number
    oiio.ImageBufAlgo.paste(masterBuf, 840, 120, 0, 0, text)

    #
    #startcolumnBox = masterBufHeight - (578+space) - (maxheight/2) -100
    startcolumnBox = 878 + (space)
    endColumnBox = startcolumnBox + 200
    startRowBox = 578 + (2 * space)
    averageScene = (0, 0, 0)
    for col in averageList:
        averageScene = tuple(map(sum, zip(averageScene, col)))
        oiio.ImageBufAlgo.fill(
            masterBuf, col,
            oiio.ROI(startRowBox, startRowBox + 200, startcolumnBox,
                     endColumnBox))
        startRowBox = startRowBox + 200
        if startRowBox > masterBufwidth - (578 + (4 * space) +
                                           (2 * widthChecker)):
            startRowBox = 578 + (space)
            startcolumnBox = (878) + 200 + int(space * 1.5)
            endColumnBox = startcolumnBox + 200

    averageScene = tuple([x / len(listImages) for x in averageScene])
    #oiio.ImageBufAlgo.fill(masterBuf, averageScene, oiio.ROI(578+space, startRowBox, startcolumnBox+200, endColumnBox+200))
    oiio.ImageBufAlgo.fill(
        masterBuf, averageScene,
        oiio.ROI(masterBufwidth - ((2 * widthChecker) + 578 + (space * 2)),
                 masterBufwidth - (widthChecker + 578 + (2 * space)),
                 878 + space, 878 + space + heightChecker))

    #convert the colorspace
    oiio.ImageBufAlgo.colorconvert(masterBuf, masterBuf, 'linear',
                                   'Asterix2_Film')
    oiio.ImageBufAlgo.paste(masterBuf,
                            masterBufwidth - (widthChecker + 578 + space),
                            878 + space, 0, 0, checkerImage)
    #convert to asterix lut
    #oiio.ImageBufAlgo.colorconvert(inFile,inFile,'linear','Asterix2_Film')
    #create a single channel buffer
    #oiio.ImageBufAlgo.channels(inFileMono,inFile,("R",))
    #stats = oiio.PixelStats()
    #get the stats fronm buffer
    #oiio.ImageBufAlgo.computePixelStats(inFileMono,stats)
    #oiio.ImageBufAlgo.computePixelStats(inFile, stats)
    #print stats.avg

    # reelOut = oiio.ImageBuf()
    # oiio.ImageBufAlgo.channels(reelOut,inFile,(0,1,2))

    #oiio.ImageBufAlgo.zero(inFileMono)

    #inFile.set_write_format(oiio.UINT16)
    masterBuf.set_write_format(oiio.UINT8)

    #draw a shape on image
    #oiio.ImageBufAlgo.render_box(inFile,500,1600,300,1000,(1,1,1,1),True)

    #inFile.write(outFilename)
    masterBuf.write(
        '/s/prodanim/asterix2/_sandbox/duda/paintOver/s0180/p0100/test.jpg')
Ejemplo n.º 2
0
    ImageBufAlgo.unpremult(b, b)
    write(b, "unpremult.tif")
    ImageBufAlgo.premult(b, b)
    write(b, "premult.tif")

    b = ImageBuf("../oiiotool/src/tahoe-small.tif")
    ImageBufAlgo.rangecompress(b, b)
    write(b, "rangecompress.tif", oiio.UINT8)
    ImageBufAlgo.rangeexpand(b, b)
    write(b, "rangeexpand.tif", oiio.UINT8)

    # FIXME - colorconvert, ociolook need tests

    # computePixelStats
    b = ImageBuf("../oiiotool/src/tahoe-small.tif")
    stats = oiio.PixelStats()
    ImageBufAlgo.computePixelStats(b, stats)
    print("Stats for tahoe-small.tif:")
    print("  min         = ", stats.min)
    print("  max         = ", stats.max)
    print("  avg         = ", stats.avg)
    print("  stddev      = ", stats.stddev)
    print("  nancount    = ", stats.nancount)
    print("  infcount    = ", stats.infcount)
    print("  finitecount = ", stats.finitecount)

    compresults = oiio.CompareResults()
    ImageBufAlgo.compare(ImageBuf("flip.tif"), ImageBuf("flop.tif"), 1.0e-6,
                         1.0e-6, compresults)
    print("Comparison: of flip.tif and flop.tif")
    print("  mean = %.5g" % compresults.meanerror)
Ejemplo n.º 3
0
def placeImages(res = {}, shotgunData = True, task ='compo_comp', cutOrderSeq =[], imgh= 2294, masterBuf = oiio.ImageBuf(), printFormat = False, ncol = 13, nrow = 5, space =40, maxwidth=2048, maxheight=858, averageList = []):
    offsetwidth = 0
    offsetheight = 0
    nbimage = 0
    cutOrderSeqLen = len(cutOrderSeq)
    outLoop = 1
    for i in range(1, ncol + 1):
        if outLoop == 0:
            break
        imgw = 578
        for j in range(1, nrow + 1):
            xPos = imgw + (j * space)  # placement of the image in x
            yPos = imgh + (i * space)  # placement of the image in y
            if nbimage < cutOrderSeqLen and nbimage <= (nrow * ncol):
                shot = cutOrderSeq[nbimage]
                pathFile = res[shot]['framePath']
                fileFromList = oiio.ImageBuf()
                # if it's a quicktime movie
                if res[shot]['imgFormat'] == '.quicktime':
                    fileFromList = oiio.ImageBuf(pathFile, res[shot]['cutMid'], 0)
                else:
                    if not os.path.isfile(pathFile.replace('%04d', str(res[shot]['cutMid']).zfill(4))):
                        dirPath = pathFile[:pathFile.rfind('/')]
                        dirFiles = sorted(os.listdir(dirPath))
                        fileFromList = oiio.ImageBuf(dirPath + '/' + dirFiles[0])
                    else:
                        fileFromList = oiio.ImageBuf(pathFile.replace('%04d', str(res[shot]['cutMid']).zfill(4)))
            else:
                # fileFromList = text
                outLoop = 0
                break
            fileFromListWidth = fileFromList.spec().width
            fileFromListHeight = fileFromList.spec().height
            if fileFromListWidth > maxwidth or fileFromListHeight > maxheight:
                tmpInfile = oiio.ImageBuf(oiio.ImageSpec(maxwidth, maxheight, 3, oiio.FLOAT))
                offsetwidth = (fileFromListWidth - maxwidth) / 2
                offsetheight = (fileFromListHeight - maxheight) / 2
                oiio.ImageBufAlgo.crop(tmpInfile, fileFromList,
                                       oiio.ROI(offsetwidth, fileFromListWidth - offsetwidth, offsetheight,
                                                fileFromListHeight - offsetheight))
                fileFromList = tmpInfile
            stats = oiio.PixelStats()
            if res[shot]['imgFormat'] == '.exr' and format != 'exr':
                oiio.ImageBufAlgo.colorconvert(fileFromList, fileFromList, 'linear', 'Asterix2_Film')
                if printFormat:
                    oiio.ImageBufAlgo.computePixelStats(fileFromList, stats)
            averageList.append(stats.avg)
            oiio.ImageBufAlgo.paste(masterBuf, xPos, yPos, 0, 0, fileFromList)
            # if user want to display shotgun data
            if shotgunData:
                shotText = shot
                taskText = res[shot]['Task']
                if taskText != task:
                    oiio.ImageBufAlgo.fill(masterBuf, (1, 0, 0), oiio.ROI(xPos, xPos + maxwidth, yPos - 40, yPos))
                oiio.ImageBufAlgo.render_text(masterBuf, xPos + 10, yPos - 10, shotText, 35, _FONT_)
                oiio.ImageBufAlgo.render_text(masterBuf, xPos + maxwidth - 450, yPos - 10,
                                              taskText.upper() + '  v' + str(res[shot]['version']), 35, _FONT_)
                if taskText == task:
                    statusCol = (1, 0, 0)
                    if res[shot]['status'] == 'cmpt':
                        statusCol = (0, 1, 0)
                    oiio.ImageBufAlgo.fill(masterBuf, statusCol,
                                           oiio.ROI(xPos + maxwidth - 50, xPos + maxwidth - 10, yPos - 40, yPos))
            imgw = imgw + maxwidth
            nbimage = nbimage + 1
        imgh = imgh + maxheight

    return masterBuf, averageList
Ejemplo n.º 4
0
def contactSheet(task='compo_comp',
                 seq='s0180',
                 res={},
                 format='jpg',
                 scale='full',
                 shotgunData=True):
    path = _OUTPATH_ + '/' + seq + '/' + task + '/'
    if not os.path.isdir(path):
        os.makedirs(path)
    outdir = path + 'contactSheet_' + seq + '.' + format

    cutOrderSeq = getOrder(res)

    #import the colorchart
    checkerImage = oiio.ImageBuf(
        '/s/prodanim/asterix2/_sandbox/duda/images/chekerCrop.jpg')
    widthChecker = checkerImage.spec().width
    heightChecker = checkerImage.spec().height

    # list of color average
    averageList = []

    # space in between images
    space = 80

    # max width and height for the images
    maxwidth = 2048
    maxheight = 858

    # text sequence number
    text = oiio.ImageBuf(
        oiio.ImageSpec(int(1.5 * maxwidth), int(1.5 * maxheight), 3,
                       oiio.FLOAT))
    oiio.ImageBufAlgo.render_text(text,
                                  100, ((maxheight) / 2) + 400,
                                  seq,
                                  1050,
                                  fontname=_FONT_,
                                  textcolor=(1, 1, 1, 1))

    # na color
    na = oiio.ImageBuf(oiio.ImageSpec(200, 200, 3, oiio.FLOAT))
    oiio.ImageBufAlgo.zero(na)
    oiio.ImageBufAlgo.render_text(na,
                                  20,
                                  140,
                                  'Na',
                                  120,
                                  fontname=_FONT_,
                                  textcolor=(1, 0, 0, 0))

    # logo
    logo = oiio.ImageBuf(
        '/s/prodanim/asterix2/_source_global/Software/Nuke/scripts/contactSheetDir/logo.jpg'
    )
    widthLogo = logo.spec().width
    heightLogo = logo.spec().height

    # number of row and column for the contactsheet
    nrow = 5
    ncol = 13

    # area containing the images of sequence
    widthBufImage = (maxwidth * nrow) + (space * (nrow + 1))
    heightBufImage = (maxheight * ncol) + (space * (ncol + 1))
    buf = oiio.ImageBuf(
        oiio.ImageSpec(widthBufImage, heightBufImage, 3, oiio.FLOAT))

    # offset to move the image
    offsetwidth = 0
    offsetheight = 0

    imgh = 0
    nbimage = 0
    cutOrderSeqLen = len(cutOrderSeq)
    a = 1
    print 'tendering the frames'
    # for i in range(1,ncol+1):
    #     if a == 0:
    #         break
    imgw = 0
    for i in range(1, ncol + 1):
        if a == 0:
            break
        imgw = 0
        for j in range(1, nrow + 1):
            if nbimage < cutOrderSeqLen and nbimage <= (nrow * ncol):
                shot = cutOrderSeq[nbimage]
                fileFromList = []
                if res[shot]['imgFormat'] == '.quicktime':
                    fileFromList = oiio.ImageBuf(res[shot]['framePath'],
                                                 res[shot]['cutMid'], 0)
                else:
                    fileFromList = oiio.ImageBuf(
                        res[shot]['framePath'].replace(
                            '%04d',
                            str(res[shot]['cutMid']).zfill(4)))
            else:
                # fileFromList = text
                a = 0
                break
            fileFromListWidth = fileFromList.spec().width
            fileFromListHeight = fileFromList.spec().height
            if fileFromListWidth > maxwidth or fileFromListHeight > maxheight:
                offsetwidth = (fileFromListWidth - maxwidth) / 2
                offsetheight = (fileFromListHeight - maxheight) / 2
            tmpInfile = oiio.ImageBuf(
                oiio.ImageSpec(maxwidth, maxheight, 3, oiio.FLOAT))
            oiio.ImageBufAlgo.crop(
                tmpInfile, fileFromList,
                oiio.ROI(offsetwidth, fileFromListWidth - offsetwidth,
                         offsetheight, fileFromListHeight - offsetheight))
            stats = oiio.PixelStats()
            if res[shot]['imgFormat'] == '.exr' and format != 'exr':
                oiio.ImageBufAlgo.colorconvert(tmpInfile, tmpInfile, 'linear',
                                               'Asterix2_Film')
                oiio.ImageBufAlgo.computePixelStats(tmpInfile, stats)
            averageList.append(stats.avg)
            oiio.ImageBufAlgo.paste(buf, imgw + (j * space),
                                    imgh + (i * space), 0, 0, tmpInfile)
            if shotgunData:
                tmpData = oiio.ImageBuf(
                    oiio.ImageSpec(maxwidth, 40, 3, oiio.FLOAT))
                oiio.ImageBufAlgo.zero(tmpData)
                shotText = shot
                taskText = res[shot]['Task']
                colorTask = (1, 1, 0, 1)
                if taskText != task:
                    oiio.ImageBufAlgo.fill(tmpData, (1, 0, 0, 1))
                    colorTask = (1, 0, 0, 1)
                oiio.ImageBufAlgo.render_text(tmpData, 10, 28, shotText, 40,
                                              _FONT_)
                oiio.ImageBufAlgo.render_text(tmpData, 400, 28, taskText, 40,
                                              _FONT_)
                oiio.ImageBufAlgo.paste(buf, imgw + (j * space),
                                        (imgh - 40) + (i * space), 0, 0,
                                        tmpData)
            imgw = imgw + maxwidth
            nbimage = nbimage + 1
        imgh = imgh + maxheight

    print 'adding some salt'
    # create the master buffer
    masterBufwidth = widthBufImage + (578 * 2)
    masterBufHeight = int(masterBufwidth * 1.414)
    masterBuf = oiio.ImageBuf(
        oiio.ImageSpec(masterBufwidth, masterBufHeight, 3, oiio.FLOAT))

    # create the white border
    oiio.ImageBufAlgo.render_box(masterBuf, 518, 518, masterBufwidth - 518,
                                 masterBufHeight - 518, (1, 1, 1, 0), True)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, 578, masterBufwidth - 578,
                                 masterBufHeight - 578, (0, 0, 0, 0), True)

    # paste the buffer contactsheet in the main buffer
    oiio.ImageBufAlgo.paste(masterBuf, 578, 578 + (2 * maxheight), 0, 0, buf)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, (578 + (2 * maxheight)) - 60,
                                 masterBufwidth - 578, 578 + (2 * maxheight),
                                 (1, 1, 1, 0), True)
    oiio.ImageBufAlgo.render_box(masterBuf, 578,
                                 578 + heightBufImage + (2 * maxheight),
                                 masterBufwidth - 578,
                                 578 + heightBufImage + (2 * maxheight) + 60,
                                 (1, 1, 1, 1), True)

    print 'a bit of peper'
    # #paste the sequence number
    oiio.ImageBufAlgo.paste(masterBuf, 840, 120, 0, 0, logo)

    #
    # create the average color box
    startcolumnBox = 1178 + (space)
    endColumnBox = startcolumnBox + 200
    startRowBox = 578 + (2 * space)
    averageScene = (0, 0, 0)
    for col in averageList:
        if len(col) > 2:
            averageScene = tuple(map(sum, zip(averageScene, col)))
            oiio.ImageBufAlgo.fill(
                masterBuf, col,
                oiio.ROI(startRowBox, startRowBox + 200, startcolumnBox,
                         endColumnBox))
        else:
            oiio.ImageBufAlgo.paste(masterBuf, startRowBox, startcolumnBox, 0,
                                    0, na)
        startRowBox = startRowBox + 200
        if startRowBox > masterBufwidth - (578 + (4 * space) +
                                           (2 * widthChecker)):
            startRowBox = 578 + (2 * space)
            startcolumnBox = (1178) + 200 + int(space * 1.5)
            endColumnBox = startcolumnBox + 200

    print 'smoldering the lot'
    # create the box with the average of scene color
    averageScene = tuple([x / cutOrderSeqLen for x in averageScene])
    oiio.ImageBufAlgo.fill(
        masterBuf, averageScene,
        oiio.ROI(masterBufwidth - ((2 * widthChecker) + 578 + (space * 2)),
                 masterBufwidth - (widthChecker + 578 + (2 * space)),
                 878 + space, 878 + space + heightChecker))

    # add the checker and seq text
    oiio.ImageBufAlgo.paste(masterBuf,
                            masterBufwidth - (widthChecker + 578 + space),
                            878 + space, 0, 0, checkerImage)
    oiio.ImageBufAlgo.paste(
        masterBuf, (578 + space) + (masterBufwidth / 2) - maxwidth - 200,
        masterBufHeight - (518 + space + int(1.5 * maxheight)), 0, 0, text)

    #create the output frame
    output = oiio.ImageBuf()
    if scale == 'half':
        output = oiio.ImageBuf(
            oiio.ImageSpec(int(masterBufwidth / 2), int(masterBufHeight / 2),
                           3, oiio.FLOAT))
        oiio.ImageBufAlgo.resize(output, masterBuf)
    elif scale == 'quarter':
        output = oiio.ImageBuf(
            oiio.ImageSpec(int(masterBufwidth / 4), int(masterBufHeight / 4),
                           3, oiio.FLOAT))
        oiio.ImageBufAlgo.resize(output, masterBuf)
    else:
        output = masterBuf

    bitFormat = oiio.UINT8
    if format == 'exr':
        bitFormat = oiio.HALF
    elif format == 'tif':
        bitFormat = oiio.UINT16
    else:
        bitFormat == oiio.UINT8

    output.set_write_format(bitFormat)

    output.write(outdir)

    print 'and Voila!\n' + outdir + ' is cooked'
Ejemplo n.º 5
0
def contactSheet(task='compo_comp', seq='s0180', res={}):
    # listImages = [
    #     '/s/prodanim/asterix2/sequences/s0080/s0080_p0010/compo/compo_comp/publish/images/s0080_p0010-base-compo_comp-v026/left/s0080_p0010-base-compo_comp-left.0188.exr',
    #     '/s/prodanim/asterix2/sequences/s0080/s0080_p0020/compo/compo_comp/publish/images/s0080_p0020-base-compo_comp-v030/left/s0080_p0020-base-compo_comp-left.0101.exr',
    #     '/s/prodanim/asterix2/sequences/s0080/s0080_p0030/compo/compo_comp/publish/images/s0080_p0030-base-compo_comp-v015/left/s0080_p0030-base-compo_comp-left.0101.exr',
    #     '/s/prodanim/asterix2/sequences/s0080/s0080_p0040/compo/compo_comp/publish/images/s0080_p0040-base-compo_comp-v020/left/s0080_p0040-base-compo_comp-left.0101.exr',
    #     '/s/prodanim/asterix2/sequences/s0080/s0080_p0050/compo/compo_comp/publish/images/s0080_p0050-base-compo_comp-v012/left/s0080_p0050-base-compo_comp-left.0115.exr',
    #     '/s/prodanim/asterix2/sequences/s0080/s0080_p0060/compo/compo_comp/publish/images/s0080_p0060-base-compo_comp-v012/left/s0080_p0060-base-compo_comp-left.0101.exr'
    # ]

    cutOrderSeq = getOrder(res)
    listImages = []
    for shot in cutOrderSeq:
        if res[shot]['imgFormat'] == '.quicktime':
            listImages.append(res[shot]['framePath'])
        else:
            listImages.append(res[shot]['framePath'].replace(
                '%04d',
                str(res[shot]['cutIn']).zfill(4)))
        print shot, listImages[-1], res[shot]['fInterest'], res[shot]['Task']

    #import the colorchart
    checkerImage = oiio.ImageBuf(
        '/s/prodanim/asterix2/_sandbox/duda/images/chekerCrop.jpg')
    widthChecker = checkerImage.spec().width
    heightChecker = checkerImage.spec().height

    # list of color average
    averageList = []

    # space in between images
    space = 80

    # max width and height for the images
    maxwidth = 2048
    maxheight = 858

    # text sequence number
    text = oiio.ImageBuf(oiio.ImageSpec(maxwidth, maxheight, 4, oiio.FLOAT))
    oiio.ImageBufAlgo.render_text(text,
                                  100, (maxheight / 2) + 200,
                                  seq,
                                  700,
                                  fontname='LiberationSans-Italic',
                                  textcolor=(1, 1, 1, 1))

    # na color
    na = oiio.ImageBuf(oiio.ImageSpec(200, 200, 4, oiio.FLOAT))
    oiio.ImageBufAlgo.zero(na)
    oiio.ImageBufAlgo.render_text(na,
                                  20,
                                  140,
                                  'Na',
                                  120,
                                  fontname='LiberationSans-Italic',
                                  textcolor=(1, 0, 0, 1))

    #number of row and column for the contactsheet
    nrow = 5
    ncol = 14

    # area containing the images of sequence
    widthBufImage = (maxwidth * nrow) + (space * (nrow + 1))
    heightBufImage = (maxheight * ncol) + (space * (ncol + 1))
    buf = oiio.ImageBuf(
        oiio.ImageSpec(widthBufImage, heightBufImage, 4, oiio.FLOAT))

    # offset to move the image
    offsetwidth = 0
    offsetheight = 0

    imgh = 0
    nbimage = 0
    listImagesLen = len(listImages)
    a = 1
    for i in range(1, ncol + 1):
        if a == 0:
            break
        imgw = 0
        for j in range(1, nrow + 1):
            if nbimage < listImagesLen and nbimage <= (nrow * ncol):
                fileFromList = []
                if listImages[nbimage].rfind('.mov') > 0:
                    fileFromList = oiio.ImageBuf(listImages[nbimage], 1, 0)
                else:
                    fileFromList = oiio.ImageBuf(listImages[nbimage])
            else:
                #fileFromList = text
                a = 0
                break
            fileFromListWidth = fileFromList.spec().width
            fileFromListHeight = fileFromList.spec().height
            if fileFromListWidth > maxwidth or fileFromListHeight > maxheight:
                offsetwidth = (fileFromListWidth - maxwidth) / 2
                offsetheight = (fileFromListHeight - maxheight) / 2
            tmpInfile = oiio.ImageBuf(
                oiio.ImageSpec(maxwidth, maxheight, 4, oiio.FLOAT))
            oiio.ImageBufAlgo.crop(
                tmpInfile, fileFromList,
                oiio.ROI(offsetwidth, fileFromListWidth - offsetwidth,
                         offsetheight, fileFromListHeight - offsetheight))
            stats = oiio.PixelStats()
            if listImages[nbimage].rfind('.exr') > 0:
                oiio.ImageBufAlgo.colorconvert(tmpInfile, tmpInfile, 'linear',
                                               'Asterix2_Film')
                oiio.ImageBufAlgo.computePixelStats(tmpInfile, stats)
            averageList.append(stats.avg)
            oiio.ImageBufAlgo.paste(buf, imgw + (j * space),
                                    imgh + (i * space), 0, 0, tmpInfile)

            imgw = imgw + maxwidth
            nbimage = nbimage + 1
        imgh = imgh + maxheight

    # create the master buffer
    masterBufwidth = widthBufImage + (578 * 2)
    masterBufHeight = int(masterBufwidth * 1.414)
    masterBuf = oiio.ImageBuf(
        oiio.ImageSpec(masterBufwidth, masterBufHeight, 4, oiio.FLOAT))

    #create the white border
    oiio.ImageBufAlgo.render_box(masterBuf, 518, 518, masterBufwidth - 518,
                                 masterBufHeight - 518, (1, 1, 1, 1), True)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, 578, masterBufwidth - 578,
                                 masterBufHeight - 578, (0, 0, 0, 1), True)

    # paste the buffer contactsheet in the main buffer
    oiio.ImageBufAlgo.paste(masterBuf, 578, 578 + (2 * maxheight), 0, 0, buf)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, (578 + (2 * maxheight)) - 60,
                                 masterBufwidth - 578, 578 + (2 * maxheight),
                                 (1, 1, 1, 1), True)

    # #paste the sequence number
    oiio.ImageBufAlgo.paste(masterBuf, 840, 120, 0, 0, text)

    #
    # create the average color box
    startcolumnBox = 878 + (space)
    endColumnBox = startcolumnBox + 200
    startRowBox = 578 + (2 * space)
    averageScene = (0, 0, 0)
    for col in averageList:
        if len(col) > 2:
            averageScene = tuple(map(sum, zip(averageScene, col)))
            oiio.ImageBufAlgo.fill(
                masterBuf, col,
                oiio.ROI(startRowBox, startRowBox + 200, startcolumnBox,
                         endColumnBox))
        else:
            oiio.ImageBufAlgo.paste(masterBuf, startRowBox, startcolumnBox, 0,
                                    0, na)
        startRowBox = startRowBox + 200
        if startRowBox > masterBufwidth - (578 + (4 * space) +
                                           (2 * widthChecker)):
            startRowBox = 578 + (2 * space)
            startcolumnBox = (878) + 200 + int(space * 1.5)
            endColumnBox = startcolumnBox + 200

    # create the box with the average of scene color
    averageScene = tuple([x / len(listImages) for x in averageScene])
    oiio.ImageBufAlgo.fill(
        masterBuf, averageScene,
        oiio.ROI(masterBufwidth - ((2 * widthChecker) + 578 + (space * 2)),
                 masterBufwidth - (widthChecker + 578 + (2 * space)),
                 878 + space, 878 + space + heightChecker))

    #convert the colorspace
    #oiio.ImageBufAlgo.colorconvert(masterBuf,masterBuf,'linear','Asterix2_Film')
    oiio.ImageBufAlgo.paste(masterBuf,
                            masterBufwidth - (widthChecker + 578 + space),
                            878 + space, 0, 0, checkerImage)

    masterBuf.set_write_format(oiio.UINT8)

    #draw a shape on image
    #oiio.ImageBufAlgo.render_box(inFile,500,1600,300,1000,(1,1,1,1),True)

    #inFile.write(outFilename)
    masterBuf.write(
        '/s/prodanim/asterix2/_sandbox/duda/paintOver/s0180/p0100/test.jpg')
Ejemplo n.º 6
0
def contactSheet(task='compo_comp',
                 seq='s0180',
                 res={},
                 format='jpg',
                 scale='full',
                 shotgunData=True,
                 printFormat=False):

    path = _OUTPATH_ + '/' + seq + '/' + task + '/'
    if not os.path.isdir(path):
        os.makedirs(path)
    outdir = path + 'contactSheet_' + seq + '.' + format
    if printFormat:
        outdir = path + 'contactSheet_print_' + seq + '.' + format

    cutOrderSeq = getOrder(res)

    #import the colorchart if in printFormat mode
    if printFormat:
        checkerImage = oiio.ImageBuf(
            '/s/prodanim/asterix2/_sandbox/duda/images/chekerCrop.jpg')
        widthChecker = checkerImage.spec().width
        heightChecker = checkerImage.spec().height

    # list of color average
    averageList = []

    # space in between images
    space = 80

    # max width and height for the images
    maxwidth = 2048
    maxheight = 858

    # na color
    na = oiio.ImageBuf(oiio.ImageSpec(200, 200, 3, oiio.FLOAT))
    oiio.ImageBufAlgo.zero(na)
    oiio.ImageBufAlgo.render_text(na,
                                  20,
                                  140,
                                  'Na',
                                  120,
                                  fontname=_FONT_,
                                  textcolor=(1, 0, 0, 0))

    # logo
    logo = oiio.ImageBuf(
        '/s/prodanim/asterix2/_source_global/Software/Nuke/scripts/contactSheetDir/logo.jpg'
    )

    # number of row and column and page (if in printFormat) for the contactsheet
    nrow = 5
    ncol = 0
    nbPage = 1
    if printFormat:
        ncol = 13
        imbNb = 1
        nbPage = 1
        for shot in cutOrderSeq:
            imMod = imbNb % 66  # (ncol*nrow) + 1
            if imMod != 0:
                res[shot]['page'] = nbPage
            else:
                nbPage = nbPage + 1
                res[shot]['page'] = nbPage
            imbNb = imbNb + 1
        tmpLogo = oiio.ImageBuf(oiio.ImageSpec(1558, 1030, 3, oiio.FLOAT))
        oiio.ImageBufAlgo.resize(tmpLogo, logo)
        logo = tmpLogo
    else:
        ncolTmpFloat = float(len(res.keys()) / float(nrow))
        ncolTmpInt = int(len(res.keys()) / nrow)
        if ncolTmpFloat - ncolTmpInt > 0:
            ncol = ncolTmpInt + 1
        else:
            ncol = ncolTmpInt
        tmpLogo = oiio.ImageBuf(oiio.ImageSpec(2366, 1544, 3, oiio.FLOAT))
        oiio.ImageBufAlgo.resize(tmpLogo, logo)
        logo = tmpLogo

    widthLogo = logo.spec().width
    heightLogo = logo.spec().height

    # area containing the images of sequence
    widthBufImage = (maxwidth * nrow) + (space * (nrow + 1))
    heightBufImage = (maxheight * ncol) + (space * (ncol + 1))
    buf = oiio.ImageBuf(
        oiio.ImageSpec(widthBufImage, heightBufImage, 3, oiio.FLOAT))

    # offset to move the image
    offsetwidth = 0
    offsetheight = 0

    imgh = 0
    nbimage = 0
    cutOrderSeqLen = len(cutOrderSeq)
    a = 1
    print 'tendering the frames'
    for i in range(1, ncol + 1):
        if a == 0:
            break
        imgw = 0
        for j in range(1, nrow + 1):
            if nbimage < cutOrderSeqLen and nbimage <= (nrow * ncol):
                shot = cutOrderSeq[nbimage]
                pathFile = res[shot]['framePath']
                fileFromList = oiio.ImageBuf()
                if res[shot]['imgFormat'] == '.quicktime':
                    fileFromList = oiio.ImageBuf(pathFile, res[shot]['cutMid'],
                                                 0)
                else:
                    if not os.path.isfile(
                            pathFile.replace(
                                '%04d',
                                str(res[shot]['cutMid']).zfill(4))):
                        dirPath = pathFile[:pathFile.rfind('/')]
                        dirFiles = sorted(os.listdir(dirPath))
                        fileFromList = oiio.ImageBuf(dirPath + '/' +
                                                     dirFiles[0])
                    else:
                        fileFromList = oiio.ImageBuf(
                            pathFile.replace(
                                '%04d',
                                str(res[shot]['cutMid']).zfill(4)))
            else:
                # fileFromList = text
                a = 0
                break
            fileFromListWidth = fileFromList.spec().width
            fileFromListHeight = fileFromList.spec().height
            if fileFromListWidth > maxwidth or fileFromListHeight > maxheight:
                offsetwidth = (fileFromListWidth - maxwidth) / 2
                offsetheight = (fileFromListHeight - maxheight) / 2
            tmpInfile = oiio.ImageBuf(
                oiio.ImageSpec(maxwidth, maxheight, 3, oiio.FLOAT))
            oiio.ImageBufAlgo.crop(
                tmpInfile, fileFromList,
                oiio.ROI(offsetwidth, fileFromListWidth - offsetwidth,
                         offsetheight, fileFromListHeight - offsetheight))
            stats = oiio.PixelStats()
            if res[shot]['imgFormat'] == '.exr' and format != 'exr':
                oiio.ImageBufAlgo.colorconvert(tmpInfile, tmpInfile, 'linear',
                                               'Asterix2_Film')
                if printFormat:
                    oiio.ImageBufAlgo.computePixelStats(tmpInfile, stats)
            averageList.append(stats.avg)
            oiio.ImageBufAlgo.paste(buf, imgw + (j * space),
                                    imgh + (i * space), 0, 0, tmpInfile)
            if shotgunData:
                tmpData = oiio.ImageBuf(
                    oiio.ImageSpec(maxwidth, 40, 3, oiio.FLOAT))
                oiio.ImageBufAlgo.zero(tmpData)
                shotText = shot
                taskText = res[shot]['Task']
                if taskText != task:
                    oiio.ImageBufAlgo.fill(tmpData, (1, 0, 0, 1))
                oiio.ImageBufAlgo.render_text(tmpData, 10, 30, shotText, 35,
                                              _FONT_)
                oiio.ImageBufAlgo.render_text(
                    tmpData, maxwidth - 450, 30,
                    taskText.upper() + '  v' + str(res[shot]['version']), 35,
                    _FONT_)
                if taskText == task:
                    statusCol = (1, 0, 0)
                    if res[shot]['status'] == 'cmpt':
                        statusCol = (0, 1, 0)
                    oiio.ImageBufAlgo.fill(
                        tmpData, statusCol,
                        oiio.ROI(maxwidth - 50, maxwidth - 10, 0, 40))
                oiio.ImageBufAlgo.paste(buf, imgw + (j * space),
                                        (imgh - 40) + (i * space), 0, 0,
                                        tmpData)
            imgw = imgw + maxwidth
            nbimage = nbimage + 1
        imgh = imgh + maxheight

    print 'adding some salt'
    # create the master buffer
    masterBufwidth = widthBufImage + (578 * 2)
    masterBufHeight = int(heightBufImage + (4 * maxheight) + (2 * 578))
    if printFormat:
        masterBufHeight = int(masterBufwidth * 1.414)
    masterBuf = oiio.ImageBuf(
        oiio.ImageSpec(masterBufwidth, masterBufHeight, 3, oiio.FLOAT))

    # create the white border
    oiio.ImageBufAlgo.render_box(masterBuf, 518, 518, masterBufwidth - 518,
                                 masterBufHeight - 518, (1, 1, 1, 0), True)
    oiio.ImageBufAlgo.render_box(masterBuf, 578, 578, masterBufwidth - 578,
                                 masterBufHeight - 578, (0, 0, 0, 0), True)

    # paste the buffer contactsheet in the main buffer
    oiio.ImageBufAlgo.paste(masterBuf, 578, 578 + (2 * maxheight), 0, 0, buf)
    # top bar
    oiio.ImageBufAlgo.render_box(masterBuf, 578, (578 + (2 * maxheight)) - 60,
                                 masterBufwidth - 578, 578 + (2 * maxheight),
                                 (1, 1, 1, 0), True)
    # bottom bar
    oiio.ImageBufAlgo.render_box(masterBuf, 578,
                                 578 + heightBufImage + (2 * maxheight),
                                 masterBufwidth - 578,
                                 578 + heightBufImage + (2 * maxheight) + 60,
                                 (1, 1, 1, 1), True)

    print 'a bit of pepper'
    # #paste the sequence number

    if printFormat:
        print 'smoldering the lot'
        # create the average color box
        startcolumnBox = 1178 + (space)
        endColumnBox = startcolumnBox + 200
        startRowBox = 578 + (2 * space)
        averageScene = (0, 0, 0)
        for col in averageList:
            if len(col) > 2:
                averageScene = tuple(map(sum, zip(averageScene, col)))
                oiio.ImageBufAlgo.fill(
                    masterBuf, col,
                    oiio.ROI(startRowBox, startRowBox + 200, startcolumnBox,
                             endColumnBox))
            else:
                oiio.ImageBufAlgo.paste(masterBuf, startRowBox, startcolumnBox,
                                        0, 0, na)
            startRowBox = startRowBox + 200
            if startRowBox > masterBufwidth - (578 + (4 * space) +
                                               (2 * widthChecker)):
                startRowBox = 578 + (2 * space)
                startcolumnBox = (1178) + 200 + int(space * 1.5)
                endColumnBox = startcolumnBox + 200

        # create the box with the average of scene color
        averageScene = tuple([x / cutOrderSeqLen for x in averageScene])
        oiio.ImageBufAlgo.fill(
            masterBuf, averageScene,
            oiio.ROI(masterBufwidth - ((2 * widthChecker) + 578 + (space * 2)),
                     masterBufwidth - (widthChecker + 578 + (2 * space)),
                     878 + space, 878 + space + heightChecker))

        # add the checker and seq text
        oiio.ImageBufAlgo.paste(masterBuf,
                                masterBufwidth - (widthChecker + 578 + space),
                                878 + space, 0, 0, checkerImage)

    # adding the task,seq number and logo
    if printFormat:
        oiio.ImageBufAlgo.paste(masterBuf,
                                (masterBufwidth / 2) - (widthLogo / 2), 60, 0,
                                0, logo)
    else:
        oiio.ImageBufAlgo.paste(masterBuf,
                                (masterBufwidth / 2) - (widthLogo / 2), 628, 0,
                                0, logo)
    oiio.ImageBufAlgo.render_text(masterBuf,
                                  int(masterBufwidth / 2) + 200,
                                  int(masterBufHeight - (maxheight + 200)),
                                  task.upper(),
                                  400,
                                  fontname=_FONT_,
                                  textcolor=(1, 1, 1, 1))
    oiio.ImageBufAlgo.render_text(masterBuf,
                                  x=int((masterBufwidth / 2) -
                                        (1.35 * maxwidth)),
                                  y=int(masterBufHeight - (maxheight + 200)),
                                  text=seq,
                                  fontsize=1050,
                                  fontname=_FONT_,
                                  textcolor=(1, 1, 1, 1))

    #create the output frame
    output = oiio.ImageBuf()
    if scale == 'half':
        output = oiio.ImageBuf(
            oiio.ImageSpec(int(masterBufwidth / 2), int(masterBufHeight / 2),
                           3, oiio.FLOAT))
        oiio.ImageBufAlgo.resize(output, masterBuf)
    elif scale == 'quarter':
        output = oiio.ImageBuf(
            oiio.ImageSpec(int(masterBufwidth / 4), int(masterBufHeight / 4),
                           3, oiio.FLOAT))
        oiio.ImageBufAlgo.resize(output, masterBuf)
    else:
        output = masterBuf

    bitFormat = oiio.UINT8
    if format == 'exr':
        bitFormat = oiio.HALF
    elif format == 'tif':
        bitFormat = oiio.UINT16
    else:
        bitFormat == oiio.UINT8

    output.set_write_format(bitFormat)

    output.write(outdir)

    print 'and Voila!\n' + outdir + ' is cooked, Enjoy with no moderation!!!!'