Commit 72bd0382 authored by Debarshi Ray's avatar Debarshi Ray

Add photos_gegl_compute_checksum_for_buffer

GNOME/gnome-photos!84
parent 085e6634
/*
* Photos - access, organize and share your photos on GNOME
* Copyright © 2013 – 2017 Red Hat, Inc.
* Copyright © 2013 – 2018 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -507,6 +507,55 @@ photos_gegl_buffer_zoom_finish (GeglBuffer *buffer, GAsyncResult *res, GError **
}
gchar *
photos_gegl_compute_checksum_for_buffer (GChecksumType checksum_type, GeglBuffer *buffer)
{
const Babl *format;
g_autoptr (GChecksum) checksum = NULL;
GeglRectangle bbox;
GeglRectangle roi;
const gchar *str;
gchar *ret_val = NULL;
gint bpp;
gint i;
gint stride;
g_autofree guchar *buf = NULL;
checksum = g_checksum_new (checksum_type);
if (checksum == NULL)
goto out;
bbox = *gegl_buffer_get_extent (buffer);
roi.x = bbox.x;
roi.y = bbox.y;
roi.height = 1;
roi.width = bbox.width;
format = gegl_buffer_get_format (buffer);
bpp = babl_format_get_bytes_per_pixel (format);
if (bpp > 0 && bbox.width > 0 && bbox.width > G_MAXINT / bpp)
goto out;
stride = bpp * bbox.width;
buf = (guchar *) g_malloc0_n ((gsize) bbox.width, (gsize) bpp);
for (i = 0; i < bbox.height; i++)
{
gegl_buffer_get (buffer, &roi, 1.0, format, buf, stride, GEGL_ABYSS_NONE);
g_checksum_update (checksum, buf, (gssize) stride);
roi.y++;
}
str = g_checksum_get_string (checksum);
ret_val = g_strdup (str);
out:
return ret_val;
}
GdkPixbuf *
photos_gegl_create_pixbuf_from_node (GeglNode *node)
{
......
/*
* Photos - access, organize and share your photos on GNOME
* Copyright © 2013 – 2017 Red Hat, Inc.
* Copyright © 2013 – 2018 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -39,6 +39,8 @@ void photos_gegl_buffer_zoom_async (GeglBuffer *buffer,
GeglBuffer *photos_gegl_buffer_zoom_finish (GeglBuffer *buffer, GAsyncResult *res, GError **error);
gchar *photos_gegl_compute_checksum_for_buffer (GChecksumType checksum_type, GeglBuffer *buffer);
GdkPixbuf *photos_gegl_create_pixbuf_from_node (GeglNode *node);
GeglBuffer *photos_gegl_dup_buffer_from_node (GeglNode *node, const Babl *format);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment