mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-16 09:37:52 +00:00
- Changed KGContext_gdi to use KGImage read functions to support all available KGImage formats and use the KGRGBA8888 blending&coverage function. Removed CGGraphicsSourceOver_bgra32_onto_bgrx32, CGGraphicsSourceOver_rgba32_onto_bgrx32.
- NSBitmapImageRep fixes for CGImage creation/drawing
This commit is contained in:
parent
b2c1a12edf
commit
44d0f81c97
@ -107,4 +107,6 @@ void KGRasterizeSetBlendMode(KGRasterizer *self,CGBlendMode blendMode);
|
||||
void KGRasterizeSetMask(KGRasterizer *self,KGSurface* mask);
|
||||
void KGRasterizeSetPaint(KGRasterizer *self,KGPaint* paint);
|
||||
|
||||
void KGBlendSpanNormal_8888_coverage(KGRGBA8888 *src,KGRGBA8888 *dst,int coverage,int length);
|
||||
|
||||
@end
|
||||
|
@ -621,7 +621,7 @@ static void KGApplyCoverageAndMaskToSpan_lRGBA8888_PRE(KGRGBA8888 *dst,int icove
|
||||
}
|
||||
}
|
||||
|
||||
static void KGApplyCoverageToSpan_lRGBA8888_PRE(KGRGBA8888 *dst,int coverage,KGRGBA8888 *src,int length){
|
||||
void KGApplyCoverageToSpan_lRGBA8888_PRE(KGRGBA8888 *dst,int coverage,KGRGBA8888 *src,int length){
|
||||
int i;
|
||||
|
||||
if(coverage==256){
|
||||
@ -641,7 +641,7 @@ static void KGApplyCoverageToSpan_lRGBA8888_PRE(KGRGBA8888 *dst,int coverage,KGR
|
||||
}
|
||||
}
|
||||
|
||||
static inline void KGBlendSpanNormal_8888_coverage(KGRGBA8888 *src,KGRGBA8888 *dst,int coverage,int length){
|
||||
void KGBlendSpanNormal_8888_coverage(KGRGBA8888 *src,KGRGBA8888 *dst,int coverage,int length){
|
||||
// Passes Visual Test
|
||||
int i;
|
||||
|
||||
|
@ -367,7 +367,7 @@ KGRGBA8888 *KGImageRead_GA88_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *s
|
||||
KGRGBA8888 *KGImageRead_RGBA8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_ABGR8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_BGRA8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_BGR888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_RGB888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_BGRX8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_XRGB8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
KGRGBA8888 *KGImageRead_G3B5X1R5G2_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length);
|
||||
|
@ -151,18 +151,17 @@ static BOOL initFunctionsForRGBColorSpace(KGImage *self,size_t bitsPerComponent,
|
||||
return YES;
|
||||
|
||||
case 24:
|
||||
switch(bitmapInfo&kCGBitmapAlphaInfoMask){
|
||||
case kCGImageAlphaNone:
|
||||
// FIXME: how is endian ness interpreted ?
|
||||
self->_read_lRGBA8888_PRE=KGImageRead_RGB888_to_RGBA8888;
|
||||
return YES;
|
||||
}
|
||||
break;
|
||||
|
||||
case 32:
|
||||
switch(bitmapInfo&kCGBitmapAlphaInfoMask){
|
||||
case kCGImageAlphaNone:
|
||||
switch(bitmapInfo&kCGBitmapByteOrderMask){
|
||||
case kCGBitmapByteOrder16Little:
|
||||
case kCGBitmapByteOrder32Little:
|
||||
self->_read_lRGBA8888_PRE=KGImageRead_BGR888_to_RGBA8888;
|
||||
return YES;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case kCGImageAlphaLast:
|
||||
@ -823,7 +822,7 @@ KGRGBA8888 *KGImageRead_BGRA8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
return NULL;
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_BGR888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length) {
|
||||
KGRGBA8888 *KGImageRead_RGB888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length) {
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
@ -835,9 +834,9 @@ KGRGBA8888 *KGImageRead_BGR888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888
|
||||
for(i=0;i<length;i++){
|
||||
KGRGBA8888 result;
|
||||
|
||||
result.b = *scanline++;
|
||||
result.r = *scanline++;
|
||||
result.g = *scanline++;
|
||||
result.r = *scanline++;
|
||||
result.b = *scanline++;
|
||||
result.a = 255;
|
||||
*span++=result;
|
||||
}
|
||||
|
@ -322,10 +322,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(CGImageRef)CGImage {
|
||||
if(_image!=NULL)
|
||||
return _image;
|
||||
|
||||
-(CGImageRef)createCGImage {
|
||||
if(_isPlanar)
|
||||
NSUnimplementedMethod();
|
||||
|
||||
@ -337,11 +334,25 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return [image autorelease];
|
||||
}
|
||||
|
||||
-(CGImageRef)CGImage {
|
||||
if(_image!=NULL)
|
||||
return _image;
|
||||
|
||||
return [[self createCGImage] autorelease];
|
||||
}
|
||||
|
||||
-(BOOL)draw {
|
||||
CGContextRef context=NSCurrentGraphicsPort();
|
||||
NSSize size=[self size];
|
||||
CGImageRef image=[_image retain];
|
||||
|
||||
if(image==nil)
|
||||
image=[self createCGImage];
|
||||
|
||||
CGContextDrawImage(context,NSMakeRect(0,0,size.width,size.height),[self CGImage]);
|
||||
CGContextDrawImage(context,NSMakeRect(0,0,size.width,size.height),image);
|
||||
|
||||
CGImageRelease(image);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -357,17 +368,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
-(CGBitmapInfo)CGBitmapInfo {
|
||||
CGBitmapInfo result=kCGBitmapByteOrderDefault;
|
||||
|
||||
if(_bitmapFormat&NSAlphaFirstBitmapFormat){
|
||||
if(_bitmapFormat&NSAlphaNonpremultipliedBitmapFormat)
|
||||
result|=kCGImageAlphaFirst;
|
||||
else
|
||||
result|=kCGImageAlphaPremultipliedFirst;
|
||||
}
|
||||
if(![self hasAlpha])
|
||||
result|=kCGImageAlphaNone;
|
||||
else {
|
||||
if(_bitmapFormat&NSAlphaNonpremultipliedBitmapFormat)
|
||||
result|=kCGImageAlphaLast;
|
||||
else
|
||||
result|=kCGImageAlphaPremultipliedLast;
|
||||
if(_bitmapFormat&NSAlphaFirstBitmapFormat){
|
||||
if(_bitmapFormat&NSAlphaNonpremultipliedBitmapFormat)
|
||||
result|=kCGImageAlphaFirst;
|
||||
else
|
||||
result|=kCGImageAlphaPremultipliedFirst;
|
||||
}
|
||||
else {
|
||||
if(_bitmapFormat&NSAlphaNonpremultipliedBitmapFormat)
|
||||
result|=kCGImageAlphaLast;
|
||||
else
|
||||
result|=kCGImageAlphaPremultipliedLast;
|
||||
}
|
||||
}
|
||||
if(_bitmapFormat&NSFloatingPointSamplesBitmapFormat)
|
||||
result|=kCGBitmapFloatComponents;
|
||||
|
@ -782,69 +782,26 @@ static void extend(HDC dc,int i,int direction,float bandInterval,NSPoint startPo
|
||||
}
|
||||
|
||||
#if 1
|
||||
void CGGraphicsSourceOver_rgba32_onto_bgrx32(unsigned char *sourceRGBA,unsigned char *resultBGRX,int width,int height,float fraction) {
|
||||
int sourceIndex=0;
|
||||
int sourceLength=width*height*4;
|
||||
int destinationReadIndex=0;
|
||||
int destinationWriteIndex=0;
|
||||
|
||||
fraction *= 256.0/255.0;
|
||||
while(sourceIndex<sourceLength){
|
||||
unsigned srcr=sourceRGBA[sourceIndex++];
|
||||
unsigned srcg=sourceRGBA[sourceIndex++];
|
||||
unsigned srcb=sourceRGBA[sourceIndex++];
|
||||
unsigned srca=sourceRGBA[sourceIndex++]*fraction;
|
||||
|
||||
unsigned dstb=resultBGRX[destinationReadIndex++];
|
||||
unsigned dstg=resultBGRX[destinationReadIndex++];
|
||||
unsigned dstr=resultBGRX[destinationReadIndex++];
|
||||
unsigned dsta=256-srca;
|
||||
|
||||
destinationReadIndex++;
|
||||
|
||||
dstr=(srcr*srca+dstr*dsta)>>8;
|
||||
dstg=(srcg*srca+dstg*dsta)>>8;
|
||||
dstb=(srcb*srca+dstb*dsta)>>8;
|
||||
|
||||
resultBGRX[destinationWriteIndex++]=dstb;
|
||||
resultBGRX[destinationWriteIndex++]=dstg;
|
||||
resultBGRX[destinationWriteIndex++]=dstr;
|
||||
destinationWriteIndex++; // skip x
|
||||
static void sourceOverImage(KGImage *image,KGRGBA8888 *resultBGRX,int width,int height,float fraction){
|
||||
KGRGBA8888 *span=__builtin_alloca(width*sizeof(KGRGBA8888));
|
||||
int y,coverage=RI_INT_CLAMP(fraction*256,0,256);
|
||||
|
||||
for(y=0;y<height;y++){
|
||||
KGRGBA8888 *direct=image->_read_lRGBA8888_PRE(image,0,y,span,width);
|
||||
KGRGBA8888 *combine=resultBGRX+width*y;
|
||||
|
||||
if(direct!=NULL){
|
||||
int x;
|
||||
|
||||
for(x=0;x<width;x++)
|
||||
span[x]=direct[x];
|
||||
}
|
||||
|
||||
KGBlendSpanNormal_8888_coverage(span,combine,coverage,width);
|
||||
}
|
||||
}
|
||||
|
||||
void CGGraphicsSourceOver_bgra32_onto_bgrx32(unsigned char *sourceBGRA,unsigned char *resultBGRX,int width,int height,float fraction) {
|
||||
int sourceIndex=0;
|
||||
int sourceLength=width*height*4;
|
||||
int destinationReadIndex=0;
|
||||
int destinationWriteIndex=0;
|
||||
|
||||
fraction *= 256.0/255.0;
|
||||
while(sourceIndex<sourceLength){
|
||||
unsigned srcb=sourceBGRA[sourceIndex++];
|
||||
unsigned srcg=sourceBGRA[sourceIndex++];
|
||||
unsigned srcr=sourceBGRA[sourceIndex++];
|
||||
unsigned srca=sourceBGRA[sourceIndex++]*fraction;
|
||||
|
||||
unsigned dstb=resultBGRX[destinationReadIndex++];
|
||||
unsigned dstg=resultBGRX[destinationReadIndex++];
|
||||
unsigned dstr=resultBGRX[destinationReadIndex++];
|
||||
unsigned dsta=256-srca;
|
||||
|
||||
destinationReadIndex++;
|
||||
|
||||
dstr=(srcr*srca+dstr*dsta)>>8;
|
||||
dstg=(srcg*srca+dstg*dsta)>>8;
|
||||
dstb=(srcb*srca+dstb*dsta)>>8;
|
||||
|
||||
resultBGRX[destinationWriteIndex++]=dstb;
|
||||
resultBGRX[destinationWriteIndex++]=dstg;
|
||||
resultBGRX[destinationWriteIndex++]=dstr;
|
||||
destinationWriteIndex++; // skip x
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void)drawBitmapImage:(KGImage *)image inRect:(NSRect)rect ctm:(CGAffineTransform)ctm fraction:(float)fraction {
|
||||
int width=[image width];
|
||||
int height=[image height];
|
||||
@ -857,7 +814,7 @@ void CGGraphicsSourceOver_bgra32_onto_bgrx32(unsigned char *sourceBGRA,unsigned
|
||||
HBITMAP bitmap;
|
||||
BITMAPINFO info;
|
||||
void *bits;
|
||||
unsigned char *combineBGRX;
|
||||
KGRGBA8888 *combineBGRX;
|
||||
unsigned char *imageRGBA=(void *)data;
|
||||
|
||||
if(transformIsFlipped(ctm))
|
||||
@ -890,10 +847,7 @@ void CGGraphicsSourceOver_bgra32_onto_bgrx32(unsigned char *sourceBGRA,unsigned
|
||||
BitBlt(combineDC,0,0,combineWidth,combineHeight,sourceDC,point.x,point.y,SRCCOPY);
|
||||
GdiFlush();
|
||||
|
||||
if((CGImageGetAlphaInfo(image)==kCGImageAlphaPremultipliedFirst) && ([image bitmapInfo]&kCGBitmapByteOrderMask)==kCGBitmapByteOrder32Little)
|
||||
CGGraphicsSourceOver_bgra32_onto_bgrx32(imageRGBA,combineBGRX,width,height,fraction);
|
||||
else
|
||||
CGGraphicsSourceOver_rgba32_onto_bgrx32(imageRGBA,combineBGRX,width,height,fraction);
|
||||
sourceOverImage(image,combineBGRX,width,height,fraction);
|
||||
|
||||
BitBlt(sourceDC,point.x,point.y,combineWidth,combineHeight,combineDC,0,0,SRCCOPY);
|
||||
DeleteObject(bitmap);
|
||||
@ -997,16 +951,7 @@ static void zeroBytes(void *bytes,int size){
|
||||
|
||||
-(void)drawImage:(KGImage *)image inRect:(NSRect)rect {
|
||||
CGAffineTransform transformToDevice=[self userSpaceToDeviceSpaceTransform];
|
||||
|
||||
if([image bitsPerComponent]!=8){
|
||||
NSLog(@"Does not support bitsPerComponent=%d",[image bitsPerComponent]);
|
||||
return;
|
||||
}
|
||||
if([image bitsPerPixel]!=32){
|
||||
NSLog(@"Does not support bitsPerPixel=%d",[image bitsPerPixel]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
[self drawBitmapImage:image inRect:rect ctm:transformToDevice fraction:[[self fillColor] alpha]];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user