Beispiel #1
0
void CGColor::getHSV(float &h, float &s, float &v) const
{
    // see https://de.wikipedia.org/wiki/HSV-Farbraum
    float rr=redf();
    float gg=greenf();
    float bb=bluef();
    float ma=std::max(std::max(rr,gg),bb);
    float mi=std::min(std::min(rr,gg),bb);

    if (ma==mi) h=0;
    else if (ma==rr) h=60.0*(0.0+(gg-bb)/(ma-mi));
    else if (ma==gg) h=60.0*(2.0+(bb-rr)/(ma-mi));
    else if (ma==bb) h=60.0*(4.0+(rr-gg)/(ma-mi));
    if (h<0.0) h=h+360.0;

    if (ma==0.0) s=0.0;
    else s=(ma-mi)/ma;

    v=ma;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    char *filename = argc < 2 ? "fat.ima" : argv[1];

    FILE *f = fopen(filename, "r");

    if(f == NULL) {
        errorf("couldn't open file '%s'\n", filename);
        return 1;
    }

    if(!check_sig(f))
        return 1;

    struct BPB_t bpb;
    read_bytes(f, 0x0, &bpb, sizeof(bpb));

    if(bpb.BytsPerSec != 512 || bpb.NumFATs != 2)
        return 1;

    greenf( "FAT addr: 0x%x\n"
            "Root addr: 0x%x\n"
            "Data addr: 0x%x\n",
            BPB_FAT_addr(&bpb),
            BPB_Root_addr(&bpb),
            BPB_Data_addr(&bpb)
          );

    for(int i = 0; i < bpb.RootEntCnt; i++) {
        struct dir_t dir;
        uint32_t offset = BPB_Root_addr(&bpb) + i*32;
        read_bytes(f, offset, &dir, sizeof(dir));

        if(dir.Name[0] == 0) {
            break;
        } else if(dir.Name[0] == 0xE5) {
            printf("<unused space>\n");
            continue;
        }


        purplef("\n%.*s", (int)(sizeof(dir.Name)/sizeof(char)), dir.Name);
        const char *type;

        if(dir.Attr & DIR_ATTR_LFN) {
            purplef("<LONG FILENAME>\n");
        } else if(dir.Attr & DIR_ATTR_DIRECTORY) {
            purplef("<DIRECTORY>\n");
        } else {
            purplef("<FILE>\n");

            //if(i == 0xF)
            //    print_cluster(f, &bpb, &dir);
            //else
                printf("<omitting print>\n");
        }
    }

    fclose(f);

    return 0;
}