示例#1
0
void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, const Color& color, ColorSpace colorSpace)
{
    if (paintingDisabled())
        return;
    CGFloat xOffset = offset.width();
    CGFloat yOffset = offset.height();
    CGFloat blurRadius = blur;
    CGContextRef context = platformContext();

    if (!m_state.shadowsIgnoreTransforms) {
        CGAffineTransform userToBaseCTM = wkGetUserToBaseCTM(context);

        CGFloat A = userToBaseCTM.a * userToBaseCTM.a + userToBaseCTM.b * userToBaseCTM.b;
        CGFloat B = userToBaseCTM.a * userToBaseCTM.c + userToBaseCTM.b * userToBaseCTM.d;
        CGFloat C = B;
        CGFloat D = userToBaseCTM.c * userToBaseCTM.c + userToBaseCTM.d * userToBaseCTM.d;

        CGFloat smallEigenvalue = narrowPrecisionToCGFloat(sqrt(0.5 * ((A + D) - sqrt(4 * B * C + (A - D) * (A - D)))));

        // Extreme "blur" values can make text drawing crash or take crazy long times, so clamp
        blurRadius = min(blur * smallEigenvalue, narrowPrecisionToCGFloat(1000.0));

        CGSize offsetInBaseSpace = CGSizeApplyAffineTransform(offset, userToBaseCTM);

        xOffset = offsetInBaseSpace.width;
        yOffset = offsetInBaseSpace.height;
    }

    // Work around <rdar://problem/5539388> by ensuring that the offsets will get truncated
    // to the desired integer.
    static const CGFloat extraShadowOffset = narrowPrecisionToCGFloat(1.0 / 128);
    if (xOffset > 0)
        xOffset += extraShadowOffset;
    else if (xOffset < 0)
        xOffset -= extraShadowOffset;

    if (yOffset > 0)
        yOffset += extraShadowOffset;
    else if (yOffset < 0)
        yOffset -= extraShadowOffset;

    // Check for an invalid color, as this means that the color was not set for the shadow
    // and we should therefore just use the default shadow color.
    if (!color.isValid())
        CGContextSetShadow(context, CGSizeMake(xOffset, yOffset), blurRadius);
    else
        CGContextSetShadowWithColor(context, CGSizeMake(xOffset, yOffset), blurRadius, cachedCGColor(color, colorSpace));
}
void
renderspu_SystemWindowSize(WindowInfo *window, GLint w, GLint h)
{
    CRASSERT(window);
    CRASSERT(window->window);

    OSStatus status = noErr;
    /* Send a event to the main thread, cause some function of Carbon aren't
     * thread safe */
    EventRef evt;
    status = CreateEvent(NULL, kEventClassVBox, kEventVBoxResizeWindow, 0, kEventAttributeNone, &evt);
    CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): CreateEvent Failed ");
    status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window);
    CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SetEventParameter Failed");
    HISize s = CGSizeMake (w, h);
    status = SetEventParameter(evt, kEventParamDimensions, typeHISize, sizeof (s), &s);
    CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SetEventParameter Failed");
    status = SetEventParameter(evt, kEventParamUserData, typeVoidPtr, sizeof (window), &window);
    CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SetEventParameter Failed");
    status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
    CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SendEventToEventTarget Failed");

    DEBUG_MSG_POETZSCH (("Size %d visible %d\n", window->BltInfo.Base.id, IsWindowVisible (window->window)));
    /* save the new size */
    window->BltInfo.width = w;
    window->BltInfo.height = h;
}
示例#3
0
Pixmap
Tk_GetPixmap(
    Display *display,	/* Display for new pixmap (can be null). */
    Drawable d,		/* Drawable where pixmap will be used (ignored). */
    int width,		/* Dimensions of pixmap. */
    int height,
    int depth)		/* Bits per pixel for pixmap. */
{
    MacDrawable *macPix;

    if (display != NULL) {
	display->request++;
    }
    macPix = (MacDrawable *) ckalloc(sizeof(MacDrawable));
    macPix->winPtr = NULL;
    macPix->xOff = 0;
    macPix->yOff = 0;
    macPix->visRgn = NULL;
    macPix->aboveVisRgn = NULL;
    macPix->drawRect = CGRectNull;
    macPix->referenceCount = 0;
    macPix->toplevel = NULL;
    macPix->flags = TK_IS_PIXMAP | (depth == 1 ? TK_IS_BW_PIXMAP : 0);
    macPix->grafPtr = NULL;
    macPix->context = NULL;
    macPix->size = CGSizeMake(width, height);
    AllocGWorld(width, height, depth==1, &macPix->grafPtr);

    return (Pixmap) macPix;
}
示例#4
0
static ATSUStyle
CreateSizedCopyOfStyle(ATSUStyle inStyle, cairo_matrix_t *scale)
{
    ATSUStyle style;
    OSStatus err;


    // Set the style's size
    CGAffineTransform theTransform =
        CGAffineTransformMakeWithCairoFontScale(scale);
    Fixed theSize =
        FloatToFixed(CGSizeApplyAffineTransform
                     (CGSizeMake(1.0, 1.0), theTransform).height);
    const ATSUAttributeTag theFontStyleTags[] = { kATSUSizeTag };
    const ByteCount theFontStyleSizes[] = { sizeof(Fixed) };
    ATSUAttributeValuePtr theFontStyleValues[] = { &theSize };

    err = ATSUCreateAndCopyStyle(inStyle, &style);

    err = ATSUSetAttributes(style,
                            sizeof(theFontStyleTags) /
                            sizeof(ATSUAttributeTag), theFontStyleTags,
                            theFontStyleSizes, theFontStyleValues);

    return style;
}
示例#5
0
void GraphicsContext::fillRect(const FloatRect& rect)
{
    if (paintingDisabled())
        return;

    CGContextRef context = platformContext();

    if (m_state.fillGradient) {
        CGContextSaveGState(context);
        CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
        if (hasShadow()) {
            CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(rect.width(), rect.height()), 0);
            CGContextRef layerContext = CGLayerGetContext(layer);
            m_state.fillGradient->paint(layerContext);
            CGContextDrawLayerAtPoint(context, CGPointMake(rect.left(), rect.top()), layer);
            CGLayerRelease(layer);
        } else {
            CGContextClipToRect(context, rect);
            m_state.fillGradient->paint(this);
        }
        CGContextRestoreGState(context);
        return;
    }

    if (m_state.fillPattern)
        applyFillPattern();
    CGContextFillRect(context, rect);
}
void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha)
{
    state().m_shadowOffset = FloatSize(width, height);
    state().m_shadowBlur = blur;
    state().m_shadowColor = color;

    GraphicsContext* c = drawingContext();
    if (!c)
        return;
    // FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
    RGBA32 rgba = CSSParser::parseColor(color);
    const CGFloat components[4] = {
        ((rgba >> 16) & 0xFF) / 255.0f,
        ((rgba >> 8) & 0xFF) / 255.0f,
        (rgba & 0xFF) / 255.0f,
        alpha
    };
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef shadowColor = CGColorCreate(colorSpace, components);
    CGColorSpaceRelease(colorSpace);
    CGContextSetShadowWithColor(c->platformContext(), CGSizeMake(width, height), blur, shadowColor);
    CGColorRelease(shadowColor);
#endif
}
// Missing glyphs run constructor. Core Text will not generate a run of missing glyphs, instead falling back on
// glyphs from LastResort. We want to use the primary font's missing glyph in order to match the fast text code path.
void ComplexTextController::ComplexTextRun::createTextRunFromFontDataCoreText(bool ltr)
{
    m_coreTextIndicesVector.reserveInitialCapacity(m_stringLength);
    unsigned r = 0;
    while (r < m_stringLength) {
        m_coreTextIndicesVector.uncheckedAppend(r);
        if (U_IS_SURROGATE(m_characters[r])) {
            ASSERT(r + 1 < m_stringLength);
            ASSERT(U_IS_SURROGATE_LEAD(m_characters[r]));
            ASSERT(U_IS_TRAIL(m_characters[r + 1]));
            r += 2;
        } else
            r++;
    }
    m_glyphCount = m_coreTextIndicesVector.size();
    if (!ltr) {
        for (unsigned r = 0, end = m_glyphCount - 1; r < m_glyphCount / 2; ++r, --end)
            std::swap(m_coreTextIndicesVector[r], m_coreTextIndicesVector[end]);
    }
    m_coreTextIndices = m_coreTextIndicesVector.data();

    // Synthesize a run of missing glyphs.
    m_glyphsVector.fill(0, m_glyphCount);
    m_glyphs = m_glyphsVector.data();
    m_advancesVector.fill(CGSizeMake(m_fontData->widthForGlyph(0), 0), m_glyphCount);
    m_advances = m_advancesVector.data();
}
示例#8
0
oop CGContextConvertSizeToUserSpace_wrap(CGContextRef c, float x, float y) {
  CGSize p = CGContextConvertSizeToUserSpace(c, CGSizeMake(x, y));
  objVectorOop r = Memory->objVectorObj->cloneSize(2);
  r->obj_at_put(0, as_floatOop(p.width),  false);
  r->obj_at_put(1, as_floatOop(p.height), false);
  return r;
}
void wkSetPatternPhaseInUserSpace(CGContextRef context, CGPoint phasePoint)
{
    CGAffineTransform userToBase = CGAffineTransformConcat(CGContextGetCTM(context),
        CGAffineTransformInvert(CGContextGetBaseCTM(context)));
    CGPoint phase = CGPointApplyAffineTransform(phasePoint, userToBase);
            
    CGContextSetPatternPhase(context, CGSizeMake(phase.x, phase.y));
}
示例#10
0
void CGContextSetShadowWithColor_wrap2(CGContext *con, float x, float y, float blur,
                                        float r, float g, float b, float a) {
  float comps[] = {r, g, b, a};
  CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
  CGColorRef c = CGColorCreate( cs, comps );
  CGContextSetShadowWithColor(con, CGSizeMake(x, y), blur, c);
  CGColorRelease(c);
  CGColorSpaceRelease(cs);
}
示例#11
0
CGSize PDFPageGetSize(CGPDFPageRef page, CGPDFBox box)
{
	CGRect boxRect = CGPDFPageGetBoxRect(page, box);
	int rotation = PDFPageGetRotation(page);
	bool invertSize = (rotation % 2) == 1;
	
	CGFloat width = invertSize ? CGRectGetHeight(boxRect) : CGRectGetWidth(boxRect);
	CGFloat height = invertSize ? CGRectGetWidth(boxRect) : CGRectGetHeight(boxRect);
	
	return CGSizeMake(width, height);
}
示例#12
0
void GraphicsContext::setShadow(const IntSize& size, int blur, const Color& color)
{
    // Extreme "blur" values can make text drawing crash or take crazy long times, so clamp
    blur = min(blur, 1000);

    if (paintingDisabled())
        return;
    // Check for an invalid color, as this means that the color was not set for the shadow
    // and we should therefore just use the default shadow color.
    CGContextRef context = platformContext();
    if (!color.isValid())
        CGContextSetShadow(context, CGSizeMake(size.width(), -size.height()), blur); // y is flipped.
    else {
        CGColorRef colorCG = cgColor(color);
        CGContextSetShadowWithColor(context,
                                    CGSizeMake(size.width(), -size.height()), // y is flipped.
                                    blur, 
                                    colorCG);
        CGColorRelease(colorCG);
    }
}
示例#13
0
//
// Stage 4 - Draw a 2K by 2K source image to an offscreen 512 x 512 CG Layer,
// effectively caching the original image. The test measures how fast drawing 
// the cached layer takes. The cache alleviates the time taken to color match the
// image and also time required to downsample the image. 
// This cache technique is useful when the image has to be repeatedly draw at the
// same scale. The difference between this test the previous is that the previous 
// performed the caching using a bitmap context. This one caches using a CGLayerRef.
// Notice that we don't need to know the colorspace or destination context's device
// specific information when creating a CG Layer. 
// The source image is created programattically as a gradient between colors.
// Returns: the number of operations per second for this stage
//
float drawStage4(CGContextRef context, CGRect rect)
{
    size_t numOperations;
    CGImageRef image;
    double delta;    
    int i;
    unsigned char *data;
    CGLayerRef lyr;
    CGContextRef lyrContext;
    
    data = createGradientARGBBuffer(W, H);
    if (data == NULL) return 0;
    
    // Create the source image from the data provider
    image = createImage(W, H, data);
    
    
    // Create a layer from the destination context. The layer is the best representation
    // for the layer. We have to specify the size of the layer we want to create 
    // in default userspace units. 
    lyr = CGLayerCreateWithContext(context,CGSizeMake(ScaledToWidth,ScaledToHeight),NULL);
    // Now we want to draw in to layer, so get the CGContext for the layer to draw to
    lyrContext = CGLayerGetContext(lyr);
    
    // Draw the 3K x 3K source image once to the layer context
    CGContextDrawImage(lyrContext, CGRectMake(0,0,ScaledToWidth,ScaledToHeight), image);
    CFRelease(image);	// Done with the image - now cached in the layer ref
    free(data);		// free the source data
    
    // Perform the drawing operation once to get an rough idea of how long it will take
    delta = currentTime();
        // Draw the contents of the layer to the destination
        CGContextDrawLayerAtPoint(context,CGPointMake(0,0),lyr);
    delta = currentTime() - delta;   
    
    // Calculate the approximage number of operations needed in one second
    numOperations = SecsPerTest / delta;
    
    // Now run the test again repeatedly
    delta = currentTime();
    
    for (i = 0 ; i < numOperations; i++) {
        // Draw the contents of the layer to the destination
        CGContextDrawLayerAtPoint(context,CGPointMake(0,0),lyr);
    }
    
    delta = currentTime() - delta;   
    
    CFRelease(lyr);	// done with the layer ref
    
    return (numOperations / delta);
}
示例#14
0
文件: cgbitmap.cpp 项目: DaniM/lyngo
//-----------------------------------------------------------------------------
CGLayerRef CGBitmap::createCGLayer (CGContextRef context)
{
	if (layer && !dirty)
		return layer;
	CGImageRef image = getCGImage ();
	layer = image ? CGLayerCreateWithContext (context, CGSizeMake (size.x, size.y), 0) : 0;
	if (layer)
	{
		CGContextRef layerContext = CGLayerGetContext (layer);
		CGContextDrawImage (layerContext, CGRectMake (0, 0, size.x, size.y), image);
	}
	return layer;
}
示例#15
0
文件: element.cpp 项目: JakimLi/kwm
bool AXLibSetWindowSize(AXUIElementRef WindowRef, int Width, int Height)
{
    bool Result = false;

    CGSize WindowSize = CGSizeMake(Width, Height);
    CFTypeRef WindowSizeRef = (CFTypeRef)AXValueCreate(kAXValueCGSizeType, (void*)&WindowSize);
    if(WindowSizeRef)
    {
        Result = AXLibSetWindowProperty(WindowRef, kAXSizeAttribute, WindowSizeRef);
        CFRelease(WindowSizeRef);
    }

    return Result;
}
示例#16
0
	bool CCLabelTTF::initWithString(const char *label, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
	{
		assert(label != NULL);
		if (CCSprite::init())
		{
			m_tDimensions = CGSizeMake( dimensions.width * CC_CONTENT_SCALE_FACTOR(), dimensions.height * CC_CONTENT_SCALE_FACTOR() );
			m_eAlignment = alignment;
			m_sFontName = fontName;
			m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR();
			this->setString(label);
			return true;
		}
		return false;
	}
OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize)
{
    // load the actual file
    CFDataRef fileData = nil;
    CFDictionaryRef propertyDictionary = nil;
    SInt32 errorCode;
    if (CFURLCreateDataAndPropertiesFromResource(NULL, url, &fileData, &propertyDictionary, nil, &errorCode)) {
        
        CFIndex dataLength = CFDataGetLength(fileData);
        UInt8 *bytes = (UInt8 *)CFDataGetBytePtr(fileData);
        long pages = dataLength / ONE_LCD_FRAME_BYTESIZE;
        CGSize lcdSize = CGSizeMake(LCD_FRAME_PIXEL_WIDTH, LCD_FRAME_PIXEL_HEIGHT * pages);
        CGContextRef cgContext = QLThumbnailRequestCreateContext(thumbnail, lcdSize, true, NULL);
        if(cgContext) {
            
            CGColorRef lcdForegroundColor = CGColorCreateGenericRGB(0.467, 0.522, 0.047, 1.000);
            CGColorRef lcdBackgroundColor = CGColorCreateGenericRGB(0.227, 0.192, 0.000, 1.000);
            CGContextSetFillColorWithColor(cgContext, lcdBackgroundColor);
            CGContextFillRect(cgContext, CGRectMake(0,0,lcdSize.width,lcdSize.height));
            
            CGPoint origin = CGPointMake(0,0);
            while (pages-- > 0) {
                CGContextSetFillColorWithColor(cgContext, lcdForegroundColor);
                //                CGContextFillRect(cgContext, CGRectMake(origin.x,origin.y,10,10));
                for (int y=0;y<9;y++) {
                    for (int x=0; x < LCD_FRAME_PIXEL_WIDTH; x++) {
                        UInt8 byte = bytes[y*LCD_FRAME_PIXEL_WIDTH + (LCD_FRAME_PIXEL_WIDTH - x - 1)];
                        if (byte > 0) {
                            UInt8 byteMask = 1;
                            for (int littleY = 0; littleY < 8; littleY++) {
                                if ((byte & (byteMask << littleY))) {
                                    CGContextFillRect(cgContext, CGRectMake(origin.x + x,origin.y + y*8 + littleY,1,1));
                                }
                            }
                        }
                    }
                }
                origin.y += 68;
                bytes    += ONE_LCD_FRAME_BYTESIZE;
            }
            
            // When we are done with our drawing code QLPreviewRequestFlushContext() is called to flush the context
            QLThumbnailRequestFlushContext(thumbnail, cgContext);
        }
        CFRelease(cgContext);
        CFRelease(fileData);
        CFRelease(propertyDictionary);
    }
    return noErr;
}
示例#18
0
文件: NDTile.cpp 项目: chaosren/HHHH
NDTile::NDTile()
: m_Texture(NULL)
, m_bReverse(false)
, m_Rotation(NDRotationEnumRotation0)
, m_vertices(NULL)
, m_coordinates(NULL)
{
	m_CutRect		= CGRectMake(0, 0, 0, 0);
	m_DrawRect		= CGRectMake(0, 0, 0, 0);
	m_MapSize		= CGSizeMake(0, 0);

	m_coordinates = (float *)malloc(sizeof(float) * 8);
	m_vertices = (float *)malloc(sizeof(float) * 12);
}
static inline CGSize adjustedShadowSize(CGFloat width, CGFloat height)
{
    // Work around <rdar://problem/5539388> by ensuring that shadow offsets will get truncated
    // to the desired integer.
    static const CGFloat extraShadowOffset = narrowPrecisionToCGFloat(1.0 / 128);
    if (width > 0)
        width += extraShadowOffset;
    else if (width < 0)
        width -= extraShadowOffset;

    if (height > 0)
        height += extraShadowOffset;
    else if (height < 0)
        height -= extraShadowOffset;

    return CGSizeMake(width, height);
}
void doPixelAlignedFillAndStroke(CGContextRef context)
{
    CGPoint p1 = CGPointMake(16.7, 17.8);
    CGPoint p2 = CGPointMake(116.7, 17.8);
    CGRect r = CGRectMake(16.7, 20.8, 100.6, 100.6);
    CGSize s;
    
    CGContextSetLineWidth(context, 2);
    CGContextSetRGBFillColor(context, 1., 0., 0., 1.);
    CGContextSetRGBStrokeColor(context, 1., 0., 0., 1.);
    
    // Unaligned drawing.
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, p1.x, p1.y);
    CGContextAddLineToPoint(context, p2.x, p2.y);
    CGContextStrokePath(context);
    CGContextFillRect(context, r);
    
    // Translate to the right before drawing along
    // aligned coordinates.
    CGContextTranslateCTM(context, 106, 0);
    
    // Aligned drawing.
    
    // Compute the length of the line in user space.
    s = CGSizeMake(p2.x - p1.x, p2.y - p1.y);
    
    CGContextBeginPath(context);
    // Align the starting point to a device
    // pixel boundary.
    p1 = alignPointToUserSpace(context, p1);
    // Establish the starting point of the line.
    CGContextMoveToPoint(context, p1.x, p1.y);
    // Compute the line length as an integer
    // number of device pixels.
    s = alignSizeToUserSpace(context, s);
    CGContextAddLineToPoint(context, 
				p1.x + s.width, 
				p1.y + s.height);
    CGContextStrokePath(context);
    // Compute a rect that is aligned to device
    // space with a width that is an integer
    // number of device pixels.
    r = alignRectToUserSpace(context, r);
    CGContextFillRect(context, r);
}
void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha)
{
    state().m_shadowOffset = FloatSize(width, height);
    state().m_shadowBlur = blur;
    state().m_shadowColor = "";

    GraphicsContext* c = drawingContext();
    if (!c)
        return;
    // FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
    const CGFloat components[2] = { grayLevel, alpha };
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
    CGColorRef color = CGColorCreate(colorSpace, components);
    CGColorSpaceRelease(colorSpace);
    CGContextSetShadowWithColor(c->platformContext(), CGSizeMake(width, height), blur, color);
    CGColorRelease(color);
#endif
}
void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a)
{
    state().m_shadowOffset = FloatSize(width, height);
    state().m_shadowBlur = blur;
    state().m_shadowColor = "";

    GraphicsContext* dc = drawingContext();
    if (!dc)
        return;
    // FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
    const CGFloat components[5] = { c, m, y, k, a };
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceCMYK();
    CGColorRef shadowColor = CGColorCreate(colorSpace, components);
    CGColorSpaceRelease(colorSpace);
    CGContextSetShadowWithColor(dc->platformContext(), CGSizeMake(width, height), blur, shadowColor);
    CGColorRelease(shadowColor);
#endif
}
示例#23
0
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
	CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url);
	if (!dataProvider) return -1;
	CFDataRef data = CGDataProviderCopyData(dataProvider);
	CGDataProviderRelease(dataProvider);
	if (!data) return -1;
	
	int width, height, channels;
	unsigned char* rgbadata = SOIL_load_image_from_memory(CFDataGetBytePtr(data), CFDataGetLength(data), &width, &height, &channels, SOIL_LOAD_RGBA);
	CFStringRef format=CFStringCreateWithBytes(NULL, CFDataGetBytePtr(data) + 0x54, 4, kCFStringEncodingASCII, false);
    CFRelease(data);
	if (!rgbadata) return -1;
	
	CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
	CGContextRef context = CGBitmapContextCreate(rgbadata, width, height, 8, width * 4, rgb, kCGImageAlphaPremultipliedLast);
	SOIL_free_image_data(rgbadata);
	CGColorSpaceRelease(rgb);
	if (!context) return -1;

	CGImageRef image = CGBitmapContextCreateImage(context);
	CGContextRelease(context);
	if (!image) return -1;

	/* Add basic metadata to title */
	CFStringRef name = CFURLCopyLastPathComponent(url);
	CFTypeRef keys[1] = {kQLPreviewPropertyDisplayNameKey};
	CFTypeRef values[1] = {CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%dx%d %@)"), name, width, height, format)};
 	CFDictionaryRef properties = CFDictionaryCreate(NULL, (const void**)keys, (const void**)values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	CFRelease(name);

	context = QLPreviewRequestCreateContext(preview, CGSizeMake(width, height), true, properties);
	CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
	QLPreviewRequestFlushContext(preview, context);
	
	CGContextRelease(context);
	CFRelease(format);
	CFRelease(properties);
	
	return noErr;
}
Screenshot* ScreenShooter::take_screenshot(const CFStringRef format, float compression) {
  CGImageRef* images = new CGImageRef[_dsp_count];
   
  /* Grab the images */
  for (unsigned int i = 0; i < _dsp_count; i++) {
     images[i] = CGDisplayCreateImage(_displays[i]);
  }

  /* Calculate size of image to produce */
  CGSize finalSize = CGSizeMake(_top_right.x - _bottom_left.x, _bottom_left.y - _top_right.y);

  /* Round out the bitmap size information */
  size_t bytesPerRow = finalSize.width * CGImageGetBitsPerPixel(images[0]) / 8;

  /* Create context around bitmap */
  CGContextRef context = CGBitmapContextCreate(
    NULL, finalSize.width, finalSize.height,
    CGImageGetBitsPerComponent(images[0]), bytesPerRow,
    CGImageGetColorSpace(images[0]), CGImageGetBitmapInfo(images[0])
  );

  /* Draw images into the bitmap */
  for (unsigned int i = 0; i < _dsp_count; i++)
  {
      /* Adjust the positions to account for coordinate system shifts
         (displays origin is at top left; image origin is at bottom left) */
      CGRect adjustedPoint = CGRectMake(_display_bounds[i].origin.x - _bottom_left.x,
                                        _bottom_left.y - _display_bounds[i].size.height - _display_bounds[i].origin.y,
                                        _display_bounds[i].size.width,
                                        _display_bounds[i].size.height);
      CGContextDrawImage(context, adjustedPoint, images[i]);
  }
  
  delete [] images;

  return new Screenshot(context, format, compression);
}
void GetAspectFillVertices(CGSize viewSize, CGSize frameSize,
                           GLfloat *vertices/*[8]*/,
                           GLfloat *textureVertices/*[8]*/) {
    // Preserve aspect ratio; fill layer bounds
    CGSize samplingSize;
    CGSize scaleRatio = CGSizeMake( viewSize.width / frameSize.width,
                                   viewSize.height / frameSize.height );
    if ( scaleRatio.height > scaleRatio.width ) {
        samplingSize.width = viewSize.width / ( frameSize.width * scaleRatio.height );
        samplingSize.height = 1.0;
    }
    else {
        samplingSize.width = 1.0;
        samplingSize.height = viewSize.height / ( frameSize.height * scaleRatio.width );
    }

    vertices[0] = -1.0;  // bottom left
    vertices[1] = -1.0;
    vertices[2] =  1.0;  // bottom right
    vertices[3] = -1.0;
    vertices[4] = -1.0;  // top left
    vertices[5] =  1.0;
    vertices[6] =  1.0;  // top right
    vertices[7] =  1.0;

    // Perform a vertical flip by swapping the top left and the bottom left coordinate.
    // CVPixelBuffers have a top left origin and OpenGL has a bottom left origin.
    textureVertices[0] = ( 1.0 - samplingSize.width )  / 2.0; // top left
    textureVertices[1] = ( 1.0 + samplingSize.height ) / 2.0;
    textureVertices[2] = ( 1.0 + samplingSize.width )  / 2.0; // top right
    textureVertices[3] = ( 1.0 + samplingSize.height ) / 2.0;
    textureVertices[4] = ( 1.0 - samplingSize.width )  / 2.0; // bottom left
    textureVertices[5] = ( 1.0 - samplingSize.height ) / 2.0;
    textureVertices[6] = ( 1.0 + samplingSize.width )  / 2.0; // bottom right
    textureVertices[7] = ( 1.0 - samplingSize.height ) / 2.0;
}
示例#26
0
GlyphBufferAdvance HarfBuzzShaper::createGlyphBufferAdvance(float width, float height)
{
    return CGSizeMake(width, height);
}
void x_async_refresh(CGContextRef myContext,CGRect myBoundingBox)
{
	
#ifdef ENABLEQD
	CEmulatorMac* pEmu = (CEmulatorMac*)CEmulator::theEmulator;
	if (!pEmu) return ;
#endif
    
#ifndef DRIVER_IOS
	x_vbl_count++;
#endif
	
	addFrameRate(0);

	CHANGE_BORDER(1,0xFF);
	
	// OG
	if (macUsingCoreGraphics)
	{
		if(r_sim65816.is_emulator_offscreen_available() && g_kimage_offscreen.dev_handle)
		{
	
            /*
			void addConsoleWindow(Kimage* _dst);
			addConsoleWindow(&g_kimage_offscreen);
	*/
            
			CGContextSaveGState(myContext);
			
#ifndef DRIVER_IOS
		//	CGContextTranslateCTM(myContext,0.0, X_A2_WINDOW_HEIGHT);
        	CGContextTranslateCTM(myContext,0.0, myBoundingBox.size.height);    
			CGContextScaleCTM(myContext,1.0,-1.0);
#endif
			
			
			CGImageRef myImage = CGBitmapContextCreateImage((CGContextRef)g_kimage_offscreen.dev_handle);
            
            
            
			CGContextDrawImage(myContext, myBoundingBox, myImage);// 6
	
#ifndef VIDEO_SINGLEVLINE
			if (r_sim65816.get_video_fx() == VIDEOFX_CRT)
			{
                

				CGContextSetRGBFillColor(myContext,0,0,0,0.5);
				for(int h=0;h<g_kimage_offscreen.height;h+=2)
				{
					CGRect r = CGRectMake(0,h,g_kimage_offscreen.width_act,1);
					CGContextFillRect(myContext,r);
				}
                
			}            
           
#endif
            
			CGImageRelease(myImage);
		
			CGContextRestoreGState(myContext);
#ifndef DRIVER_IOS
			if (!messageLine.IsEmpty())
			{
				CGContextSaveGState(myContext);
				CGContextSetTextMatrix(myContext,CGAffineTransformIdentity);
				CGContextTranslateCTM(myContext,0.0, X_A2_WINDOW_HEIGHT);
				CGContextScaleCTM(myContext,1.0,-1.0);

				CGContextSelectFont(myContext, "Courier", 14.0, kCGEncodingMacRoman);
				CGContextSetTextDrawingMode(myContext, kCGTextFill);
				CGContextSetRGBFillColor (myContext, 1,1, 1, 1);
				CGContextSetShouldAntialias(myContext, true);
#define SHADOW 4.0
                

                CGFloat           myColorValues[] = {0.5, 0.5, 0.5, 1.0};
                
               
                CGColorSpaceRef  myColorSpace = CGColorSpaceCreateDeviceRGB ();// 9
                 CGColorRef  myColor = CGColorCreate (myColorSpace, myColorValues);
				CGContextSetShadowWithColor(myContext, CGSizeMake(SHADOW, -SHADOW), 4,
                                            myColor
                                            //CGColorCreateGenericGray(0.5,1.0)
                    
                                            );
				CGContextShowTextAtPoint(myContext, 20.0, X_A2_WINDOW_HEIGHT-20.0, messageLine.c_str(), messageLine.GetLength());
			
				CGContextRestoreGState(myContext);
				messageLineVBL--;
				if (messageLineVBL<0)
					messageLine.Empty();
				else 
					x_refresh_video();

			}
#endif
			
		}
		else
		{
			CGContextSaveGState(myContext);
#if defined(DRIVER_IOS)
            // efface en noir si l'émulateur n'avait pas encore démarré (le cas sur 3GS)
			CGContextSetRGBFillColor (myContext, 0, 0, 0, 1);
#else
            CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
#endif
			CGContextFillRect (myContext, CGRectMake (0, 0, X_A2_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT));

			CGContextRestoreGState(myContext);

		}
		
	}
	else
	{
#ifdef ENABLEQD
		CGrafPtr window_port = pEmu->window_port;
		Rect src_rect;
		Rect dest_rect;
		SetRect(&src_rect,0,0,704,462);
		SetRect(&dest_rect,0,0,704,462);
		
		if (pixmap_backbuffer)
			CopyBits( (BitMap *)(*pixmap_backbuffer),
					 GetPortBitMapForCopyBits(window_port), &src_rect, &dest_rect,
					 srcCopy, NULL);
		
#endif
	}
	
	
	CHANGE_BORDER(1,0);
    
    if (r_sim65816.is_emulator_offscreen_available() && g_driver.x_handle_state_on_paint)
        g_driver.x_handle_state_on_paint(myBoundingBox.size.width,myBoundingBox.size.height);

}
IntSize::operator CGSize() const
{
    return CGSizeMake(m_width, m_height);
}
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
{
    graphicsContext->save();
    
    wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());

    wxFont* wxfont = font->getWxFont();
    graphicsContext->setFillColor(graphicsContext->fillColor(), DeviceColorSpace);

    CGContextRef cgContext = static_cast<CGContextRef>(dc->GetGraphicsContext()->GetNativeContext());

    CGFontRef cgFont;

#ifdef wxOSX_USE_CORE_TEXT && wxOSX_USE_CORE_TEXT
    cgFont = CTFontCopyGraphicsFont((CTFontRef)wxfont->OSXGetCTFont(), NULL);
#else
    ATSFontRef fontRef;
    
    fontRef = FMGetATSFontRefFromFont(wxfont->MacGetATSUFontID());
    
    if (fontRef)
        cgFont = CGFontCreateWithPlatformFont((void*)&fontRef);
#endif
    
    CGContextSetFont(cgContext, cgFont);

    CGContextSetFontSize(cgContext, wxfont->GetPointSize());

    CGFloat red, green, blue, alpha;
    graphicsContext->fillColor().getRGBA(red, green, blue, alpha);
    CGContextSetRGBFillColor(cgContext, red, green, blue, alpha);

    CGAffineTransform matrix = CGAffineTransformIdentity;
    matrix.b = -matrix.b;
    matrix.d = -matrix.d;
    
    CGContextSetTextMatrix(cgContext, matrix);

    CGContextSetTextPosition(cgContext, point.x(), point.y());
    
    const FloatSize* advanceSizes = static_cast<const FloatSize*>(glyphBuffer.advances(from));
    int size = glyphBuffer.size() - from;
    CGSize sizes[size];
    CGGlyph glyphs[numGlyphs];
    
    // if the function doesn't exist, we're probably on tiger and need to grab the
    // function under its old name, CGFontGetGlyphsForUnicodes
    if (!CGFontGetGlyphsForUnichars)
        CGFontGetGlyphsForUnichars = (CGFontGetGlyphsForUnicharsPtr)dlsym(RTLD_DEFAULT, "CGFontGetGlyphsForUnicodes");
    
    // Let's make sure we got the function under one name or another!
    ASSERT(CGFontGetGlyphsForUnichars);
    CGFontGetGlyphsForUnichars(cgFont, glyphBuffer.glyphs(from), glyphs, numGlyphs);
    
    for (int i = 0; i < size; i++) {
        FloatSize fsize = advanceSizes[i];
        sizes[i] = CGSizeMake(fsize.width(), fsize.height());
    }
    
    CGContextShowGlyphsWithAdvances(cgContext, glyphs, sizes, numGlyphs);
    
    if (cgFont)
        CGFontRelease(cgFont);
    graphicsContext->restore();
}
示例#30
0
static void initNeedle(unsigned w, unsigned h, unsigned max)
{
    CGColorSpaceRef colorspace;
    CGContextRef  gc;
    unsigned char *data;
    float cx, cy;
    float angle, radius, needle;

    data = (unsigned char *)malloc(w * h * 4);

    colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    gc         = CGBitmapContextCreate(data, w, h, 8, w * 4, colorspace,
                                   kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);


    cx    = CENTERX * w;
    cy    = CENTERY * h;
    radius = 0.5 * (w > h ? w : h);
    needle = radius * 0.85;

    CGContextTranslateCTM(gc, 0.0, h);
    CGContextScaleCTM(gc, 1.0, -1.0);
    CGContextClearRect(gc, CGRectMake(0, 0, w, h));
    angle = 0;//angleForValue(0, max);

    {
        // draw glow reflecting on inner bevel
        float    dx, dy;
        dx         = -cos(angle) + 1;
        dy         = -sin(angle) + 1;

        CGGradientRef gradient;
        size_t num_locations = 2;
        CGFloat locations[2] = { 0.0, 1.0 };
        CGFloat components[8] = { 0.7, 0.7, 1.0, 0.7,  // Start color
                                  0.0, 0.0, 0.0, 0.0
                                }; // End color

        gradient = CGGradientCreateWithColorComponents (colorspace, components,
                   locations, num_locations);
        CGContextSaveGState(gc);
        CGContextAddArc(gc, cx, cy, needle*1.05, 0, 2*M_PI, false);
        CGContextAddArc(gc, cx, cy, needle*0.96, 0, 2*M_PI, false);
        CGContextEOClip(gc);
        CGContextDrawRadialGradient (gc, gradient,
                                     CGPointMake(cx*dx, cy*dy), radius*0.1,
                                     CGPointMake(cx*1.0, cy*1.0), radius*1.0, 0);
        CGContextRestoreGState(gc);
    }

    CGContextSetRGBFillColor(gc, 0.9, 0.9, 1.0, 1.0);

    // draw several glow passes, with the content offscreen
    CGContextTranslateCTM(gc, 0, OFFSCREEN - 10);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, 0, 20);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, -10, -10);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, 20, 0);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, -10, -OFFSCREEN);

    // draw real content
    CGContextSetShadowWithColor(gc, CGSizeMake(0, 1), 6.0, CGColorCreateGenericRGB(0.0, 0.0, 0.5, 0.7));
    drawNeedle(gc, w, h, angle);

    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);

    CGContextRelease(gc);
    CGColorSpaceRelease(colorspace);
    free(data);
}