diff options
| -rw-r--r-- | io-psd.c | 26 |
1 files changed, 14 insertions, 12 deletions
| @@ -33,7 +33,6 @@ | |||
| 33 | #include <gdk-pixbuf/gdk-pixbuf-io.h> | 33 | #include <gdk-pixbuf/gdk-pixbuf-io.h> |
| 34 | #include <glib/gstdio.h> | 34 | #include <glib/gstdio.h> |
| 35 | 35 | ||
| 36 | |||
| 37 | typedef struct | 36 | typedef struct |
| 38 | { | 37 | { |
| 39 | guchar signature[4]; /* file ID, always "8BPS" */ | 38 | guchar signature[4]; /* file ID, always "8BPS" */ |
| @@ -211,6 +210,7 @@ static void | |||
| 211 | decompress_line(const guchar* src, guint line_length, guchar* dest) | 210 | decompress_line(const guchar* src, guint line_length, guchar* dest) |
| 212 | { | 211 | { |
| 213 | guint16 bytes_read = 0; | 212 | guint16 bytes_read = 0; |
| 213 | int k; | ||
| 214 | while (bytes_read < line_length) { | 214 | while (bytes_read < line_length) { |
| 215 | gchar byte = src[bytes_read]; | 215 | gchar byte = src[bytes_read]; |
| 216 | ++bytes_read; | 216 | ++bytes_read; |
| @@ -221,7 +221,7 @@ decompress_line(const guchar* src, guint line_length, guchar* dest) | |||
| 221 | gint count = byte + 1; | 221 | gint count = byte + 1; |
| 222 | 222 | ||
| 223 | /* copy next count bytes */ | 223 | /* copy next count bytes */ |
| 224 | for (int k = 0; k < count; ++k) { | 224 | for (k = 0; k < count; ++k) { |
| 225 | *dest = src[bytes_read]; | 225 | *dest = src[bytes_read]; |
| 226 | ++dest; | 226 | ++dest; |
| 227 | ++bytes_read; | 227 | ++bytes_read; |
| @@ -232,7 +232,7 @@ decompress_line(const guchar* src, guint line_length, guchar* dest) | |||
| 232 | /* copy next byte count times */ | 232 | /* copy next byte count times */ |
| 233 | guchar next_byte = src[bytes_read]; | 233 | guchar next_byte = src[bytes_read]; |
| 234 | ++bytes_read; | 234 | ++bytes_read; |
| 235 | for (int k = 0; k < count; ++k) { | 235 | for (k = 0; k < count; ++k) { |
| 236 | *dest = next_byte; | 236 | *dest = next_byte; |
| 237 | ++dest; | 237 | ++dest; |
| 238 | } | 238 | } |
| @@ -303,7 +303,8 @@ gdk_pixbuf__psd_image_stop_load (gpointer context_ptr, GError **error) | |||
| 303 | g_free(ctx->buffer); | 303 | g_free(ctx->buffer); |
| 304 | g_free(ctx->lines_lengths); | 304 | g_free(ctx->lines_lengths); |
| 305 | if (ctx->ch_bufs) { | 305 | if (ctx->ch_bufs) { |
| 306 | for (int i = 0; i < ctx->channels; i++) { | 306 | int i; |
| 307 | for (i = 0; i < ctx->channels; i++) { | ||
| 307 | g_free(ctx->ch_bufs[i]); | 308 | g_free(ctx->ch_bufs[i]); |
| 308 | } | 309 | } |
| 309 | } | 310 | } |
| @@ -320,6 +321,7 @@ gdk_pixbuf__psd_image_load_increment (gpointer context_ptr, | |||
| 320 | GError **error) | 321 | GError **error) |
| 321 | { | 322 | { |
| 322 | PsdContext* ctx = (PsdContext*) context_ptr; | 323 | PsdContext* ctx = (PsdContext*) context_ptr; |
| 324 | int i, j; | ||
| 323 | 325 | ||
| 324 | while (size > 0) { | 326 | while (size > 0) { |
| 325 | switch (ctx->state) { | 327 | switch (ctx->state) { |
| @@ -387,7 +389,7 @@ gdk_pixbuf__psd_image_load_increment (gpointer context_ptr, | |||
| 387 | 389 | ||
| 388 | /* create separate buffers for each channel */ | 390 | /* create separate buffers for each channel */ |
| 389 | ctx->ch_bufs = g_malloc(sizeof(guchar*) * ctx->channels); | 391 | ctx->ch_bufs = g_malloc(sizeof(guchar*) * ctx->channels); |
| 390 | for (int i = 0; i < ctx->channels; i++) { | 392 | for (i = 0; i < ctx->channels; i++) { |
| 391 | ctx->ch_bufs[i] = | 393 | ctx->ch_bufs[i] = |
| 392 | g_malloc(ctx->width*ctx->height*ctx->depth_bytes); | 394 | g_malloc(ctx->width*ctx->height*ctx->depth_bytes); |
| 393 | 395 | ||
| @@ -448,7 +450,7 @@ gdk_pixbuf__psd_image_load_increment (gpointer context_ptr, | |||
| 448 | &size, 2 * ctx->height * ctx->channels)) | 450 | &size, 2 * ctx->height * ctx->channels)) |
| 449 | { | 451 | { |
| 450 | /* convert from different endianness */ | 452 | /* convert from different endianness */ |
| 451 | for (int i = 0; i < ctx->height * ctx->channels; i++) { | 453 | for (i = 0; i < ctx->height * ctx->channels; i++) { |
| 452 | ctx->lines_lengths[i] = read_uint16( | 454 | ctx->lines_lengths[i] = read_uint16( |
| 453 | (guchar*) &ctx->lines_lengths[i]); | 455 | (guchar*) &ctx->lines_lengths[i]); |
| 454 | } | 456 | } |
| @@ -505,8 +507,8 @@ gdk_pixbuf__psd_image_load_increment (gpointer context_ptr, | |||
| 505 | guint b = ctx->depth_bytes; | 507 | guint b = ctx->depth_bytes; |
| 506 | 508 | ||
| 507 | if (ctx->color_mode == PSD_MODE_RGB) { | 509 | if (ctx->color_mode == PSD_MODE_RGB) { |
| 508 | for (int i = 0; i < ctx->height; i++) { | 510 | for (i = 0; i < ctx->height; i++) { |
| 509 | for (int j = 0; j < ctx->width; j++) { | 511 | for (j = 0; j < ctx->width; j++) { |
| 510 | pixels[3*j+0] = ctx->ch_bufs[0][ctx->width*i*b + j*b]; | 512 | pixels[3*j+0] = ctx->ch_bufs[0][ctx->width*i*b + j*b]; |
| 511 | pixels[3*j+1] = ctx->ch_bufs[1][ctx->width*i*b + j*b]; | 513 | pixels[3*j+1] = ctx->ch_bufs[1][ctx->width*i*b + j*b]; |
| 512 | pixels[3*j+2] = ctx->ch_bufs[2][ctx->width*i*b + j*b]; | 514 | pixels[3*j+2] = ctx->ch_bufs[2][ctx->width*i*b + j*b]; |
| @@ -516,8 +518,8 @@ gdk_pixbuf__psd_image_load_increment (gpointer context_ptr, | |||
| 516 | } else if (ctx->color_mode == PSD_MODE_GRAYSCALE || | 518 | } else if (ctx->color_mode == PSD_MODE_GRAYSCALE || |
| 517 | ctx->color_mode == PSD_MODE_DUOTONE) | 519 | ctx->color_mode == PSD_MODE_DUOTONE) |
| 518 | { | 520 | { |
| 519 | for (int i = 0; i < ctx->height; i++) { | 521 | for (i = 0; i < ctx->height; i++) { |
| 520 | for (int j = 0; j < ctx->width; j++) { | 522 | for (j = 0; j < ctx->width; j++) { |
| 521 | pixels[3*j+0] = pixels[3*j+1] = pixels[3*j+2] = | 523 | pixels[3*j+0] = pixels[3*j+1] = pixels[3*j+2] = |
| 522 | ctx->ch_bufs[0][ctx->width*i*b + j*b]; | 524 | ctx->ch_bufs[0][ctx->width*i*b + j*b]; |
| 523 | } | 525 | } |
| @@ -528,8 +530,8 @@ gdk_pixbuf__psd_image_load_increment (gpointer context_ptr, | |||
| 528 | CMYK-RGB conversion distorts colors significantly */ | 530 | CMYK-RGB conversion distorts colors significantly */ |
| 529 | 531 | ||
| 530 | guchar* pixels = gdk_pixbuf_get_pixels(ctx->pixbuf); | 532 | guchar* pixels = gdk_pixbuf_get_pixels(ctx->pixbuf); |
| 531 | for (int i = 0; i < ctx->height; i++) { | 533 | for (i = 0; i < ctx->height; i++) { |
| 532 | for (int j = 0; j < ctx->width; j++) { | 534 | for (j = 0; j < ctx->width; j++) { |
| 533 | double c = 1.0 - | 535 | double c = 1.0 - |
| 534 | (double) ctx->ch_bufs[0][ctx->width*i + j] / 255.0; | 536 | (double) ctx->ch_bufs[0][ctx->width*i + j] / 255.0; |
| 535 | double m = 1.0 - | 537 | double m = 1.0 - |
