static void read_jpg_metadata(struct jpeg_decompress_struct *cinfo, GP_DataStorage *storage) { jpeg_saved_marker_ptr marker; GP_DataStorageAddInt(storage, NULL, "Width", cinfo->image_width); GP_DataStorageAddInt(storage, NULL, "Height", cinfo->image_height); GP_DataStorageAddInt(storage, NULL, "Channels", cinfo->num_components); GP_DataStorageAddString(storage, NULL, "Color Space", get_colorspace(cinfo->out_color_space)); for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { switch (marker->marker) { case JPEG_COM: { //TODO: Is comment NULL terminated? char buf[marker->data_length+1]; GP_DEBUG(3, "JPEG_COM comment block, size %u", (unsigned int)marker->data_length); memcpy(buf, marker->data, marker->data_length); buf[marker->data_length] = '\0'; GP_DataStorageAddString(storage, NULL, "Comment", buf); //GP_MetaDataCreateString(data, "comment", (void*)marker->data, // marker->data_length, 1); } break; case JPEG_APP0: GP_TODO("JFIF"); break; case JPEG_APP0 + 1: { GP_IO *io = GP_IOMem(marker->data, marker->data_length, NULL); if (!io) { GP_WARN("Failed to create MemIO"); return; } GP_ReadExif(io, storage); GP_IOClose(io); } break; } } }
static void fill_metadata(opj_image_t *img, GP_DataStorage *storage) { unsigned int i; GP_DataStorageAddInt(storage, NULL, "Width", img->x1 - img->x0); GP_DataStorageAddInt(storage, NULL, "Height", img->y1 - img->y0); GP_DataStorageAddString(storage, NULL, "Color Space", color_space_name(img->color_space)); GP_DataStorageAddInt(storage, NULL, "Samples per Pixel", img->numcomps); for (i = 0; i < img->numcomps; i++) { char buf[32]; GP_DataNode *comp_node; snprintf(buf, sizeof(buf), "Channel %u", i); comp_node = GP_DataStorageAddDict(storage, NULL, buf); GP_DataStorageAddInt(storage, comp_node, "Width", img->comps[i].w); GP_DataStorageAddInt(storage, comp_node, "Height", img->comps[i].h); GP_DataStorageAddInt(storage, comp_node, "Bits per Sample", img->comps[i].prec); } }