@@ -183,11 +183,36 @@ static GdkPixbuf *icon_pixbuf_scale_to_size(GdkPixbuf *pixbuf, double dpi_scale,
183183 return pixbuf ;
184184}
185185
186- GdkPixbuf * get_pixbuf_from_file (const char * filename , int min_size , int max_size , double scale )
186+ static char * get_id_from_data (const uint8_t * data_pb , size_t width , size_t height , size_t pixelstride , size_t rowstride )
187+ {
188+ /* To calculate a checksum of the current image, we have to remove
189+ * all excess spacers, so that our checksummed memory only contains
190+ * real data. */
191+
192+ size_t data_chk_len = pixelstride * width * height ;
193+ unsigned char * data_chk = g_malloc (data_chk_len );
194+ size_t rowstride_short = pixelstride * width ;
195+
196+ for (int i = 0 ; i < height ; i ++ ) {
197+ memcpy (data_chk + (i * rowstride_short ),
198+ data_pb + (i * rowstride ),
199+ rowstride_short );
200+ }
201+
202+ char * id = g_compute_checksum_for_data (G_CHECKSUM_MD5 , data_chk , data_chk_len );
203+ g_free (data_chk );
204+
205+ return id ;
206+ }
207+
208+ GdkPixbuf * get_pixbuf_from_file (const char * filename , char * * id , int min_size , int max_size , double scale )
187209{
188210 GError * error = NULL ;
189211 gint w , h ;
190212
213+ ASSERT_OR_RET (filename , NULL );
214+ ASSERT_OR_RET (id , NULL );
215+
191216 if (!gdk_pixbuf_get_file_info (filename , & w , & h )) {
192217 LOG_W ("Failed to load image info for %s" , STR_NN (filename ));
193218 return NULL ;
@@ -206,6 +231,13 @@ GdkPixbuf *get_pixbuf_from_file(const char *filename, int min_size, int max_size
206231 g_error_free (error );
207232 }
208233
234+ const uint8_t * data = gdk_pixbuf_get_pixels (pixbuf );
235+ size_t rowstride = gdk_pixbuf_get_rowstride (pixbuf );
236+ size_t n_channels = gdk_pixbuf_get_n_channels (pixbuf );
237+ size_t bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf );
238+ size_t pixelstride = (n_channels * bits_per_sample + 7 )/8 ;
239+
240+ * id = get_id_from_data (data , w , h , pixelstride , rowstride );
209241 return pixbuf ;
210242}
211243
@@ -366,22 +398,9 @@ GdkPixbuf *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int mi
366398 return NULL ;
367399 }
368400
369- /* To calculate a checksum of the current image, we have to remove
370- * all excess spacers, so that our checksummed memory only contains
371- * real data. */
372- size_t data_chk_len = pixelstride * width * height ;
373- unsigned char * data_chk = g_malloc (data_chk_len );
374- size_t rowstride_short = pixelstride * width ;
375-
376- for (int i = 0 ; i < height ; i ++ ) {
377- memcpy (data_chk + (i * rowstride_short ),
378- data_pb + (i * rowstride ),
379- rowstride_short );
380- }
381401
382- * id = g_compute_checksum_for_data ( G_CHECKSUM_MD5 , data_chk , data_chk_len );
402+ * id = get_id_from_data ( data_pb , width , height , pixelstride , rowstride );
383403
384- g_free (data_chk );
385404 g_variant_unref (data_variant );
386405
387406 pixbuf = icon_pixbuf_scale_to_size (pixbuf , dpi_scale , min_size , max_size );
0 commit comments