How do I load and save FILES from TPT

  • Videogamer555
    28th Apr 2011 Member 0 Permalink
    I see there is now a new feature on the downloads page that allows you to download directly to a file of the extension *.cps but how do I load that file in TPT? Also is it possible to directly save to *.cps files from TPT?
  • Pilihp64
    28th Apr 2011 Developer 0 Permalink
    in powder toy, press ctrl-i . this will install a registry entry for *.cps and *.stm files, you then can just double click on them and they will open in powder toy.

    .cps and .stm are exactly the same thing, you can simply change the file extension by renaming.
  • Videogamer555
    28th Apr 2011 Member 0 Permalink
    Ok but how to I load such files without loading them as stamps or as registered files? How do I access the hidden File/load and File/save menus in TPT?

    Also if I want to edit the content of a stamp file in a 3rd party software (which I plan to do) I'll need to know the specs of such a file. How do I find the specs on these files?
  • Pilihp64
    28th Apr 2011 Developer 0 Permalink
    save files are stored as stamps, the only other way to load them is by putting them in the stamps folder and editing stamps.def. The extension register is much simpler.
    For reading the contents of a stamp, you can look in main.c for the save/load functions.
    theres no need for another program to open them... powder toy does that just fine.
  • Videogamer555
    28th Apr 2011 Member 0 Permalink
    I meant I'm looking to make an automated system where I can do what some other people have done and create a program which convert normal pictures into TPT stamps. To do that I'll need to know the exact format of how a stamp file stores the data. I can find info on BMP image file format from Wikipedia, but I don't know where to find the info on the TPT stamp file format.
  • vanquish349
    28th Apr 2011 Member 0 Permalink
    @Videogamer555 (View Post)
    have you read the rules, it says you cant do it
  • Pilihp64
    28th Apr 2011 Developer 0 Permalink
    ok i see, there's no real guide on the format of save files, but if you look in main.c at the save function, its pretty clear.

    the image program which i made drew elements onto the screen directly from python (you would need to compile the python console version). But it could create a stamp file instead.

    good luck.

    EDIT to vanquish: yes you can make it, its a good challenge, just don't make them public.
  • Videogamer555
    28th Apr 2011 Member 0 Permalink
    Is it really against the rules to publish saves that are conversions of picture files? Also does that only apply for copyright pictures? What if I use my OWN picture (like a photo I took myself) for the source?
  • dnerd
    28th Apr 2011 Member 0 Permalink
    @Videogamer555 (View Post)
    you can trace it yourself, but using a program to do it is chating.
  • Videogamer555
    28th Apr 2011 Member 0 Permalink
    Ok I finally found the code for saving Stamps (I think), but I can't make heads or tales of it because I don't do a lot of C programming. I looked a stamp file in a hex editor but the data appears compressed. I don't know what algorithm it uses either.


    And here is the C code dump I found. Could someone explain the important parts to me a bit.

    // stamps library

    stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y];

    int stamp_count = 0;

    unsigned last_time=0, last_name=0;
    void stamp_gen_name(char *fn)
    {
    unsigned t=(unsigned)time(NULL);

    if (last_time!=t)
    {
    last_time=t;
    last_name=0;
    }
    else
    last_name++;

    sprintf(fn, "%08x%02x", last_time, last_name);
    }

    void stamp_update(void)
    {
    FILE *f;
    int i;
    f=fopen("stamps" PATH_SEP "stamps.def", "wb");
    if (!f)
    return;
    for (i=0; i {
    if (!stamps[i].name[0])
    break;
    if (stamps[i].dodelete!=1)
    {
    fwrite(stamps[i].name, 1, 10, f);
    }
    }
    fclose(f);
    }

    void stamp_gen_thumb(int i)
    {
    char fn[64];
    void *data;
    int size, factor_x, factor_y;
    pixel *tmp;

    if (stamps[i].thumb)
    {
    free(stamps[i].thumb);
    stamps[i].thumb = NULL;
    }

    sprintf(fn, "stamps" PATH_SEP "%s.stm", stamps[i].name);
    data = file_load(fn, &size);

    if (data)
    {
    stamps[i].thumb = prerender_save(data, size, &(stamps[i].thumb_w), &(stamps[i].thumb_h));
    if (stamps[i].thumb && (stamps[i].thumb_w>XRES/GRID_S || stamps[i].thumb_h>YRES/GRID_S))
    {
    factor_x = ceil((float)stamps[i].thumb_w/(float)(XRES/GRID_S));
    factor_y = ceil((float)stamps[i].thumb_h/(float)(YRES/GRID_S));
    if (factor_y > factor_x)
    factor_x = factor_y;
    tmp = rescale_img(stamps[i].thumb, stamps[i].thumb_w, stamps[i].thumb_h, &(stamps[i].thumb_w), &(stamps[i].thumb_h), factor_x);
    free(stamps[i].thumb);
    stamps[i].thumb = tmp;
    }
    }

    free(data);
    }

    int clipboard_ready = 0;
    void *clipboard_data = 0;
    int clipboard_length = 0;

    void stamp_save(int x, int y, int w, int h)
    {
    FILE *f;
    int n;
    char fn[64], sn[16];
    void *s=build_save(&n, x, y, w, h, bmap, fvx, fvy, signs, parts);

    #ifdef WIN32
    _mkdir("stamps");
    #else
    mkdir("stamps", 0755);
    #endif

    stamp_gen_name(sn);
    sprintf(fn, "stamps" PATH_SEP "%s.stm", sn);

    f = fopen(fn, "wb");
    if (!f)
    return;
    fwrite(s, n, 1, f);
    fclose(f);

    free(s);

    if (stamps[STAMP_MAX-1].thumb)
    free(stamps[STAMP_MAX-1].thumb);
    memmove(stamps+1, stamps, sizeof(struct stamp)*(STAMP_MAX-1));
    memset(stamps, 0, sizeof(struct stamp));
    if (stamp_count stamp_count++;

    strcpy(stamps[0].name, sn);
    stamp_gen_thumb(0);

    stamp_update();
    }