def resizer(img, drawable, size_max): gimp.context_push() img.undo_group_start() w = img.width h = img.height if w > h: factor = float(size_max) / w else: factor = float(size_max) / h pdb.gimp_image_scale_full( img, w * factor, h * factor, INTERPOLATION_CUBIC) config.set("sizes", "max", size_max) with open(CONFIG_FILE, 'wb') as configfile: config.write(configfile) img.undo_group_end() gimp.context_pop()
def makeLayer(self, timg, tdrawable, lmode, up, inner, width, height, shape, prenoise, azimuth, elevation, depth, postblur, opacity, gloss, ialpha): if timg.base_type is RGB: ltype = RGBA_IMAGE else: ltype = GRAYA_IMAGE if type(self.activelayer) == gimp.Layer: pdb.gimp_image_set_active_layer(timg, self.activelayer) activename = self.activelayer.name else: activename = "" gimp.context_push() timg.undo_group_start() #create the bevel layer if inner: lname = "Inner Bevel: " + activename else: lname = "Outer Bevel: " + activename newlayer = gimp.Layer(timg, lname, timg.width, timg.height, ltype, opacity, lmode) timg.add_layer(newlayer, -1) #save current selection tmpchan2 = pdb.gimp_selection_save(timg) #intersect with alpha? if ialpha and (type(self.activelayer) == gimp.Layer): pdb.gimp_selection_layer_alpha(self.activelayer) tmpchan = pdb.gimp_selection_save(timg) pdb.gimp_channel_combine_masks(tmpchan, tmpchan2, 3, 0, 0) pdb.gimp_selection_load(tmpchan) else: tmpchan = pdb.gimp_selection_save(timg) #set fg and bg colours and fill the layer with black pdb.gimp_context_set_foreground((0, 0, 0)) pdb.gimp_context_set_background((255, 255, 255)) newlayer.fill(FOREGROUND_FILL) #fill the selection with white and apply blur pdb.gimp_edit_fill(newlayer, BACKGROUND_FILL) #at this point, select all... pdb.gimp_selection_all(timg) #blurs pdb.plug_in_gauss_rle(timg, newlayer, width, 1, 0) pdb.plug_in_gauss_rle(timg, newlayer, height, 0, 1) #apply shape curve if shape != 0: pdb.gimp_curves_spline(newlayer, 0, 6, (0, 0, int(127 + (shape / 10)), (shape + 127), 255, 255)) #invert colours of whole layer if down if not up: pdb.gimp_invert(newlayer) #prenoise if prenoise > 0: pdb.plug_in_hsv_noise(timg, newlayer, 4, 0, 0, prenoise) #emboss the selection pdb.plug_in_emboss(timg, newlayer, azimuth, elevation, depth, 1) #gloss if gloss > 0: y1 = int(1.0 * gloss) y2 = int(3.0 * gloss) y3 = int(9.6 * gloss) y4 = int(3.2 * gloss) y5 = int(4.0 * gloss) y6 = int(0.4 * gloss) pdb.gimp_curves_spline(newlayer, 0, 16, (0, 0, 63, (63 + y1), 95, (95 + y2), 127, (127 - y3), 156, (156 + y4), 191, (191 - y5), 223, (223 + y6), 255, 255)) #postblur if postblur > 0: pdb.plug_in_gauss_rle(timg, newlayer, postblur, 1, 1) pdb.gimp_layer_set_lock_alpha(newlayer, False) #reload selection pdb.gimp_selection_load(tmpchan) #clear excess if inner: pdb.gimp_selection_invert(timg) if not pdb.gimp_selection_is_empty(timg): pdb.gimp_edit_clear(newlayer) #reload original selection pdb.gimp_selection_load(tmpchan2) #remove temp channels timg.remove_channel(tmpchan) timg.remove_channel(tmpchan2) #set active layer to what it was if type(self.activelayer) == gimp.Layer: pdb.gimp_image_set_active_layer(timg, self.activelayer) else: pdb.gimp_image_set_active_layer(timg, newlayer) #end undo group and finish plugin gimp.context_pop() timg.undo_group_end() pdb.gimp_displays_flush() # debugMessage("I got to end of makelayer") return newlayer
def run(img, layer, name, domain, axis): if axis == "X": (X, Y) = (layer.width, layer.height) else: (Y, X) = (layer.width, layer.height) mag_layer = None pha_layer = None type = None new_layers = [] gimp.context_push() img.undo_group_start() if img.base_type == gimpfu.RGB: type = gimpfu.RGBA_IMAGE else: type = gimpfu.GRAY_IMAGE if domain == "FORWARD": w = X X = FFTransform.roundUp2(X) new_layers.append( gimp.Layer(img, name + " Phase %d" % w, X/2, Y, type, 100.0, gimpfu.NORMAL_MODE)) new_layers.append( gimp.Layer(img, name + " Magnitude %d" % w, X/2, Y, type, 100.0, gimpfu.NORMAL_MODE)) elif domain == "REVERSE": # Search the image for the highest layers that are labeled with Phase # and Magnitude for l in img.layers: if " Magnitude " in l.name: mag_layer = l elif " Phase " in l.name: pha_layer = l if mag_layer != None and pha_layer != None: break if mag_layer == None: raise Exception("Could not locate 'FFT Magnitude X' layer!") elif pha_layer == None: raise Exception("Could not locate 'FFT Phase X' layer!") # Okay, we have both layers, read the width in the name X = None t1 = re.search(" [0-9]+", mag_layer.name).group(0) t2 = re.search(" [0-9]+", pha_layer.name).group(0) if t1 == t2: X = int(t1) if X == None: raise Exception("Could not determing layer's original size!") new_layers.append( gimp.Layer(img, name + " Reverse", X, Y, type, 100.0, gimpfu.NORMAL_MODE)) for i in range (len(new_layers)): new_layers[i].set_offsets(layer.offsets[0],layer.offsets[1]) new_layers[i].fill(gimpfu.TRANSPARENT_FILL) img.add_layer(new_layers[i], 0) # New mask mask = new_layers[i].create_mask(0) new_layers[i].add_mask(mask) gimp.progress_init("Transforming pixels ...") transform = FFTransform(X) if domain == "FORWARD": for y in range(Y): gimp.progress_update(float(y) / float(Y)) pixels = getRow(layer, y, axis) output_pixels = [ [], [] ] for color in range(len(pixels)): buf = pixels[color] buf.normalize() # Transform into frequency domain if domain == "FORWARD": # Perform over sampled FFT fdomain = transform.fft(buf, X, 0) mag = fdomain[0].getMagnitude() pha = fdomain[0].getPhase() mag.normalize() pha.normalize() # Scale to pixel max mag *= 255.0 pha *= 255.0 # Stuff into the output pixels output_pixels[0].append(pha) output_pixels[1].append(mag) for i in range(len(output_pixels)): setRow(new_layers[i], y, output_pixels[i], axis) elif domain == "REVERSE": for y in range(Y): gimp.progress_update(float(y) / float(Y)) pixels = {} pixels["mag"] = getRow(mag_layer, y, axis) pixels["pha"] = getRow(pha_layer, y, axis) output_pixels = [] for color in range(len(pixels["mag"])): mag = pixels["mag"][color] pha = pixels["pha"][color] mag.normalize() # Center the phase about 0.0 and scale by PI pha -= 0.5 * pha.getMean() pha.normalize() pha *= math.pi ch = FFTChunk(X) ch.setPolar(mag,pha) tdomain = transform.ifft([ch]) tdomain.normalize() output_pixels.append(255.0 * tdomain) setRow(new_layers[0], y, output_pixels, axis) gimp.progress_update(1.0) # Apply changes for i in range(len(new_layers)): new_layers[i].remove_mask(gimpfu.MASK_APPLY) img.undo_group_end() gimp.context_pop()
def run(img, layer, name, hi_lo, ftype, order, frequency, direction): gimp.context_push() img.undo_group_start() is_iir = None if ftype == "IIR": is_iir = True else: is_iir = False if img.base_type == gimpfu.RGB: type = gimpfu.RGBA_IMAGE else: type = gimpfu.GRAY_IMAGE new_layer = gimp.Layer(img, name, layer.width, layer.height, type, 100.0, gimpfu.NORMAL_MODE) new_layer.set_offsets(layer.offsets[0], layer.offsets[1]) new_layer.fill(gimpfu.TRANSPARENT_FILL) img.add_layer(new_layer, 0) # New mask mask = new_layer.create_mask(0) new_layer.add_mask(mask) f = None sample_rate = float(layer.width) if is_iir: if hi_lo == "LP": f = FilterLowPassIIR(sample_rate, order, frequency, 0.0) else: f = FilterHighPassIIR(sample_rate, order, frequency, 0.0) # Estimate filter delay pulse = Buffer(2 * order) pulse << 1.0 for i in range(0, order): pulse << 0.0 result = Buffer(2 * order) result << f.filter(pulse) # Find the peak mmax = result.getMax() delay = None for i in range(0, result.getLength()): if result[i] == mmax: delay = i + 1 break else: if hi_lo == "LP": f = FilterLowPassFIR(sample_rate, order, frequency) else: f = FilterHighPassFIR(sample_rate, order, frequency) delay = (f.getKernelSize() - 1) / 2 gimp.progress_init("Filtering pixels ...") done_factor = 1.0 offset = 0.0 directions = [direction] if direction == "Both": done_factor = 0.5 directions = ["X", "Y"] for axis in directions: if "X" == axis: (X, Y) = (layer.width, layer.height) else: (Y, X) = (layer.width, layer.height) for y in range(0, Y): gimp.progress_update(offset + done_factor * float(y) / float(Y)) pixels = getRow(layer, y, axis) for i in range(len(pixels)): buf = pixels[i] f.reset() # Prime the filter for j in range(delay): f.filter(buf[0]) last = buf[-1] k = 0 for j in range(buf.getLength()): # while j is < delay, throw out samples if j < delay: f.filter(buf[j]) else: buf[k] = f.filter(buf[j]) k += 1 for j in range(delay): buf[k] = f.filter(last) k += 1 pixels[i] = buf setRow(new_layer, y, pixels, axis) offset += 0.5 layer = new_layer gimp.progress_update(1.0) # Apply changes new_layer.remove_mask(gimpfu.MASK_APPLY) img.undo_group_end() gimp.context_pop()