[AD] RLE patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Here is a first version of the patch. Unfinished. This one applies on
4.1.3, as opposed to the base one, which was from 4.1.1.

-- 
Vincent Penquerc'h
--- dat2c.c.rle	Wed Oct  9 19:36:11 2002
+++ dat2c.c	Wed Oct  9 21:31:10 2002
@@ -614,6 +614,24 @@
 
 enum dat2c_file { C, H };
 
+static void write_newline(FILE *fp, enum lineformat lf)
+{
+   switch(lf) {
+      case lineformat_dos:
+         putc(13, fp);
+         putc(10, fp);
+         break;
+
+      case lineformat_mac:
+         putc(13, fp);
+         break;
+
+      default:
+         putc(10, fp);
+         break;
+   }
+}
+
 static void cwrite(struct dat2c* dat2c, enum dat2c_file x, 
     const char* fmt, ...)
 {
@@ -646,20 +664,7 @@
             } else if(!strncmp(rd, "$n$", 3)) {
                 /* newline sequence */
                 
-                switch(dat2c->lformat) {
-                    case lineformat_dos:
-                        putc(13, fp);
-                        putc(10, fp);
-                        break;
-
-                    case lineformat_mac:
-                        putc(13, fp);
-                        break;
-
-                    default:
-                        putc(10, fp);
-                        break;
-                }
+                write_newline(fp, dat2c->lformat);
                 
             } else if(!strncmp(rd, "$int$", 5)) {
                 /* plain integer */
@@ -766,20 +771,7 @@
                     remaining -= 50;
                     data += 50;
                     
-                    switch(dat2c->lformat) {
-                        case lineformat_dos:
-                            putc(13, fp);
-                            putc(10, fp);
-                            break;
-
-                        case lineformat_mac:
-                            putc(13, fp);
-                            break;
-
-                        default:
-                            putc(10, fp);
-                            break;
-                    }
+                    write_newline(fp, dat2c->lformat);
                     for(sp = offset; sp; sp--) putc(' ', fp);
                 }
                 
@@ -796,18 +788,22 @@
                 size_t c, count = va_arg(va, size_t);
                 const unsigned int sub_offset = va_arg(va, const unsigned int);
                 const char *add_offset = va_arg(va, const char*);
+                const char *type = va_arg(va, const char*);
                 const void **array = va_arg(va, const void**);
                 fprintf(fp, "{");
                 for (c=0; c<count; ++c) {
                    const void *p = *array++ - sub_offset;
                    /* do not use %p, this would output NULL in "text" format */
                    if (add_offset) {
-                      fprintf(fp, "%s + 0x%08x,", add_offset, (unsigned int)p);
+                      fprintf(fp, "(%s)(%s + 0x%08x),", type, add_offset, (unsigned int)p);
                    }
                    else {
                       fprintf(fp, "0x%08x,", (unsigned int)p);
                    }
-                   if (!((c+1)&7)) fprintf(fp, "\n");
+                   if (!((c+1)&1)) {
+                     write_newline(fp, dat2c->lformat);
+                     if (c!=count-1) fprintf(fp, "    ");
+                   }
                 }
                 fprintf(fp, "}");
                 
@@ -1439,12 +1435,11 @@
  *
  *  Writes an RLE sprite.
  */
-static int cvt_RLE_SPRITE(struct dat2c* dat2c, DATAFILE* dat, 
-    const char* name)
+static int cvt_RLE_SPRITE(struct dat2c* dat2c, DATAFILE* dat, const char* name)
 {
     RLE_SPRITE* rle = dat->dat;
-    char *symbol = malloc(strlen("((int))")+strlen(name)+1),*ptr;
-    sprintf(symbol,"((int)%s)",name);
+    char *symbol = malloc(strlen("((int))&")+strlen(name)+1),*ptr;
+    sprintf(symbol,"((int)&%s)",name);
     for (ptr=symbol;*ptr;++ptr) *ptr=tolower(*ptr);
 
     /* declare this in the header if we are exporting objects */
@@ -1453,11 +1448,17 @@
             name);
     }
 
+    cwrite(dat2c, C, "extern RLE_SPRITE $string lower$;$n$", name);
+    cwrite(dat2c, C, "static signed char *$string lower$_lines[] = $n$"
+                     "    $pointer-array$"
+                     ";$n$",
+                     name,
+                     rle->h+1, rle, symbol, "signed char*", rle->lines);
     cwrite(dat2c, C, "$string$RLE_SPRITE $string lower$ = {$n$"
                      "    $int$, $int$, /* width, height */$n$"
                      "    $int$, /* color depth */$n$"
                      "    $int$, /* compressed size (bytes) */$n$"
-                     "    $pointer-array$, /* pointers to sprite's lines */$n$"
+                     "    $string lower$_lines, /* sprite line pointers */$n$"
                      "    $data$$n$"
                      "};$n$"
                      "$n$$n$$n$",
@@ -1466,7 +1467,7 @@
         rle->w, rle->h,
         rle->color_depth,
         rle->size,
-        rle->h+1, rle, symbol, rle->lines,
+        name,
         rle->size, 4, rle->dat);
 
     free(symbol);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/