糖果派对官方网站_可以赌钱的糖果游戏_手机版
bb电子糖果派对DirectDraw 呈现 YUV

bb电子糖果派对DirectDraw 呈现 YUV

作者:操作系统    来源:未知    发布时间:2020-01-29 05:54    浏览量:

bb电子糖果派对 1

在网上找了一段代码,能工作,但是颜色不对,红的变成蓝色的,黄的变青色了,有时间找找问题。

ios ColorLUT滤镜,ioscolorlut滤镜

bb电子糖果派对 2

通过这种方格图片实现滤镜

代码:

"CIFilter+ColorLUT.h"

bb电子糖果派对 3

"CIFilter+ColorLUT.m"

 

#import "CIFilter+ColorLUT.h"

#import <CoreImage/CoreImage.h>

#import <OpenGLES/EAGL.h>

@implementation CIFilter (ColorLUT)

  • (CIFilter *)colorCubeWithColorLUTImageNamed:(NSString *)imageName dimension:(NSInteger)n

{

    UIImage *image = [bb电子糖果派对DirectDraw 呈现 YUV。UIImage imageNamed:imageName];

    int width = CGImageGetWidth(image.CGImage);

    int height = CGImageGetHeight(image.CGImage);

    int rowNum = height / n;

    int columnNum = width / n;

    if ((width % n != 0) || (height % n != 0) || (rowNum * columnNum != n))

    {

        NSLog(@"Invalid colorLUT");

        return nil;

    }

    unsigned char *bitmap = [self createRGBABitmapFromImage:image.CGImage];  

    if (bitmap == NULL)

bb电子糖果派对,    {

        return nil;

    }

    int size = n * n * n * sizeof(float) * 4;

    float *data = malloc(size);

    int bitmapOffest = 0;

    int z = 0;

    for (int row = 0; row <  rowNum; row++)

    {

        for (int y = 0; y < n; y++)

        {

            int tmp = z;

            for (int col = 0; col < columnNum; col++)

            {

                for (int x = 0; x < n; x++) {

                    float r = (unsigned int)bitmap[bitmapOffest];

                    float g = (unsigned int)bitmap[bitmapOffest + 1];

                    float b = (unsigned int)bitmap[bitmapOffest + 2];

                    float a = (unsigned int)bitmap[bitmapOffest + 3];

                    int dataOffset = (z*n*n + y*n + x) * 4;

                    data[dataOffset] = r / 255.0;

                    data[dataOffset + 1] = g / 255.0;

                    data[dataOffset + 2] = b / 255.0;

                    data[dataOffset + 3] = a / 255.0;

                    bitmapOffest += 4;

                }

                z++;

            }

            z = tmp;

        }

        z += columnNum;

    }

    free(bitmap);

    CIFilter *filter = [CIFilter filterWithName:@"CIColorCube"];

    [filter setValue:[NSData dataWithBytesNoCopy:data length:size freeWhenDone:YES] forKey:@"inputCubeData"];

    [filter setValue:[NSNumber numberWithInteger:n] forKey:@"inputCubeDimension"];

    return filter;

}

  • (unsigned char *)createRGBABitmapFromImage:(CGImageRef)image

{

    CGContextRef context = NULL;

    CGColorSpaceRef colorSpace;

    unsigned char *bitmap;

    int bitmapSize;

    int bytesPerRow;

    size_t width = CGImageGetWidth(image);

    size_t height = CGImageGetHeight(image);

    bytesPerRow   = (width * 4);

    bitmapSize     = (bytesPerRow * height);    

    bitmap = malloc( bitmapSize );

    if (bitmap == NULL)

    {

        return NULL;

    }

    colorSpace = CGColorSpaceCreateDeviceRGB();

    if (colorSpace == NULL)

    {

        free(bitmap);

        return NULL;

    }

    context = CGBitmapContextCreate (bitmap,

                                     width,

                                     height,

                                     8,

                                     bytesPerRow,

                                     colorSpace,

                                     kCGImageAlphaPremultipliedLast);

    CGColorSpaceRelease( colorSpace );

    if (context == NULL)

    {

        free (bitmap);

    }

    CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);

    CGContextRelease(context);

    return bitmap;

}

调用时生成使用图片

CIFilter *colorCube = [CIFilter colorCubeWithColorLUTImageNamed:@"方块图片"dimension:64];

CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"选择的照片"]];

 [colorCube setValue:inputImage forKey:@"inputImage"];

CIImage *outputImage = [colorCube outputImage];

 

CIContext *context = [CIContext contextWithOptions:[NSDictionary dictionaryWithObject:(__bridge id)(CGColorSpaceCreateDeviceRGB()) forKey:kCIContextWorkingColorSpace]];

UIImage *newImage = [UIImage imageWithCGImage:[context createCGImage:outputImage fromRect:outputImage.extent]];

生成后的的滤镜图片newImage

ColorLUT滤镜,ioscolorlut滤镜 通过这种方格图片实现滤镜 代码: "CIFilter+ColorLUT.h" "CIFilter+ColorLUT.m" #import "CIFilter+ColorLUT.h" #import CoreImage/Co...

使用K-means算法实现图像1到图像2的变化。这里使用了5个Cluster,然后要计算每个像素点到5个cluster的距离,然后判断像素点属于哪一个cluster,然后更新5个cluster的值,再计算每个像素点到新的cluster的距离,直到最终值不在变化。#includestdio.h#includestdlib.h#includemath.h#defineHEIGHT512#defineWIDTH512//inthisassignment3,wefixthekby5#definek5//definetotype"BYTE":1bytetypedefunsignedcharBYTE;//definetotype"RGB":3byte(red,green,blue)typedefstructRGB{BYTEred;BYTEgreen;BYTEblue;};voidmain(){//vars//FILEvarforinputimage(onlyread)FILE*inputImage;//fileopenfopen_s(inputImage,"input.raw","rb");//FILEvarforoutputimage(onlywrite)FILE*outputImage;//fileopenfopen_s(outputImage,"output.raw","wb");//memoryforinputimageRGB*m_inputImage=newRGB[HEIGHT*WIDTH];//memoryforoutputimageRGB*m_outputImage=newRGB[HEIGHT*WIDTH];//memoryforcluster'snumberBYTE*m_clusterNumbers=newBYTE[HEIGHT*WIDTH];//Fileread.Notethat,weneedtoallocate3*byte.Because,weusethergbfileinhere.fread(m_inputImage,sizeof(BYTE)*3,HEIGHT*WIDTH,inputImage);//SetuptheinitialcentralpointsRGBcentral_point[k];central_point[0]={123,52,192};central_point[1]={12,152,92};central_point[2]={10,52,51};central_point[3]={200,130,220};central_point[4]={240,201,130};//RepeatuntilclustersarenotchangedboolisConverge=false;while(!isConverge){//dosomething}//Createtheoutputimage.Outputimageiscomposedof5centralpoints.//weassignthecolorofpixelusingcentral_pointandclusterNumbers.for(introw=0;rowHEIGHT;row++){for(intcol=0;colWIDTH;col++){m_outputImage[row*WIDTH+col]=central_point[m_clusterNumbers[row*WIDTH+col]];}}fwrite(m_outputImage,sizeof(BYTE)*3,HEIGHT*WIDTH,outputImage);deletem_clusterNumbers;deletem_inputImage;deletem_outputImage;fclose(inputImage);fclose(outputImage);}

这个问题在我初学DirectX是困惑了我很久,贴出来为初学者提供一个参考。

 

#include "ddraw.h"
#pragma comment(lib,"ddraw.lib")

下一篇:没有了
友情链接: 网站地图
Copyright © 2015-2019 http://www.tk-web.com. bb电子糖果派对有限公司 版权所有