Example #1
0
File: main.c Project: LuckJC/pro-mk
static void release_images(struct image **images, unsigned int num_images)
{
    unsigned int i;

    assert(images != NULL);
    assert(*images != NULL);

    for (i=0; i<num_images; ++i)
    {
        struct image *image_i = &(*images)[i];
        release_image(image_i);
    }

    free(*images);
    *images = NULL;
}
Example #2
0
int write_image( const Image& image, const char *filename )
{
    if(std::string(filename).rfind(".png") == std::string::npos && std::string(filename).rfind(".PNG") == std::string::npos )
    {
        printf("writing color image '%s'... failed, not a PNG image.\n", filename);
        return -1;
    }
    
    // flip de l'image : Y inverse entre GL et BMP
    Image flip= create_image(image.width, image.height, 4, make_color(0, 0, 0));
    for(int y= 0; y < image.height; y++)
    for(int x= 0; x < image.width; x++)
        image_set_pixel(flip, x, image.height - y -1, image_pixel(image, x, y));

    SDL_Surface *bmp= SDL_CreateRGBSurfaceFrom((void *) &flip.data.front(),
        image.width, image.height,
        32, image.width * 4,
#if 0
        0xFF000000,
        0x00FF0000,
        0x0000FF00,
        0x000000FF
#else
        0x000000FF,
        0x0000FF00,
        0x00FF0000,
        0xFF000000
#endif
    );

    int code= IMG_SavePNG(bmp, filename);
    SDL_FreeSurface(bmp);
    release_image(flip);
    
    if(code < 0)
        printf("writing color image '%s'... failed\n%s\n", filename, SDL_GetError());
    else
        printf("writing color image '%s'...\n", filename);
    return code;
}
Example #3
0
File: main.c Project: LuckJC/pro-mk
int main(int argc,char *argv[])
{
    //struct image *norImages = NULL;
    //unsigned int num_nor_images = 0;
    struct image download_agent = { NULL, 0, 0, "", 0 };
    struct image download_agent_TCM = { NULL, 0, 0, "", 0 };
    struct image download_EPP = { NULL, 0, 0, "", 0 };
    struct image nor_flash_table = { NULL, 0, 0, "", 0 };
    struct image nand_flash_table = { NULL, 0, 0, "", 0 };
    struct image *linux_images = NULL;
    //unsigned int num_images = 0;
    unsigned int num_linux_images = 0;
    unsigned int bmt_address = 0;
    //int i = 0;

    struct image boot_loader = { NULL, 0, 0, "", 0 };
    struct image ext_boot_loader = { NULL, 0, 0, "", 0 };
    //struct image dsp_boot_loader = { NULL, 0, 0, "", 0 };
    struct image rom_image = { NULL, 0, 0, "", 0 };
    //struct image secondary_rom_image = { NULL, 0, 0, "", 0 };
    //struct image dsp_rom_image = { NULL, 0, 0, "", 0 };
    //struct image demand_paging_image = { NULL, 0, 0, "", 0 };

    //jone.wang@

    //freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
    //freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
    //fflush(stdout);
    //fflush(stderr);
    //setbuf(stdout, NULL);
    //setbuf(stderr, NULL);
    //fprintf(stdout, "Brom Ite main =================\n");
    //added by xiaohui 4-19

    if (argc < 2) {
        fprintf(stderr, "Usage: %s filepath [write_block_size] [trace_log]\n", basename(argv[0]));
        return -1;
    }

    char path[BUFSIZ] = "";
    strcpy(path, argv[1]);

    /* "/system/etc/firmware/modem" normally */
    if (access(path, R_OK) != 0) {
        fprintf(stderr, "path '%s` is invalid. %d, %s\n", path, errno, strerror(errno));
        return -1;
    }

    path[strlen(path)] = '/';
    LOG("path: %s\n", path);

    if (generate_all_image_path(path) != 0)
        return -1;

    //strcpy(dev_path,argv[2]);
    //pipe_fd = atoi(argv[3]);
    //pipe_buf = (char *)malloc(PIPE_BUF_SIZE);
    //if(!pipe_buf)
        //return 0;
    //printf("dev_path=%s\n",dev_path);
    //printf("pipe fd=%d\n",pipe_fd);

    log_feedback("begin to feedback!!!\n");
    //printf("%s\n",pipe_buf);
    //return 0;
    //added by xiaohui 4-19    

    if (argc > 2) {
        int psiz = atoi(argv[2]);
        if (psiz > 0) {
            PSIZ = psiz;
        }
    }
    LOG("PSIZ = %d\n", PSIZ);

    int trace_log = 0;
    if (argc > 3) {
        if (argv[3][0] == '0')
            trace_log = 0;
        else
            trace_log = 1;
    }
    if (trace_log)
        LOG("enable log tracing\n");
    enable_log = trace_log;

    int rc = -1;

    do {
        // Acquire pointers to DA, flash tables, and images
        if ((rc = acquire_download_agent(&download_agent,DOWNLOAD_AGENT_FILE_PATH,DOWNLOAD_AGENT_LOAD_ADDR)) != 0)
            break;
        //acquire_download_agent(&download_agent_TCM,DOWNLOAD_AGENT_TCM_FILE_PATH, DOWNLOAD_AGENT_TCM_LOAD_ADDR);
        if ((rc = acquire_download_agent(&download_EPP,DOWNLOAD_EPP_FILE_PATH, DOWNLOAD_EPP_LOAD_ADDR)) != 0)
            break;
        if ((rc = acquire_flash_table(&nor_flash_table, NOR_FLASH_TABLE_FILE_PATH)) != 0)
            break;
        if ((rc = acquire_flash_table(&nand_flash_table, NAND_FLASH_TABLE_FILE_PATH)) != 0)
            break;

        //Acquire Boot loader
        if ((rc = acquire_image(&boot_loader, BOOT_LOADER_FILE_PATH,0)) != 0)
            break;
        if ((rc = acquire_image(&ext_boot_loader, EXT_BOOT_LOADER_FILE_PATH,0)) != 0)
            break;
        //acquire_image(&dsp_boot_loader, DSP_BOOT_LOADER_FILE_PATH,0);
        //Acquire ROM images
        if ((rc = acquire_image(&rom_image, ROM_FILE_PATH,0)) != 0)
            break;
        //acquire_image(&secondary_rom_image, SECONDARY_ROM_FILE_PATH,0);
        //acquire_image(&dsp_rom_image, DSP_ROM_FILE_PATH,0);
        //acquire_image(&demand_paging_image, DEMAND_PAGING_ROM0_FILE_PATH,0);

        //Acquire linux partition images
        if ((rc = acquire_linux_images(&linux_images, &num_linux_images, &bmt_address)) != 0)
            break;
    } while (0);

    if (rc != 0)
        return rc;

    rc = download_images(&download_agent,
                         &download_agent_TCM,
                         &nor_flash_table,
                         &nand_flash_table,
                         &download_EPP,
                         &boot_loader,
                         &ext_boot_loader,
                         NULL, //&dsp_boot_loader,
                         &rom_image,
                         NULL, //&secondary_rom_image,
                         NULL, //&dsp_rom_image,
                         NULL, //&demand_paging_image,
                         linux_images,
                         (const struct ExternalMemorySetting *)&externalMemorySetting,
                         sizeof(LINUX_PARTITION_IMAGE_FILE_NAME) / sizeof(LINUX_PARTITION_IMAGE_FILE_NAME[0]), //num_linux_images,modified by xiaohui 4-22
                         bmt_address,
                         1, /*0:UART, 1:USB*/
                         1 /*0:NOR, 1:NAND*/);
    if (rc != S_DONE) {
        printf("download failed, rc %d\n", rc);
    } else {
        //jone.wang
        printf("download done\n");
    }

    release_images(&linux_images, num_linux_images);

    release_image(&boot_loader);
    release_image(&ext_boot_loader);
    release_image(&rom_image);
    //release_image(&secondary_rom_image);
    //release_image(&demand_paging_image);

    release_flash_table(&nand_flash_table);
    release_flash_table(&nor_flash_table);
    release_download_agent(&download_agent);
    release_download_agent(&download_agent_TCM);
    release_download_agent(&download_EPP);

    //added by xiaohui 4-19
    //close(pipe_fd);
    //free(pipe_buf);

    printf("brom_lite end, rc %d\n", rc);
    return rc;
}
Example #4
0
File: main.c Project: LuckJC/pro-mk
static void release_flash_table(struct image *flash_table)
{
    release_image(flash_table);
}
Example #5
0
File: main.c Project: LuckJC/pro-mk
static void release_download_agent(struct image *download_agent)
{
    release_image(download_agent);
}
Example #6
0
int get_image(VASurfaceID surface, Image *dst_img)
{
    VAAPIContext * const vaapi = vaapi_get_context();
    VAImage image;
    VAImageFormat *image_format = NULL;
    VAStatus status;
    Image bound_image;
    int i, is_bound_image = 0, is_derived_image = 0, error = -1;

    image.image_id = VA_INVALID_ID;
    image.buf      = VA_INVALID_ID;

    if (!image_format) {
        status = vaDeriveImage(vaapi->display, surface, &image);
        if (vaapi_check_status(status, "vaDeriveImage()")) {
            if (image.image_id != VA_INVALID_ID && image.buf != VA_INVALID_ID) {
                D(bug("using vaDeriveImage()\n"));
                is_derived_image = 1;
                image_format = &image.format;
            }
            else {
                D(bug("vaDeriveImage() returned success but VA image is invalid. Trying vaGetImage()\n"));
            }
        }
    }

    if (!image_format) {
        for (i = 0; image_formats[i] != 0; i++) {
            if (get_image_format(vaapi, image_formats[i], &image_format))
                break;
        }
    }

    if (!image_format)
        goto end;
    D(bug("selected %s image format for getimage\n",
          string_of_VAImageFormat(image_format)));

    if (!is_derived_image) {
        status = vaCreateImage(vaapi->display, image_format,
                               vaapi->picture_width, vaapi->picture_height,
                               &image);
        if (!vaapi_check_status(status, "vaCreateImage()"))
            goto end;
        D(bug("created image with id 0x%08x and buffer id 0x%08x\n",
              image.image_id, image.buf));

        VARectangle src_rect;

        src_rect.x      = 0;
        src_rect.y      = 0;
        src_rect.width  = vaapi->picture_width;
        src_rect.height = vaapi->picture_height;

        D(bug("src rect (%d,%d):%ux%u\n",
              src_rect.x, src_rect.y, src_rect.width, src_rect.height));

        status = vaGetImage(
            vaapi->display, vaapi->surface_id,
            src_rect.x, src_rect.y, src_rect.width, src_rect.height,
            image.image_id
        );
        if (!vaapi_check_status(status, "vaGetImage()")) {
            vaDestroyImage(vaapi->display, image.image_id);
            goto end;
        }
    }

    if (bind_image(&image, &bound_image) < 0)
        goto end;
    is_bound_image = 1;

    if (image_convert(dst_img, &bound_image) < 0)
        goto end;

    error = 0;
end:
    if (is_bound_image) {
        if (release_image(&image) < 0)
            error = -1;
    }

    if (image.image_id != VA_INVALID_ID) {
        status = vaDestroyImage(vaapi->display, image.image_id);
        if (!vaapi_check_status(status, "vaDestroyImage()"))
            error = -1;
    }
    return error;
}