only load 1st level in XCF files SDL-1.2
authorThomas Bernard <miniupnp@free.fr>
Thu, 06 Dec 2018 13:57:45 +0100
branchSDL-1.2
changeset 6361d33bfccd462
parent 635 1d88a9866410
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 13:44:10 2018 +0100
     1.2 +++ b/IMG_xcf.c	Thu Dec 06 13:57:45 2018 +0100
     1.3 @@ -647,6 +647,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 @@ -665,7 +666,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 @@ -673,29 +677,23 @@
    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 -        if (level->tile_file_offsets [j+1] <= level->tile_file_offsets [j])
    1.31 -          break;
    1.32 -	tile = load_tile
    1.33 -	  (src,
    1.34 -	   level->tile_file_offsets [j+1] - level->tile_file_offsets [j],
    1.35 -	   hierarchy->bpp,
    1.36 -	   ox, oy);
    1.37 +      if (level->tile_file_offsets [j+1] > level->tile_file_offsets [j]) {
    1.38 +        length = level->tile_file_offsets [j+1] - level->tile_file_offsets [j];
    1.39        }
    1.40 -      else {
    1.41 -	tile = load_tile
    1.42 -	  (src,
    1.43 -	   ox*oy*6,
    1.44 -	   hierarchy->bpp,
    1.45 -	   ox, oy);
    1.46 -      }
    1.47 +      tile = load_tile
    1.48 +             (src,
    1.49 +              length,
    1.50 +              hierarchy->bpp,
    1.51 +              ox, oy);
    1.52 +
    1.53        if (!tile) {
    1.54 -	if (hierarchy)
    1.55 -	  free_xcf_hierarchy(hierarchy);
    1.56 -	if (level)
    1.57 -	  free_xcf_level(level);
    1.58 -	return 1;
    1.59 +        if (hierarchy)
    1.60 +          free_xcf_hierarchy(hierarchy);
    1.61 +        if (level)
    1.62 +          free_xcf_level(level);
    1.63 +        return 1;
    1.64        }
    1.65  
    1.66        p8  = tile;