瀏覽代碼

* Added hability to save jpeg using modular codec

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3081 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
jylam 16 年之前
父節點
當前提交
245b982a17
共有 2 個檔案被更改,包括 74 行新增2 行删除
  1. +5
    -1
      pipi/codec.c
  2. +69
    -1
      pipi/codec/modular/jpeg.c

+ 5
- 1
pipi/codec.c 查看文件

@@ -38,7 +38,7 @@ pipi_image_t *pipi_load(char const *name)
if(!ret)
ret = pipi_load_oric(name);

#if USE_LIBJPEG
#if USE_MODULAR
if(!ret)
ret = pipi_load_modular(name);
#endif
@@ -90,6 +90,10 @@ int pipi_save(pipi_image_t *img, const char *name)
if(ret < 0)
ret = pipi_save_oric(img, name);

#if USE_MODULAR
if(ret < 0)
ret = pipi_save_modular(img, name);
#endif
#if USE_IMLIB2
if(ret < 0)
ret = pipi_save_imlib2(img, name);


+ 69
- 1
pipi/codec/modular/jpeg.c 查看文件

@@ -119,11 +119,79 @@ end:

int pipi_save_jpeg(pipi_image_t *img, const char *name)
{
return 0;
int quality = 75; /* FIXME */

struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
unsigned char *data = NULL;
unsigned char *line = NULL;

pipi_pixels_t *pixels = pipi_getpixels(img, PIPI_PIXELS_RGBA_C);

if (!pixels)
return 0;

data = pixels->pixels;


line = malloc(img->w * 3 * sizeof(unsigned char));
if (!line)
return 0;

FILE *fp = fopen(name, "wb");
if (!fp) {
free(line);
return 0;
}

jerr.error_exit = error_msg;
jerr.emit_message = emit_msg;
jerr.output_message = output_msg;

cinfo.err = jpeg_std_error(&(jerr));

jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, fp);
cinfo.image_width = img->w;
cinfo.image_height = img->h;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;

jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);

int j, i, y = 0;
uint32_t *ptr = (uint32_t*)data;
JSAMPROW *jbuf;

while (cinfo.next_scanline < cinfo.image_height)
{
for (j = 0, i = 0; i < img->w; i++)
{
line[j++] = ((*ptr) >> 16) & 0xff;
line[j++] = ((*ptr) >> 8) & 0xff;
line[j++] = ((*ptr)) & 0xff;
ptr++;
}
/* write scanline */
jbuf = (JSAMPROW *) (&line);
jpeg_write_scanlines(&cinfo, jbuf, 1);
y++;
}

jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
free(line);
fclose(fp);

return 1;
}

static int pipi_free_jpeg(pipi_image_t *img)
{
if(img->p[PIPI_PIXELS_RGBA_C].pixels)
free(img->p[PIPI_PIXELS_RGBA_C].pixels);
return 0;
}



Loading…
取消
儲存