Exemple #1
0
Image Image::Resize(unsigned int width, unsigned int height)
{
  Image i;
  i.width_ = width;
  i.height_ = height;
  i.format_ = format_;
  auto *n = new std::vector<uint8_t>();
  auto &v = GetData();
  int bytes_per_pixel = get_bytes_per_pixel(format_);
  n->resize(width*height*bytes_per_pixel);
  for (int i=0;i<width;++i)
  {
    float off_x = i/(float)width * width_;
    int off_x_pix = floor(off_x);
    float off_x_wei = fmod(off_x, 1.0);
    for (int j=0;j<height;++j)
    {
      float off_y = j/(float)height * height_;
      int off_y_pix = floor(off_y);
      float off_y_wei = fmod(off_y, 1.0);
      for (int k=0;k<bytes_per_pixel;++k)
      {
        float mean1 = 0.0;
        float mean2 = 0.0;
        mean1 += v[((off_x_pix)+(off_y_pix)*width)*bytes_per_pixel+k]*(1.0-off_x_wei);
        mean1 += v[((off_x_pix+1)+(off_y_pix)*width)*bytes_per_pixel+k]*(off_x_wei);
        mean2 += v[((off_x_pix)+(off_y_pix+1)*width)*bytes_per_pixel+k]*(1.0-off_x_wei);
        mean2 += v[((off_x_pix)+(off_y_pix+1)*width)*bytes_per_pixel+k]*(off_x_wei);
        n->at((i+j*width)*bytes_per_pixel+k) = (mean1*(1.0-off_y_wei)+mean2*(off_y_wei))*0.25;
      }
    }
  }
  i.data_.reset(n);
  return i;
}
int simple_draw(char *dest, const char *src, int img_width,
        struct fb_var_screeninfo *var)
{
    int bytes_per_pixel = get_bytes_per_pixel(var->bits_per_pixel);
    unsigned int y;

    for (y = 0; y < var->yres; y++)
        memcpy(dest + y * var->xres * bytes_per_pixel,
               src + y * img_width * bytes_per_pixel,
               var->xres * bytes_per_pixel);

    return 0;
}
Exemple #3
0
static void
write_tiff (UcaRingBuffer *buffer,
            Options *opts,
            guint width,
            guint height,
            guint bits_per_pixel)
{
    TIFF *tif;
    guint32 rows_per_strip;
    guint n_frames;
    guint bits_per_sample;
    gsize bytes_per_pixel;

    if (opts->filename)
        tif = TIFFOpen (opts->filename, "w");
    else
        tif = TIFFOpen ("frames.tif", "w");

    n_frames = uca_ring_buffer_get_num_blocks (buffer);
    rows_per_strip = TIFFDefaultStripSize (tif, (guint32) - 1);
    bytes_per_pixel = get_bytes_per_pixel (bits_per_pixel);
    bits_per_sample = bits_per_pixel > 8 ? 16 : 8;

    /* Write multi page TIFF file */
    TIFFSetField (tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);

    for (guint i = 0; i < n_frames; i++) {
        gpointer data;
        gsize offset = 0;

        data = uca_ring_buffer_get_read_pointer (buffer);

        TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
        TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
        TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
        TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
        TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 1);
        TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
        TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip);
        TIFFSetField (tif, TIFFTAG_PAGENUMBER, i, n_frames);

        for (guint y = 0; y < height; y++, offset += width * bytes_per_pixel)
            TIFFWriteScanline (tif, data + offset, y, 0);

        TIFFWriteDirectory (tif);
    }

    TIFFClose (tif);
}
Exemple #4
0
static GError *
record_frames (UcaCamera *camera, Options *opts)
{
    guint roi_width;
    guint roi_height;
    guint bits;
    guint pixel_size;
    gsize size;
    gint n_frames;
    guint n_allocated;
    GTimer *timer;
    UcaRingBuffer *buffer;
    GError *error = NULL;
    gdouble last_printed;

    g_object_get (G_OBJECT (camera),
                  "roi-width", &roi_width,
                  "roi-height", &roi_height,
                  "sensor-bitdepth", &bits,
                  NULL);

    pixel_size = get_bytes_per_pixel (bits);
    size = roi_width * roi_height * pixel_size;
    n_allocated = opts->n_frames > 0 ? opts->n_frames : 256;
    buffer = uca_ring_buffer_new (size, n_allocated);
    timer = g_timer_new();

    g_print("Start recording: %ix%i at %i bits/pixel\n",
            roi_width, roi_height, bits);

    uca_camera_start_recording(camera, &error);

    if (error != NULL)
        return error;

    n_frames = 0;
    g_timer_start(timer);
    last_printed = 0.0;

    while (1) {
        gdouble elapsed;

        uca_camera_grab (camera, uca_ring_buffer_get_write_pointer (buffer), &error);
        uca_ring_buffer_write_advance (buffer);

        if (error != NULL)
            return error;

        n_frames++;
        elapsed = g_timer_elapsed (timer, NULL);

        if (n_frames == opts->n_frames || (opts->duration > 0.0 && elapsed >= opts->duration))
            break;

        if (elapsed - last_printed >= 1.0) {
            g_print ("Recorded %i frames at %.2f frames/s\n",
                     n_frames, n_frames / elapsed);
            last_printed = elapsed;
        }
    }

    g_print ("Stop recording: %3.2f frames/s\n",
             n_frames / g_timer_elapsed (timer, NULL));

    uca_camera_stop_recording (camera, &error);

#ifdef HAVE_LIBTIFF
    if (opts->write_tiff)
        write_tiff (buffer, opts, roi_width, roi_height, bits);
    else
        write_raw (buffer, opts);
#else
    write_raw (buffer, opts);
#endif

    g_object_unref (buffer);
    g_timer_destroy (timer);

    return error;
}