#ifndef image_h #define image_h /* Camicro - Microscope camera viewer. * * Copyright (C) 2019 Nicolas Schodet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Contact : * Web: http://ni.fr.eu.org/ * Email: */ #include #include #include /* Error domain for image related errors. */ #define IMAGE_ERROR image_error_quark() /* Image format. */ enum image_format { #define IMAGE_FORMAT_FOURCC(a, b, c, d) \ (((uint32_t)(a)) | ((uint32_t)(b) << 8) \ | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) /* Bayer image format: * G R G R * B G B G */ IMAGE_FORMAT_SGRBG8 = IMAGE_FORMAT_FOURCC('B', 'R', 'B', 'G'), /* RGB 32 bits, B in LSB. */ IMAGE_FORMAT_XBGR32 = IMAGE_FORMAT_FOURCC('X', 'R', '2', '4'), }; struct image; /* Image release callback. */ typedef void (*image_release_f)(struct image *image, void *user_data); /* Image with attached information. */ struct image { /* Image width. */ int width; /* Image height. */ int height; /* Byte offset between a line and the next line. */ int stride; /* Image format. */ enum image_format format; /* Frame buffer. */ uint8_t *pixels; /* Number of reference to this image. */ int refs; /* Release callback. */ image_release_f release; /* Release callback user data. */ void *release_user_data; }; /* Reference for white balance. */ struct image_white_balance_reference { /* White (maximum of each component). */ uint8_t r, g, b; }; /* Error codes. */ enum ImageError { /* Error writing an image to disk. */ IMAGE_ERROR_SAVE, }; /* Return quark of error domain for image related errors. */ GQuark image_error_quark(void); /* Allocate an image using system allocator. */ struct image * image_new(int width, int height, int stride, enum image_format format); /* Add a reference to an image. */ void image_ref(struct image *image); /* Release a reference to an image. */ void image_unref(struct image *image); /* Compute histogram(s), should provide an uint32_t[3][256] array. */ void image_histogram(const struct image *image, uint32_t histogram[3][256]); /* Calibrate for white balance. */ void image_white_balance_calibrate(const struct image *image, struct image_white_balance_reference *reference); /* Apply the given white balance. */ void image_white_balance(struct image *image, const struct image_white_balance_reference *reference); /* Copy an image to another one, converting format. */ void image_convert(struct image *dst, const struct image *src); /* Save image to PNG. */ bool image_save(const struct image *image, const char *name, GError **error); #endif /* image_h */