Как объединить / подать два буфера uint8_t? - PullRequest
0 голосов
/ 23 января 2020

Привет, извините за этот вопрос новичка, но я думаю, что я просто упускаю что-то очевидное ... Буду очень рад некоторым советам по этому поводу:


Встроенный документ esp_camera.h:

/**
 * @brief Data structure of camera frame buffer
 */
typedef struct {
    uint8_t * buf;              /*!< Pointer to the pixel data */
    size_t len;                 /*!< Length of the buffer in bytes */
    size_t width;               /*!< Width of the buffer in pixels */
    size_t height;              /*!< Height of the buffer in pixels */
    pixformat_t format;         /*!< Format of the pixel data */
} camera_fb_t;

плюс извлечение демонстрационного кода: из кода esp32:

    //replace this with your own function
    display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);

код, получающий кадровый буфер

    camera_fb_t * fb = NULL;
    esp_err_t res = ESP_OK;

    fb = esp_camera_fb_get(); // framebuffer in grayscale

и буфер подачи fb в imagebuffer

    int w, h;
    int i, count;
    uint8_t *imagebuffer = quirc_begin(qr, &w, &h);

    //Feed 'fb' into 'imagebuffer' somehow?
    //-------------------------------
    // ----- DUMMY CODE?! not the proper way? ----
    imagebuffer = fb->buf; //fb's own buf field, holding the pixel data

    //Comment from quirc below:
    /* Fill out the image buffer here.
     * 'imagebuffer' is a pointer to a w*h bytes.
     * One byte per pixel, w pixels per line, h lines in the buffer.
     */
    //
    quirc_end(qr);

Встроенный комментарий к документу quir c ниже:

    /* These functions are used to process images for QR-code recognition.
     * quirc_begin() must first be called to obtain access to a buffer into
     * which the input image should be placed. Optionally, the current
     * width and height may be returned.
     *
     * After filling the buffer, quirc_end() should be called to process
     * the image for QR-code recognition. The locations and content of each
     * code may be obtained using accessor functions described below.
     */
    uint8_t *quirc_begin(struct quirc *q, int *w, int *h);
    void quirc_end(struct quirc *q);

https://github.com/dlbeer/quirc


Я просмотрел код, исходные файлы и т.д. c, но, поскольку я новичок, я не знаю, как объединить или вставить одно в другое.


Может кто-нибудь указывает мне правильное направление здесь? Я не грязно просматривал кучу кода, но моя неопытность с C является проблемой здесь: S Спасибо!

1 Ответ

0 голосов
/ 24 января 2020

Автор библиотеки любезно объяснил это, разместив здесь код ответа, так как он может помочь другим:

  int w, h;
  int i, count;
  uint8_t *buff = quirc_begin(qr, &w, &h);
  //
  int total_pixels = w * h;

  for (int i = 0; i < total_pixels; i++) {
    // grab a pixel from your source image at element i
    // convert it somehow, then store it
    buff[i] = fb->buf[i]; //?
  }
  //
  quirc_end(qr);

  count = quirc_count(qr);
  Serial.println("count found codes:");
  Serial.println(count);

github с объяснением автора lib

...