only load 1st level in XCF files
authorThomas Bernard <miniupnp@free.fr>
Thu, 06 Dec 2018 14:19:10 +0100
changeset 633d3c9832b95fb
parent 632 6536f264b1eb
child 637 dd18f877db67
only load 1st level in XCF files

Does just like GIMP !
see https://gitlab.gnome.org/GNOME/gimp/issues/2604
IMG_xcf.c
     1.1 --- a/IMG_xcf.c	Thu Dec 06 14:12:38 2018 +0100
     1.2 +++ b/IMG_xcf.c	Thu Dec 06 14:19:10 2018 +0100
     1.3 @@ -633,6 +633,7 @@
     1.4      int            i, j;
     1.5      Uint32         x, y, tx, ty, ox, oy;
     1.6      Uint32         *row;
     1.7 +    Uint32         length;
     1.8  
     1.9      SDL_RWseek(src, layer->hierarchy_file_offset, RW_SEEK_SET);
    1.10      hierarchy = read_xcf_hierarchy(src, head);
    1.11 @@ -651,7 +652,10 @@
    1.12  
    1.13      level = NULL;
    1.14      for (i = 0; hierarchy->level_file_offsets[i]; i++) {
    1.15 -        SDL_RWseek(src, hierarchy->level_file_offsets[i], RW_SEEK_SET);
    1.16 +        if (SDL_RWseek(src, hierarchy->level_file_offsets[i], RW_SEEK_SET) < 0)
    1.17 +            break;
    1.18 +        if (i > 0) // skip level except the 1st one, just like GIMP does
    1.19 +            continue;
    1.20          level = read_xcf_level(src, head);
    1.21  
    1.22          ty = tx = 0;
    1.23 @@ -659,12 +663,12 @@
    1.24              SDL_RWseek(src, level->tile_file_offsets[j], RW_SEEK_SET);
    1.25              ox = tx + 64 > level->width ? level->width % 64 : 64;
    1.26              oy = ty + 64 > level->height ? level->height % 64 : 64;
    1.27 +            length = ox*oy*6;
    1.28  
    1.29 -            if (level->tile_file_offsets[j + 1]) {
    1.30 -                tile = load_tile(src, level->tile_file_offsets[j + 1] - level->tile_file_offsets[j], hierarchy->bpp, ox, oy);
    1.31 -            } else {
    1.32 -                tile = load_tile(src, ox * oy * 6, hierarchy->bpp, ox, oy);
    1.33 +            if (level->tile_file_offsets[j + 1] > level->tile_file_offsets[j]) {
    1.34 +                length = level->tile_file_offsets[j + 1] - level->tile_file_offsets[j];
    1.35              }
    1.36 +            tile = load_tile(src, length, hierarchy->bpp, ox, oy);
    1.37  
    1.38              if (!tile) {
    1.39                  if (hierarchy) {