IMG_xcf.c
changeset 368 8a61842d00ce
parent 367 b2aa197f6774
child 415 1700d607fce3
     1.1 --- a/IMG_xcf.c	Thu Apr 25 00:22:51 2013 -0700
     1.2 +++ b/IMG_xcf.c	Tue May 21 21:24:32 2013 -0700
     1.3 @@ -208,21 +208,21 @@
     1.4  /* See if an image is contained in a data source */
     1.5  int IMG_isXCF(SDL_RWops *src)
     1.6  {
     1.7 -	Sint64 start;
     1.8 -	int is_XCF;
     1.9 -	char magic[14];
    1.10 +    Sint64 start;
    1.11 +    int is_XCF;
    1.12 +    char magic[14];
    1.13  
    1.14 -	if ( !src )
    1.15 -		return 0;
    1.16 -	start = SDL_RWtell(src);
    1.17 -	is_XCF = 0;
    1.18 -	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    1.19 -		if (SDL_strncmp(magic, "gimp xcf ", 9) == 0) {
    1.20 -			is_XCF = 1;
    1.21 -		}
    1.22 -	}
    1.23 -	SDL_RWseek(src, start, RW_SEEK_SET);
    1.24 -	return(is_XCF);
    1.25 +    if ( !src )
    1.26 +        return 0;
    1.27 +    start = SDL_RWtell(src);
    1.28 +    is_XCF = 0;
    1.29 +    if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    1.30 +        if (SDL_strncmp(magic, "gimp xcf ", 9) == 0) {
    1.31 +            is_XCF = 1;
    1.32 +        }
    1.33 +    }
    1.34 +    SDL_RWseek(src, start, RW_SEEK_SET);
    1.35 +    return(is_XCF);
    1.36  }
    1.37  
    1.38  static char * read_string (SDL_RWops * src) {
    1.39 @@ -381,8 +381,8 @@
    1.40        break;
    1.41      case PROP_COLOR:
    1.42        l->color = ((Uint32) prop.data.color[0] << 16)
    1.43 -	| ((Uint32) prop.data.color[1] << 8)
    1.44 -	| ((Uint32) prop.data.color[2]);
    1.45 +    | ((Uint32) prop.data.color[1] << 8)
    1.46 +    | ((Uint32) prop.data.color[2]);
    1.47        break;
    1.48      case PROP_SELECTION:
    1.49        l->selection = 1;
    1.50 @@ -474,42 +474,42 @@
    1.51      d    = data + i;
    1.52      size = x*y;
    1.53      count = 0;
    1.54 - 
    1.55 +
    1.56      while (size > 0) {
    1.57        val = *t++;
    1.58  
    1.59        length = val;
    1.60        if (length >= 128) {
    1.61 -	length = 255 - (length - 1);
    1.62 -	if (length == 128) {
    1.63 -	  length = (*t << 8) + t[1];
    1.64 -	  t += 2;
    1.65 -	}
    1.66 +    length = 255 - (length - 1);
    1.67 +    if (length == 128) {
    1.68 +      length = (*t << 8) + t[1];
    1.69 +      t += 2;
    1.70 +    }
    1.71  
    1.72 -	count += length;
    1.73 -	size -= length;
    1.74 +    count += length;
    1.75 +    size -= length;
    1.76  
    1.77 -	while (length-- > 0) {
    1.78 -	  *d = *t++;
    1.79 -	  d += bpp;
    1.80 -	}
    1.81 +    while (length-- > 0) {
    1.82 +      *d = *t++;
    1.83 +      d += bpp;
    1.84 +    }
    1.85        }
    1.86        else {
    1.87 -	length += 1;
    1.88 -	if (length == 128) {
    1.89 -	  length = (*t << 8) + t[1];
    1.90 -	  t += 2;
    1.91 -	}
    1.92 +    length += 1;
    1.93 +    if (length == 128) {
    1.94 +      length = (*t << 8) + t[1];
    1.95 +      t += 2;
    1.96 +    }
    1.97  
    1.98 -	count += length;
    1.99 -	size -= length;
   1.100 +    count += length;
   1.101 +    size -= length;
   1.102  
   1.103 -	val = *t++;
   1.104 +    val = *t++;
   1.105  
   1.106 -	for (j = 0; j < length; j++) {
   1.107 -	  *d = val;
   1.108 -	  d += bpp;
   1.109 -	}
   1.110 +    for (j = 0; j < length; j++) {
   1.111 +      *d = val;
   1.112 +      d += bpp;
   1.113 +    }
   1.114        }
   1.115      }
   1.116    }
   1.117 @@ -568,98 +568,98 @@
   1.118        oy = ty+64 > level->height ? level->height % 64 : 64;
   1.119  
   1.120        if (level->tile_file_offsets [j+1]) {
   1.121 -	tile = load_tile
   1.122 -	  (src,
   1.123 -	   level->tile_file_offsets [j+1] - level->tile_file_offsets [j],
   1.124 -	   hierarchy->bpp,
   1.125 -	   ox, oy);
   1.126 +    tile = load_tile
   1.127 +      (src,
   1.128 +       level->tile_file_offsets [j+1] - level->tile_file_offsets [j],
   1.129 +       hierarchy->bpp,
   1.130 +       ox, oy);
   1.131        }
   1.132        else {
   1.133 -	tile = load_tile
   1.134 -	  (src,
   1.135 -	   ox*oy*6,
   1.136 -	   hierarchy->bpp,
   1.137 -	   ox, oy);
   1.138 +    tile = load_tile
   1.139 +      (src,
   1.140 +       ox*oy*6,
   1.141 +       hierarchy->bpp,
   1.142 +       ox, oy);
   1.143        }
   1.144  
   1.145        p8  = tile;
   1.146        p16 = (Uint16 *) p8;
   1.147        p   = (Uint32 *) p8;
   1.148        for (y=ty; y < ty+oy; y++) {
   1.149 -	row = (Uint32 *)((Uint8 *)surface->pixels + y*surface->pitch + tx*4);
   1.150 -	switch (hierarchy->bpp) {
   1.151 -	case 4:
   1.152 -	  for (x=tx; x < tx+ox; x++)
   1.153 -	    *row++ = Swap32 (*p++);
   1.154 -	  break;
   1.155 -	case 3:
   1.156 -	  for (x=tx; x < tx+ox; x++) {
   1.157 -	    *row = 0xFF000000;
   1.158 -	    *row |= ((Uint32) *(p8++) << 16);
   1.159 -	    *row |= ((Uint32) *(p8++) << 8);
   1.160 -	    *row |= ((Uint32) *(p8++) << 0);
   1.161 -	    row++;
   1.162 -	  }
   1.163 -	  break;
   1.164 -	case 2: // Indexed/Greyscale + Alpha
   1.165 -	  switch (head->image_type) {
   1.166 -	  case IMAGE_INDEXED:
   1.167 -	    for (x=tx; x < tx+ox; x++) {
   1.168 -	      *row =  ((Uint32) (head->cm_map [*p8*3])     << 16);
   1.169 -	      *row |= ((Uint32) (head->cm_map [*p8*3+1])   << 8);
   1.170 -	      *row |= ((Uint32) (head->cm_map [*p8++*3+2]) << 0);
   1.171 -	      *row |= ((Uint32) *p8++ << 24);;
   1.172 -	      row++;
   1.173 -	    }
   1.174 -	    break;
   1.175 -	  case IMAGE_GREYSCALE:
   1.176 -	    for (x=tx; x < tx+ox; x++) {
   1.177 -	      *row = ((Uint32) *p8 << 16);
   1.178 -	      *row |= ((Uint32) *p8 << 8);
   1.179 -	      *row |= ((Uint32) *p8++ << 0);
   1.180 -	      *row |= ((Uint32) *p8++ << 24);;
   1.181 -	      row++;
   1.182 -	    }
   1.183 -	    break;	    
   1.184 -	  default:
   1.185 -	    fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
   1.186 -	    return 1;
   1.187 -	  }
   1.188 -	  break;
   1.189 -	case 1: // Indexed/Greyscale
   1.190 -	  switch (head->image_type) {
   1.191 -	  case IMAGE_INDEXED:
   1.192 -	    for (x = tx; x < tx+ox; x++) {
   1.193 -	      *row++ = 0xFF000000
   1.194 -		| ((Uint32) (head->cm_map [*p8*3]) << 16)
   1.195 -		| ((Uint32) (head->cm_map [*p8*3+1]) << 8)
   1.196 -		| ((Uint32) (head->cm_map [*p8*3+2]) << 0);
   1.197 -	      p8++;
   1.198 -	    }
   1.199 -	    break;
   1.200 -	  case IMAGE_GREYSCALE:
   1.201 -	    for (x=tx; x < tx+ox; x++) {
   1.202 -	      *row++ = 0xFF000000
   1.203 -		| (((Uint32) (*p8)) << 16)
   1.204 -		| (((Uint32) (*p8)) << 8)
   1.205 -		| (((Uint32) (*p8)) << 0);
   1.206 -			++p8;
   1.207 -	    }
   1.208 -	    break;	    
   1.209 -	  default:
   1.210 -	    fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
   1.211 -	    return 1;
   1.212 -	  }
   1.213 -	  break;
   1.214 -	}
   1.215 +    row = (Uint32 *)((Uint8 *)surface->pixels + y*surface->pitch + tx*4);
   1.216 +    switch (hierarchy->bpp) {
   1.217 +    case 4:
   1.218 +      for (x=tx; x < tx+ox; x++)
   1.219 +        *row++ = Swap32 (*p++);
   1.220 +      break;
   1.221 +    case 3:
   1.222 +      for (x=tx; x < tx+ox; x++) {
   1.223 +        *row = 0xFF000000;
   1.224 +        *row |= ((Uint32) *(p8++) << 16);
   1.225 +        *row |= ((Uint32) *(p8++) << 8);
   1.226 +        *row |= ((Uint32) *(p8++) << 0);
   1.227 +        row++;
   1.228 +      }
   1.229 +      break;
   1.230 +    case 2: // Indexed/Greyscale + Alpha
   1.231 +      switch (head->image_type) {
   1.232 +      case IMAGE_INDEXED:
   1.233 +        for (x=tx; x < tx+ox; x++) {
   1.234 +          *row =  ((Uint32) (head->cm_map [*p8*3])     << 16);
   1.235 +          *row |= ((Uint32) (head->cm_map [*p8*3+1])   << 8);
   1.236 +          *row |= ((Uint32) (head->cm_map [*p8++*3+2]) << 0);
   1.237 +          *row |= ((Uint32) *p8++ << 24);;
   1.238 +          row++;
   1.239 +        }
   1.240 +        break;
   1.241 +      case IMAGE_GREYSCALE:
   1.242 +        for (x=tx; x < tx+ox; x++) {
   1.243 +          *row = ((Uint32) *p8 << 16);
   1.244 +          *row |= ((Uint32) *p8 << 8);
   1.245 +          *row |= ((Uint32) *p8++ << 0);
   1.246 +          *row |= ((Uint32) *p8++ << 24);;
   1.247 +          row++;
   1.248 +        }
   1.249 +        break;
   1.250 +      default:
   1.251 +        fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
   1.252 +        return 1;
   1.253 +      }
   1.254 +      break;
   1.255 +    case 1: // Indexed/Greyscale
   1.256 +      switch (head->image_type) {
   1.257 +      case IMAGE_INDEXED:
   1.258 +        for (x = tx; x < tx+ox; x++) {
   1.259 +          *row++ = 0xFF000000
   1.260 +        | ((Uint32) (head->cm_map [*p8*3]) << 16)
   1.261 +        | ((Uint32) (head->cm_map [*p8*3+1]) << 8)
   1.262 +        | ((Uint32) (head->cm_map [*p8*3+2]) << 0);
   1.263 +          p8++;
   1.264 +        }
   1.265 +        break;
   1.266 +      case IMAGE_GREYSCALE:
   1.267 +        for (x=tx; x < tx+ox; x++) {
   1.268 +          *row++ = 0xFF000000
   1.269 +        | (((Uint32) (*p8)) << 16)
   1.270 +        | (((Uint32) (*p8)) << 8)
   1.271 +        | (((Uint32) (*p8)) << 0);
   1.272 +            ++p8;
   1.273 +        }
   1.274 +        break;
   1.275 +      default:
   1.276 +        fprintf (stderr, "Unknown Gimp image type (%d)\n", head->image_type);
   1.277 +        return 1;
   1.278 +      }
   1.279 +      break;
   1.280 +    }
   1.281        }
   1.282        tx += 64;
   1.283        if (tx >= level->width) {
   1.284 -	tx = 0;
   1.285 -	ty += 64;
   1.286 +    tx = 0;
   1.287 +    ty += 64;
   1.288        }
   1.289        if (ty >= level->height) {
   1.290 -	break;
   1.291 +    break;
   1.292        }
   1.293  
   1.294        free_xcf_tile (tile);
   1.295 @@ -668,7 +668,7 @@
   1.296    }
   1.297  
   1.298    free_xcf_hierarchy (hierarchy);
   1.299 -  
   1.300 +
   1.301    return 0;
   1.302  }
   1.303  
   1.304 @@ -711,7 +711,7 @@
   1.305  
   1.306    /* Create the surface of the appropriate type */
   1.307    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
   1.308 -			     0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   1.309 +                 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   1.310  
   1.311    if ( surface == NULL ) {
   1.312      error = "Out of memory";
   1.313 @@ -727,9 +727,9 @@
   1.314      offsets++;
   1.315    }
   1.316    fp = SDL_RWtell (src);
   1.317 - 
   1.318 +
   1.319    lays = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
   1.320 -			  0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   1.321 +              0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   1.322  
   1.323    if ( lays == NULL ) {
   1.324      error = "Out of memory";
   1.325 @@ -769,14 +769,14 @@
   1.326      fp = SDL_RWtell (src);
   1.327      SDL_RWseek (src, offset, RW_SEEK_SET);
   1.328      channel [chnls++] = (read_xcf_channel (src));
   1.329 -    SDL_RWseek (src, fp, RW_SEEK_SET);    
   1.330 +    SDL_RWseek (src, fp, RW_SEEK_SET);
   1.331    }
   1.332  
   1.333    if (chnls) {
   1.334      SDL_Surface * chs;
   1.335  
   1.336      chs = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
   1.337 -			   0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   1.338 +               0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   1.339  
   1.340      if (chs == NULL) {
   1.341        error = "Out of memory";
   1.342 @@ -785,8 +785,8 @@
   1.343      for (i = 0; i < chnls; i++) {
   1.344        //      printf ("CNLBLT %i\n", i);
   1.345        if (!channel [i]->selection && channel [i]->visible) {
   1.346 -	create_channel_surface (chs, (xcf_image_type)head->image_type, channel [i]->color, channel [i]->opacity);
   1.347 -	SDL_BlitSurface (chs, NULL, surface, NULL);
   1.348 +    create_channel_surface (chs, (xcf_image_type)head->image_type, channel [i]->color, channel [i]->opacity);
   1.349 +    SDL_BlitSurface (chs, NULL, surface, NULL);
   1.350        }
   1.351        free_xcf_channel (channel [i]);
   1.352      }