const void *Image::GetData(std::size_t *out_data_size) { out_data_size = 0; if (!image_) return NULL; if (IsLoading()) { return NULL; } return sp_image_data(image_, out_data_size); }
static void image_loaded(sp_image *img, void *user) { gazify_t *g = (gazify_t*)user; size_t img_size; const void *data = sp_image_data(img,&img_size); sp_artist *a = sp_track_artist(g->current_t,0); sp_album *alb = sp_track_album(g->current_t); g->g->postTrackInfo(sp_artist_name(a),sp_album_name(alb),sp_track_name(g->current_t),data,img_size); //sp_image_remove_load_callback(img,&image_loaded,user); // sp_image_release(img); //fiuckit, let's leak! }
static void _track_write_image_to_file(sp_image* img, gpointer data) { GError* err = NULL; const guchar* img_data = NULL; gsize len; gchar* filename = (gchar*) data; img_data = sp_image_data(img, &len); if (!img_data) g_error("Can't read image data"); g_debug("Saving image to %s", filename); if (!g_file_set_contents(filename, (gchar*) img_data, len, &err)) g_error("Can't save image to file: %s", err->message); g_free(filename); sp_image_release(img); }
void QSpotifySession::receiveImageResponse(sp_image *image) { Q_ASSERT(image); qDebug() << "QSpotifySession::receiveImageResponse"; sp_image_remove_load_callback(image, callback_image_loaded, 0); QString id = g_imageRequestObject.take(image); QImage im; if (sp_image_error(image) == SP_ERROR_OK) { size_t dataSize; const void *data = sp_image_data(image, &dataSize); im = QImage::fromData(reinterpret_cast<const uchar *>(data), dataSize, "JPG"); } sp_image_release(image); g_imageRequestMutex.lock(); g_imageRequestImages.insert(id, im); g_imageRequestConditions[id]->wakeAll(); g_imageRequestMutex.unlock(); }
gboolean track_get_image_data(sp_track* track, gpointer* data, gsize* len) { sp_image* img; const guchar* img_data = NULL; img = track_get_image(track); if (!img) { /* No cover */ *data = NULL; *len = 0; return TRUE; } if (!sp_image_is_loaded(img)) return FALSE; img_data = sp_image_data(img, len); if (!img_data) g_error("Can't read image data"); *data = g_memdup(img_data, *len); sp_image_release(img); return TRUE; }
PHP_METHOD(SpotifyArtist, getPortrait) { int timeout = 0; zval *index, *object = getThis(); spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(object TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { return; } zval tempretval, *thisptr = getThis(); SPOTIFY_METHOD(SpotifyArtist, browse, &tempretval, thisptr); int numportraits = sp_artistbrowse_num_portraits(p->artistbrowse); if(Z_LVAL_P(index) > numportraits) { RETURN_FALSE; } const byte* image_id = sp_artistbrowse_portrait(p->artistbrowse, Z_LVAL_P(index)); sp_image *image = sp_image_create(p->session, image_id); while(!sp_image_is_loaded(image)) { sp_session_process_events(p->session, &timeout); } size_t size; const byte* image_data = sp_image_data(image, &size); RETURN_STRINGL(image_data, size, 1); sp_image_release(image); }
JNIEXPORT int JNICALL Java_jahspotify_impl_JahSpotifyImpl_readImage (JNIEnv *env, jobject obj, jstring uri, jobject outputStream) { uint8_t *nativeURI = ( uint8_t * ) ( *env )->GetStringUTFChars ( env, uri, NULL ); sp_link *imageLink = sp_link_create_from_string(nativeURI); size_t size; jclass jClass; int numBytesWritten = -1; if (imageLink) { sp_link_add_ref(imageLink); sp_image *image = sp_image_create_from_link(g_sess,imageLink); if (image) { sp_image_add_ref(image); sp_image_add_load_callback(image, imageLoadedCallback, NULL); int count = 0; while (!sp_image_is_loaded(image) && count < 5) { sleep(1); count++; } if (count == 5) { fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_readImage: Timeout waiting for image to load ...\n"); sp_image_release(image); sp_link_release(imageLink); return -1; } byte *data = (byte*)sp_image_data(image,&size); jClass = (*env)->FindClass(env,"Ljava/io/OutputStream;"); if (jClass == NULL) { fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_readImage: could not load class java.io.OutputStream\n"); return -1; } // Lookup the method now - saves us looking it up for each iteration of the loop jmethodID jMethod = (*env)->GetMethodID(env,jClass,"write","(I)V"); if (jMethod == NULL) { fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_readImage: could not load method write(int) on class java.io.OutputStream\n"); return -1; } int i = 0; for (i = 0; i < size; i++) { (*env)->CallVoidMethod(env,outputStream,jMethod,*data); data++; numBytesWritten++; } sp_image_release(image); } sp_link_release(imageLink); } // Plus one because we start at -1 return numBytesWritten+1; }
static PyObject *Image_data(Image *self) { size_t data_size; void *ptr; ptr = sp_image_data(self->_image, &data_size); return PyBuffer_FromMemory(ptr, data_size); }