Skip to content

Commit

Permalink
Support for images, shading, layers, shadows, global alpha... for the…
Browse files Browse the repository at this point in the history
… AntiGrain context (not 100% complete yet)
  • Loading branch information
plasq committed Jun 22, 2011
1 parent 364fc85 commit 0df24ed
Show file tree
Hide file tree
Showing 13 changed files with 1,685 additions and 263 deletions.
32 changes: 18 additions & 14 deletions AppKit/NSImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -755,20 +755,24 @@ -(void)drawInRect:(NSRect)rect fromRect:(NSRect)source operation:(NSCompositingO

CGContextSaveGState(context);

if(fraction!=1.0){
// fraction is accomplished with a 1x1 alpha mask
// FIXME: could use a float format image to completely preserve fraction
uint8_t bytes[1]={ MIN(MAX(0,fraction*255),255) };
CGDataProviderRef provider=CGDataProviderCreateWithData(NULL,bytes,1,NULL);
CGImageRef mask=CGImageMaskCreate(1,1,8,8,1,provider,NULL,NO);

CGContextClipToMask(context,rect,mask);
CGImageRelease(mask);
CGDataProviderRelease(provider);
}

[[NSGraphicsContext currentContext] setCompositingOperation:operation];

if ([context supportsGlobalAlpha] == NO) {
// That should really be done by setting the context alpha - and the compositing done in the context implementation
if(fraction!=1.0){
// fraction is accomplished with a 1x1 alpha mask
// FIXME: could use a float format image to completely preserve fraction
uint8_t bytes[1]={ MIN(MAX(0,fraction*255),255) };
CGDataProviderRef provider=CGDataProviderCreateWithData(NULL,bytes,1,NULL);
CGImageRef mask=CGImageMaskCreate(1,1,8,8,1,provider,NULL,NO);

CGContextClipToMask(context,rect,mask);
CGImageRelease(mask);
CGDataProviderRelease(provider);
}
} else {
CGContextSetAlpha(context, fraction);
}
[[NSGraphicsContext currentContext] setCompositingOperation:operation];

[self drawRepresentation:drawRep inRect:rect];

CGContextRestoreGState(context);
Expand Down
47 changes: 38 additions & 9 deletions O2Context_AntiGrain/O2Context_AntiGrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#ifdef ANTIGRAIN_PRESENT
#include <agg_basics.h>
#include <agg_pixfmt_rgba.h>
#include <agg_pixfmt_gray.h>
#include <agg_alpha_mask_u8.h>
#include <agg_scanline_p.h>
#include <agg_scanline_u.h>
#include <agg_alpha_mask_u8.h>
#include <agg_path_storage.h>
#include <agg_renderer_base.h>
#include <agg_renderer_mclip.h>
Expand All @@ -14,22 +19,46 @@
#include <agg_conv_stroke.h>
#include <agg_conv_adaptor_vcgen.h>

typedef agg::comp_op_adaptor_rgba<agg::rgba8, agg::order_bgra> blender_type;
typedef agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer> pixfmt_type;
@class O2Context_AntiGrain;

class context_renderer;

typedef agg::renderer_base<pixfmt_type> renderer_base;
typedef agg::pixfmt_gray8 pixfmt_alphaMaskType;
typedef agg::renderer_base<pixfmt_alphaMaskType> BaseRendererWithAlphaMaskType;
typedef agg::rasterizer_scanline_aa<> RasterizerType; // We use an anti-aliased scanline rasterizer for AGG rendering.

@interface O2Context_AntiGrain : O2Context_builtin_gdi {
agg::rendering_buffer *renderingBuffer;
pixfmt_type *pixelFormat;
agg::rasterizer_scanline_aa<> *rasterizer;
renderer_base *ren_base;
agg::path_storage *path;
agg::rendering_buffer *renderingBuffer;

// Rendering buffer to use for shadow rendering
uint8_t *pixelShadowBytes;
agg::rendering_buffer *renderingBufferShadow;

agg::path_storage *path;
RasterizerType *rasterizer;

context_renderer *renderer;

// Rendering buffer to use for alpha masking (bezier path clipping)
agg::rendering_buffer* rBufAlphaMask[2];
agg::alpha_mask_gray8* alphaMask[2];
pixfmt_alphaMaskType* pixelFormatAlphaMask[2];
BaseRendererWithAlphaMaskType* baseRendererAlphaMask[2];
agg::renderer_scanline_aa_solid<BaseRendererWithAlphaMaskType>* solidScanlineRendererAlphaMask[2];
int currentMask;

NSArray *savedClipPhases;
BOOL maskValid;
BOOL useMask;
}

- (BOOL)useMask;
- (agg::alpha_mask_gray8*)currentMask;
- (RasterizerType *)rasterizer;
- (context_renderer *)renderer;
@end

#else
#import <Onyx2D/O2Context_builtin_gdi.h>

@interface O2Context_AntiGrain : O2Context_builtin_gdi
@end
Expand Down
Loading

0 comments on commit 0df24ed

Please sign in to comment.