Permalink
Browse files

Onyx2D improvements

  • Loading branch information...
1 parent a236f72 commit db257f13d8544ef19356920a7122d407da3587ab @cjwl cjwl committed Oct 22, 2010
Showing with 11,205 additions and 3,163 deletions.
  1. +324 −0 AppKit/AppKit.xcodeproj/project.pbxproj
  2. +80 −11 AppKit/NSBitmapImageRep.m
  3. +3 −3 AppKit/Win32.subproj/CGLContext.m
  4. +1 −1 AppKit/Win32.subproj/KTFont_gdi.m
  5. +13 −1 AppKit/Win32.subproj/O2Context_builtin_gdi.h
  6. +430 −34 AppKit/Win32.subproj/O2Context_builtin_gdi.m
  7. +55 −94 AppKit/Win32.subproj/O2Context_gdi.m
  8. +5 −56 AppKit/Win32.subproj/O2DeviceContext_gdi.m
  9. +2 −2 AppKit/Win32.subproj/O2DeviceContext_gdiDIBSection.h
  10. +34 −1 AppKit/Win32.subproj/O2DeviceContext_gdiDIBSection.m
  11. +4 −0 AppKit/Win32.subproj/O2Font_gdi.h
  12. +86 −6 AppKit/Win32.subproj/O2Font_gdi.m
  13. +1 −1 AppKit/Win32.subproj/O2Surface_DIBSection.h
  14. +6 −2 AppKit/Win32.subproj/O2Surface_DIBSection.m
  15. +2 −2 Cocoa/Cocoa.xcodeproj/project.pbxproj
  16. +0 −4 CoreGraphics/CGContext.m
  17. +0 −752 CoreGraphics/CoreGraphics.xcodeproj/project.pbxproj
  18. +0 −32 CoreText/CoreText.xcodeproj/project.pbxproj
  19. +0 −777 Onyx2D/O2Blending.h
  20. +8 −0 Onyx2D/O2ClipMask.h
  21. 0 Onyx2D/O2ClipMask.m
  22. +43 −0 Onyx2D/O2ClipState.h
  23. +144 −0 Onyx2D/O2ClipState.m
  24. +3 −0 Onyx2D/O2Color.h
  25. +101 −0 Onyx2D/O2Color.m
  26. +1 −1 Onyx2D/O2ColorSpace+PDF.h
  27. +96 −4 Onyx2D/O2ColorSpace+PDF.m
  28. +46 −15 Onyx2D/O2Context.h
  29. +250 −164 Onyx2D/O2Context.m
  30. +1 −1 Onyx2D/O2Context_builtin.h
  31. +97 −259 Onyx2D/O2Context_builtin.m
  32. +19 −0 Onyx2D/O2Context_distill.h
  33. +89 −0 Onyx2D/O2Context_distill.m
  34. +1 −1 Onyx2D/O2Encoder_TIFF.m
  35. +27 −0 Onyx2D/O2Encoding.h
  36. +155 −0 Onyx2D/O2Encoding.m
  37. +8 −3 Onyx2D/O2Font+PDF.m
  38. +12 −6 Onyx2D/O2Font.h
  39. +4,339 −8 Onyx2D/O2Font.m
  40. +3 −2 Onyx2D/O2Function+PDF.h
  41. +61 −4 Onyx2D/O2Function+PDF.m
  42. +14 −0 Onyx2D/O2Geometry.h
  43. +18 −0 Onyx2D/O2GlyphStencil.h
  44. +49 −0 Onyx2D/O2GlyphStencil.m
  45. +41 −22 Onyx2D/O2GraphicsState.h
  46. +106 −70 Onyx2D/O2GraphicsState.m
  47. +50 −37 Onyx2D/O2Image+PDF.m
  48. +16 −223 Onyx2D/O2Image.h
  49. +137 −73 Onyx2D/O2Image.m
  50. +1 −0 Onyx2D/O2ImageSource.m
  51. +4 −1 Onyx2D/O2ImageSource_BMP.m
  52. +3 −3 Onyx2D/O2ImageSource_GIF.m
  53. +26 −0 Onyx2D/O2ImageSource_ICNS.h
  54. +614 −0 Onyx2D/O2ImageSource_ICNS.m
  55. +2 −0 Onyx2D/O2ImageSource_JPEG.h
  56. +17 −0 Onyx2D/O2ImageSource_JPEG.m
  57. +3 −0 Onyx2D/O2ImageSource_PNG.m
  58. +13 −7 Onyx2D/O2MutablePath.m
  59. +1 −0 Onyx2D/O2PDFArray.h
  60. +19 −0 Onyx2D/O2PDFArray.m
  61. +14 −0 Onyx2D/O2PDFBlock.h
  62. +36 −0 Onyx2D/O2PDFBlock.m
  63. +14 −0 Onyx2D/O2PDFCharWidths.h
  64. +34 −0 Onyx2D/O2PDFCharWidths.m
  65. +3 −1 Onyx2D/O2PDFContentStream.h
  66. +15 −1 Onyx2D/O2PDFContentStream.m
  67. +14 −21 Onyx2D/O2PDFContext.m
  68. +1 −1 Onyx2D/O2PDFDictionary.m
  69. +11 −10 Onyx2D/O2PDFFilter.m
  70. +21 −0 Onyx2D/O2PDFFont.h
  71. +242 −0 Onyx2D/O2PDFFont.m
  72. +30 −0 Onyx2D/O2PDFFunction_Type0.h
  73. +109 −0 Onyx2D/O2PDFFunction_Type0.m
  74. +20 −0 Onyx2D/O2PDFFunction_Type4.h
  75. +636 −0 Onyx2D/O2PDFFunction_Type4.m
  76. +12 −0 Onyx2D/O2PDFObject.h
  77. +21 −0 Onyx2D/O2PDFObject.m
  78. +3 −0 Onyx2D/O2PDFObject_const.h
  79. +7 −0 Onyx2D/O2PDFObject_const.m
  80. +45 −0 Onyx2D/O2PDFObject_identifier.h
  81. +384 −184 Onyx2D/O2PDFOperators.m
  82. +9 −9 Onyx2D/O2PDFScanner.h
  83. +143 −49 Onyx2D/O2PDFScanner.m
  84. +1 −0 Onyx2D/O2PDFStream.h
  85. +13 −3 Onyx2D/O2PDFStream.m
  86. +7 −0 Onyx2D/O2PDFString.h
  87. +9 −0 Onyx2D/O2PDFString.m
  88. +4 −2 Onyx2D/O2Paint_image.h
  89. +66 −9 Onyx2D/O2Paint_image.m
  90. +7 −4 Onyx2D/O2Path.m
  91. +6 −5 Onyx2D/O2Shading+PDF.m
  92. +6 −1 Onyx2D/O2Surface.m
  93. +3 −0 Onyx2D/O2TTFDecoder.h
  94. +51 −0 Onyx2D/O2TTFDecoder.m
  95. +144 −0 Onyx2D/O2argb32f.h
  96. +646 −0 Onyx2D/O2argb32f.m
  97. +152 −0 Onyx2D/O2argb8u.h
  98. +324 −0 Onyx2D/O2argb8u.m
  99. +254 −178 Onyx2D/Onyx2D.xcodeproj/project.pbxproj
  100. +4 −2 Onyx2D/VGPath.m

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -15,19 +15,19 @@
@implementation NSBitmapImageRep
+(NSArray *)imageUnfilteredFileTypes {
- return [NSArray arrayWithObjects:@"tiff",@"tif",@"png",@"jpg",@"gif",@"bmp",nil];
+ return [NSArray arrayWithObjects:@"tiff",@"tif",@"png",@"jpg",@"gif",@"bmp",@"icns",nil];
}
+(NSArray *)imageRepsWithContentsOfFile:(NSString *)path {
- NSMutableArray *result=[NSMutableArray array];
- NSBitmapImageRep *rep=[[[NSBitmapImageRep alloc] initWithContentsOfFile:path] autorelease];
+ NSData *data=[NSData dataWithContentsOfFile:path];
- if(rep==nil)
+ if(data==nil)
return nil;
- [result addObject:rep];
+ if([self canInitWithData:data])
+ return [self imageRepsWithData:data];
- return result;
+ return nil;
}
+(void)getTIFFCompressionTypes:(const NSTIFFCompression **)types count:(int *)count {
@@ -62,13 +62,54 @@ +(NSData *)representationOfImageRepsInArray:(NSArray *)array usingType:(NSBitmap
return nil;
}
++(BOOL)canInitWithData:(NSData *)data {
+ CGImageSourceRef imageSource=CGImageSourceCreateWithData((CFDataRef)data,nil);
+ BOOL result=(imageSource!=NULL)?YES:NO;
+ CFRelease(imageSource);
+ return result;
+}
+
+(NSArray *)imageRepsWithData:(NSData *)data {
- id result=[self imageRepWithData:data];
+ NSMutableArray *result=[NSMutableArray array];
+ CGImageSourceRef imageSource=CGImageSourceCreateWithData((CFDataRef)data,nil);
- if(result==nil)
+ if(imageSource==nil)
return nil;
- return [NSArray arrayWithObject:result];
+ size_t i,count=CGImageSourceGetCount(imageSource);
+
+ for(i=0;i<count;i++){
+ CGImageRef cgImage=CGImageSourceCreateImageAtIndex(imageSource,i,nil);
+
+ if(cgImage==nil)
+ break;
+
+ CFDictionaryRef properties=CGImageSourceCopyPropertiesAtIndex(imageSource,i,nil);
+ NSNumber *xres=[[(id)CFDictionaryGetValue(properties,kCGImagePropertyDPIWidth) copy] autorelease];
+ NSNumber *yres=[[(id)CFDictionaryGetValue(properties,kCGImagePropertyDPIHeight) copy] autorelease];
+
+ CFRelease(properties);
+
+ NSBitmapImageRep *imageRep=[[self alloc] initWithCGImage:cgImage];
+ NSSize size={ CGImageGetWidth(cgImage),CGImageGetHeight(cgImage) };
+
+ CGImageRelease(cgImage);
+
+ if(xres!=nil && [xres doubleValue]>0)
+ size.width*=72.0/[xres doubleValue];
+
+ if(yres!=nil && [yres doubleValue]>0)
+ size.height*=72.0/[yres doubleValue];
+
+ [imageRep setSize:size];
+
+ if(imageRep!=nil)
+ [result addObject:imageRep];
+}
+
+ CFRelease(imageSource);
+
+ return result;
}
+imageRepWithData:(NSData *)data {
@@ -134,7 +175,20 @@ +(NSArray *)imageRepsWithData:(NSData *)data {
}
-initWithFocusedViewRect:(NSRect)rect {
- return [self initWithData:(NSData *)CGContextCaptureBitmap(NSCurrentGraphicsPort(), rect)];
+ CGContextRef graphicsPort=NSCurrentGraphicsPort();
+
+ if(graphicsPort==NULL){
+ [self dealloc];
+ return nil;
+}
+
+ CGImageRef image=CGBitmapContextCreateImage(graphicsPort);
+
+ self=[self initWithCGImage:image];
+
+ CGImageRelease(image);
+
+ return self;
}
-initWithData:(NSData *)data {
@@ -197,15 +251,30 @@ -(void)createBitmapIfNeeded {
_bitmapPlanes[0]=NSZoneCalloc(NULL,_bytesPerRow*_pixelsHigh,1);
if(_cgImage!=NULL){
+ CGBitmapInfo bitmapInfo=CGImageGetBitmapInfo(_cgImage);
CGDataProviderRef provider=CGImageGetDataProvider(_cgImage);
// FIXME: inefficient but there is no API to get mutable bytes out of an image or image source
CFDataRef bitmapData=CGDataProviderCopyData(provider);
const unsigned char *bytes=CFDataGetBytePtr(bitmapData);
int i,length=_bytesPerRow*_pixelsHigh;
+ if(bitmapInfo==(kCGImageAlphaPremultipliedLast|kCGBitmapByteOrder32Big)){
for(i=0;i<length;i++)
_bitmapPlanes[0][i]=bytes[i];
-
+ }
+ else {
+ for(i=0;i<length;i+=4){
+ unsigned char b=bytes[i+0];
+ unsigned char g=bytes[i+1];
+ unsigned char r=bytes[i+2];
+ unsigned char a=bytes[i+3];
+
+ _bitmapPlanes[0][i+0]=r;
+ _bitmapPlanes[0][i+1]=g;
+ _bitmapPlanes[0][i+2]=b;
+ _bitmapPlanes[0][i+3]=a;
+ }
+ }
CFRelease(bitmapData);
}
}
@@ -399,9 +399,9 @@ CGLError CGLFlushDrawable(CGLContextObj context) {
unsigned int r=imageRow[c+2];
unsigned int a=imageRow[c+3];
- imageRow[c+2]=alphaMultiply(r,a);
- imageRow[c+1]=alphaMultiply(g,a);
- imageRow[c+0]=alphaMultiply(b,a);
+ imageRow[c+2]=O2Image_8u_mul_8u_div_255(r,a);
+ imageRow[c+1]=O2Image_8u_mul_8u_div_255(g,a);
+ imageRow[c+0]=O2Image_8u_mul_8u_div_255(b,a);
}
}
@@ -407,7 +407,7 @@ -(void)fetchMetrics {
case kCTFontMenuItemFontType:
if(size==0)
size=10;
- font=[O2Font createWithFontName:@"Tahoma"];
+ font=O2FontCreateWithFontName(@"Tahoma");
#if 0
// We should be able to get the menu font but this doesnt work
@@ -7,12 +7,24 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Onyx2D/O2Context_builtin.h>
#import <windows.h>
+#import <Onyx2D/O2GlyphStencil.h>
-@class Win32Font,O2DeviceContext_gdi;
+@class Win32Font,O2DeviceContext_gdi,O2DeviceContext_gdiDIBSection;
@interface O2Context_builtin_gdi : O2Context_builtin {
HDC _dc;
Win32Font *_gdiFont;
+ int _gdiDescent;
+ O2Paint *_textFillPaint;
+ size_t _glyphCacheCount;
+ O2GlyphStencilRef *_glyphCache;
+
+ int _scratchWidth;
+ int _scratchHeight;
+ O2DeviceContext_gdiDIBSection *_scratchContext;
+ HDC _scratchDC;
+ uint8_t *_scratchBitmap;
+ Win32Font *_scratchFont;
}
-(O2DeviceContext_gdi *)deviceContext;
Oops, something went wrong.

0 comments on commit db257f1

Please sign in to comment.