Formatting CIColorCube data

后端 未结 3 1232
半阙折子戏
半阙折子戏 2020-12-19 19:23

Recently, I\'ve been trying to set up a CIColorCube on a CIImage to create a custom effect. Here\'s what I have now:

uint8_t color_cube_data[8*4] = {
    0,          


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 19:32

    Your problem is that you are using value 1(which is next to zero) for alpha channel, max for uint8_t is 255

    See example below:

    CIFilter *cubeHeatmapLookupFilter = [CIFilter filterWithName:@"CIColorCube"];
    
    int dimension = 4;  // Must be power of 2, max of 128
    int cubeDataSize = 4 * dimension * dimension * dimension;
    
    unsigned char cubeDataBytes[cubeDataSize];
    
    //cubeDataBytes[cubeDataSize]
    unsigned char cubeDataBytes[4*4*4*4] = {
        0,      0,      0,      0,
        255,    0,      0,      170,
        255,    250,    0,      200,
        255,    255,    255,    255
    };
    
    NSData *cube_data = [NSData dataWithBytes:cubeDataBytes length:(cubeDataSize*sizeof(char))];
    
    //applying
    [cubeHeatmapLookupFilter setValue:myImage forKey:@"inputImage"];
    [cubeHeatmapLookupFilter setValue:cube_data forKey:@"inputCubeData"];
    [cubeHeatmapLookupFilter setValue:@(dimension) forKey:@"inputCubeDimension"];
    

    This is link to full project https://github.com/knerush/heatMap

提交回复
热议问题