# Make Interlaced 3D v1.2 # (copyLEFT) 2012 Andrey "Efenstor" Pivovarov. No rights reserved # Copy freely, modify freely, spread the word and remeber me in your prayers #!/usr/bin/env python import math from gimpfu import * def deinit(img): pdb.gimp_undo_push_group_end(img) pdb.gimp_progress_end() pdb.gimp_displays_flush() def make_interlaced_3d(img, drawable, coff, vertical, antialias, swap, anaglyph, flatten): # Initialization if anaglyph==0 and not len(img.layers)==2: pdb.gimp_message("Your project must consist of two layers (left and right eye). No more, no less.") return if anaglyph==1 and not len(img.layers)==1: pdb.gimp_message("Your project must contain only one anaglyph layer.") return gimp.progress_init("Preparing...") pdb.gimp_undo_push_group_start(img) # Scale pdb.gimp_context_set_interpolation(2) aspect = float(img.width)/float(img.height) nwidth = int(1080*aspect) pdb.gimp_image_scale(img, nwidth, 1080) # De-anaglyph if anaglyph==1: # Make layers cyan = img.layers[0] cyan.name = "Cyan" red = cyan.copy() red.name = "Red" img.add_layer(red, -1) # Filter layers pdb.plug_in_colors_channel_mixer(img, cyan, FALSE, 0,0,0, 0,1,0, 0,0,1) pdb.plug_in_colors_channel_mixer(img, red, FALSE, 1,0,0, 0,0,0, 0,0,0) # Anti-alias if antialias>0: if vertical==0: if antialias==1: matrix_up = [0]*25 matrix_down = [0]*25 matrix_up[11] = 0.5 matrix_up[12] = 0.5 matrix_down[12] = 0.5 matrix_down[13] = 0.5 else: matrix_up = [0]*25 matrix_up[11] = 0.333 matrix_up[12] = 0.333 matrix_up[13] = 0.333 matrix_down = matrix_up else: if antialias==1: matrix_up = [0]*25 matrix_down = [0]*25 matrix_up[7] = 0.5 matrix_up[12] = 0.5 matrix_down[12] = 0.5 matrix_down[17] = 0.5 else: matrix_up = [0]*25 matrix_up[7] = 0.333 matrix_up[12] = 0.333 matrix_up[17] = 0.333 matrix_down = matrix_up if swap==0: m1 = matrix_down; m2 = matrix_up else: m1 = matrix_up; m2 = matrix_down pdb.plug_in_convmatrix(img, img.layers[0], 25, m1, 0, 1, 0, 5, (1,1,1,0,0), 0) pdb.plug_in_convmatrix(img, img.layers[1], 25, m2, 0, 1, 0, 5, (1,1,1,0,0), 0) # Crop/expand gimp.set_background(0,0,0) hoff = (1920/2)-(nwidth/2) img.resize(1920, 1080, hoff, 0) if swap==0: img.layers[0].translate(-coff, 0); img.layers[1].translate(coff, 0) else: img.layers[0].translate(coff, 0) img.layers[1].translate(-coff, 0) pdb.gimp_layer_resize_to_image_size(img.layers[0]) pdb.gimp_layer_resize_to_image_size(img.layers[1]) # Erase every other row mask = img.layers[0].create_mask(0) img.layers[0].add_mask(mask) if swap==0: start = 0 else: start = 1 if vertical==0: for y in range(start, 1080, 2): pdb.gimp_rect_select(img, 0, y, 1920, 1, 2, FALSE, 0) pdb.gimp_edit_clear(mask) else: for x in range(start, 1920, 2): pdb.gimp_rect_select(img, x, 0, 1, 1080, 2, FALSE, 0) pdb.gimp_edit_clear(mask) pdb.gimp_selection_none(img) # Deinitialization if flatten: img.flatten() deinit(img) register( "make_interlaced_3d", "Combines two layers (or a single anaglyph) into one interlaced picture for viewing on 3D-Ready monitors", "", "Efesntor", "(copyLEFT) Andrey \"Efenstor\" Pivovarov", "2012", "/Filters/Combine/Make Interlaced 3D...", "RGB*, GRAY*", [ (PF_INT, "coff", "Depth correction offset", 60), (PF_TOGGLE, "vertical", "Vertical interlace", 0), (PF_SPINNER, "antialias" , "Anti-aliasing strength", 1, (0,2,1)), (PF_TOGGLE, "swap", "Swap left and right", 0), (PF_TOGGLE, "anaglyph", "Anaglyph source", 0), (PF_TOGGLE, "flatten", "Flatten", 1) ], [], make_interlaced_3d) main()