Image Blur mit Metal

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Image Blur mit Metal

    Hallo,
    ich versuche gerade erstmalig mit Metal ein Bild zu bearbeiten und bekomme kein Output. Und zwar möchte ich ein Bild unscharf machen.
    Das ist der Code dazu:

    id <MTLDevice> dev = MTLCreateSystemDefaultDevice();

    MTLTextureDescriptor *intd = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:pw height:ph mipmapped:NO];
    id <MTLTexture> intex = [dev newTextureWithDescriptor:intd];
    [intex replaceRegion:MTLRegionMake2D(0, 0, pw, ph) mipmapLevel:0 withBytes:bitmapdata bytesPerRow:bpr];

    MTLTextureDescriptor *outtd = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:pw height:ph mipmapped:NO];
    outtd.storageMode = MTLStorageModeManaged;
    outtd.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite;
    id <MTLTexture> outtex = [dev newTextureWithDescriptor:outtd];

    id <MTLCommandQueue> cq = dev.newCommandQueue;
    id <MTLCommandBuffer> commandBuffer = [cq commandBuffer];
    MPSImageGaussianBlur *blur = [[MPSImageGaussianBlur alloc] initWithDevice:dev sigma:3];
    [blur encodeToCommandBuffer:commandBuffer sourceTexture:intex destinationTexture:outtex];
    [blur release];
    [commandBuffer commit];
    [commandBuffer waitUntilCompleted];

    [outtex getBytes:bitmapdata bytesPerRow:bpr fromRegion:MTLRegionMake2D(0, 0, pw, ph) mipmapLevel:0];

    Die Werte für bitmapdata, pw, ph und bpr stammen von meinem Bild und sind korrekt.
    Die Eingangstextur "intex" wird erfolgreich mit dem Bild gefüllt (hab ich geprüft), aber in der Ausgangstextur "outtex" kommt nichts an.
    Es gibt keine Fehlermeldung obwohl es laut Beschreibung so funktionieren soll.
    Kann mir jemand sagen was ich falsch mache ?

    Danke
    Thomas