Browse Source

* Added file extension detection to modular codec

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3083 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
jylam 16 years ago
parent
commit
d9c4fee5be
2 changed files with 27 additions and 5 deletions
  1. +23
    -1
      pipi/codec/modular.c
  2. +4
    -4
      pipi/codec/modular/jpeg.c

+ 23
- 1
pipi/codec/modular.c View File

@@ -1,3 +1,22 @@
/*
* libpipi Pathetic image processing interface library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* 2008 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* $Id$
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/*
* modular.c: hand-written codecs multiplexer
*/

#include "modular.h"


@@ -8,5 +27,8 @@ pipi_image_t *pipi_load_modular(const char *name)

int pipi_save_modular(pipi_image_t *img, const char *name)
{
return pipi_save_jpeg(img, name);
if(!strncasecmp(&name[strlen(name) - 3], "jpg", 3) ||
!strncasecmp(&name[strlen(name) - 4], "jpeg", 4) )
return pipi_save_jpeg(img, name);
return -1;
}

+ 4
- 4
pipi/codec/modular/jpeg.c View File

@@ -47,13 +47,14 @@ pipi_image_t *pipi_load_jpeg(const char *name)
FILE *fp = fopen(name, "rb");
if(!fp) goto end;

/* Set callbacks */
cinfo.err = jpeg_std_error(&jerr);
jerr.error_exit = error_msg;
jerr.emit_message = emit_msg;
jerr.output_message = output_msg;
jerr.format_message = format_msg;

/* Initialize libjpeg */
jpeg_create_decompress(&cinfo);
cinfo.client_data = 0x0;
jpeg_stdio_src(&cinfo, fp);
@@ -69,12 +70,13 @@ pipi_image_t *pipi_load_jpeg(const char *name)
goto end;
}

/* One scanline */
image = malloc(cinfo.output_width * cinfo.output_height * 4);
if(!image) goto end;

scanline = malloc(cinfo.output_width * 3);

/* Read scanlines, converting them to RGBA */
for(i=0; i < cinfo.output_height; i++)
{
jpeg_read_scanlines(&cinfo, &scanline, 1);
@@ -133,7 +135,6 @@ int pipi_save_jpeg(pipi_image_t *img, const char *name)

data = pixels->pixels;


line = malloc(img->w * 3 * sizeof(unsigned char));
if (!line)
return 0;
@@ -174,7 +175,6 @@ int pipi_save_jpeg(pipi_image_t *img, const char *name)
line[j++] = ((*ptr)) & 0xff;
ptr++;
}
/* write scanline */
jbuf = (JSAMPROW *) (&line);
jpeg_write_scanlines(&cinfo, jbuf, 1);
y++;


Loading…
Cancel
Save