diff --git a/.gitignore b/.gitignore index 1dfa7f9aa0..3427518389 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ wiiu/wut/elf2rpl/elf2rpl *.smdh /retroarch_3ds.core /retroarch_3ds.icn +/retroarch_3ds_salamander.icn # Ctags /tags diff --git a/Makefile.common b/Makefile.common index 7091f66d1c..b255b1937a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -199,7 +199,7 @@ OBJ += frontend/frontend.o \ $(LIBRETRO_COMM_DIR)/audio/audio_mixer.o \ input/input_driver.o \ led/led_driver.o \ - led/null_led_driver.o \ + led/drivers/led_null.o \ gfx/video_coord_array.o \ gfx/video_display_server.o \ gfx/video_driver.o \ @@ -796,7 +796,7 @@ ifeq ($(HAVE_OVERLAY), 1) OBJ += \ tasks/task_overlay.o \ input/input_overlay.o \ - led/overlay_led_driver.o + led/drivers/led_overlay.o endif ifeq ($(HAVE_STB_FONT), 1) @@ -1667,5 +1667,5 @@ OBJ += libretro-common/audio/dsp_filters/echo.o \ endif ifeq ($(HAVE_RPILED), 1) - OBJ += led/rpi_led_driver.o + OBJ += led/drivers/led_rpi.o endif diff --git a/frontend/drivers/platform_ctr.c b/frontend/drivers/platform_ctr.c index ec1030047b..529580d5ab 100644 --- a/frontend/drivers/platform_ctr.c +++ b/frontend/drivers/platform_ctr.c @@ -24,6 +24,8 @@ #include <3ds/svc.h> #include <3ds/os.h> #include <3ds/services/cfgu.h> +#include <3ds/services/ptmu.h> +#include <3ds/services/mcuhwc.h> #include @@ -135,6 +137,8 @@ static void frontend_ctr_deinit(void *data) parallax_layer_reg_state = (*(float*)0x1FF81080 == 0.0)? 0x0 : 0x00010001; GSPGPU_WriteHWRegs(0x202000, ¶llax_layer_reg_state, 4); + mcuHwcExit(); + ptmuExit(); cfguExit(); ndspExit(); csndExit(); @@ -373,6 +377,8 @@ static void frontend_ctr_init(void *data) if(ndspInit() != 0) audio_ctr_dsp = audio_null; cfguInit(); + ptmuInit(); + mcuHwcInit(); #endif } @@ -430,6 +436,100 @@ static int frontend_ctr_parse_drive_list(void *data, bool load_content) return 0; } +static uint64_t frontend_ctr_get_mem_total(void) +{ + return osGetMemRegionSize(MEMREGION_ALL); +} + +static uint64_t frontend_ctr_get_mem_used(void) +{ + return osGetMemRegionUsed(MEMREGION_ALL); +} + +static enum frontend_powerstate frontend_ctr_get_powerstate(int *seconds, int *percent) +{ + u8 battery_percent = 0; + u8 charging = 0; + enum frontend_powerstate pwr_state = FRONTEND_POWERSTATE_NONE; + + mcuHwcGetBatteryLevel(&battery_percent); + *percent = battery_percent; + + /* 3ds does not support seconds of charge remaining */ + *seconds = -1; + + PTMU_GetBatteryChargeState(&charging); + if (charging) + { + if (battery_percent == 100) + { + pwr_state = FRONTEND_POWERSTATE_CHARGED; + } + else + { + pwr_state = FRONTEND_POWERSTATE_CHARGING; + } + } + else + { + pwr_state = FRONTEND_POWERSTATE_ON_POWER_SOURCE; + } + + return pwr_state; +} + +static void frontend_ctr_get_os(char *s, size_t len, int *major, int *minor) +{ + OS_VersionBin cver; + OS_VersionBin nver; + + strlcpy(s, "3DS OS", len); + Result data_invalid = osGetSystemVersionData(&nver, &cver); + if (data_invalid == 0) + { + *major = cver.mainver; + *minor = cver.minor; + } + else + { + *major = 0; + *minor = 0; + } + +} + +static void frontend_ctr_get_name(char *s, size_t len) +{ + u8 device_model = 0xFF; + CFGU_GetSystemModel(&device_model);/*(0 = O3DS, 1 = O3DSXL, 2 = N3DS, 3 = 2DS, 4 = N3DSXL, 5 = N2DSXL)*/ + + switch (device_model) + { + case 0: + strlcpy(s, "Old 3DS", len); + break; + case 1: + strlcpy(s, "Old 3DS XL", len); + break; + case 2: + strlcpy(s, "New 3DS", len); + break; + case 3: + strlcpy(s, "Old 2DS", len); + break; + case 4: + strlcpy(s, "New 3DS XL", len); + break; + case 5: + strlcpy(s, "New 2DS XL", len); + break; + + default: + strlcpy(s, "Unknown Device", len); + break; + } +} + frontend_ctx_driver_t frontend_ctx_ctr = { frontend_ctr_get_environment_settings, frontend_ctr_init, @@ -443,15 +543,15 @@ frontend_ctx_driver_t frontend_ctx_ctr = { frontend_ctr_set_fork, #endif frontend_ctr_shutdown, - NULL, /* get_name */ - NULL, /* get_os */ + frontend_ctr_get_name, + frontend_ctr_get_os, frontend_ctr_get_rating, NULL, /* load_content */ frontend_ctr_get_architecture, - NULL, /* get_powerstate */ + frontend_ctr_get_powerstate, frontend_ctr_parse_drive_list, - NULL, /* get_mem_total */ - NULL, /* get_mem_free */ + frontend_ctr_get_mem_total, + frontend_ctr_get_mem_used, NULL, /* install_signal_handler */ NULL, /* get_signal_handler_state */ NULL, /* set_signal_handler_state */ diff --git a/griffin/griffin.c b/griffin/griffin.c index 4f7fc0384a..9fbefe32fe 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -498,7 +498,7 @@ INPUT #ifdef HAVE_OVERLAY #include "../input/input_overlay.c" -#include "../led/overlay_led_driver.c" +#include "../led/drivers/led_overlay.c" #include "../tasks/task_overlay.c" #endif @@ -674,10 +674,10 @@ LEDS #include "../led/led_driver.c" -#include "../led/null_led_driver.c" +#include "../led/drivers/led_null.c" #if defined(HAVE_RPILED) -#include "../led/rpi_led_driver.c" +#include "../led/drivers/led_rpi.c" #endif /*============================================================ diff --git a/led/null_led_driver.c b/led/drivers/led_null.c similarity index 79% rename from led/null_led_driver.c rename to led/drivers/led_null.c index 08827e7782..3f178a1389 100644 --- a/led/null_led_driver.c +++ b/led/drivers/led_null.c @@ -12,18 +12,17 @@ * If not, see . */ -#include "led_driver.h" -#include "../verbosity.h" +#include "../led_driver.h" +#include "../../verbosity.h" static void null_init(void) { } static void null_free(void) { } -static void null_set(int led,int state) { } +static void null_set(int led, int state) { } -static led_driver_t null_led_driver_ins = { +const led_driver_t null_led_driver = { null_init, null_free, - null_set + null_set, + "null" }; -led_driver_t *null_led_driver = &null_led_driver_ins; - diff --git a/led/overlay_led_driver.c b/led/drivers/led_overlay.c similarity index 69% rename from led/overlay_led_driver.c rename to led/drivers/led_overlay.c index e47066face..f8f7bcd21b 100644 --- a/led/overlay_led_driver.c +++ b/led/drivers/led_overlay.c @@ -1,12 +1,12 @@ #include -#include "led_driver.h" -#include "led_defines.h" +#include "../led_driver.h" +#include "../led_defines.h" -#include "../configuration.h" -#include "../verbosity.h" +#include "../../configuration.h" +#include "../../verbosity.h" -#include "../gfx/video_driver.h" -#include "../input/input_overlay.h" +#include "../../gfx/video_driver.h" +#include "../../input/input_overlay.h" typedef struct { @@ -41,12 +41,12 @@ static void overlay_free(void) RARCH_LOG("[LED]: overlay LED driver free\n"); } -static void overlay_set(int led,int state) +static void overlay_set(int led, int state) { int gpio = 0; if ((led < 0) || (led >= MAX_LEDS)) { - RARCH_WARN("[LED]: invalid led %d\n",led); + RARCH_WARN("[LED]: invalid led %d\n", led); return; } @@ -59,13 +59,12 @@ static void overlay_set(int led,int state) state ? OVERLAY_VISIBILITY_VISIBLE : OVERLAY_VISIBILITY_HIDDEN); - RARCH_LOG("[LED]: set visibility %d %d\n",gpio,state); + RARCH_LOG("[LED]: set visibility %d %d\n", gpio, state); } -static led_driver_t overlay_led_driver_ins = { +const led_driver_t overlay_led_driver = { overlay_init, overlay_free, - overlay_set + overlay_set, + "Overlay" }; - -led_driver_t *overlay_led_driver = &overlay_led_driver_ins; diff --git a/led/rpi_led_driver.c b/led/drivers/led_rpi.c similarity index 75% rename from led/rpi_led_driver.c rename to led/drivers/led_rpi.c index b17600d5f5..d6797fcb98 100644 --- a/led/rpi_led_driver.c +++ b/led/drivers/led_rpi.c @@ -14,11 +14,11 @@ #include -#include "led_driver.h" -#include "led_defines.h" +#include "../led_driver.h" +#include "../led_defines.h" -#include "../configuration.h" -#include "../verbosity.h" +#include "../../configuration.h" +#include "../../verbosity.h" typedef struct { @@ -41,7 +41,7 @@ static void rpi_init(void) { cur->setup[i] = 0; cur->map[i] = settings->uints.led_map[i]; - RARCH_LOG("[LED]: rpi map[%d]=%d\n",i,cur->map[i]); + RARCH_LOG("[LED]: rpi map[%d]=%d\n", i, cur->map[i]); } } @@ -49,20 +49,20 @@ static void rpi_free(void) { } -static int set_gpio(int gpio,int value) +static int set_gpio(int gpio, int value) { FILE *fp; char buf[256]; snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/value", gpio); - fp = fopen(buf,"w"); + fp = fopen(buf, "w"); if(!fp) { - RARCH_WARN("[LED]: failed to set GPIO %d\n",gpio); + RARCH_WARN("[LED]: failed to set GPIO %d\n", gpio); return -1; } - fprintf(fp,"%d\n",value?1:0); + fprintf(fp, "%d\n", value ? 1 : 0); fclose(fp); return 1; } @@ -72,24 +72,24 @@ static int setup_gpio(int gpio) FILE *fp; char buf[256]; snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction", gpio); - fp = fopen(buf,"w"); + fp = fopen(buf, "w"); if(!fp) { snprintf(buf, sizeof(buf), "/sys/class/gpio/export"); - fp = fopen(buf,"w"); + fp = fopen(buf, "w"); if(!fp) { - RARCH_WARN("[LED]: failed to export GPIO %d\n",gpio); + RARCH_WARN("[LED]: failed to export GPIO %d\n", gpio); return -1; } - fprintf(fp,"%d\n",gpio); + fprintf(fp,"%d\n", gpio); fclose(fp); - snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",gpio); - fp = fopen(buf,"w"); + snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction", gpio); + fp = fopen(buf, "w"); } if(!fp) @@ -99,18 +99,18 @@ static int setup_gpio(int gpio) return -1; } - fprintf(fp,"out\n"); + fprintf(fp, "out\n"); fclose(fp); return 1; } -static void rpi_set(int led,int state) +static void rpi_set(int led, int state) { int gpio = 0; if((led < 0) || (led >= MAX_LEDS)) { - RARCH_WARN("[LED]: invalid led %d\n",led); + RARCH_WARN("[LED]: invalid led %d\n", led); return; } @@ -118,7 +118,7 @@ static void rpi_set(int led,int state) if(gpio <= 0) return; - if(cur->setup[led]==0) + if(cur->setup[led] == 0) { RARCH_LOG("[LED]: rpi setup led %d gpio %d\n", led, gpio, state); @@ -133,14 +133,13 @@ static void rpi_set(int led,int state) { RARCH_LOG("[LED]: rpi LED driver set led %d gpio %d = %d\n", led, gpio, state); - set_gpio(gpio,state); + set_gpio(gpio, state); } } -static led_driver_t rpi_led_driver_ins = { +const led_driver_t rpi_led_driver = { rpi_init, rpi_free, - rpi_set + rpi_set, + "rpi" }; - -led_driver_t *rpi_led_driver = &rpi_led_driver_ins; diff --git a/led/led_defines.h b/led/led_defines.h index 3789886c5a..67756a802a 100644 --- a/led/led_defines.h +++ b/led/led_defines.h @@ -12,8 +12,8 @@ * If not, see . */ -#ifndef __OUTPUT_DEFINES__H -#define __OUTPUT_DEFINES__H +#ifndef __LED_DEFINES__H +#define __LED_DEFINES__H #define MAX_LEDS 32 diff --git a/led/led_driver.c b/led/led_driver.c index fb1e796078..185245c6de 100644 --- a/led/led_driver.c +++ b/led/led_driver.c @@ -19,7 +19,7 @@ #include "../configuration.h" #include "../verbosity.h" -static led_driver_t *current_led_driver = NULL; +static const led_driver_t *current_led_driver = NULL; bool led_driver_init(void) { @@ -29,20 +29,20 @@ bool led_driver_init(void) if(!drivername) drivername = (char*)"null"; - current_led_driver = null_led_driver; + current_led_driver = &null_led_driver; #ifdef HAVE_OVERLAY - if(string_is_equal("overlay",drivername)) - current_led_driver = overlay_led_driver; + if(string_is_equal("overlay", drivername)) + current_led_driver = &overlay_led_driver; #endif #if HAVE_RPILED if(string_is_equal("rpi", drivername)) - current_led_driver = rpi_led_driver; + current_led_driver = &rpi_led_driver; #endif RARCH_LOG("[LED]: LED driver = '%s' %p\n", - drivername,current_led_driver); + drivername, current_led_driver); if(current_led_driver) (*current_led_driver->init)(); @@ -56,8 +56,8 @@ void led_driver_free(void) (*current_led_driver->free)(); } -void led_driver_set_led(int led,int value) +void led_driver_set_led(int led, int value) { if(current_led_driver) - (*current_led_driver->set_led)(led,value); + (*current_led_driver->set_led)(led, value); } diff --git a/led/led_driver.h b/led/led_driver.h index 1e6dc8ba0c..916ee95306 100644 --- a/led/led_driver.h +++ b/led/led_driver.h @@ -31,7 +31,8 @@ typedef struct led_driver { void (*init)(void); void (*free)(void); - void (*set_led)(int led,int value); + void (*set_led)(int led, int value); + const char *ident; } led_driver_t; @@ -39,11 +40,11 @@ bool led_driver_init(void); void led_driver_free(void); -void led_driver_set_led(int led,int value); +void led_driver_set_led(int led, int value); -extern led_driver_t *null_led_driver; -extern led_driver_t *overlay_led_driver; -extern led_driver_t *rpi_led_driver; +extern const led_driver_t null_led_driver; +extern const led_driver_t overlay_led_driver; +extern const led_driver_t rpi_led_driver; RETRO_END_DECLS diff --git a/record/record_driver.h b/record/record_driver.h index 8a4da8e44c..a8b087163a 100644 --- a/record/record_driver.h +++ b/record/record_driver.h @@ -84,7 +84,7 @@ typedef struct record_driver { void *(*init)(const struct ffemu_params *params); void (*free)(void *data); - bool (*push_video)(void *data,const struct ffemu_video_data *video_data); + bool (*push_video)(void *data, const struct ffemu_video_data *video_data); bool (*push_audio)(void *data, const struct ffemu_audio_data *audio_data); bool (*finalize)(void *data); const char *ident; diff --git a/translation/drivers/translation_cached_google.c b/translation/drivers/translation_cached_google.c new file mode 100644 index 0000000000..0e694b1128 --- /dev/null +++ b/translation/drivers/translation_cached_google.c @@ -0,0 +1,28 @@ +#include "../translation_driver.h" + +static void* translation_cached_google_init(const struct translation_driver_info *params) +{ + return NULL; +} + +static void translation_cached_google_free(void* data) +{ +} + +static char* translation_cached_google_translate_text(const char* game_text) +{ + return ""; +} + +static char* translation_cached_google_translate_image(struct ocr_image_info image) +{ + return ""; +} + +const translation_driver_t translation_cached_google = { + translation_cached_google_init, + translation_cached_google_free, + translation_cached_google_translate_text, + translation_cached_google_translate_image, + "cached_google" +}; \ No newline at end of file diff --git a/translation/drivers/translation_null.c b/translation/drivers/translation_null.c new file mode 100644 index 0000000000..deea614d98 --- /dev/null +++ b/translation/drivers/translation_null.c @@ -0,0 +1,23 @@ +#include "../translation_driver.h" + +static void* translation_null_init(const struct translation_driver_info *params) +{ + return NULL; +} + +static void translation_null_free(void* data) +{ +} + +static char* translation_null_translate_text(const char* game_text) +{ + return ""; +} + +const translation_driver_t translation_null = { + translation_null_init, + translation_null_free, + translation_null_translate_text, + NULL, + "null" +}; \ No newline at end of file diff --git a/translation/drivers_ocr/ocr_null.c b/translation/drivers_ocr/ocr_null.c new file mode 100644 index 0000000000..3ffd874ea2 --- /dev/null +++ b/translation/drivers_ocr/ocr_null.c @@ -0,0 +1,22 @@ +#include "../ocr_driver.h" + +static void* ocr_null_init() +{ + return NULL; +} + +static void ocr_null_free(void* data) +{ +} + +char* ocr_null_get_text(struct ocr_image_info image) +{ + return ""; +} + +const ocr_driver_t ocr_null = { + ocr_null_init, + ocr_null_free, + ocr_null_get_text, + "null" +}; \ No newline at end of file diff --git a/translation/drivers_ocr/ocr_tesseract.c b/translation/drivers_ocr/ocr_tesseract.c new file mode 100644 index 0000000000..9b0157a7bc --- /dev/null +++ b/translation/drivers_ocr/ocr_tesseract.c @@ -0,0 +1,22 @@ +#include "../ocr_driver.h" + +static void* ocr_tesseract_init() +{ + return NULL; +} + +static void ocr_tesseract_free(void* data) +{ +} + +char* ocr_tesseract_get_text(struct ocr_image_info image) +{ + return ""; +} + +const ocr_driver_t ocr_tesseract = { + ocr_tesseract_init, + ocr_tesseract_free, + ocr_tesseract_get_text, + "tesseract" +}; \ No newline at end of file diff --git a/translation/drivers_ocr/tesseract/capi.h b/translation/drivers_ocr/tesseract/capi.h new file mode 100644 index 0000000000..8195c68f12 --- /dev/null +++ b/translation/drivers_ocr/tesseract/capi.h @@ -0,0 +1,397 @@ +/////////////////////////////////////////////////////////////////////// +// File: capi.h +// Description: C-API TessBaseAPI +// +// (C) Copyright 2012, Google Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/////////////////////////////////////////////////////////////////////// + +#ifndef API_CAPI_H_ +#define API_CAPI_H_ + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +# include "baseapi.h" +# include "pageiterator.h" +# include "resultiterator.h" +# include "renderer.h" +#else +# include "platform.h" +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef TESS_CALL +# if defined(WIN32) +# define TESS_CALL __cdecl +# else +# define TESS_CALL +# endif +#endif + +#ifndef BOOL +# define BOOL int +# define TRUE 1 +# define FALSE 0 +#endif + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +typedef tesseract::TessResultRenderer TessResultRenderer; +typedef tesseract::TessTextRenderer TessTextRenderer; +typedef tesseract::TessHOcrRenderer TessHOcrRenderer; +typedef tesseract::TessPDFRenderer TessPDFRenderer; +typedef tesseract::TessUnlvRenderer TessUnlvRenderer; +typedef tesseract::TessBoxTextRenderer TessBoxTextRenderer; +typedef tesseract::TessBaseAPI TessBaseAPI; +typedef tesseract::PageIterator TessPageIterator; +typedef tesseract::ResultIterator TessResultIterator; +typedef tesseract::MutableIterator TessMutableIterator; +typedef tesseract::ChoiceIterator TessChoiceIterator; +typedef tesseract::OcrEngineMode TessOcrEngineMode; +typedef tesseract::PageSegMode TessPageSegMode; +typedef tesseract::ImageThresholder TessImageThresholder; +typedef tesseract::PageIteratorLevel TessPageIteratorLevel; +typedef tesseract::DictFunc TessDictFunc; +typedef tesseract::ProbabilityInContextFunc TessProbabilityInContextFunc; +// typedef tesseract::ParamsModelClassifyFunc TessParamsModelClassifyFunc; +typedef tesseract::FillLatticeFunc TessFillLatticeFunc; +typedef tesseract::Dawg TessDawg; +typedef tesseract::TruthCallback TessTruthCallback; +typedef tesseract::Orientation TessOrientation; +typedef tesseract::ParagraphJustification TessParagraphJustification; +typedef tesseract::WritingDirection TessWritingDirection; +typedef tesseract::TextlineOrder TessTextlineOrder; +typedef PolyBlockType TessPolyBlockType; +#else +typedef struct TessResultRenderer TessResultRenderer; +typedef struct TessTextRenderer TessTextRenderer; +typedef struct TessHOcrRenderer TessHOcrRenderer; +typedef struct TessPDFRenderer TessPDFRenderer; +typedef struct TessUnlvRenderer TessUnlvRenderer; +typedef struct TessBoxTextRenderer TessBoxTextRenderer; +typedef struct TessBaseAPI TessBaseAPI; +typedef struct TessPageIterator TessPageIterator; +typedef struct TessResultIterator TessResultIterator; +typedef struct TessMutableIterator TessMutableIterator; +typedef struct TessChoiceIterator TessChoiceIterator; +typedef enum TessOcrEngineMode { OEM_TESSERACT_ONLY, OEM_LSTM_ONLY, OEM_TESSERACT_LSTM_COMBINED, OEM_DEFAULT } TessOcrEngineMode; +typedef enum TessPageSegMode { PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO, PSM_SINGLE_COLUMN, PSM_SINGLE_BLOCK_VERT_TEXT, + PSM_SINGLE_BLOCK, PSM_SINGLE_LINE, PSM_SINGLE_WORD, PSM_CIRCLE_WORD, PSM_SINGLE_CHAR, PSM_SPARSE_TEXT, + PSM_SPARSE_TEXT_OSD, PSM_COUNT } TessPageSegMode; +typedef enum TessPageIteratorLevel { RIL_BLOCK, RIL_PARA, RIL_TEXTLINE, RIL_WORD, RIL_SYMBOL} TessPageIteratorLevel; +typedef enum TessPolyBlockType { PT_UNKNOWN, PT_FLOWING_TEXT, PT_HEADING_TEXT, PT_PULLOUT_TEXT, PT_EQUATION, PT_INLINE_EQUATION, + PT_TABLE, PT_VERTICAL_TEXT, PT_CAPTION_TEXT, PT_FLOWING_IMAGE, PT_HEADING_IMAGE, + PT_PULLOUT_IMAGE, PT_HORZ_LINE, PT_VERT_LINE, PT_NOISE, PT_COUNT } TessPolyBlockType; +typedef enum TessOrientation { ORIENTATION_PAGE_UP, ORIENTATION_PAGE_RIGHT, ORIENTATION_PAGE_DOWN, ORIENTATION_PAGE_LEFT } TessOrientation; +typedef enum TessParagraphJustification { JUSTIFICATION_UNKNOWN, JUSTIFICATION_LEFT, JUSTIFICATION_CENTER, JUSTIFICATION_RIGHT } TessParagraphJustification; +typedef enum TessWritingDirection { WRITING_DIRECTION_LEFT_TO_RIGHT, WRITING_DIRECTION_RIGHT_TO_LEFT, WRITING_DIRECTION_TOP_TO_BOTTOM } TessWritingDirection; +typedef enum TessTextlineOrder { TEXTLINE_ORDER_LEFT_TO_RIGHT, TEXTLINE_ORDER_RIGHT_TO_LEFT, TEXTLINE_ORDER_TOP_TO_BOTTOM } TessTextlineOrder; +typedef struct ETEXT_DESC ETEXT_DESC; +#endif + +struct Pix; +struct Boxa; +struct Pixa; + +/* General free functions */ + +TESS_API const char* + TESS_CALL TessVersion(); +TESS_API void TESS_CALL TessDeleteText(char* text); +TESS_API void TESS_CALL TessDeleteTextArray(char** arr); +TESS_API void TESS_CALL TessDeleteIntArray(int* arr); +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API void TESS_CALL TessDeleteBlockList(BLOCK_LIST* block_list); +#endif + +/* Renderer API */ +TESS_API TessResultRenderer* TESS_CALL TessTextRendererCreate(const char* outputbase); +TESS_API TessResultRenderer* TESS_CALL TessHOcrRendererCreate(const char* outputbase); +TESS_API TessResultRenderer* TESS_CALL TessHOcrRendererCreate2(const char* outputbase, BOOL font_info); +TESS_API TessResultRenderer* TESS_CALL TessPDFRendererCreate(const char* outputbase, const char* datadir, + BOOL textonly); +TESS_API TessResultRenderer* TESS_CALL TessUnlvRendererCreate(const char* outputbase); +TESS_API TessResultRenderer* TESS_CALL TessBoxTextRendererCreate(const char* outputbase); + +TESS_API void TESS_CALL TessDeleteResultRenderer(TessResultRenderer* renderer); +TESS_API void TESS_CALL TessResultRendererInsert(TessResultRenderer* renderer, TessResultRenderer* next); +TESS_API TessResultRenderer* + TESS_CALL TessResultRendererNext(TessResultRenderer* renderer); +TESS_API BOOL TESS_CALL TessResultRendererBeginDocument(TessResultRenderer* renderer, const char* title); +TESS_API BOOL TESS_CALL TessResultRendererAddImage(TessResultRenderer* renderer, TessBaseAPI* api); +TESS_API BOOL TESS_CALL TessResultRendererEndDocument(TessResultRenderer* renderer); + +TESS_API const char* TESS_CALL TessResultRendererExtention(TessResultRenderer* renderer); +TESS_API const char* TESS_CALL TessResultRendererTitle(TessResultRenderer* renderer); +TESS_API int TESS_CALL TessResultRendererImageNum(TessResultRenderer* renderer); + +/* Base API */ + +TESS_API TessBaseAPI* + TESS_CALL TessBaseAPICreate(); +TESS_API void TESS_CALL TessBaseAPIDelete(TessBaseAPI* handle); + +TESS_API size_t TESS_CALL TessBaseAPIGetOpenCLDevice(TessBaseAPI* handle, void **device); + +TESS_API void TESS_CALL TessBaseAPISetInputName( TessBaseAPI* handle, const char* name); +TESS_API const char* TESS_CALL TessBaseAPIGetInputName(TessBaseAPI* handle); + +TESS_API void TESS_CALL TessBaseAPISetInputImage(TessBaseAPI* handle, struct Pix* pix); +TESS_API struct Pix* TESS_CALL TessBaseAPIGetInputImage(TessBaseAPI* handle); + +TESS_API int TESS_CALL TessBaseAPIGetSourceYResolution(TessBaseAPI* handle); +TESS_API const char* TESS_CALL TessBaseAPIGetDatapath(TessBaseAPI* handle); + +TESS_API void TESS_CALL TessBaseAPISetOutputName(TessBaseAPI* handle, const char* name); + +TESS_API BOOL TESS_CALL TessBaseAPISetVariable(TessBaseAPI* handle, const char* name, const char* value); +TESS_API BOOL TESS_CALL TessBaseAPISetDebugVariable(TessBaseAPI* handle, const char* name, const char* value); + +TESS_API BOOL TESS_CALL TessBaseAPIGetIntVariable( const TessBaseAPI* handle, const char* name, int* value); +TESS_API BOOL TESS_CALL TessBaseAPIGetBoolVariable( const TessBaseAPI* handle, const char* name, BOOL* value); +TESS_API BOOL TESS_CALL TessBaseAPIGetDoubleVariable(const TessBaseAPI* handle, const char* name, double* value); +TESS_API const char* + TESS_CALL TessBaseAPIGetStringVariable(const TessBaseAPI* handle, const char* name); + +TESS_API void TESS_CALL TessBaseAPIPrintVariables( const TessBaseAPI* handle, FILE* fp); +TESS_API BOOL TESS_CALL TessBaseAPIPrintVariablesToFile(const TessBaseAPI* handle, const char* filename); +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API BOOL TESS_CALL TessBaseAPIGetVariableAsString(TessBaseAPI* handle, const char* name, STRING* val); +#endif + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API int TESS_CALL TessBaseAPIInit(TessBaseAPI* handle, const char* datapath, const char* language, + TessOcrEngineMode mode, char** configs, int configs_size, + const STRING* vars_vec, size_t vars_vec_size, + const STRING* vars_values, size_t vars_values_size, BOOL set_only_init_params); +#endif +TESS_API int TESS_CALL TessBaseAPIInit1(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode oem, + char** configs, int configs_size); +TESS_API int TESS_CALL TessBaseAPIInit2(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode oem); +TESS_API int TESS_CALL TessBaseAPIInit3(TessBaseAPI* handle, const char* datapath, const char* language); + +TESS_API int TESS_CALL TessBaseAPIInit4(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode mode, + char** configs, int configs_size, + char** vars_vec, char** vars_values, size_t vars_vec_size, + BOOL set_only_non_debug_params); + +TESS_API const char* + TESS_CALL TessBaseAPIGetInitLanguagesAsString(const TessBaseAPI* handle); +TESS_API char** + TESS_CALL TessBaseAPIGetLoadedLanguagesAsVector(const TessBaseAPI* handle); +TESS_API char** + TESS_CALL TessBaseAPIGetAvailableLanguagesAsVector(const TessBaseAPI* handle); + +TESS_API int TESS_CALL TessBaseAPIInitLangMod(TessBaseAPI* handle, const char* datapath, const char* language); +TESS_API void TESS_CALL TessBaseAPIInitForAnalysePage(TessBaseAPI* handle); + +TESS_API void TESS_CALL TessBaseAPIReadConfigFile(TessBaseAPI* handle, const char* filename); +TESS_API void TESS_CALL TessBaseAPIReadDebugConfigFile(TessBaseAPI* handle, const char* filename); + +TESS_API void TESS_CALL TessBaseAPISetPageSegMode(TessBaseAPI* handle, TessPageSegMode mode); +TESS_API TessPageSegMode + TESS_CALL TessBaseAPIGetPageSegMode(const TessBaseAPI* handle); + +TESS_API char* TESS_CALL TessBaseAPIRect(TessBaseAPI* handle, const unsigned char* imagedata, + int bytes_per_pixel, int bytes_per_line, + int left, int top, int width, int height); + +TESS_API void TESS_CALL TessBaseAPIClearAdaptiveClassifier(TessBaseAPI* handle); + +TESS_API void TESS_CALL TessBaseAPISetImage(TessBaseAPI* handle, const unsigned char* imagedata, int width, int height, + int bytes_per_pixel, int bytes_per_line); +TESS_API void TESS_CALL TessBaseAPISetImage2(TessBaseAPI* handle, struct Pix* pix); + +TESS_API void TESS_CALL TessBaseAPISetSourceResolution(TessBaseAPI* handle, int ppi); + +TESS_API void TESS_CALL TessBaseAPISetRectangle(TessBaseAPI* handle, int left, int top, int width, int height); + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API void TESS_CALL TessBaseAPISetThresholder(TessBaseAPI* handle, TessImageThresholder* thresholder); +#endif + +TESS_API struct Pix* + TESS_CALL TessBaseAPIGetThresholdedImage( TessBaseAPI* handle); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetRegions( TessBaseAPI* handle, struct Pixa** pixa); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetTextlines( TessBaseAPI* handle, struct Pixa** pixa, int** blockids); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetTextlines1( TessBaseAPI* handle, const BOOL raw_image, const int raw_padding, + struct Pixa** pixa, int** blockids, int** paraids); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetStrips( TessBaseAPI* handle, struct Pixa** pixa, int** blockids); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetWords( TessBaseAPI* handle, struct Pixa** pixa); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetConnectedComponents(TessBaseAPI* handle, struct Pixa** cc); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetComponentImages( TessBaseAPI* handle, const TessPageIteratorLevel level, const BOOL text_only, + struct Pixa** pixa, int** blockids); +TESS_API struct Boxa* + TESS_CALL TessBaseAPIGetComponentImages1( TessBaseAPI* handle, const TessPageIteratorLevel level, const BOOL text_only, + const BOOL raw_image, const int raw_padding, + struct Pixa** pixa, int** blockids, int** paraids); + +TESS_API int TESS_CALL TessBaseAPIGetThresholdedImageScaleFactor(const TessBaseAPI* handle); + +TESS_API void TESS_CALL TessBaseAPIDumpPGM(TessBaseAPI* handle, const char* filename); + +TESS_API TessPageIterator* + TESS_CALL TessBaseAPIAnalyseLayout(TessBaseAPI* handle); + +TESS_API int TESS_CALL TessBaseAPIRecognize(TessBaseAPI* handle, ETEXT_DESC* monitor); +TESS_API int TESS_CALL TessBaseAPIRecognizeForChopTest(TessBaseAPI* handle, ETEXT_DESC* monitor); +TESS_API BOOL TESS_CALL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename, const char* retry_config, + int timeout_millisec, TessResultRenderer* renderer); +TESS_API BOOL TESS_CALL TessBaseAPIProcessPage(TessBaseAPI* handle, struct Pix* pix, int page_index, const char* filename, + const char* retry_config, int timeout_millisec, TessResultRenderer* renderer); + +TESS_API TessResultIterator* + TESS_CALL TessBaseAPIGetIterator(TessBaseAPI* handle); +TESS_API TessMutableIterator* + TESS_CALL TessBaseAPIGetMutableIterator(TessBaseAPI* handle); + +TESS_API char* TESS_CALL TessBaseAPIGetUTF8Text(TessBaseAPI* handle); +TESS_API char* TESS_CALL TessBaseAPIGetHOCRText(TessBaseAPI* handle, int page_number); +TESS_API char* TESS_CALL TessBaseAPIGetBoxText(TessBaseAPI* handle, int page_number); +TESS_API char* TESS_CALL TessBaseAPIGetUNLVText(TessBaseAPI* handle); +TESS_API int TESS_CALL TessBaseAPIMeanTextConf(TessBaseAPI* handle); +TESS_API int* TESS_CALL TessBaseAPIAllWordConfidences(TessBaseAPI* handle); +TESS_API BOOL TESS_CALL TessBaseAPIAdaptToWordStr(TessBaseAPI* handle, TessPageSegMode mode, const char* wordstr); + +TESS_API void TESS_CALL TessBaseAPIClear(TessBaseAPI* handle); +TESS_API void TESS_CALL TessBaseAPIEnd(TessBaseAPI* handle); + +TESS_API int TESS_CALL TessBaseAPIIsValidWord(TessBaseAPI* handle, const char* word); +TESS_API BOOL TESS_CALL TessBaseAPIGetTextDirection(TessBaseAPI* handle, int* out_offset, float* out_slope); + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API void TESS_CALL TessBaseAPISetDictFunc(TessBaseAPI* handle, TessDictFunc f); +TESS_API void TESS_CALL TessBaseAPIClearPersistentCache(TessBaseAPI* handle); +TESS_API void TESS_CALL TessBaseAPISetProbabilityInContextFunc(TessBaseAPI* handle, TessProbabilityInContextFunc f); + +TESS_API void TESS_CALL TessBaseAPISetFillLatticeFunc(TessBaseAPI* handle, TessFillLatticeFunc f); + +// Call TessDeleteText(*best_script_name) to free memory allocated by this function +TESS_API BOOL TESS_CALL TessBaseAPIDetectOrientationScript(TessBaseAPI* handle, + int* orient_deg, float* orient_conf, const char **script_name, float* script_conf); + +TESS_API void TESS_CALL TessBaseAPIGetFeaturesForBlob(TessBaseAPI* handle, TBLOB* blob, INT_FEATURE_STRUCT* int_features, + int* num_features, int* FeatureOutlineIndex); + +TESS_API ROW* TESS_CALL TessFindRowForBox(BLOCK_LIST* blocks, int left, int top, int right, int bottom); +TESS_API void TESS_CALL TessBaseAPIRunAdaptiveClassifier(TessBaseAPI* handle, TBLOB* blob, int num_max_matches, + int* unichar_ids, float* ratings, int* num_matches_returned); +#endif + +TESS_API const char* + TESS_CALL TessBaseAPIGetUnichar(TessBaseAPI* handle, int unichar_id); + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API const TessDawg* + TESS_CALL TessBaseAPIGetDawg(const TessBaseAPI* handle, int i); +TESS_API int TESS_CALL TessBaseAPINumDawgs(const TessBaseAPI* handle); +#endif + +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API ROW* TESS_CALL TessMakeTessOCRRow(float baseline, float xheight, float descender, float ascender); +TESS_API TBLOB* + TESS_CALL TessMakeTBLOB(Pix* pix); +TESS_API void TESS_CALL TessNormalizeTBLOB(TBLOB* tblob, ROW* row, BOOL numeric_mode); + +TESS_API TessOcrEngineMode + TESS_CALL TessBaseAPIOem(const TessBaseAPI* handle); +TESS_API void TESS_CALL TessBaseAPIInitTruthCallback(TessBaseAPI* handle, TessTruthCallback* cb); +#endif + +TESS_API void TESS_CALL TessBaseAPISetMinOrientationMargin(TessBaseAPI* handle, double margin); +#ifdef TESS_CAPI_INCLUDE_BASEAPI +TESS_API void TESS_CALL TessBaseGetBlockTextOrientations(TessBaseAPI* handle, int** block_orientation, BOOL** vertical_writing); + +TESS_API BLOCK_LIST* + TESS_CALL TessBaseAPIFindLinesCreateBlockList(TessBaseAPI* handle); +#endif + +/* Page iterator */ + +TESS_API void TESS_CALL TessPageIteratorDelete(TessPageIterator* handle); +TESS_API TessPageIterator* + TESS_CALL TessPageIteratorCopy(const TessPageIterator* handle); + +TESS_API void TESS_CALL TessPageIteratorBegin(TessPageIterator* handle); +TESS_API BOOL TESS_CALL TessPageIteratorNext(TessPageIterator* handle, TessPageIteratorLevel level); +TESS_API BOOL TESS_CALL TessPageIteratorIsAtBeginningOf(const TessPageIterator* handle, TessPageIteratorLevel level); +TESS_API BOOL TESS_CALL TessPageIteratorIsAtFinalElement(const TessPageIterator* handle, TessPageIteratorLevel level, + TessPageIteratorLevel element); + +TESS_API BOOL TESS_CALL TessPageIteratorBoundingBox(const TessPageIterator* handle, TessPageIteratorLevel level, + int* left, int* top, int* right, int* bottom); +TESS_API TessPolyBlockType + TESS_CALL TessPageIteratorBlockType(const TessPageIterator* handle); + +TESS_API struct Pix* + TESS_CALL TessPageIteratorGetBinaryImage(const TessPageIterator* handle, TessPageIteratorLevel level); +TESS_API struct Pix* + TESS_CALL TessPageIteratorGetImage(const TessPageIterator* handle, TessPageIteratorLevel level, int padding, + struct Pix* original_image, int* left, int* top); + +TESS_API BOOL TESS_CALL TessPageIteratorBaseline(const TessPageIterator* handle, TessPageIteratorLevel level, + int* x1, int* y1, int* x2, int* y2); + +TESS_API void TESS_CALL TessPageIteratorOrientation(TessPageIterator* handle, TessOrientation* orientation, + TessWritingDirection* writing_direction, TessTextlineOrder* textline_order, + float* deskew_angle); + +TESS_API void TESS_CALL TessPageIteratorParagraphInfo(TessPageIterator* handle, TessParagraphJustification* justification, + BOOL *is_list_item, BOOL *is_crown, int *first_line_indent); + +/* Result iterator */ + +TESS_API void TESS_CALL TessResultIteratorDelete(TessResultIterator* handle); +TESS_API TessResultIterator* + TESS_CALL TessResultIteratorCopy(const TessResultIterator* handle); +TESS_API TessPageIterator* + TESS_CALL TessResultIteratorGetPageIterator(TessResultIterator* handle); +TESS_API const TessPageIterator* + TESS_CALL TessResultIteratorGetPageIteratorConst(const TessResultIterator* handle); +TESS_API TessChoiceIterator* + TESS_CALL TessResultIteratorGetChoiceIterator(const TessResultIterator* handle); + +TESS_API BOOL TESS_CALL TessResultIteratorNext(TessResultIterator* handle, TessPageIteratorLevel level); +TESS_API char* TESS_CALL TessResultIteratorGetUTF8Text(const TessResultIterator* handle, TessPageIteratorLevel level); +TESS_API float TESS_CALL TessResultIteratorConfidence(const TessResultIterator* handle, TessPageIteratorLevel level); +TESS_API const char* + TESS_CALL TessResultIteratorWordRecognitionLanguage(const TessResultIterator* handle); +TESS_API const char* + TESS_CALL TessResultIteratorWordFontAttributes(const TessResultIterator* handle, BOOL* is_bold, BOOL* is_italic, + BOOL* is_underlined, BOOL* is_monospace, BOOL* is_serif, + BOOL* is_smallcaps, int* pointsize, int* font_id); + +TESS_API BOOL TESS_CALL TessResultIteratorWordIsFromDictionary(const TessResultIterator* handle); +TESS_API BOOL TESS_CALL TessResultIteratorWordIsNumeric(const TessResultIterator* handle); +TESS_API BOOL TESS_CALL TessResultIteratorSymbolIsSuperscript(const TessResultIterator* handle); +TESS_API BOOL TESS_CALL TessResultIteratorSymbolIsSubscript(const TessResultIterator* handle); +TESS_API BOOL TESS_CALL TessResultIteratorSymbolIsDropcap(const TessResultIterator* handle); + +TESS_API void TESS_CALL TessChoiceIteratorDelete(TessChoiceIterator* handle); +TESS_API BOOL TESS_CALL TessChoiceIteratorNext(TessChoiceIterator* handle); +TESS_API const char* TESS_CALL TessChoiceIteratorGetUTF8Text(const TessChoiceIterator* handle); +TESS_API float TESS_CALL TessChoiceIteratorConfidence(const TessChoiceIterator* handle); + +#ifdef __cplusplus +} +#endif + +#endif // API_CAPI_H_ diff --git a/translation/ocr_driver.c b/translation/ocr_driver.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/translation/ocr_driver.h b/translation/ocr_driver.h new file mode 100644 index 0000000000..2bbfbf4805 --- /dev/null +++ b/translation/ocr_driver.h @@ -0,0 +1,28 @@ +#ifndef __OCR_DRIVER__H +#define __OCR_DRIVER__H + +struct ocr_image_info +{ + int game_character_set; + unsigned image_width; + unsigned image_height; + unsigned pixel_format; + void* image_data; +}; + +typedef struct ocr_driver +{ + void* (*init)(); + void (*free)(void* data); + + char* (*get_text)(struct ocr_image_info image); + + const char *ident; +} ocr_driver_t; + +extern const ocr_driver_t ocr_tesseract; +extern const ocr_driver_t ocr_null; + +char* ocr_get_text(struct ocr_image_info image); + +#endif \ No newline at end of file diff --git a/translation/translation_driver.c b/translation/translation_driver.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/translation/translation_driver.h b/translation/translation_driver.h new file mode 100644 index 0000000000..574d205b8b --- /dev/null +++ b/translation/translation_driver.h @@ -0,0 +1,39 @@ +#ifndef __TRANSLATION_DRIVER__H +#define __TRANSLATION_DRIVER__H + +#include "ocr_driver.h" + +enum translation_init_errors +{ + TRANSLATION_INIT_SUCCESS = 0, + TRANSLATION_INIT_UNSUPPORTED_DEVICE_LANGUAGE, + TRANSLATION_INIT_UNSUPPORTED_GAME_LANGUAGE, + TRANSLATION_INIT_UNKNOWN_DEVICE_LANGUAGE, + TRANSLATION_INIT_UNKNOWN_GAME_LANGUAGE +}; + +struct translation_driver_info +{ + int device_language; + int game_language; +}; + +typedef struct translation_driver +{ + void* (*init)(const struct translation_driver_info *params); + void (*free)(void* data); + + /* use translate_image if non NULL else run image through ocr driver then run translate_text */ + /* NOTE: translate_image is allowed to call the ocr driver itself if it wants */ + char* (*translate_text)(const char* game_text); + char* (*translate_image)(struct ocr_image_info image); + + const char *ident; +} translation_driver_t; + +extern const translation_driver_t translation_cached_google; +extern const translation_driver_t translation_null; + +char* translation_translate_image(struct ocr_image_info image); + +#endif \ No newline at end of file