コード例 #1
0
void pfm::pfm_output_file::write_color_scanline(const color_pixel* scanline, std::size_t length)
{
  assert(format_ == color_format);
  assert(scanline != 0);
  assert(length == width_);

  const color_pixel* scanline_begin = scanline;
  const color_pixel* scanline_end = scanline_begin + length;
  for (const color_pixel* scanline_iterator = scanline_begin; scanline_iterator != scanline_end; ++scanline_iterator) {
    color_pixel pixel = *scanline_iterator;
    if (byte_order_ != host_byte_order) {
      swap_byte_order(pixel[0]);
    }
    ostream_.write(reinterpret_cast<const char*>(&pixel[0]), 4);
    if (!ostream_) {
      #ifdef PFM_DEBUG
        std::cerr << istream_.tellp() << ": " << "error: " << std::endl;
      #endif
      throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__);
    }
    if (byte_order_ != host_byte_order) {
      swap_byte_order(pixel[1]);
    }
    ostream_.write(reinterpret_cast<const char*>(&pixel[1]), 4);
    if (!ostream_) {
      #ifdef PFM_DEBUG
        std::cerr << istream_.tellp() << ": " << "error: " << std::endl;
      #endif
      throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__);
    }
    if (byte_order_ != host_byte_order) {
      swap_byte_order(pixel[2]);
    }
    ostream_.write(reinterpret_cast<const char*>(&pixel[2]), 4);
    if (!ostream_) {
      #ifdef PFM_DEBUG
        std::cerr << istream_.tellp() << ": " << "error: " << std::endl;
      #endif
      throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__);
    }
  }
}
コード例 #2
0
sep_keymaster_return_t generate_keypair_cmd_buf(
        intel_keymaster_firmware_cmd_t * lib_cmd,
        ANDROID_HECI_KEYMASTER_CMD_RSA_GEN_KEY_REQUEST * fw_cmd) {
    sep_keymaster_return_t result = SEP_KEYMASTER_FAILURE;

    if (!(lib_cmd && fw_cmd)) {
        result = SEP_KEYMASTER_BAD_PARAMETER;
        LOGERR("Invalid parameters while creating keypair buffer\n");
        goto exit;
    }
    //Assuming that key type is RSA for now. TODO: change later
    if (lib_cmd->cmd_data_length
            < sizeof(intel_keymaster_keygen_params_t)
                    + sizeof(intel_keymaster_rsa_keygen_params_t)) {
        result = SEP_KEYMASTER_BAD_PARAMETER;
        LOGERR("Invalid input parameters while creating keypair buffer\n");
        goto exit;
    }

    intel_keymaster_keygen_params_t *keygen_params =
            (intel_keymaster_keygen_params_t *) lib_cmd->cmd_data;

    if (keygen_params->key_type != KEY_TYPE_RSA) //TODO: has to change later when other key types are supported
            {
        result = SEP_KEYMASTER_BAD_PARAMETER;
        LOGERR("Invalid key type while creating keypair buffer\n");
        goto exit;
    }

    intel_keymaster_rsa_keygen_params_t *rsa_keygen_params_t =
            (intel_keymaster_rsa_keygen_params_t *) keygen_params->key_params;

    fw_cmd->KeySize = rsa_keygen_params_t->modulus_size / 8;
    //Note, only copying ANDROID_HECI_KEYMASTER_PUBLIC_EXPONENT_MAX_SIZE bytes in
    memcpy(fw_cmd->PublicExponent, &rsa_keygen_params_t->public_exponent,
            ANDROID_HECI_KEYMASTER_PUBLIC_EXPONENT_MAX_SIZE);
    swap_byte_order(fw_cmd->PublicExponent,
            ANDROID_HECI_KEYMASTER_PUBLIC_EXPONENT_MAX_SIZE); //Exponent needs to be big-endian

    fw_cmd->Header.InputSize =
            sizeof(ANDROID_HECI_KEYMASTER_CMD_RSA_GEN_KEY_REQUEST)
                    - sizeof(ANDROID_HECI_AGENT_REQ_HEADER);

    result = SEP_KEYMASTER_SUCCESS;
    exit: return result;
}
コード例 #3
0
void pfm::pfm_input_file::read_grayscale_scanline(grayscale_pixel* scanline, std::size_t length)
{
  assert(format_ == grayscale_format);
  assert(scanline != 0);
  assert(length == width_);

  grayscale_pixel* scanline_begin = scanline;
  grayscale_pixel* scanline_end = scanline_begin + length;
  for (grayscale_pixel* scanline_iterator = scanline_begin; scanline_iterator != scanline_end; ++scanline_iterator) {
    grayscale_pixel& pixel = *scanline_iterator;
    istream_.read(reinterpret_cast<char*>(&pixel), 4);
    if (!istream_) {
      #ifdef PFM_DEBUG
        std::cerr << istream_.tellg() << ": " << "error: " << std::endl;
      #endif
      throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__);
    }
    if (byte_order_ != host_byte_order) {
      swap_byte_order(pixel);
    }
  }
}
コード例 #4
0
ファイル: lvledit.cpp プロジェクト: Gendron5000/triplane
int main(int argc, char **argv) {

    FILE *faili;
    int c;

    printf("\n");
    printf(" Lvledit for Triplane   Copyright (c) 1996 Dodekaedron Software Creations, Inc.");
    printf("\n\r\n\r");

    if (argc != 2) {
        printf("Usage: LVLEDIT level_filename\n");
        exit(1);
    }

    printf("Loading directory structure\n\r");
    dksinit("fokker.dks");

    strcpy(filename, argv[1]);

    if ((faili = fopen(filename, "rb")) == NULL) {
        printf("Creating new level.\n\r");

        strcpy(leveldata.pb_name, "MAISDT");
        for (c = 0; c < MAX_STRUCTURES; c++) {
            leveldata.struct_x[c] = 0;
            leveldata.struct_y[c] = 0;
            leveldata.struct_hit[c] = 0;
            leveldata.pd_name[c][0] = 0;
            leveldata.struct_owner[c] = 4;
            leveldata.struct_type[c] = 0;



        }
        for (c = 0; c < 4; c++) {
            leveldata.airfield_x[c] = 0;
            leveldata.airfield_y[c] = 0;
            leveldata.airfield_lenght[c] = 110;
            leveldata.plane_direction[c] = 0;
        }

    } else {
        printf("Loading existing level.\n\r");
        fread(&leveldata, sizeof(leveldata), 1, faili);
        fclose(faili);

        for (c = 0; c < MAX_STRUCTURES; c++) {

            if (leveldata.struct_x[c]) {
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                struct_picture[c]->info(&picture_width[c], &picture_height[c]);
            }
        }
    }

    printf("Loading font \"FROST\"\n\r");
    fontti = new Font("G2FONT");

    printf("Loading cursor\n\r");
    hiirik = new Bitmap("FONTT1");
    hiirikursori = hiirik;

    if (leveldata.pb_name[0]) {
        printf("Loading background picture\n\r");

        pb_picture = new Bitmap(leveldata.pb_name);

    }

    printf("Loading background papers\n\r");

    lappu1 = new Bitmap("LAPPU1");
    lappu2 = new Bitmap("LAPPU2");

    init_vga("PALET5");

    edit_level();

    swap_byte_order();
    faili = fopen(filename, "wb");
    fwrite(&leveldata, sizeof(leveldata), 1, faili);
    fclose(faili);
    swap_byte_order();

    delete pb_picture;
    delete lappu1;
    delete lappu2;
    delete hiirik;
    delete fontti;
    for (c = 0; c < MAX_STRUCTURES; c++)
        if (leveldata.struct_x[c])
            delete struct_picture[c];

    return 0;

}
コード例 #5
0
ファイル: lvledit.cpp プロジェクト: Gendron5000/triplane
void edit_level(void) {
    int ch = 0;
    int kohta = 0;
    int c;
    int x, y, n1, n2;
    int current = -1;
    int active = -1;
    int airfield_set = -1;
    unsigned char colori = 0;
    FILE *faili;

    Bitmap *pointti;
    pointti = new Bitmap(1, 1, &colori);

    while (!(ch == SDLK_ESCAPE)) {
        colori++;
        pb_picture->blit(-kohta, 0);
        for (c = 0; c < MAX_STRUCTURES; c++) {
            if (leveldata.struct_x[c]) {
                struct_picture[c]->blit(leveldata.struct_x[c] - kohta, leveldata.struct_y[c]);
            }
        }

        if (active != -1) {
            if (leveldata.struct_x[active] >= kohta && leveldata.struct_x[active] <= (kohta + 300))

                boxi(leveldata.struct_x[active] - kohta,
                     leveldata.struct_y[active],
                     leveldata.struct_x[active] - kohta + picture_width[active], leveldata.struct_y[active] + picture_height[active], 1);
        }

        for (c = 0; c < 4; c++)
            if (leveldata.airfield_x[c])
                omaline(leveldata.airfield_x[c] - kohta, leveldata.airfield_y[c],
                        leveldata.airfield_x[c] - kohta + leveldata.airfield_lenght[c], leveldata.airfield_y[c], colori);


        if (active != -1) {
            lappu1->blit(220, 0);
            fontti->printf(235, 4, "%s", leveldata.pd_name[active]);
            fontti->printf(235, 14, "X:%d Y:%d", leveldata.struct_x[active], leveldata.struct_y[active]);
            fontti->printf(235, 23, "%s", owner_names[leveldata.struct_owner[active]]);
            fontti->printf(235, 32, "%s", hitting_names[leveldata.struct_hit[active]]);
            fontti->printf(235, 41, "%s", type_names[leveldata.struct_type[active]]);
        }

        lappu2->blit(262, 184);
        fontti->printf(265, 188, "%s", leveldata.pb_name);

        koords(&x, &y, &n1, &n2);
        hiirikursori->blit(x, y);

        if (airfield_set != -1 && (n1 || n2)) {
            hiirikursori = hiirik;
            leveldata.airfield_x[airfield_set] = x + kohta;
            leveldata.airfield_y[airfield_set] = y;
            if (n1)
                leveldata.plane_direction[airfield_set] = 0;
            else
                leveldata.plane_direction[airfield_set] = 1;
            airfield_set = -1;
        }

        if (n1 && (current != -1)) {
            leveldata.struct_x[current] = x + kohta;
            leveldata.struct_y[current] = y;
            hiirikursori = hiirik;
            current = -1;
        } else if (n1 && (active == -1)) {
            for (c = 0; c < MAX_STRUCTURES; c++) {
                if ((x + kohta) >= leveldata.struct_x[c] &&
                    (x + kohta) <= (leveldata.struct_x[c] + picture_width[c]) && y >= leveldata.struct_y[c] && y <= (leveldata.struct_y[c] + picture_height[c]))
                    break;

            }

            if (c != MAX_STRUCTURES) {
                active = c;

            }
        }


        if (n2 && (active != -1)) {
            active = -1;
        }

        do_all();
        //while(!kbhit());

        if (kbhit()) {
            ch = getch();

            switch (ch) {
            case SDLK_F2:
                swap_byte_order();
                faili = fopen(filename, "wb");
                fwrite(&leveldata, sizeof(leveldata), 1, faili);
                fclose(faili);
                swap_byte_order();
                break;

            case SDLK_INSERT:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                fontti->printf(10, 10, "StructureNAME");
                fontti->scanf(10, 20, leveldata.pd_name[c], 6);
                if (!leveldata.pd_name[c][0])
                    break;
                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F5:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;

                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 0;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F6:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 1;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F7:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 2;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F8:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 3;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;


            case SDLK_DELETE:
                if (active != -1) {
                    leveldata.struct_x[active] = 0;
                    delete struct_picture[active];
                    active = -1;

                }
                break;

            case SDLK_HOME:
                if (active != -1) {
                    leveldata.struct_owner[active]++;
                    if (leveldata.struct_owner[active] >= 5)
                        leveldata.struct_owner[active] = 0;

                }
                break;

            case SDLK_END:
                if (active != -1) {
                    leveldata.struct_hit[active]++;
                    if (leveldata.struct_hit[active] >= 2)
                        leveldata.struct_hit[active] = 0;
                }
                break;
            case SDLK_RIGHT:
                kohta += 106;
                if (kohta > 2080)
                    kohta = 2080;
                break;

            case SDLK_LEFT:
                kohta -= 106;
                if (kohta < 0)
                    kohta = 0;
                break;

            case SDLK_PAGEUP:
                char temp_stringi[10];
                temp_stringi[0] = 0;
                fontti->scanf(265, 178, temp_stringi, 6);

                if (!bitmap_exists(temp_stringi))
                    break;


                strcpy(leveldata.pb_name, temp_stringi);
                delete pb_picture;
                pb_picture = new Bitmap(temp_stringi);
                break;

            case SDLK_PAGEDOWN:
                if (active != -1) {
                    leveldata.struct_type[active]++;
                    if (leveldata.struct_type[active] >= MAX_TYPES)
                        leveldata.struct_type[active] = 0;
                }
                break;
            case SDLK_q:
                leveldata.airfield_lenght[0]++;
                if (leveldata.airfield_lenght[0] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[0] = MAX_AIRFIELD_LENGHT;
                break;
            case SDLK_w:
                leveldata.airfield_lenght[1]++;
                if (leveldata.airfield_lenght[1] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[1] = MAX_AIRFIELD_LENGHT;
                break;
            case SDLK_e:
                leveldata.airfield_lenght[2]++;
                if (leveldata.airfield_lenght[2] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[2] = MAX_AIRFIELD_LENGHT;
                break;
            case SDLK_r:
                leveldata.airfield_lenght[3]++;
                if (leveldata.airfield_lenght[3] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[3] = MAX_AIRFIELD_LENGHT;
                break;

            case SDLK_a:
                leveldata.airfield_lenght[0]--;
                if (leveldata.airfield_lenght[0] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[0] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_s:
                leveldata.airfield_lenght[1]--;
                if (leveldata.airfield_lenght[1] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[1] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_d:
                leveldata.airfield_lenght[2]--;
                if (leveldata.airfield_lenght[2] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[2] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_f:
                leveldata.airfield_lenght[3]--;
                if (leveldata.airfield_lenght[3] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[3] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_PLUS:
                if (active == -1 || active == 99)
                    break;

                if (leveldata.struct_x[active + 1]);
                active++;
                break;

            case SDLK_MINUS:
                if (active < 1)
                    break;

                if (leveldata.struct_x[active - 1]);
                active--;
                break;
            default:
                if ((ch >= SDLK_1) && (ch <= SDLK_4)) {
                    airfield_set = ch - SDLK_1;
                    hiirikursori = pointti;
                }
                break;
            }
        }
    }

    delete pointti;

}
コード例 #6
0
ファイル: fdd.cpp プロジェクト: open-develop/unrealspeccyp
//=============================================================================
//	eFdd::UpdateCRC
//-----------------------------------------------------------------------------
void eFdd::UpdateCRC(eUdi::eTrack::eSector* s) const
{
	int len = s->Len();
	SectorDataW(s, len, swap_byte_order(Crc(s->data - 1, len + 1)));
}
コード例 #7
0
ファイル: fdd.cpp プロジェクト: djdron/UnrealSpeccyP
//=============================================================================
//	eUdi::eTrack::eSector::UpdateCRC
//-----------------------------------------------------------------------------
void eUdi::eTrack::eSector::UpdateCRC()
{
	int len = Len();
	DataW(len, swap_byte_order(eFdd::Crc(data - 1, len + 1)));
}