Exemplo n.º 1
0
int main(int argc, char **argv)
{
#ifdef ANDROID
  std::string img_name("/data/local/share/vikit_test_data/scene_000.png");
#else
  std::string img_name("/home/equilibrium/src/rpg_vikit/vikit_common/test/data/scene_000.png");
#endif
  cv::Mat img(cv::imread(img_name, 0));
  assert(!img.empty());

  testZMSSD(img);

  return 0;
}
Exemplo n.º 2
0
void read_jpg_info(integer img)
{
    int i, units = 0;
    unsigned char jpg_id[] = "JFIF";
    img_xres(img) = img_yres(img) = 0;
    jpg_ptr(img)->file = xfopen(img_name(img), FOPEN_RBIN_MODE);
    /* no LFS needed, as JPEG is limited to <4GiB */
    xfseek(jpg_ptr(img)->file, 0, SEEK_END, cur_file_name);
    jpg_ptr(img)->length = xftell(jpg_ptr(img)->file, cur_file_name);
    xfseek(jpg_ptr(img)->file, 0, SEEK_SET, cur_file_name);
    if (read2bytes(jpg_ptr(img)->file) != 0xFFD8)
        pdftex_fail("reading JPEG image failed (no JPEG header found)");
    /* currently only true JFIF files allow extracting img_xres and img_yres */
    if (read2bytes(jpg_ptr(img)->file) == 0xFFE0) {     /* check for JFIF */
        (void) read2bytes(jpg_ptr(img)->file);
        for (i = 0; i < 5; i++) {
            if (xgetc(jpg_ptr(img)->file) != jpg_id[i])
                break;
        }
        if (i == 5) {           /* it's JFIF */
            read2bytes(jpg_ptr(img)->file);
            units = xgetc(jpg_ptr(img)->file);
            img_xres(img) = read2bytes(jpg_ptr(img)->file);
            img_yres(img) = read2bytes(jpg_ptr(img)->file);
            switch (units) {
            case 1:
                break;          /* pixels per inch */
            case 2:
                img_xres(img) *= 2.54;
                img_yres(img) *= 2.54;
                break;          /* pixels per cm */
            default:
                img_xres(img) = img_yres(img) = 0;
                break;
            }
        }
    }
    xfseek(jpg_ptr(img)->file, 0, SEEK_SET, cur_file_name);
    while (1) {
        if (feof(jpg_ptr(img)->file))
            pdftex_fail("reading JPEG image failed (premature file end)");
        if (fgetc(jpg_ptr(img)->file) != 0xFF)
            pdftex_fail("reading JPEG image failed (no marker found)");
        switch (xgetc(jpg_ptr(img)->file)) {
        case M_SOF5:
        case M_SOF6:
        case M_SOF7:
        case M_SOF9:
        case M_SOF10:
        case M_SOF11:
        case M_SOF13:
        case M_SOF14:
        case M_SOF15:
            pdftex_fail("unsupported type of compression");
        case M_SOF2:
            if (fixedpdfminorversion <= 2)
                pdftex_fail("cannot use progressive DCT with PDF-1.2");
        case M_SOF0:
        case M_SOF1:
        case M_SOF3:
            (void) read2bytes(jpg_ptr(img)->file);      /* read segment length  */
            jpg_ptr(img)->bits_per_component = xgetc(jpg_ptr(img)->file);
            img_height(img) = read2bytes(jpg_ptr(img)->file);
            img_width(img) = read2bytes(jpg_ptr(img)->file);
            jpg_ptr(img)->color_space = xgetc(jpg_ptr(img)->file);
            xfseek(jpg_ptr(img)->file, 0, SEEK_SET, cur_file_name);
            switch (jpg_ptr(img)->color_space) {
            case JPG_GRAY:
                img_color(img) = IMAGE_COLOR_B;
                break;
            case JPG_RGB:
                img_color(img) = IMAGE_COLOR_C;
                break;
            case JPG_CMYK:
                img_color(img) = IMAGE_COLOR_C;
                break;
            default:
                pdftex_fail("Unsupported color space %i",
                            (int) jpg_ptr(img)->color_space);
            }
            return;
        case M_SOI:            /* ignore markers without parameters */
        case M_EOI:
        case M_TEM:
        case M_RST0:
        case M_RST1:
        case M_RST2:
        case M_RST3:
        case M_RST4:
        case M_RST5:
        case M_RST6:
        case M_RST7:
            break;
        default:               /* skip variable length markers */
            xfseek(jpg_ptr(img)->file, read2bytes(jpg_ptr(img)->file) - 2,
                   SEEK_CUR, cur_file_name);
            break;
        }
    }
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
  if(argc < 2) {
    std::cerr << "usage: " << argv[0] << " IMAGE"
      << std::endl;
    return EXIT_FAILURE;
  }
  std::string img_name(argv[1]);

  sdl::gl_display display(800, 600, false);
  display.set_caption("vbo demo");
  gl::init();

  glEnable(GL_TEXTURE_2D);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);

  ghp::texture<ghp::RGBA<uint8_t> > raw_pic;
  sdl::load_image(img_name, raw_pic);
  
  gl::texture<2, ghp::RGB<uint8_t> > texture;
  texture.write(raw_pic);
  gl::bind_texture<>(texture);

  vertex vertices[4];
  vertices[0].loc = ghp::vector3<float>(raw_pic.get_width()/2, 
      -raw_pic.get_height()/2, 0);
  vertices[0].tex = ghp::vector2<float>(1, 1);
  vertices[1].loc = ghp::vector3<float>(raw_pic.get_width()/2,
      raw_pic.get_height()/2, 0);
  vertices[1].tex = ghp::vector2<float>(1, 0);
  vertices[2].loc = ghp::vector3<float>(-raw_pic.get_width()/2,
      raw_pic.get_height()/2, 0);
  vertices[2].tex = ghp::vector2<float>(0, 0);
  vertices[3].loc = ghp::vector3<float>(-raw_pic.get_width()/2,
      -raw_pic.get_height()/2, 0);
  vertices[3].tex = ghp::vector2<float>(0, 1);

  gl::vbo<GL_ARRAY_BUFFER> object_vbo;
  object_vbo.write(vertices, sizeof(vertices));

  uint32_t idx[] = { 0, 1, 3, 1, 2, 3 };
  
  gl::vbo<GL_ELEMENT_ARRAY_BUFFER> element_vbo;
  element_vbo.write(idx, sizeof(idx));

  sdl::input input;
  input.quit_slot().connect(handle_quit);
  input.keyboard_slot().connect(handle_key);

  while(running) {
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(-display.get_width()/2, display.get_width()/2, 
        -display.get_height()/2, display.get_height()/2);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gl::bind_buffer(object_vbo);
    gl::vertex_pointer<float>(3, sizeof(vertex), 0);
    gl::tex_coord_pointer<float>(2, sizeof(vertex), 3*sizeof(float));
    gl::bind_buffer(element_vbo);
    gl::draw_elements<uint32_t>(GL_TRIANGLES, 2*3, 0);

    display.update();
    input.handle_events();
  }
}