2

pdb.gimp_paintbrush_default は非常に遅いようです (標準ブラシを使用して 500 ドットの場合、数秒。線は明らかに悪化します)。これはそうですか?ユーザーが選択したブラシを使用して直線を描くときに速度を上げる方法はありますか?

pythonfu コンソール コード:

from random import randint
img=gimp.image_list()[0]
drw = pdb.gimp_image_active_drawable(img)

width = pdb.gimp_image_width(img)
height = pdb.gimp_image_height(img)

point_number = 500
while (point_number > 0):
  x = randint(0, width)
  y = randint(0, height)
  pdb.gimp_paintbrush_default(drw,2,[x,y])
  point_number -= 1
4

1 に答える 1

2

私は非常によく似たものに取り組んでおり、この問題にも遭遇しました。これは、関数を約 5 倍高速化するために見つけた 1 つの手法です。

  1. 一時的なイメージを作成する
  2. 作業中のレイヤーを一時画像にコピーします
  3. 一時レイヤーに描画を行います
  4. 元のレイヤーの上に一時レイヤーをコピーします

GIMP は編集内容を画面に描画する必要がないため、これで速度が向上すると思いますが、100% 確実ではありません。これが私の機能です:

def splotches(img, layer, size, variability, quantity):

    gimp.context_push()
    img.undo_group_start()

    width = layer.width
    height = layer.height

    temp_img = pdb.gimp_image_new(width, height, img.base_type)
    temp_img.disable_undo()

    temp_layer = pdb.gimp_layer_new_from_drawable(layer, temp_img)
    temp_img.insert_layer(temp_layer)

    brush = pdb.gimp_brush_new("Splotch")
    pdb.gimp_brush_set_hardness(brush, 1.0)
    pdb.gimp_brush_set_shape(brush, BRUSH_GENERATED_CIRCLE)
    pdb.gimp_brush_set_spacing(brush, 1000)
    pdb.gimp_context_set_brush(brush)

    for i in range(quantity):
        random_size = size + random.randrange(variability)

        x = random.randrange(width)
        y = random.randrange(height)

        pdb.gimp_context_set_brush_size(random_size)
        pdb.gimp_paintbrush(temp_layer, 0.0, 2, [x, y, x, y], PAINT_CONSTANT, 0.0)

        gimp.progress_update(float(i) / float(quantity))

    temp_layer.flush()
    temp_layer.merge_shadow(True)

    # Delete the original layer and copy the new layer in its place
    new_layer = pdb.gimp_layer_new_from_drawable(temp_layer, img)
    name = layer.name
    img.remove_layer(layer)
    pdb.gimp_item_set_name(new_layer, name)
    img.insert_layer(new_layer)

    gimp.delete(temp_img)

    img.undo_group_end()
    gimp.context_pop()
于 2016-03-08T17:38:16.973 に答える