mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-27 05:50:27 +00:00
- KGImage, KGDataProvider fixes
This commit is contained in:
parent
eea6bf491e
commit
b9423eb45a
@ -26,6 +26,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
-(NSData *)data;
|
||||
-(const void *)bytes;
|
||||
-(size_t)length;
|
||||
|
||||
-(NSData *)copyData;
|
||||
|
||||
|
@ -18,6 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
_data=[data retain];
|
||||
_isDirectAccess=YES;
|
||||
_bytes=[data bytes];
|
||||
_length=[data length];
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -25,6 +26,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
_data=nil;
|
||||
_isDirectAccess=YES;
|
||||
_bytes=bytes;
|
||||
_length=length;
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -35,6 +37,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
_isDirectAccess=NO;
|
||||
_bytes=NULL;
|
||||
_length=0;
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -55,6 +58,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return _bytes;
|
||||
}
|
||||
|
||||
-(size_t)length {
|
||||
return _length;
|
||||
}
|
||||
|
||||
-(NSData *)copyData {
|
||||
if(_data!=nil)
|
||||
return [_data copy];
|
||||
|
@ -277,6 +277,8 @@ typedef CGFloat *(*KGImageReadSpan_Af)(KGImage *self,int x,int y,CGFloat *spa
|
||||
|
||||
NSData *_directData;
|
||||
const unsigned char *_directBytes;
|
||||
unsigned _directLength;
|
||||
|
||||
BOOL _clampExternalPixels;
|
||||
VGColorInternalFormat _colorFormat;
|
||||
|
||||
|
@ -350,6 +350,7 @@ static BOOL initFunctionsForParameters(KGImage *self,size_t bitsPerComponent,siz
|
||||
_mask=nil;
|
||||
|
||||
_directBytes=NULL;
|
||||
_directLength=0;
|
||||
|
||||
_clampExternalPixels=NO; // only do this if premultiplied format
|
||||
if(!initFunctionsForParameters(self,bitsPerComponent,bitsPerPixel,colorSpace,bitmapInfo)){
|
||||
@ -501,15 +502,29 @@ static inline const void *directBytes(KGImage *self){
|
||||
if(self->_directBytes==NULL){
|
||||
if([self->_provider isDirectAccess]){
|
||||
self->_directData=[[self->_provider data] retain];
|
||||
}
|
||||
self->_directBytes=[self->_provider bytes];
|
||||
self->_directLength=[self->_provider length];
|
||||
}
|
||||
else {
|
||||
self->_directData=[self->_provider copyData];
|
||||
self->_directBytes=[self->_directData bytes];
|
||||
self->_directLength=[self->_directData length];
|
||||
}
|
||||
self->_directBytes=[self->_directData bytes];
|
||||
}
|
||||
return self->_directBytes;
|
||||
}
|
||||
|
||||
static inline const void *scanlineAtY(KGImage *self,int y){
|
||||
const void *bytes=directBytes(self);
|
||||
int offset=self->_bytesPerRow*y;
|
||||
int max=offset+self->_bytesPerRow;
|
||||
|
||||
if(max<=self->_directLength)
|
||||
return bytes+offset;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
-(NSData *)directData {
|
||||
directBytes(self);
|
||||
return _directData;
|
||||
@ -524,6 +539,7 @@ static inline const void *directBytes(KGImage *self){
|
||||
[_directData release];
|
||||
_directData=nil;
|
||||
_directBytes=NULL;
|
||||
_directLength=0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,9 +593,12 @@ float bytesLittleToFloat(const unsigned char *scanline){
|
||||
}
|
||||
|
||||
KGRGBAffff *KGImageRead_RGBAffffLittle_to_RGBAffff(KGImage *self,int x,int y,KGRGBAffff *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*16;
|
||||
for(i=0;i<length;i++){
|
||||
KGRGBAffff result;
|
||||
@ -620,9 +639,12 @@ float bytesBigToFloat(const unsigned char *scanline){
|
||||
}
|
||||
|
||||
KGRGBAffff *KGImageRead_RGBAffffBig_to_RGBAffff(KGImage *self,int x,int y,KGRGBAffff *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*16;
|
||||
for(i=0;i<length;i++){
|
||||
KGRGBAffff result;
|
||||
@ -642,9 +664,12 @@ KGRGBAffff *KGImageRead_RGBAffffBig_to_RGBAffff(KGImage *self,int x,int y,KGRGBA
|
||||
}
|
||||
|
||||
uint8_t *KGImageRead_G8_to_A8(KGImage *self,int x,int y,uint8_t *alpha,int length) {
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x;
|
||||
for(i=0;i<length;i++){
|
||||
*alpha++=*scanline++;
|
||||
@ -678,9 +703,12 @@ CGFloat *KGImageRead_ANY_to_A8_to_Af(KGImage *self,int x,int y,CGFloat *alpha,in
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_G8_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x;
|
||||
for(i=0;i<length;i++){
|
||||
KGRGBA8888 result;
|
||||
@ -696,9 +724,12 @@ KGRGBA8888 *KGImageRead_G8_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *spa
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_GA88_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*2;
|
||||
for(i=0;i<length;i++){
|
||||
KGRGBA8888 result;
|
||||
@ -713,8 +744,11 @@ 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){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*4;
|
||||
for(i=0;i<length;i++){
|
||||
@ -730,8 +764,11 @@ KGRGBA8888 *KGImageRead_RGBA8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_ABGR8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*4;
|
||||
for(i=0;i<length;i++){
|
||||
@ -747,8 +784,11 @@ KGRGBA8888 *KGImageRead_ABGR8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_BGRA8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length) {
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*4;
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
@ -768,8 +808,11 @@ KGRGBA8888 *KGImageRead_BGRA8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_XRGB8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length) {
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*4;
|
||||
|
||||
@ -787,8 +830,11 @@ KGRGBA8888 *KGImageRead_XRGB8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
|
||||
// kCGBitmapByteOrder16Little|kCGImageAlphaNoneSkipFirst
|
||||
KGRGBA8888 *KGImageRead_G3B5X1R5G2_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*2;
|
||||
for(i=0;i<length;i++){
|
||||
@ -808,8 +854,11 @@ KGRGBA8888 *KGImageRead_G3B5X1R5G2_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_RGBA4444_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*2;
|
||||
for(i=0;i<length;i++){
|
||||
@ -827,8 +876,11 @@ KGRGBA8888 *KGImageRead_RGBA4444_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_BARG4444_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*2;
|
||||
for(i=0;i<length;i++){
|
||||
@ -846,8 +898,11 @@ KGRGBA8888 *KGImageRead_BARG4444_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
}
|
||||
|
||||
KGRGBA8888 *KGImageRead_RGBA2222_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x;
|
||||
for(i=0;i<length;i++){
|
||||
@ -865,8 +920,11 @@ KGRGBA8888 *KGImageRead_RGBA2222_to_RGBA8888(KGImage *self,int x,int y,KGRGBA888
|
||||
|
||||
KGRGBA8888 *KGImageRead_CMYK8888_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *span,int length){
|
||||
// poor results
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x*4;
|
||||
for(i=0;i<length;i++){
|
||||
@ -891,9 +949,12 @@ KGRGBA8888 *KGImageRead_I8_to_RGBA8888(KGImage *self,int x,int y,KGRGBA8888 *spa
|
||||
unsigned hival=[indexed hival];
|
||||
const unsigned char *palette=[indexed paletteBytes];
|
||||
|
||||
const RIuint8 *scanline = directBytes(self) + y * self->_bytesPerRow;
|
||||
const RIuint8 *scanline = scanlineAtY(self,y);
|
||||
int i;
|
||||
|
||||
if(scanline==NULL)
|
||||
return NULL;
|
||||
|
||||
scanline+=x;
|
||||
|
||||
for(i=0;i<length;i++){
|
||||
|
@ -195,7 +195,6 @@ KGRGBAffff KGPaintColorRamp(KGPaint_ramp *self,CGFloat gradient, CGFloat rho) {
|
||||
RI_ASSERT(rho >= 0.0f);
|
||||
|
||||
KGRGBAffff c=KGRGBAffffInit(0,0,0,0);
|
||||
KGRGBAffff avg=KGRGBAffffInit(0,0,0,0);
|
||||
|
||||
if(rho == 0.0f)
|
||||
{ //filter size is zero or gradient is degenerate
|
||||
|
@ -526,7 +526,7 @@ static BOOL initFunctionsForParameters(KGSurface *self,size_t bitsPerComponent,s
|
||||
int bitsPerPixel=32;
|
||||
|
||||
if(bytes!=NULL){
|
||||
provider=[[[KGDataProvider alloc] initWithBytes:bytes length:_bytesPerRow*_height] autorelease];
|
||||
provider=[[[KGDataProvider alloc] initWithBytes:bytes length:bytesPerRow*height] autorelease];
|
||||
m_ownsData=NO;
|
||||
}
|
||||
else {
|
||||
@ -543,7 +543,7 @@ static BOOL initFunctionsForParameters(KGSurface *self,size_t bitsPerComponent,s
|
||||
|
||||
if([provider isDirectAccess])
|
||||
_pixelBytes=(void *)[provider bytes];
|
||||
|
||||
|
||||
if(!initFunctionsForParameters(self,bitsPerComponent,_bitsPerPixel,colorSpace,bitmapInfo))
|
||||
NSLog(@"KGSurface -init error, return");
|
||||
|
||||
|
@ -245,7 +245,7 @@
|
||||
[KGContext createWithBytes:bytes width:w height:h bitsPerComponent:bpc bytesPerRow:bpr colorSpace:cs bitmapInfo:bi]
|
||||
|
||||
#define CGBitmapContextGetData(self) \
|
||||
[self bytes]
|
||||
[self pixelBytes]
|
||||
|
||||
#define CGBitmapContextGetWidth(self) \
|
||||
[self width]
|
||||
|
Loading…
Reference in New Issue
Block a user