jsval long_to_jsval( JSContext *cx, long number ) { #ifdef __LP64__ NSCAssert( sizeof(long)==8, @"Error!"); char chr[128]; snprintf(chr, sizeof(chr)-1, "%ld", number); JSString *ret_obj = JS_NewStringCopyZ(cx, chr); return STRING_TO_JSVAL(ret_obj); #else CCAssert( sizeof(int)==4, "Error!"); return INT_TO_JSVAL(number); #endif }
static void _GraphicsScreen_imageFromFile (GraphicsScreen me, const wchar_t *relativeFileName, double x1, double x2, double y1, double y2) { long x1DC = wdx (x1), x2DC = wdx (x2), y1DC = wdy (y1), y2DC = wdy (y2); long width = x2DC - x1DC, height = my yIsZeroAtTheTop ? y1DC - y2DC : y2DC - y1DC; #if 0 structMelderFile file = { 0 }; Melder_relativePathToFile (relativeFileName, & file); try { autoPhoto photo = Photo_readFromImageFile (& file); if (x1 == x2 && y1 == y2) { width = photo -> nx, x1DC -= width / 2, x2DC = x1DC + width; height = photo -> ny, y2DC -= height / 2, y1DC = y2DC + height; } else if (x1 == x2) { width = height * (double) photo -> nx / (double) photo -> ny; x1DC -= width / 2, x2DC = x1DC + width; } else if (y1 == y2) { height = width * (double) photo -> ny / (double) photo -> nx; y2DC -= height / 2, y1DC = y2DC + height; } autoNUMmatrix <double_rgbt> z (1, photo -> ny, 1, photo -> nx); for (long iy = 1; iy <= photo -> ny; iy ++) { for (long ix = 1; ix <= photo -> nx; ix ++) { z [iy] [ix]. red = photo -> d_red -> z [iy] [ix]; z [iy] [ix]. green = photo -> d_green -> z [iy] [ix]; z [iy] [ix]. blue = photo -> d_blue -> z [iy] [ix]; z [iy] [ix]. transparency = photo -> d_transparency -> z [iy] [ix]; } } _cellArrayOrImage (me, NULL, z.peek(), NULL, 1, photo -> nx, x1DC, x2DC, 1, photo -> ny, y1DC, y2DC, 0.0, 1.0, //wdx (my d_x1WC), wdx (my d_x2WC), wdy (my d_y1WC), wdy (my d_y2WC), // in case of clipping LONG_MIN, LONG_MAX, LONG_MAX, LONG_MIN, // in case of no clipping true); } catch (MelderError) { Melder_clearError (); } #elif win if (my d_useGdiplus) { structMelderFile file = { 0 }; Melder_relativePathToFile (relativeFileName, & file); Gdiplus::Bitmap image (file. path); if (x1 == x2 && y1 == y2) { width = image. GetWidth (), x1DC -= width / 2, x2DC = x1DC + width; height = image. GetHeight (), y2DC -= height / 2, y1DC = y2DC + height; } else if (x1 == x2) { width = height * (double) image. GetWidth () / (double) image. GetHeight (); x1DC -= width / 2, x2DC = x1DC + width; } else if (y1 == y2) { height = width * (double) image. GetHeight () / (double) image. GetWidth (); y2DC -= height / 2, y1DC = y2DC + height; } Gdiplus::Graphics dcplus (my d_gdiGraphicsContext); Gdiplus::Rect rect (x1DC, y2DC, width, height); dcplus. DrawImage (& image, rect); } else { } #elif mac structMelderFile file = { 0 }; Melder_relativePathToFile (relativeFileName, & file); char utf8 [500]; Melder_wcsTo8bitFileRepresentation_inline (file. path, utf8); CFStringRef path = CFStringCreateWithCString (NULL, utf8, kCFStringEncodingUTF8); CFURLRef url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, false); CFRelease (path); CGImageSourceRef imageSource = CGImageSourceCreateWithURL (url, NULL); CFRelease (url); if (imageSource != NULL) { CGImageRef image = CGImageSourceCreateImageAtIndex (imageSource, 0, NULL); CFRelease (imageSource); if (image != NULL) { if (x1 == x2 && y1 == y2) { width = CGImageGetWidth (image), x1DC -= width / 2, x2DC = x1DC + width; height = CGImageGetHeight (image), y2DC -= height / 2, y1DC = y2DC + height; } else if (x1 == x2) { width = height * (double) CGImageGetWidth (image) / (double) CGImageGetHeight (image); x1DC -= width / 2, x2DC = x1DC + width; } else if (y1 == y2) { height = width * (double) CGImageGetHeight (image) / (double) CGImageGetWidth (image); y2DC -= height / 2, y1DC = y2DC + height; } GraphicsQuartz_initDraw (me); CGContextSaveGState (my d_macGraphicsContext); NSCAssert(my d_macGraphicsContext, @"nil context"); CGContextTranslateCTM (my d_macGraphicsContext, 0, y1DC); CGContextScaleCTM (my d_macGraphicsContext, 1.0, -1.0); CGContextDrawImage (my d_macGraphicsContext, CGRectMake (x1DC, 0, width, height), image); CGContextRestoreGState (my d_macGraphicsContext); GraphicsQuartz_exitDraw (me); CGImageRelease (image); } } #endif }