Free Hero Mesh

Check-in [0aa4ff0fdf]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement hue/shade filter in dependent pictures.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0aa4ff0fdf8452227acd2fc877d1ca492206789f
User & Date: user on 2022-08-17 01:15:50
Other Links: manifest | tags
Context
2022-08-17
06:54
Add a Replace instruction. check-in: 1190f331f1 user: user tags: trunk
01:15
Implement hue/shade filter in dependent pictures. check-in: 0aa4ff0fdf user: user tags: trunk
2022-08-11
20:11
Implement level hashes calculation. check-in: a9af94f292 user: user tags: trunk
Changes

Modified fileformat.doc from [a630f0a978] to [bc360d3774].

185
186
187
188
189
190
191



192
193
194
195
196
197
198
a DEP lump); it is terminated in the same way as the base name is.

* 12 to 15 = Shift. The filter code is the direction: 12=up, 13=down,
14=right, 15=left. Follow by a list of pairs of shift amounts. The first
byte of each pair is the shift amount; the high bit is set if this is the
last pair. The second byte of each pair is the picture size that the shift
amount is based on.





=== xclass/*.IMG ===

A picture; the part of the name before the dot is the picture name.

The beginning of this lump data specifies how many variants and their







>
>
>







185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
a DEP lump); it is terminated in the same way as the base name is.

* 12 to 15 = Shift. The filter code is the direction: 12=up, 13=down,
14=right, 15=left. Follow by a list of pairs of shift amounts. The first
byte of each pair is the shift amount; the high bit is set if this is the
last pair. The second byte of each pair is the picture size that the shift
amount is based on.

* 16 = Hue/shade. The additional data is two bytes, being the hue adjust
(unsigned) and shade adjust (signed).


=== xclass/*.IMG ===

A picture; the part of the name before the dot is the picture name.

The beginning of this lump data specifies how many variants and their

Modified picedit.c from [e191836d4c] to [f746d76413].

34
35
36
37
38
39
40





41
42
43
44
45
46

47
48
49
50

51
52
53
54
55
56
57

typedef struct {
  Uint8 shift[32];
  Uint8 size[32];
  Uint8 nshift;
} ShiftFilter;






typedef struct {
  Uint8 code;
  // 0-7 = flip/rotations
  // 8-10 = change colours (8 is *->* *->* *->*; 9 is *->*->*->*->*; 10 is *<->* *<->* *<->*)
  // 11 = overlay
  // 12-15 = shift (up, down, right, left)

  union {
    ColorFilter color;
    OverlayFilter overlay;
    ShiftFilter shift;

  };
} Filter;

typedef struct {
  union {
    char basename[64];
    struct {







>
>
>
>
>






>




>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

typedef struct {
  Uint8 shift[32];
  Uint8 size[32];
  Uint8 nshift;
} ShiftFilter;

typedef struct {
  Uint8 hue;
  Sint8 shade;
} HueShadeFilter;

typedef struct {
  Uint8 code;
  // 0-7 = flip/rotations
  // 8-10 = change colours (8 is *->* *->* *->*; 9 is *->*->*->*->*; 10 is *<->* *<->* *<->*)
  // 11 = overlay
  // 12-15 = shift (up, down, right, left)
  // 16 = hue/shade
  union {
    ColorFilter color;
    OverlayFilter overlay;
    ShiftFilter shift;
    HueShadeFilter hueshade;
  };
} Filter;

typedef struct {
  union {
    char basename[64];
    struct {
1178
1179
1180
1181
1182
1183
1184




1185
1186
1187
1188
1189
1190
1191
        for(k=0;k<64;k++) {
          dp->filters[i].shift.shift[k]=(j=fgetc(fp))&127;
          dp->filters[i].shift.size[k]=fgetc(fp);
          if(j&128) break;
        }
        dp->filters[i].shift.nshift=k+1;
        break;




    }
  }
  fclose(fp);
}

static void save_dependent_picture(FILE*fp,DependentPicture*dp,int mode) {
  int i,j;







>
>
>
>







1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
        for(k=0;k<64;k++) {
          dp->filters[i].shift.shift[k]=(j=fgetc(fp))&127;
          dp->filters[i].shift.size[k]=fgetc(fp);
          if(j&128) break;
        }
        dp->filters[i].shift.nshift=k+1;
        break;
      case 16:
        dp->filters[i].hueshade.hue=fgetc(fp);
        dp->filters[i].hueshade.shade=(Sint8)fgetc(fp);
        break;
    }
  }
  fclose(fp);
}

static void save_dependent_picture(FILE*fp,DependentPicture*dp,int mode) {
  int i,j;
1203
1204
1205
1206
1207
1208
1209




1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
      case 12 ... 15:
        if(!dp->filters[i].shift.nshift) fwrite("\x80",1,2,fp);
        for(j=0;j<dp->filters[i].shift.nshift;j++) {
          fputc(dp->filters[i].shift.shift[j]|(j==dp->filters[i].shift.nshift-1?128:0),fp);
          fputc(dp->filters[i].shift.size[j],fp);
        }
        break;




    }
  }
}

static int add_filter(DependentPicture*dp,const char*const*const txt,Sint8 c) {
  SDL_Rect r;
  SDL_Event ev;
  Uint8 f;
  char buf[4]="<?>";
  if(c<0 || dp->nfilters>63) return;
  r.x=r.y=12; r.w=200; r.h=136;
  set_cursor(XC_iron_cross);
  redraw:
  SDL_LockSurface(screen);
  SDL_FillRect(screen,&r,0xF8);
  for(f=0;f<16;f++) {
    buf[1]=f+'a';
    draw_text(16,(f+2)<<3,buf,0xF8,0xFB);
    draw_text(48,(f+2)<<3,txt[f],0xF8,0xFF);
  }
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_QUIT: exit(0); return 0;
    case SDL_KEYDOWN:
      if(ev.key.keysym.sym==SDLK_ESCAPE || ev.key.keysym.sym==SDLK_z) return 0;
      if(ev.key.keysym.sym<SDLK_a || ev.key.keysym.sym>SDLK_p) break;
      f=ev.key.keysym.sym-SDLK_a;
      goto found;
    case SDL_VIDEOEXPOSE: goto redraw;
  }
  found:
  ++dp->nfilters;
  if(c!=63) memmove(dp->filters+c+1,dp->filters+c,(63-c)*sizeof(Filter));







>
>
>
>










|




|










|







1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
      case 12 ... 15:
        if(!dp->filters[i].shift.nshift) fwrite("\x80",1,2,fp);
        for(j=0;j<dp->filters[i].shift.nshift;j++) {
          fputc(dp->filters[i].shift.shift[j]|(j==dp->filters[i].shift.nshift-1?128:0),fp);
          fputc(dp->filters[i].shift.size[j],fp);
        }
        break;
      case 16:
        fputc(dp->filters[i].hueshade.hue,fp);
        fputc(dp->filters[i].hueshade.shade,fp);
        break;
    }
  }
}

static int add_filter(DependentPicture*dp,const char*const*const txt,Sint8 c) {
  SDL_Rect r;
  SDL_Event ev;
  Uint8 f;
  char buf[4]="<?>";
  if(c<0 || dp->nfilters>63) return;
  r.x=r.y=12; r.w=200; r.h=144;
  set_cursor(XC_iron_cross);
  redraw:
  SDL_LockSurface(screen);
  SDL_FillRect(screen,&r,0xF8);
  for(f=0;f<17;f++) {
    buf[1]=f+'a';
    draw_text(16,(f+2)<<3,buf,0xF8,0xFB);
    draw_text(48,(f+2)<<3,txt[f],0xF8,0xFF);
  }
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_QUIT: exit(0); return 0;
    case SDL_KEYDOWN:
      if(ev.key.keysym.sym==SDLK_ESCAPE || ev.key.keysym.sym==SDLK_z) return 0;
      if(ev.key.keysym.sym<SDLK_a || ev.key.keysym.sym>SDLK_q) break;
      f=ev.key.keysym.sym-SDLK_a;
      goto found;
    case SDL_VIDEOEXPOSE: goto redraw;
  }
  found:
  ++dp->nfilters;
  if(c!=63) memmove(dp->filters+c+1,dp->filters+c,(63-c)*sizeof(Filter));
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385

1386
1387
1388
1389
1390
1391
1392
      }
      goto redraw;
    case SDL_VIDEOEXPOSE: goto redraw;
  }
}

static void edit_dependent_picture(DependentPicture*dp,const char*name) {
  static const char*const txt[16]={
    "Identity",
    "Flip \x1D",
    "Flip \x12",
    "Rotate 180\xF8",
    "Transpose",
    "Transposed flip \x1D",
    "Transposed flip \x12",
    "Reverse Transpose",
    "Replace colors",
    "Advance colors",
    "Exchange colors",
    "Overlay",
    "Shift \x18",
    "Shift \x19",
    "Shift \x1A",
    "Shift \x1B",

  };
  const char*s;
  char buf[64];
  Sint8 c=-1;
  int i,j,y;
  SDL_Rect r;
  SDL_Event ev;







|
















>







1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
      }
      goto redraw;
    case SDL_VIDEOEXPOSE: goto redraw;
  }
}

static void edit_dependent_picture(DependentPicture*dp,const char*name) {
  static const char*const txt[17]={
    "Identity",
    "Flip \x1D",
    "Flip \x12",
    "Rotate 180\xF8",
    "Transpose",
    "Transposed flip \x1D",
    "Transposed flip \x12",
    "Reverse Transpose",
    "Replace colors",
    "Advance colors",
    "Exchange colors",
    "Overlay",
    "Shift \x18",
    "Shift \x19",
    "Shift \x1A",
    "Shift \x1B",
    "Hue/Shade",
  };
  const char*s;
  char buf[64];
  Sint8 c=-1;
  int i,j,y;
  SDL_Rect r;
  SDL_Event ev;
1432
1433
1434
1435
1436
1437
1438






1439
1440
1441
1442
1443
1444
1445
        draw_text(16,y,txt[j],0xF0,0xF7);
        y+=8;
        for(j=0;j<dp->filters[i].shift.nshift;j++) {
          snprintf(buf,64,"%d: %d",dp->filters[i].shift.size[j],dp->filters[i].shift.shift[j]);
          draw_text(32,y,buf,0xF0,0xFE);
          y+=8;
        }






        break;
      default:
        draw_text(16,y,"???",0xF0,0xFC);
        y+=8;
        break;
    }
  }







>
>
>
>
>
>







1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
        draw_text(16,y,txt[j],0xF0,0xF7);
        y+=8;
        for(j=0;j<dp->filters[i].shift.nshift;j++) {
          snprintf(buf,64,"%d: %d",dp->filters[i].shift.size[j],dp->filters[i].shift.shift[j]);
          draw_text(32,y,buf,0xF0,0xFE);
          y+=8;
        }
        break;
      case 16:
        draw_text(16,y,"Hue/Shade: ",0xF0,0xF7);
        snprintf(buf,64,"%d %+d",dp->filters[i].hueshade.hue,dp->filters[i].hueshade.shade);
        draw_text(104,y,buf,0xF0,0xFE);
        y+=8;
        break;
      default:
        draw_text(16,y,"???",0xF0,0xFC);
        y+=8;
        break;
    }
  }
1472
1473
1474
1475
1476
1477
1478











1479
1480
1481
1482
1483
1484
1485
                  break;
                case 11:
                  s=screen_prompt("Name of overlay picture:");
                  if(s && *s) strncpy(dp->filters[c].overlay.name,s,63);
                  break;
                case 12 ... 15:
                  edit_shift_filter(&dp->filters[c].shift);











                  break;
              }
            }
            break;
          case SDLK_DELETE: case SDLK_KP_PERIOD:
            if(c<0 || c>=dp->nfilters) break;
            --dp->nfilters;







>
>
>
>
>
>
>
>
>
>
>







1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
                  break;
                case 11:
                  s=screen_prompt("Name of overlay picture:");
                  if(s && *s) strncpy(dp->filters[c].overlay.name,s,63);
                  break;
                case 12 ... 15:
                  edit_shift_filter(&dp->filters[c].shift);
                  break;
                case 16:
                  s=screen_prompt("Hue adjust:");
                  if(s && *s) {
                    i=strtol(s,0,10);
                    s=screen_prompt("Shade adjust:");
                    if(s && *s) {
                      dp->filters[c].hueshade.hue=i;
                      dp->filters[c].hueshade.shade=strtol(s,0,10);
                    }
                  }
                  break;
              }
            }
            break;
          case SDLK_DELETE: case SDLK_KP_PERIOD:
            if(c<0 || c>=dp->nfilters) break;
            --dp->nfilters;

Modified picedit.doc from [cbbac7773d] to [db75a2ce84].

233
234
235
236
237
238
239




240
241
242
243
244
245
246
* Overlay: Paste the specified independent picture over the current
picture, showing through wherever it is transparent.

* Shift: Shift the picture. Specify the sizes and shift amounts in the
format "size: shift"; each size also affects all multiples of that size,
in which case the shift amount is also multiplied by the same amount.






=== Multidependent pictures ===

A multidependent picture lump defines several pictures which are formed
from one or more independent pictures and filters, using common sets of
base pictures and filter chains.








>
>
>
>







233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
* Overlay: Paste the specified independent picture over the current
picture, showing through wherever it is transparent.

* Shift: Shift the picture. Specify the sizes and shift amounts in the
format "size: shift"; each size also affects all multiples of that size,
in which case the shift amount is also multiplied by the same amount.

* Hue/Shade: Specify hue adjustment and shade adjustment. The hue
adjustment is unsigned, and the shade adjustment is signed; any colours
that are in range 1 to 225 are affected; other colours remain unchanged.


=== Multidependent pictures ===

A multidependent picture lump defines several pictures which are formed
from one or more independent pictures and filters, using common sets of
base pictures and filter chains.

Modified picture.c from [d56be134d2] to [57df01a3fa].

676
677
678
679
680
681
682


















683
684
685
686
687
688
689
      }
      while(sz>0 && x<128) {
        x=fgetc(fp);
        fgetc(fp);
        sz-=2;
      }
      break;


















    default:
      fprintf(stderr,"Unrecognized command in dependent picture (%d)\n",c);
      goto done;
  }
  if(sz<-1) fprintf(stderr,"Lump size of dependent picture is too short\n");
  done: sqlite3_finalize(st);
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
      }
      while(sz>0 && x<128) {
        x=fgetc(fp);
        fgetc(fp);
        sz-=2;
      }
      break;
    case 16: // Hue/shade
      fread(buf,1,2,fp);
      c=(Sint8)buf[1];
      sz-=2;
      SDL_LockSurface(picts);
      p=picts->pixels+((img&15)+picts->pitch*(img>>4))*picture_size;
      for(y=0;y<picture_size;y++) {
        for(x=0;x<picture_size;x++) {
          if(p[x] && p[x]<=225) {
            i=(p[x]-1)%15+c;
            p[x]=15*(((p[x]-1)/15+buf[0])%15)+1;
            if(i<0) p[x]=1; else if(i>14) p[x]=15; else p[x]+=i;
          }
        }
        p+=picts->pitch;
      }
      SDL_UnlockSurface(picts);
      break;
    default:
      fprintf(stderr,"Unrecognized command in dependent picture (%d)\n",c);
      goto done;
  }
  if(sz<-1) fprintf(stderr,"Lump size of dependent picture is too short\n");
  done: sqlite3_finalize(st);
}