
-
JonB
No, you never worked with a self installed numpy. If you imported numpy, then tried to install using stash/pip, you would have been able to keep using the old numpy until you force quit pythonista (or iOS kills it).
@bennr01 I thought pip had a blacklist now to prevent numpy installation?
-
JonB
Let's try this again....
** DO NOT INSTALL NUMPY.**
Pythonista already comes with a version of numpy. It cannot be updated.
-
JonB
Another way to avoid the pain of meteor creation is to reuse the destroyed meteors (or meteors far outside of the game area)
Just like you pop a meteor when you want to use it, push it back (maybe better to use a queue -- pop_right and push_left). You can change the size when you push it back, and reinitialize the position, speed, etc. That way you only ever need queues as long as the number that can be onscreen at one time -- rather than creating 1000 at a time, I have to think that 1000 is more than enough if you reuse them.
Note you can also change the texture of a sprite (with a stored version of a Texture), and that's got to be faster than creating a whole new object.
-
JonB
Delete your numpy module in site packages, restart pythonista, make sure you don't have a file called numpy.py in the path that you are trying to import from.
Then, force quit pythonista, import numpy, wait (don't hit "X"), and if you still have an error, copy the entire traceback and paste it back here. Numpy as delivered with pythonista lives in Modules/standard library 3.6/site-packages, which is not writable (unless you are jailbbroken), so if it worked before, it will work again :)
If all else fails, copy stuff you want to keep from Documents to iCloud, then uninstall/reinstall pythonista, and copy back from iCloud. I think twice in many years, I have had some strange corruption in the write only areas that was only solved by a reinstall.
-
JonB
Go to Modules & Packages, then site-packages (or maybe site-packages-3), find the nupy folde, and delete it.
You cannot update numpy on pythonista. Numpy is written in fortran. IOS does not have a fortran compiler, or allow you to compile without a developer key, or run code in an app signed by a different developer. So the only way to update numpy is for the developer to update, and that has not been a priority.
-
JonB
have you tried the later example further down in that thread?
you will also need to disable the idle timer (in console module) to keep pythonista from getting backgrounded while unattended.
-
JonB
I read somewhere that webp is not supported on iOS. Or, possibly, that newer safari versions might support display of webp, but I doubt that writing webp has been implemented in CGDestinationCreate.
Found this on GitHub:
// kUTTypeWebP seems not defined in public UTI framework, Apple use the hardcode string, we define them :) #define kSDUTTypeWebP ((__bridge CFStringRef)@"org.webmproject.webp")
So, you might try
ns('org.webmproject.webp')
.but again no guarantee that iOS can write webp without libwebm or freeimage or some other library.
-
JonB
@cvp You did the heavy lifting . A minor update above adds the quality parameter (at quality=1, lenna is 445kB. at 0, it is 3kB...
-
JonB
You were really close! CGDestnationXXX() takes imagedest as first param. ine of the signatures was wrong (needed a size_t), and the kUTType ought to be an nsstring.
This seems to work!
(edit: refactored into a convienent function)
(edit again, fixed a typo, added quality)''' https://stackoverflow.com/questions/19749482/how-do-i-convert-uiimage-to-j2k-jpeg2000-in-ios #import <ImageIO/ImageIO.h> // or @import ImageIO if modules enabled #import <MobileCoreServices/MobileCoreServices.h> // ... // quality is 0-1 (0 = smallest file size, 1 = lossless quality) + (NSData*) convertToJPEG2000:(UIImage*)image withQuality:(float)quality { NSMutableData* d = [NSMutableData data]; CGImageDestinationRef destinationRef = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)d, kUTTypeJPEG2000, 1, NULL); CGImageDestinationSetProperties(destinationRef, NULL); CGImageDestinationAddImage(destinationRef, image.CGImage, (__bridge CFDictionaryRef)@{ (NSString*)kCGImageDestinationLossyCompressionQuality: @(quality) }); if (!CGImageDestinationFinalize(destinationRef)) { d = nil; } CFRelease(destinationRef); return d; } ''' from objc_util import * import ctypes import time import ui load_framework('ImageIO') CGImageDestinationCreateWithData = c.CGImageDestinationCreateWithData CGImageDestinationCreateWithData.restype = c_void_p CGImageDestinationCreateWithData.argtypes = [c_void_p, c_void_p, ctypes.c_size_t, c_void_p] CGImageDestinationSetProperties = c.CGImageDestinationSetProperties CGImageDestinationSetProperties.restype = None CGImageDestinationSetProperties.argtypes = [c_void_p, c_void_p] CGImageDestinationAddImage = c.CGImageDestinationAddImage CGImageDestinationAddImage.restype = None CGImageDestinationAddImage.argtypes = [c_void_p, c_void_p, c_void_p] CGImageDestinationFinalize=c.CGImageDestinationFinalize CGImageDestinationFinalize.restype=ctypes.c_int CGImageDestinationFinalize.argtypes=[c_void_p] CFRelease = c.CFRelease CFRelease.restype = None CFRelease.argtypes = [c_void_p] kUTTypeJPEG2000 = c_void_p.in_dll(c,'kUTTypeJPEG2000') # UTI for a Jpeg2000 kCGImageDestinationLossyCompressionQuality=c_void_p.in_dll(c,'kCGImageDestinationLossyCompressionQuality') '''def convert_image_to_jpeg2000(uiimg, out_filename, quality=1): uiimage=ui.Image out_filename=str quality: 0=smallest, 1=lossless''' def convert_image_to_jpeg2000(uiimg, out_filename, quality=1): d = NSMutableData.new() imagedest = CGImageDestinationCreateWithData(d, kUTTypeJPEG2000, 1, None) CGImageDestinationSetProperties(imagedest, None) #img = ui.Image.named('test:Peppers').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL).objc_instance CGImageDestinationAddImage(imagedest, uiimg.objc_instance.CGImage(),ns({'kCGImageDestinationLossyCompressionQuality':quality})) if not CGImageDestinationFinalize(imagedest): raise Exception('Image Conversion Failed') CFRelease(imagedest) with open(out_filename,'wb') as f: f.write(nsdata_to_bytes(d)) if __name__=='__main__': img=ui.Image.named('test:Lenna') convert_image_to_jpeg2000(img, 'lenna.j2k',0) import console console.quicklook('lenna.j2k') print('success!' )
-
JonB
I believe that CGCreateDestination supports writing to j2k.
https://stackoverflow.com/questions/19749482/how-do-i-convert-uiimage-to-j2k-jpeg2000-in-ios