char save(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity) { ImlibImageTag *tag; uint8_t *data; float fqual; size_t size; int fd; int quality = 75; char ret = 0; if(!im->data) return 0; #ifndef __EMX__ if((fd = open(im->real_file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0) #else if((fd = open(im->real_file, O_WRONLY | O_CREAT | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0) #endif return 0; /* look for tags attached to image to get extra parameters like quality settings etc. - this is the "api" to hint for extra information for saver modules */ tag = __imlib_GetTag(im, "compression"); if(tag) { int compression = tag->val; if(compression < 0) compression = 0; else if(compression > 9) compression = 9; quality = (9 - compression) * 10; quality = quality * 10 / 9; } tag = __imlib_GetTag(im, "quality"); if(tag) { quality = tag->val; if(quality < 1) quality = 1; else if(quality > 100) quality = 100; } fqual = (float)quality; if(!(size = WebPEncodeBGRA((const uint8_t *)im->data, im->w, im->h, im->w << 2, fqual, &data))) goto EXIT; if(write(fd, data, size) != size) goto EXIT; if(progress) progress(im, 100, 0, 0, 0, 0); ret = 1; EXIT: close(fd); if(data) free(data); return ret; }
static char get_options(lopt * opt, ImlibImage * im) { size_t handle = 0, index = 0, traverse = 0; context *ctx; if (im->key) { char *key = strdup(im->key); char *tok = strtok(key, ","); traverse = 0; while (tok) { char *value = strchr(tok, '='); if (!value) { value = tok; tok = "index"; } else { *value = '\0'; value++; } if (!strcasecmp(tok, "index")) index = str2uint(value, index); else if (!strcasecmp(tok, "context")) handle = str2uint(value, handle); else if (!strcasecmp(tok, "traverse")) traverse = str2int(value, traverse); tok = strtok(NULL, ","); } free(key); } else traverse = 1; if (!handle) { ImlibImageTag *htag = __imlib_GetTag(im, "context"); if (htag && htag->val) handle = htag->val; } if (handle) ctx = context_get(handle); else if (!(ctx = context_get_by_name(im->real_file)) && !(ctx = context_create(im->real_file))) return 0; if (!index) { ImlibImageTag *htag = __imlib_GetTag(im, "index"); if (htag && htag->val) index = htag->val; } if (index < 0 || index > id3_tag_get_numframes(ctx->tag) || (index == 0 && id3_tag_get_numframes(ctx->tag) < 1)) { if (index) fprintf(stderr, "No picture frame # %d found\n", index); context_delref(ctx); return 0; } if (!index) index = 1; opt->ctx = ctx; opt->index = index; opt->traverse = traverse; opt->cache_level = (id3_tag_get_numframes(ctx->tag) > 1 ? 1 : 0); return 1; }