/*
* DWN - Desktop Window Manager
* retoor <retoor@molodetz.nl>
* OCR text extraction API
*/
#ifndef DWN_OCR_H
#define DWN_OCR_H
#include <stdbool.h>
#include <stddef.h>
#include <pthread.h>
typedef enum {
OCR_OK = 0,
OCR_ERROR_INVALID_ARG,
OCR_ERROR_INIT,
OCR_ERROR_IMAGE,
OCR_ERROR_NO_MEMORY,
OCR_ERROR_NOT_AVAILABLE
} OcrStatus;
typedef enum {
OCR_STATE_IDLE,
OCR_STATE_PENDING,
OCR_STATE_COMPLETED,
OCR_STATE_ERROR
} OcrState;
typedef struct {
char *text;
size_t length;
float confidence;
} OcrResult;
typedef struct OcrRequest {
unsigned char *png_data;
size_t png_size;
char language[16];
OcrResult result;
OcrStatus status;
OcrState state;
void (*callback)(struct OcrRequest *req);
void *user_data;
pthread_t thread;
struct OcrRequest *next;
} OcrRequest;
bool ocr_init(void);
void ocr_cleanup(void);
bool ocr_is_available(void);
OcrStatus ocr_extract_from_png(const unsigned char *png_data, size_t size,
const char *language, OcrResult *result);
OcrRequest *ocr_extract_async(const unsigned char *png_data, size_t size,
const char *language,
void (*callback)(OcrRequest *));
void ocr_process_pending(void);
void ocr_cancel(OcrRequest *req);
void ocr_result_free(OcrResult *result);
const char *ocr_status_string(OcrStatus status);
#endif