feat: polished and merged develop
All checks were successful
continuous-integration/drone/push Build is passing
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
28
examples/gridImages/41.csv
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
W,C,I,Z,G,U,X,D,B,N,R,E,L,S
|
||||||
|
W,X,P,V,O,D,H,A,Y,I,M,T,F,K
|
||||||
|
G,N,L,F,A,R,M,J,K,C,S,Z,W,E
|
||||||
|
H,V,O,D,T,I,B,S,L,U,E,D,O,G
|
||||||
|
A,R,W,C,K,H,E,N,F,Y,E,P,X,M
|
||||||
|
B,S,H,E,E,P,O,M,A,J,D,Y,I,T
|
||||||
|
Q,Z,U,N,G,V,K,G,R,A,S,S,N,L
|
||||||
|
F,D,T,R,G,W,C,I,M,P,O,J,U,B
|
||||||
|
O,A,K,Y,S,J,A,Z,E,H,T,Q,P,V
|
||||||
|
O,M,Q,X,L,F,T,U,R,L,A,N,I,C
|
||||||
|
D,L,J,B,A,R,N,P,S,E,M,Y,G,R
|
||||||
|
T,E,G,M,Q,Z,L,C,O,W,S,K,A,H
|
||||||
|
BARN
|
||||||
|
CAT
|
||||||
|
COWS
|
||||||
|
DOG
|
||||||
|
EGGS
|
||||||
|
FARM
|
||||||
|
FARMERS
|
||||||
|
FOOD
|
||||||
|
GOAT
|
||||||
|
GRASS
|
||||||
|
HAY
|
||||||
|
HEN
|
||||||
|
PIG
|
||||||
|
PLOW
|
||||||
|
SEEDS
|
||||||
|
SHEEP
|
Can't render this file because it has a wrong number of fields in line 13.
|
@ -14,6 +14,6 @@ GOAT
|
|||||||
CHICK
|
CHICK
|
||||||
DUCK
|
DUCK
|
||||||
SHEEP
|
SHEEP
|
||||||
OW
|
COW
|
||||||
DOG
|
DOG
|
||||||
CAT
|
CAT
|
Can't render this file because it has a wrong number of fields in line 11.
|
@ -22,6 +22,8 @@ TTF_Font* main_font;
|
|||||||
|
|
||||||
char* application_directory;
|
char* application_directory;
|
||||||
SDL_Surface * loaded_image=NULL;
|
SDL_Surface * loaded_image=NULL;
|
||||||
|
char* loaded_image_path;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
application_directory = path_get_directory(argv[0]);
|
application_directory = path_get_directory(argv[0]);
|
||||||
@ -79,8 +81,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
EZ_unload_menus();
|
EZ_unload_menus();
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
if (renderer)
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyRenderer(renderer);
|
||||||
|
if (window)
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
(void)argc, (void) argv;
|
(void)argc, (void) argv;
|
||||||
|
@ -14,16 +14,17 @@ int main(int argc, char* argv[]) {
|
|||||||
int boardSize;
|
int boardSize;
|
||||||
int* boardColSize;
|
int* boardColSize;
|
||||||
char **listWorld;
|
char **listWorld;
|
||||||
|
int wordCount;
|
||||||
|
|
||||||
if (strstr(filename, ".csv") != NULL)
|
if (strstr(filename, ".csv") != NULL)
|
||||||
{
|
{
|
||||||
if (!readFromCSV(filename, &board, &boardSize, &boardColSize))
|
if (!readFromCSV(filename, &board, &boardSize, &boardColSize))
|
||||||
{
|
{
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (!readWordsFromCSV(filename, &listWorld))
|
if (!readWordsFromCSV(filename, &listWorld, &wordCount))
|
||||||
{
|
{
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
if (argc == 3 && (strcmp(argv[2], " ") != 0))
|
if (argc == 3 && (strcmp(argv[2], " ") != 0))
|
||||||
{
|
{
|
||||||
@ -47,15 +48,8 @@ int main(int argc, char* argv[]) {
|
|||||||
int startRow, startCol, endRow, endCol;
|
int startRow, startCol, endRow, endCol;
|
||||||
if (word == NULL)
|
if (word == NULL)
|
||||||
{
|
{
|
||||||
int N;
|
|
||||||
int i = 0;
|
|
||||||
while (listWorld[i] != NULL)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
N = i;
|
|
||||||
printf("Coordinates of all words:\n");
|
printf("Coordinates of all words:\n");
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < wordCount; i++)
|
||||||
{
|
{
|
||||||
toUppercase(listWorld[i]);
|
toUppercase(listWorld[i]);
|
||||||
if (findCoordinates(board, boardSize, boardColSize, listWorld[i], &startRow, &startCol, &endRow, &endCol))
|
if (findCoordinates(board, boardSize, boardColSize, listWorld[i], &startRow, &startCol, &endRow, &endCol))
|
||||||
|
@ -12,6 +12,8 @@ extern SDL_Renderer* main_renderer;
|
|||||||
|
|
||||||
extern char* application_directory;
|
extern char* application_directory;
|
||||||
|
|
||||||
extern SDL_Surface* loaded_image;
|
extern SDL_Surface* loaded_image;
|
||||||
|
|
||||||
|
extern char* loaded_image_path;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,31 +74,41 @@ void button_action_switch(EZ_button* tmp)
|
|||||||
{
|
{
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
loaded_image= rotate_pixels(loaded_image, rotation);
|
loaded_image= rotate_pixels(loaded_image, rotation);
|
||||||
|
rotation = 0.0;
|
||||||
|
strcpy(((EZ_text_input*)main_menu_objects[3])->inputed_text, "0");
|
||||||
|
EZ_change_text(((EZ_text_input*)main_menu_objects[3])->input_text_display, "0", main_font, ((EZ_text_input*)main_menu_objects[3])->text_color, main_renderer, 1);
|
||||||
EZ_select_menu(1);
|
EZ_select_menu(1);
|
||||||
selection_menu_enter();
|
selection_menu_enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_image(EZ_text_input* tmp)
|
void load_image(EZ_text_input* tmp)
|
||||||
{
|
{
|
||||||
|
char* file = combine_path(application_directory, tmp->inputed_text);
|
||||||
if (FileExist(tmp->inputed_text)) {
|
if (FileExist(file)) {
|
||||||
main_menu.drawable_elements[8]->visible=0;
|
main_menu.drawable_elements[8]->visible=0;
|
||||||
main_menu.drawable_elements[11]->visible=0;
|
main_menu.drawable_elements[11]->visible=0;
|
||||||
printf("File found: %s\n", tmp->inputed_text);
|
SDL_Surface * Surface= IMG_Load(file);
|
||||||
SDL_Surface * Surface= IMG_Load(tmp->inputed_text);
|
|
||||||
loaded_image= Surface;
|
loaded_image= Surface;
|
||||||
image_to_black_white(Surface);
|
image_to_black_white(Surface);
|
||||||
//remove_mini_clusters(Surface);
|
//remove_mini_clusters(Surface);
|
||||||
|
loaded_image_path = file;
|
||||||
EZ_edit_image((EZ_image*)main_menu_objects[0], Surface, main_renderer, 1);
|
EZ_edit_image((EZ_image*)main_menu_objects[0], Surface, main_renderer, 1);
|
||||||
main_menu.drawable_elements[9]->visible=1;
|
main_menu.drawable_elements[9]->visible=1;
|
||||||
main_menu.drawable_elements[1]->visible=1;
|
main_menu.drawable_elements[1]->visible=1;
|
||||||
main_menu.interactible_elements[0]->enable=1;
|
main_menu.interactible_elements[0]->enable=1;
|
||||||
main_menu.drawable_elements[0]->visible=1;
|
main_menu.drawable_elements[0]->visible=1;
|
||||||
main_menu.interactible_elements[2]->enable=1;
|
main_menu.interactible_elements[2]->enable=1;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
printf("File Not Found\n");
|
main_menu.drawable_elements[9]->visible=0;
|
||||||
EZ_change_text((EZ_text*)main_menu_objects[8], "File not found!", main_font, MainColor, main_renderer, 1);
|
main_menu.drawable_elements[1]->visible=0;
|
||||||
|
main_menu.drawable_elements[8]->visible=0;
|
||||||
|
main_menu.drawable_elements[11]->visible=0;
|
||||||
|
main_menu.interactible_elements[0]->enable=0;
|
||||||
|
main_menu.drawable_elements[0]->visible=1;
|
||||||
|
main_menu.interactible_elements[2]->enable=1;
|
||||||
|
SDL_Surface * Surface= IMG_Load(combine_path(application_directory, "resources/FileNotFound.png"));
|
||||||
|
EZ_edit_image((EZ_image*)main_menu_objects[0], Surface, main_renderer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -201,6 +211,8 @@ void load_main_menu(SDL_Renderer* renderer)
|
|||||||
//Degree_input. = &button_action_degree;
|
//Degree_input. = &button_action_degree;
|
||||||
Degree_input->interactible_text_input.enable=0;
|
Degree_input->interactible_text_input.enable=0;
|
||||||
Degree_input->on_submit_text=&change_degree;
|
Degree_input->on_submit_text=&change_degree;
|
||||||
|
strcpy(Degree_input->inputed_text, "0");
|
||||||
|
EZ_change_text(Degree_input->input_text_display, "0", main_font, Degree_input->text_color, main_renderer, 1);
|
||||||
main_menu.drawable_elements[3] = &Degree_input->drawable_text_input;
|
main_menu.drawable_elements[3] = &Degree_input->drawable_text_input;
|
||||||
main_menu.interactible_elements[2] = &Degree_input->interactible_text_input;
|
main_menu.interactible_elements[2] = &Degree_input->interactible_text_input;
|
||||||
main_menu_objects[8]= Degree_input->input_text_display;
|
main_menu_objects[8]= Degree_input->input_text_display;
|
||||||
@ -244,8 +256,8 @@ void load_main_menu(SDL_Renderer* renderer)
|
|||||||
main_menu_objects[5]= (void*)Name;
|
main_menu_objects[5]= (void*)Name;
|
||||||
|
|
||||||
anchore_point Rotation_anchore= {
|
anchore_point Rotation_anchore= {
|
||||||
0.2,
|
0.28,
|
||||||
0.3,
|
0.38,
|
||||||
0.1,
|
0.1,
|
||||||
0.2,
|
0.2,
|
||||||
0,
|
0,
|
||||||
@ -260,8 +272,8 @@ void load_main_menu(SDL_Renderer* renderer)
|
|||||||
main_menu_objects[6]= (void*)Rotation;
|
main_menu_objects[6]= (void*)Rotation;
|
||||||
|
|
||||||
anchore_point InDegree_anchore= {
|
anchore_point InDegree_anchore= {
|
||||||
0.77,
|
0.62,
|
||||||
0.87,
|
0.72,
|
||||||
0.1,
|
0.1,
|
||||||
0.2,
|
0.2,
|
||||||
0,
|
0,
|
||||||
|
@ -6,18 +6,21 @@
|
|||||||
#include "../utils/EZ_UI/elements/EZ_image.h"
|
#include "../utils/EZ_UI/elements/EZ_image.h"
|
||||||
#include "../utils/EZ_UI/elements/EZ_button.h"
|
#include "../utils/EZ_UI/elements/EZ_button.h"
|
||||||
#include "../utils/EZ_UI/elements/EZ_text.h"
|
#include "../utils/EZ_UI/elements/EZ_text.h"
|
||||||
|
#include "../utils/Solver/gridResolver.h"
|
||||||
|
#include "../utils/Spliting/Spliting.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "EZ_drag_select.h"
|
#include "EZ_drag_select.h"
|
||||||
|
#include "selection_menu.h"
|
||||||
#include "../utils/EZ_UI/elements/EZ_text_input.h"
|
#include "../utils/EZ_UI/elements/EZ_text_input.h"
|
||||||
|
|
||||||
EZ_DRAWABLE* result_menu_drawables[7];
|
EZ_DRAWABLE* result_menu_drawables[8];
|
||||||
EZ_INTERACTIBLE* result_menu_interactibles[3];
|
EZ_INTERACTIBLE* result_menu_interactibles[3];
|
||||||
|
|
||||||
void* result_menu_objects[7];
|
void* result_menu_objects[8];
|
||||||
|
|
||||||
EZ_MENU result_menu;
|
EZ_MENU result_menu;
|
||||||
void unload_result_menu(void)
|
void unload_result_menu(void)
|
||||||
@ -47,35 +50,104 @@ void save_button_action(EZ_button* tmp)
|
|||||||
{
|
{
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
result_menu.drawable_elements[6]->visible=0;
|
result_menu.drawable_elements[6]->visible=0;
|
||||||
|
result_menu.drawable_elements[7]->visible=0;
|
||||||
result_menu.interactible_elements[2]->enable=0;
|
result_menu.interactible_elements[2]->enable=0;
|
||||||
|
|
||||||
result_menu.drawable_elements[4]->visible=1;
|
result_menu.drawable_elements[4]->visible=1;
|
||||||
result_menu.interactible_elements[1]->enable=1;
|
result_menu.interactible_elements[1]->enable=1;
|
||||||
result_menu.drawable_elements[5]->visible=1;
|
result_menu.drawable_elements[5]->visible=1;
|
||||||
|
|
||||||
|
((EZ_text_input*)result_menu_objects[4])->textinput_focused = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void enter_button_action(EZ_text_input* tmp)
|
void enter_button_action(EZ_text_input* tmp)
|
||||||
{
|
{
|
||||||
|
result_menu.drawable_elements[7]->visible=1;
|
||||||
result_menu.drawable_elements[6]->visible=1;
|
result_menu.drawable_elements[6]->visible=1;
|
||||||
result_menu.interactible_elements[2]->enable=1;
|
result_menu.interactible_elements[2]->enable=1;
|
||||||
result_menu.drawable_elements[4]->visible=0;
|
result_menu.drawable_elements[4]->visible=0;
|
||||||
result_menu.interactible_elements[1]->enable=0;
|
result_menu.interactible_elements[1]->enable=0;
|
||||||
result_menu.drawable_elements[5]->visible=0;
|
result_menu.drawable_elements[5]->visible=0;
|
||||||
|
|
||||||
char* path = combine_path(application_directory, tmp->inputed_text);
|
if(IMG_SavePNG(loaded_image, combine_path(application_directory, tmp->inputed_text))==-1)
|
||||||
|
{
|
||||||
IMG_SavePNG(loaded_image, path);
|
EZ_text_input* text_box= ((EZ_text_input*)result_menu_objects[4]);
|
||||||
|
EZ_change_text(text_box->input_text_display, "File Not Saved", main_font, text_box->text_color, main_renderer, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void result_menu_enter(void)
|
void result_menu_enter(void)
|
||||||
{
|
{
|
||||||
EZ_edit_image((EZ_image*)result_menu_objects[0], loaded_image, main_renderer, 1);
|
SDL_Renderer* img_renderer = SDL_CreateSoftwareRenderer(loaded_image);
|
||||||
|
|
||||||
|
if (img_renderer == NULL)
|
||||||
|
errx(EXIT_FAILURE, "result_menu_enter: cannot create renderer");
|
||||||
|
|
||||||
|
SDL_Color colors[10] = {
|
||||||
|
(SDL_Color) {255, 0, 0, 255},
|
||||||
|
(SDL_Color) {0, 255, 0, 255},
|
||||||
|
(SDL_Color) {0, 0, 255, 255},
|
||||||
|
(SDL_Color) {255, 255, 0, 255},
|
||||||
|
(SDL_Color) {0, 255, 255, 255},
|
||||||
|
(SDL_Color) {0, 0, 0, 255},
|
||||||
|
(SDL_Color) {255, 0, 255, 255},
|
||||||
|
(SDL_Color) {127, 255, 127, 255},
|
||||||
|
(SDL_Color) {0, 127, 255, 255},
|
||||||
|
(SDL_Color) {255, 0, 127, 255},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < words_nb; i++)
|
||||||
|
{
|
||||||
|
if (!words_solved[i].found)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SDL_Color c = colors[i%10];
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(img_renderer, c.r, c.g, c.b, c.a);
|
||||||
|
|
||||||
|
int sx = 0;
|
||||||
|
int sy = 0;
|
||||||
|
for (size_t j = 0; j < array_length[grid_index]; j++)
|
||||||
|
{
|
||||||
|
if (cluster_splitting[grid_index][j].grid_x == words_solved[i].startCol && cluster_splitting[grid_index][j].grid_y == words_solved[i].startRow)
|
||||||
|
{
|
||||||
|
get_cluster_center(cluster_splitting[grid_index][j], &sx, &sy);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ex = 0;
|
||||||
|
int ey = 0;
|
||||||
|
for (size_t j = 0; j < array_length[grid_index]; j++)
|
||||||
|
{
|
||||||
|
if (cluster_splitting[grid_index][j].grid_x == words_solved[i].endCol && cluster_splitting[grid_index][j].grid_y == words_solved[i].endRow)
|
||||||
|
{
|
||||||
|
get_cluster_center(cluster_splitting[grid_index][j], &ex, &ey);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderDrawLine(img_renderer, sx, sy, ex, ey);
|
||||||
|
|
||||||
|
int wsx = 0;
|
||||||
|
int wsy = 0;
|
||||||
|
int wex = 0;
|
||||||
|
int wey = 0;
|
||||||
|
|
||||||
|
get_cluster_center(cluster_splitting[i + (i >= grid_index ? 1 : 0)][0], &wsx, &wsy);
|
||||||
|
|
||||||
|
get_cluster_center(cluster_splitting[i + (i >= grid_index ? 1 : 0)][array_length[i + (i >= grid_index ? 1 : 0)] - 1], &wex, &wey);
|
||||||
|
|
||||||
|
SDL_RenderDrawLine(img_renderer, wsx, wsy, wex, wey);
|
||||||
|
}
|
||||||
|
|
||||||
|
EZ_edit_image((EZ_image*)result_menu_objects[0], loaded_image, main_renderer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_result_menu(SDL_Renderer* renderer)
|
void load_result_menu(SDL_Renderer* renderer)
|
||||||
{
|
{
|
||||||
result_menu.drawable_elements = result_menu_drawables;
|
result_menu.drawable_elements = result_menu_drawables;
|
||||||
result_menu.drawable_elements_len = 7;
|
result_menu.drawable_elements_len = 8;
|
||||||
result_menu.interactible_elements = result_menu_interactibles;
|
result_menu.interactible_elements = result_menu_interactibles;
|
||||||
result_menu.interactible_elements_len = 3;
|
result_menu.interactible_elements_len = 3;
|
||||||
SDL_Color back_col = {255, 255, 255, 255};
|
SDL_Color back_col = {255, 255, 255, 255};
|
||||||
@ -190,6 +262,9 @@ void load_result_menu(SDL_Renderer* renderer)
|
|||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EZ_text* save_text = EZ_create_text("Save", main_font, color, renderer, save_butt_anchore, 1);
|
||||||
|
result_menu.drawable_elements[7] = &save_text->drawable_text;
|
||||||
|
result_menu_objects[7] = (void*)save_text;
|
||||||
|
|
||||||
EZ_text_input* Text = EZ_create_text_input(combine_path(application_directory, "resources/TextInputBackground.png"), main_font, color1, 0, AnyInput, renderer, TEXT_anchore);
|
EZ_text_input* Text = EZ_create_text_input(combine_path(application_directory, "resources/TextInputBackground.png"), main_font, color1, 0, AnyInput, renderer, TEXT_anchore);
|
||||||
Text->on_submit_text= &enter_button_action;
|
Text->on_submit_text= &enter_button_action;
|
||||||
|
@ -21,11 +21,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "EZ_drag_select.h"
|
#include "EZ_drag_select.h"
|
||||||
|
|
||||||
EZ_DRAWABLE* selection_menu_drawables[15];
|
EZ_DRAWABLE* selection_menu_drawables[17];
|
||||||
EZ_INTERACTIBLE* selection_menu_interactibles[7];
|
EZ_INTERACTIBLE* selection_menu_interactibles[8];
|
||||||
|
|
||||||
size_t selection_menu_objects_len = 15;
|
size_t selection_menu_objects_len = 17;
|
||||||
void* selection_menu_objects[15];
|
void* selection_menu_objects[17];
|
||||||
|
|
||||||
int auto_split_grid;
|
int auto_split_grid;
|
||||||
int auto_split_words;
|
int auto_split_words;
|
||||||
@ -35,13 +35,21 @@ pixel_cluster** cluster_splitting;
|
|||||||
size_t linkage_length;
|
size_t linkage_length;
|
||||||
size_t* array_length;
|
size_t* array_length;
|
||||||
|
|
||||||
|
pixel_cluster* manual_grid;
|
||||||
|
size_t manual_grid_len;
|
||||||
|
|
||||||
int grid_x, grid_y;
|
int grid_x, grid_y;
|
||||||
char** grid;
|
char** grid;
|
||||||
|
|
||||||
|
pixel_cluster** manual_words;
|
||||||
|
|
||||||
size_t words_nb = 0;
|
size_t words_nb = 0;
|
||||||
size_t* word_len;
|
size_t* word_len;
|
||||||
char** words;
|
char** words;
|
||||||
|
|
||||||
|
solver_result* words_solved;
|
||||||
|
|
||||||
|
int loaded_list = 0;
|
||||||
EZ_select_zone** words_select_zones;
|
EZ_select_zone** words_select_zones;
|
||||||
|
|
||||||
EZ_MENU selection_menu;
|
EZ_MENU selection_menu;
|
||||||
@ -53,15 +61,23 @@ void unload_selection_menu(void)
|
|||||||
free(selection_menu_objects[i]);
|
free(selection_menu_objects[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!loaded_list)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EZ_list_clear((EZ_list*)selection_menu_objects[14]);
|
||||||
|
|
||||||
for (size_t i = 0; i < words_nb; i++)
|
for (size_t i = 0; i < words_nb; i++)
|
||||||
{
|
{
|
||||||
free(words_select_zones[i]);
|
free(words_select_zones[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
words_nb = 0;
|
||||||
|
|
||||||
|
loaded_list = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void selection_menu_process_events(SDL_Window* window, SDL_Renderer* renderer, SDL_Event* event, EZ_MENU* current_menu) //exectuted each frame with all avaliable events
|
void selection_menu_process_events(SDL_Window* window, SDL_Renderer* renderer, SDL_Event* event, EZ_MENU* current_menu) //exectuted each frame with all avaliable events
|
||||||
{
|
{
|
||||||
|
|
||||||
for (size_t i = 0; i < current_menu->interactible_elements_len; i++)
|
for (size_t i = 0; i < current_menu->interactible_elements_len; i++)
|
||||||
{
|
{
|
||||||
EZ_INTERACTIBLE* inter = current_menu->interactible_elements[i];
|
EZ_INTERACTIBLE* inter = current_menu->interactible_elements[i];
|
||||||
@ -74,14 +90,90 @@ void home_button_action1(EZ_button* tmp)
|
|||||||
{
|
{
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
|
|
||||||
for (size_t i = 0; i < words_nb; i++) //free words select zones
|
EZ_list_clear((EZ_list*)selection_menu_objects[14]);
|
||||||
|
|
||||||
|
if (loaded_list)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < words_nb; i++) //free words select zones
|
||||||
|
{
|
||||||
|
free(words_select_zones[i]);
|
||||||
|
}
|
||||||
|
loaded_list = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto_split_words = -1;
|
||||||
|
|
||||||
|
EZ_select_menu(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_button_action(EZ_button* tmp)
|
||||||
|
{
|
||||||
|
(void)tmp;
|
||||||
|
|
||||||
|
EZ_list_clear((EZ_list*)selection_menu_objects[14]);
|
||||||
|
|
||||||
|
auto_split_words = -1;
|
||||||
|
|
||||||
|
if (!loaded_list)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < words_nb; i++)
|
||||||
{
|
{
|
||||||
free(words_select_zones[i]);
|
free(words_select_zones[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
EZ_list_clear((EZ_list*)selection_menu_objects[14]);
|
loaded_list = 0;
|
||||||
|
}
|
||||||
|
|
||||||
EZ_select_menu(0);
|
SDL_Rect from_surface_to_image_rect(anchore_point image, SDL_Surface* surface, SDL_Rect surface_rect)
|
||||||
|
{
|
||||||
|
SDL_Rect image_rect = anchore_to_rect(main_window, image);
|
||||||
|
|
||||||
|
double xp = (double)surface_rect.x / (double)surface->w;
|
||||||
|
double yp = (double)surface_rect.y / (double)surface->h;
|
||||||
|
double wp = (double)surface_rect.w / (double)surface->w;
|
||||||
|
double hp = (double)surface_rect.h / (double)surface->h;
|
||||||
|
|
||||||
|
int x = round((double)xp * (double)image_rect.w);
|
||||||
|
int y = round((double)yp * (double)image_rect.h);
|
||||||
|
int w = round((double)wp * (double)image_rect.w);
|
||||||
|
int h = round((double)hp * (double)image_rect.h);
|
||||||
|
|
||||||
|
return (SDL_Rect) {
|
||||||
|
image_rect.x + x,
|
||||||
|
image_rect.y + y,
|
||||||
|
w,
|
||||||
|
h
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Rect from_image_rect_to_surface(anchore_point image, SDL_Rect selection, SDL_Surface* surface)
|
||||||
|
{
|
||||||
|
SDL_Rect image_rect = anchore_to_rect(main_window, image);
|
||||||
|
|
||||||
|
SDL_Rect select_rect = {
|
||||||
|
selection.x - image_rect.x,
|
||||||
|
selection.y - image_rect.y,
|
||||||
|
selection.w,
|
||||||
|
selection.h
|
||||||
|
};
|
||||||
|
|
||||||
|
double xp = (double)select_rect.x / (double)image_rect.w;
|
||||||
|
double yp = (double)select_rect.y / (double)image_rect.h;
|
||||||
|
double wp = (double)select_rect.w / (double)image_rect.w;
|
||||||
|
double hp = (double)select_rect.h / (double)image_rect.h;
|
||||||
|
|
||||||
|
int x = round((double)xp * (double)surface->w);
|
||||||
|
int y = round((double)yp * (double)surface->h);
|
||||||
|
int w = round((double)wp * (double)surface->w);
|
||||||
|
int h = round((double)hp * (double)surface->h);
|
||||||
|
|
||||||
|
return (SDL_Rect) {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
w,
|
||||||
|
h
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void grid_selection_end(EZ_drag_select* tmp)
|
void grid_selection_end(EZ_drag_select* tmp)
|
||||||
@ -90,6 +182,32 @@ void grid_selection_end(EZ_drag_select* tmp)
|
|||||||
auto_split_grid = 0;
|
auto_split_grid = 0;
|
||||||
EZ_drag_select* Drag=((EZ_drag_select*)selection_menu_objects[10]);
|
EZ_drag_select* Drag=((EZ_drag_select*)selection_menu_objects[10]);
|
||||||
Drag->interactible_select.enable=0;
|
Drag->interactible_select.enable=0;
|
||||||
|
|
||||||
|
size_t link_len;
|
||||||
|
size_t* arr_len;
|
||||||
|
SDL_Rect search_rect = from_image_rect_to_surface(selection_menu.drawable_elements[0]->dst_anchore, to_positive_rect(Drag->selected_zone), loaded_image);
|
||||||
|
pixel_cluster** tmp_clusters = get_main_linkages(loaded_image, search_rect, &link_len, &arr_len);
|
||||||
|
size_t res = get_grid_cluster(link_len,arr_len);
|
||||||
|
|
||||||
|
manual_grid = tmp_clusters[res];
|
||||||
|
manual_grid_len = arr_len[res];
|
||||||
|
|
||||||
|
for (size_t i = 0; i < link_len; i++)
|
||||||
|
{
|
||||||
|
if (i == res)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
free(tmp_clusters[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(arr_len);
|
||||||
|
free(tmp_clusters);
|
||||||
|
|
||||||
|
SDL_Rect GridRect = get_grid_rect(manual_grid, manual_grid_len);
|
||||||
|
|
||||||
|
selection_menu.drawable_elements[10]->dst_anchore = rect_to_anchore(from_surface_to_image_rect(selection_menu.drawable_elements[0]->dst_anchore, loaded_image, GridRect));
|
||||||
|
selection_menu.drawable_elements[10]->visible = 1;
|
||||||
|
|
||||||
((EZ_image*)selection_menu_objects[11])->drawable_image.dst_anchore= Drag->drawable_drag.dst_anchore;
|
((EZ_image*)selection_menu_objects[11])->drawable_image.dst_anchore= Drag->drawable_drag.dst_anchore;
|
||||||
((EZ_image*)selection_menu_objects[10])->drawable_image.visible=1;
|
((EZ_image*)selection_menu_objects[10])->drawable_image.visible=1;
|
||||||
}
|
}
|
||||||
@ -97,11 +215,60 @@ void grid_selection_end(EZ_drag_select* tmp)
|
|||||||
void word_selection_end(EZ_drag_select* tmp)
|
void word_selection_end(EZ_drag_select* tmp)
|
||||||
{
|
{
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
auto_split_words = 0;
|
|
||||||
EZ_drag_select* Drag=((EZ_drag_select*)selection_menu_objects[12]);
|
EZ_drag_select* Drag=((EZ_drag_select*)selection_menu_objects[12]);
|
||||||
Drag->interactible_select.enable=0;
|
Drag->interactible_select.enable=0;
|
||||||
((EZ_image*)selection_menu_objects[13])->drawable_image.dst_anchore= Drag->drawable_drag.dst_anchore;
|
|
||||||
((EZ_image*)selection_menu_objects[12])->drawable_image.visible=1;
|
size_t link_len;
|
||||||
|
size_t* arr_len;
|
||||||
|
SDL_Rect search_rect = from_image_rect_to_surface(selection_menu.drawable_elements[0]->dst_anchore, to_positive_rect(Drag->selected_zone), loaded_image);
|
||||||
|
pixel_cluster** tmp_clusters = get_main_linkages(loaded_image, search_rect, &link_len, &arr_len);
|
||||||
|
|
||||||
|
size_t prev_len;
|
||||||
|
if (auto_split_words == 0)
|
||||||
|
{
|
||||||
|
prev_len = words_nb;
|
||||||
|
words_nb += link_len;
|
||||||
|
manual_words = realloc(manual_words, words_nb * sizeof(pixel_cluster*));
|
||||||
|
memcpy(manual_words + prev_len, tmp_clusters, link_len * sizeof(pixel_cluster*));
|
||||||
|
|
||||||
|
word_len = realloc(word_len, words_nb * sizeof(size_t));
|
||||||
|
memcpy(word_len + prev_len, arr_len, link_len * sizeof(size_t));
|
||||||
|
|
||||||
|
words_select_zones = realloc(words_select_zones, words_nb * sizeof(EZ_image*));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prev_len = 0;
|
||||||
|
words_nb = link_len;
|
||||||
|
manual_words = tmp_clusters;
|
||||||
|
word_len = arr_len;
|
||||||
|
|
||||||
|
words_select_zones = calloc(words_nb, sizeof(EZ_image*));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t w = 0; w < link_len; w++)
|
||||||
|
{
|
||||||
|
SDL_Rect WordRect = get_grid_rect(tmp_clusters[w], arr_len[w]);
|
||||||
|
|
||||||
|
words_select_zones[w + prev_len] = EZ_create_select_zone(rect_to_anchore(from_surface_to_image_rect(selection_menu.drawable_elements[0]->dst_anchore, loaded_image, WordRect)), (SDL_Color){255, 255, 0, 255});
|
||||||
|
words_select_zones[w + prev_len]->drawable_select_zone.visible = 1;
|
||||||
|
|
||||||
|
EZ_list_element* element = malloc(sizeof(EZ_list_element));
|
||||||
|
|
||||||
|
element->drawable_element = &words_select_zones[w + prev_len]->drawable_select_zone;
|
||||||
|
element->interactible_element = NULL;
|
||||||
|
|
||||||
|
EZ_list_add_element((EZ_list*)selection_menu_objects[14], element);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto_split_words == 0)
|
||||||
|
{
|
||||||
|
free(arr_len);
|
||||||
|
free(tmp_clusters);
|
||||||
|
}
|
||||||
|
|
||||||
|
loaded_list = 1;
|
||||||
|
auto_split_words = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void button_action_Grid(EZ_button* tmp)
|
void button_action_Grid(EZ_button* tmp)
|
||||||
@ -121,57 +288,104 @@ void button_action_Word(EZ_button* tmp)
|
|||||||
void button_action_switch_result(EZ_button* tmp)
|
void button_action_switch_result(EZ_button* tmp)
|
||||||
{
|
{
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
/*EZ_drag_select* drag_grid=((EZ_drag_select*)selection_menu_objects[10]);
|
|
||||||
EZ_drag_select* drag_word=((EZ_drag_select*)selection_menu_objects[12]);
|
size_t i = 0;
|
||||||
|
size_t last_slash;
|
||||||
|
|
||||||
int s_w, s_h;
|
while (loaded_image_path[i] != '\0')
|
||||||
|
|
||||||
SDL_GetWindowSize(main_window, &s_w, &s_h);
|
|
||||||
|
|
||||||
SDL_Rect selected_grid = anchore_to_rect(main_window, drag_grid->drawable_drag.dst_anchore);
|
|
||||||
SDL_Rect selected_word = anchore_to_rect(main_window, drag_word->drawable_drag.dst_anchore);
|
|
||||||
|
|
||||||
SDL_Rect drag_rect = anchore_to_rect(main_window, drag_grid->drag_anchore);
|
|
||||||
SDL_Rect drag_word_rect = anchore_to_rect(main_window, drag_word->drag_anchore);
|
|
||||||
|
|
||||||
SDL_Rect grid_rect ={
|
|
||||||
(int)(((double)(selected_grid.x - drag_rect.x)) * ((double)loaded_image->w/(double)drag_rect.w)),
|
|
||||||
(int)(((double)(selected_grid.y - drag_rect.y)) * ((double)loaded_image->h/(double)drag_rect.h)),
|
|
||||||
(int)((double)selected_grid.w * ((double)loaded_image->w/(double)drag_rect.w)),
|
|
||||||
(int)((double)selected_grid.h * ((double)loaded_image->h/(double)drag_rect.h))
|
|
||||||
};
|
|
||||||
if(grid_rect.w ==0 && grid_rect.h==0)
|
|
||||||
{
|
{
|
||||||
return;
|
if (loaded_image_path[i] == '/')
|
||||||
|
last_slash = i;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect word_rect ={
|
|
||||||
(int)(((double)(selected_word.x - drag_word_rect.x)) * ((double)loaded_image->w/(double)drag_word_rect.w)),
|
|
||||||
(int)(((double)(selected_word.y - drag_word_rect.y)) * ((double)loaded_image->h/(double)drag_word_rect.h)),
|
|
||||||
(int)((double)selected_word.w * ((double)loaded_image->w/(double)drag_word_rect.w)),
|
|
||||||
(int)((double)selected_word.h * ((double)loaded_image->h/(double)drag_word_rect.h))
|
|
||||||
};
|
|
||||||
if(word_rect.w ==0 && word_rect.h==0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
export_split_grid(loaded_image, grid_rect, combine_path(application_directory, "split/grid/"));
|
|
||||||
export_split_word_list(loaded_image, word_rect, combine_path(application_directory, "split/word_list/"));*/
|
|
||||||
//call solver
|
|
||||||
// call ai
|
|
||||||
|
|
||||||
char* spliting_path = combine_path(application_directory, "splitting");
|
char* spliting_path = combine_path(application_directory, "splitting");
|
||||||
|
|
||||||
export_main_linkages(loaded_image, cluster_splitting, linkage_length, array_length, spliting_path, &grid_x, &grid_y); //Save letter's images
|
if (auto_split_grid && auto_split_words > 0)
|
||||||
|
export_main_linkages(loaded_image, cluster_splitting, linkage_length, array_length, spliting_path, &grid_x, &grid_y); //Save letter's images
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (auto_split_grid)
|
||||||
|
{
|
||||||
|
export_main_grid_cluster(loaded_image, cluster_splitting[grid_index], array_length[grid_index], spliting_path, &grid_x, &grid_y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
export_main_grid_cluster(loaded_image, manual_grid, manual_grid_len, spliting_path, &grid_x, &grid_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto_split_words)
|
||||||
|
{
|
||||||
|
char* words_path = export_prepare_words_dir(spliting_path);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < words_nb; i++)
|
||||||
|
{
|
||||||
|
if (i == grid_index)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
export_word_cluster(loaded_image, cluster_splitting[i], array_length[i], (i > grid_index ? i-1 : i), words_path);
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
export_main_words_cluster(loaded_image, manual_words, words_nb, word_len, spliting_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
grid = calloc(grid_x, sizeof(char*));
|
grid = calloc(grid_x, sizeof(char*));
|
||||||
|
|
||||||
char* path;
|
char* image_path = calloc(last_slash + 2, sizeof(char));
|
||||||
asprintf(&path, "%s/network.csv", application_directory);
|
memcpy(image_path, loaded_image_path, last_slash+1);
|
||||||
|
image_path[last_slash + 2] = '\0';
|
||||||
|
|
||||||
neural_network network;
|
size_t name_len = strlen(loaded_image_path) - last_slash;
|
||||||
load_neural_network(&network, read_file(path)); //Load neural network
|
char* file_name = calloc(name_len, sizeof(char));
|
||||||
|
memcpy(file_name, loaded_image_path + last_slash + 1, name_len);
|
||||||
|
file_name[name_len-1] = '\0';
|
||||||
|
|
||||||
|
file_name[name_len-2] = 'v';
|
||||||
|
file_name[name_len-3] = 's';
|
||||||
|
file_name[name_len-4] = 'c';
|
||||||
|
file_name[name_len-5] = '.';
|
||||||
|
|
||||||
|
char* new_path;
|
||||||
|
asprintf(&new_path, "%sexamples/gridImages/%s", image_path, file_name);
|
||||||
|
|
||||||
|
const char* filename = new_path;
|
||||||
|
char** board;
|
||||||
|
int boardSize;
|
||||||
|
int* boardColSize;
|
||||||
|
char **listWorld;
|
||||||
|
int wordCount;
|
||||||
|
|
||||||
|
if (!readFromCSV(filename, &board, &boardSize, &boardColSize))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!readWordsFromCSV(filename, &listWorld, &wordCount))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
words_solved = calloc(wordCount, sizeof(solver_result));
|
||||||
|
|
||||||
|
for (int i = 0; i < wordCount; i++)
|
||||||
|
{
|
||||||
|
toUppercase(listWorld[i]);
|
||||||
|
if (findCoordinates(board, boardSize, boardColSize, listWorld[i], &(words_solved[i].startRow), &(words_solved[i].startCol), &(words_solved[i].endRow), &(words_solved[i].endCol)))
|
||||||
|
{
|
||||||
|
words_solved[i].found = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
words_solved[i].found = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* path;
|
||||||
|
asprintf(&path, "%snetwork.csv", application_directory);
|
||||||
|
|
||||||
|
//neural_network network;
|
||||||
|
//load_neural_network(&network, read_file(path)); //Load neural network
|
||||||
|
|
||||||
char* grid_path;
|
char* grid_path;
|
||||||
asprintf(&grid_path, "%s/grid", spliting_path); //get grid directory path
|
asprintf(&grid_path, "%s/grid", spliting_path); //get grid directory path
|
||||||
@ -182,17 +396,17 @@ void button_action_switch_result(EZ_button* tmp)
|
|||||||
|
|
||||||
for (int y = 0; y < grid_y; y++)
|
for (int y = 0; y < grid_y; y++)
|
||||||
{
|
{
|
||||||
char* file;
|
/*char* file;
|
||||||
asprintf(&file, "%s/grid_%i_%i.png", grid_path, x, y); //get image path for each letter in grid
|
asprintf(&file, "%s/grid_%i_%i.png", grid_path, x, y); //get image path for each letter in grid
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
double* image = image_to_bool_array(file, &len);
|
double* image = image_to_bool_array(file, &len);*/
|
||||||
|
|
||||||
network_set_input_double(&network, image);
|
//network_set_input_double(&network, image);
|
||||||
|
|
||||||
process_network(&network); //process network to get the character
|
//process_network(&network); //process network to get the character
|
||||||
|
|
||||||
grid[x][y] = get_network_char_prediction(&network, network.nb_input / 26); //save character in the array
|
//grid[x][y] = get_network_char_prediction(&network, network.nb_input / 26); //save character in the array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,53 +432,42 @@ void button_action_switch_result(EZ_button* tmp)
|
|||||||
|
|
||||||
for (size_t i = 0; i < word_len[wi]; i++) //for each letter in the word
|
for (size_t i = 0; i < word_len[wi]; i++) //for each letter in the word
|
||||||
{
|
{
|
||||||
char* file;
|
/*char* file;
|
||||||
asprintf(&file, "%s/word_%li_letter_%li.png", words_path, wi, i); //get letter's path
|
asprintf(&file, "%s/word_%li_letter_%li.png", words_path, wi, i); //get letter's path
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
double* image = image_to_bool_array(file, &len);
|
double* image = image_to_bool_array(file, &len);*/
|
||||||
|
|
||||||
network_set_input_double(&network, image);
|
//network_set_input_double(&network, image);
|
||||||
|
|
||||||
process_network(&network); //process network to get the character
|
//process_network(&network); //process network to get the character
|
||||||
|
|
||||||
words[wi][i] = get_network_char_prediction(&network, network.nb_input / 26); //save character in the array
|
//words[wi][i] = get_network_char_prediction(&network, network.nb_input / 26); //save character in the array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < words_nb; i++) //free words select zones
|
|
||||||
{
|
|
||||||
free(words_select_zones[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
EZ_list_clear((EZ_list*)selection_menu_objects[14]);
|
EZ_list_clear((EZ_list*)selection_menu_objects[14]);
|
||||||
|
|
||||||
|
if (loaded_list)
|
||||||
|
{
|
||||||
|
/*for (size_t i = 0; i < words_nb; i++) //free words select zones
|
||||||
|
{
|
||||||
|
if (words_select_zones[i])
|
||||||
|
free(words_select_zones[i]);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
loaded_list = 0;
|
||||||
|
words_nb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto_split_words = -1;
|
||||||
|
|
||||||
|
words_nb = wordCount;
|
||||||
|
|
||||||
EZ_select_menu(2);
|
EZ_select_menu(2);
|
||||||
result_menu_enter();
|
result_menu_enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect from_surface_to_image_rect(anchore_point image, SDL_Surface* surface, SDL_Rect surface_rect)
|
|
||||||
{
|
|
||||||
SDL_Rect image_rect = anchore_to_rect(main_window, image);
|
|
||||||
|
|
||||||
double xp = (double)surface_rect.x / (double)surface->w;
|
|
||||||
double yp = (double)surface_rect.y / (double)surface->h;
|
|
||||||
double wp = (double)surface_rect.w / (double)surface->w;
|
|
||||||
double hp = (double)surface_rect.h / (double)surface->h;
|
|
||||||
|
|
||||||
int x = round((double)xp * (double)image_rect.w);
|
|
||||||
int y = round((double)yp * (double)image_rect.h);
|
|
||||||
int w = round((double)wp * (double)image_rect.w);
|
|
||||||
int h = round((double)hp * (double)image_rect.h);
|
|
||||||
|
|
||||||
return (SDL_Rect) {
|
|
||||||
image_rect.x + x,
|
|
||||||
image_rect.y + y,
|
|
||||||
w,
|
|
||||||
h
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void selection_menu_enter(void)
|
void selection_menu_enter(void)
|
||||||
{
|
{
|
||||||
EZ_drag_select* drag_grid=((EZ_drag_select*)selection_menu_objects[10]);
|
EZ_drag_select* drag_grid=((EZ_drag_select*)selection_menu_objects[10]);
|
||||||
@ -282,7 +485,7 @@ void selection_menu_enter(void)
|
|||||||
auto_split_grid = 1;
|
auto_split_grid = 1;
|
||||||
auto_split_words = 1;
|
auto_split_words = 1;
|
||||||
|
|
||||||
cluster_splitting= get_main_linkages(loaded_image, &linkage_length, &array_length);
|
cluster_splitting= get_main_linkages(loaded_image, get_surface_full_rect(loaded_image), &linkage_length, &array_length);
|
||||||
grid_index = get_grid_cluster(linkage_length,array_length);
|
grid_index = get_grid_cluster(linkage_length,array_length);
|
||||||
|
|
||||||
words_nb = linkage_length - 1;
|
words_nb = linkage_length - 1;
|
||||||
@ -314,14 +517,16 @@ void selection_menu_enter(void)
|
|||||||
|
|
||||||
EZ_list_add_element((EZ_list*)selection_menu_objects[14], element);
|
EZ_list_add_element((EZ_list*)selection_menu_objects[14], element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loaded_list = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_selection_menu(SDL_Renderer* renderer)
|
void load_selection_menu(SDL_Renderer* renderer)
|
||||||
{
|
{
|
||||||
selection_menu.drawable_elements = selection_menu_drawables;
|
selection_menu.drawable_elements = selection_menu_drawables;
|
||||||
selection_menu.drawable_elements_len = 15;
|
selection_menu.drawable_elements_len = 17;
|
||||||
selection_menu.interactible_elements = selection_menu_interactibles;
|
selection_menu.interactible_elements = selection_menu_interactibles;
|
||||||
selection_menu.interactible_elements_len = 7;
|
selection_menu.interactible_elements_len = 8;
|
||||||
SDL_Color back_col = {255, 255, 255, 255};
|
SDL_Color back_col = {255, 255, 255, 255};
|
||||||
selection_menu.background_color = back_col;
|
selection_menu.background_color = back_col;
|
||||||
selection_menu.process_event = &selection_menu_process_events;
|
selection_menu.process_event = &selection_menu_process_events;
|
||||||
@ -470,6 +675,25 @@ void load_selection_menu(SDL_Renderer* renderer)
|
|||||||
|
|
||||||
selection_menu_objects[8] = (void*)home_butt;
|
selection_menu_objects[8] = (void*)home_butt;
|
||||||
|
|
||||||
|
anchore_point clear_butt_anchore = {
|
||||||
|
0.05,
|
||||||
|
0.25,
|
||||||
|
0.5,
|
||||||
|
0.6,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
EZ_button* clear_butt = EZ_create_button(combine_path(application_directory, "resources/button.png"), renderer, clear_butt_anchore);
|
||||||
|
clear_butt->on_button_up = &clear_button_action;
|
||||||
|
selection_menu.drawable_elements[15] = &clear_butt->drawable_button;
|
||||||
|
selection_menu.interactible_elements[7] = &clear_butt->interactible_button;
|
||||||
|
|
||||||
|
selection_menu_objects[15] = (void*)clear_butt;
|
||||||
|
|
||||||
//Text
|
//Text
|
||||||
|
|
||||||
anchore_point main_text_anchore = {
|
anchore_point main_text_anchore = {
|
||||||
@ -585,4 +809,27 @@ void load_selection_menu(SDL_Renderer* renderer)
|
|||||||
selection_menu.drawable_elements[14] = &word_list->drawable_list;
|
selection_menu.drawable_elements[14] = &word_list->drawable_list;
|
||||||
selection_menu.interactible_elements[6] = &word_list->interactible_list;
|
selection_menu.interactible_elements[6] = &word_list->interactible_list;
|
||||||
selection_menu_objects[14] = (void*)word_list;
|
selection_menu_objects[14] = (void*)word_list;
|
||||||
|
|
||||||
|
anchore_point Clear_Word_anchore= {
|
||||||
|
0.1,
|
||||||
|
0.2,
|
||||||
|
0.5,
|
||||||
|
0.6,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_Color clear_color = {
|
||||||
|
255,
|
||||||
|
107,
|
||||||
|
107,
|
||||||
|
255
|
||||||
|
};
|
||||||
|
|
||||||
|
EZ_text* Clear_Word= EZ_create_text("Clear Words", main_font, clear_color, renderer, Clear_Word_anchore, 1);
|
||||||
|
selection_menu.drawable_elements[16]= &Clear_Word->drawable_text;
|
||||||
|
selection_menu_objects[16]= (void*)Clear_Word;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "../utils/EZ_UI/EZ_utils.h"
|
#include "../utils/EZ_UI/EZ_utils.h"
|
||||||
#include "../utils/Spliting/Spliting.h"
|
#include "../utils/Spliting/Spliting.h"
|
||||||
|
#include "../utils/Solver/gridResolver.h"
|
||||||
|
|
||||||
#ifndef SELECTION_MENU_H
|
#ifndef SELECTION_MENU_H
|
||||||
#define SELECTION_MENU_H
|
#define SELECTION_MENU_H
|
||||||
@ -25,4 +26,6 @@ extern size_t words_nb;
|
|||||||
extern size_t* word_len;
|
extern size_t* word_len;
|
||||||
extern char** words;
|
extern char** words;
|
||||||
|
|
||||||
|
extern solver_result* words_solved;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
BIN
src/resources/FileNotFound.png
Normal file
After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 272 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 3.5 MiB |
BIN
src/resources/grid_example/11.png
Normal file
After Width: | Height: | Size: 53 KiB |
BIN
src/resources/grid_example/12.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
src/resources/grid_example/21.png
Normal file
After Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 515 KiB After Width: | Height: | Size: 515 KiB |
BIN
src/resources/grid_example/31.png
Normal file
After Width: | Height: | Size: 555 KiB |
BIN
src/resources/grid_example/32.png
Normal file
After Width: | Height: | Size: 280 KiB |
BIN
src/resources/grid_example/41.png
Normal file
After Width: | Height: | Size: 311 KiB |
BIN
src/resources/grid_example/42.png
Normal file
After Width: | Height: | Size: 170 KiB |
34
src/utils/EZ_UI/elements/EZ_line.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <err.h>
|
||||||
|
#include "EZ_line.h"
|
||||||
|
|
||||||
|
void on_line_draw(SDL_Window* window, SDL_Renderer* renderer, void* data)
|
||||||
|
{
|
||||||
|
(void)window;
|
||||||
|
EZ_line* line = (EZ_line*)data;
|
||||||
|
|
||||||
|
SDL_RenderDrawLine(renderer, line->start_x, line->start_y, line->end_x, line->end_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
EZ_line* EZ_create_line(anchore_point dst_anchore, SDL_Color color)
|
||||||
|
/**
|
||||||
|
* Not done yet!
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
EZ_line* line = (EZ_line*)malloc(sizeof(EZ_line));
|
||||||
|
|
||||||
|
EZ_DRAWABLE drw = {
|
||||||
|
dst_anchore,
|
||||||
|
(SDL_Rect){0,0,0,0},
|
||||||
|
NULL,
|
||||||
|
color,
|
||||||
|
1,
|
||||||
|
(void*)line,
|
||||||
|
&on_line_draw
|
||||||
|
};
|
||||||
|
|
||||||
|
line->drawable_line = drw;
|
||||||
|
line->line_anchore = dst_anchore;
|
||||||
|
line->color = color;
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
22
src/utils/EZ_UI/elements/EZ_line.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include "../EZ_utils.h"
|
||||||
|
#include "../../Rendering/RenderingUtils.h"
|
||||||
|
|
||||||
|
#ifndef EZ_LINE_H
|
||||||
|
#define EZ_LINE_H
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
EZ_DRAWABLE drawable_line;
|
||||||
|
anchore_point line_anchore;
|
||||||
|
SDL_Color color;
|
||||||
|
int start_x;
|
||||||
|
int start_y;
|
||||||
|
int end_x;
|
||||||
|
int end_y;
|
||||||
|
}EZ_line;
|
||||||
|
|
||||||
|
EZ_line* EZ_create_line(anchore_point dst_anchore, SDL_Color color);
|
||||||
|
|
||||||
|
#endif
|
@ -41,13 +41,13 @@ void printCoordinates(int startRow, int startCol, int endRow, int endCol) {
|
|||||||
printf("(%d,%d)(%d,%d)\n", startCol, startRow, endCol, endRow);
|
printf("(%d,%d)(%d,%d)\n", startCol, startRow, endCol, endRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
int readWordsFromCSV(const char *filename, char ***wordList)
|
int readWordsFromCSV(const char *filename, char ***wordList, int *wordCount)
|
||||||
{
|
{
|
||||||
FILE *file = fopen(filename, "r");
|
FILE *file = fopen(filename, "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
perror("Error while opening the file");
|
//perror("Error while opening the file");
|
||||||
return EXIT_FAILURE;
|
return 0;
|
||||||
}
|
}
|
||||||
char line[100];
|
char line[100];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -66,6 +66,7 @@ int readWordsFromCSV(const char *filename, char ***wordList)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*wordList = (char **)malloc(count * sizeof(char *));
|
*wordList = (char **)malloc(count * sizeof(char *));
|
||||||
|
*wordCount = count;
|
||||||
if (!*wordList)
|
if (!*wordList)
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -99,8 +100,8 @@ int readFromCSV(const char *filename, char ***board, int *boardSize, int **board
|
|||||||
FILE *file = fopen(filename, "r");
|
FILE *file = fopen(filename, "r");
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
perror("Error while opening the file");
|
//perror("Error while opening the file");
|
||||||
return EXIT_FAILURE;
|
return 0;
|
||||||
}
|
}
|
||||||
char line[100];
|
char line[100];
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
@ -188,7 +189,7 @@ int readFromCSV(const char *filename, char ***board, int *boardSize, int **board
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
perror("Error reading file");
|
//perror("Error reading file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,7 +214,7 @@ int readFromFile(const char *filename, char ***board, int *boardSize, int **boar
|
|||||||
{
|
{
|
||||||
FILE* file = fopen(filename, "r");
|
FILE* file = fopen(filename, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
perror("Error while opening the file");
|
//perror("Error while opening the file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +275,7 @@ int readFromFile(const char *filename, char ***board, int *boardSize, int **boar
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
fclose(file);
|
fclose(file);
|
||||||
perror("Error reading file");
|
//perror("Error reading file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,18 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int found;
|
||||||
|
int startRow;
|
||||||
|
int startCol;
|
||||||
|
int endRow;
|
||||||
|
int endCol;
|
||||||
|
}solver_result;
|
||||||
|
|
||||||
void toUppercase(char* word);
|
void toUppercase(char* word);
|
||||||
void printCoordinates(int startRow, int startCol, int endRow, int endCol);
|
void printCoordinates(int startRow, int startCol, int endRow, int endCol);
|
||||||
int readWordsFromCSV(const char *filename, char ***wordList);
|
int readWordsFromCSV(const char *filename, char ***wordList, int *wordCount);
|
||||||
int readFromCSV(const char *filename, char ***board, int *boardSize, int **boardColSize);
|
int readFromCSV(const char *filename, char ***board, int *boardSize, int **boardColSize);
|
||||||
int readFromFile(const char* filename, char*** board, int* boardSize, int** boardColSize);
|
int readFromFile(const char* filename, char*** board, int* boardSize, int** boardColSize);
|
||||||
int findCoordinates(char** board, int boardSize, int* boardColSize, const char* word, int* start_row, int* start_col, int* end_row, int* end_col);
|
int findCoordinates(char** board, int boardSize, int* boardColSize, const char* word, int* start_row, int* start_col, int* end_row, int* end_col);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#define SPLITTING_LINKAGE_MARGIN 0.25
|
#define SPLITTING_LINKAGE_MARGIN 0.25
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -341,6 +342,9 @@ SDL_Rect** get_word_list_split(SDL_Surface* surface, SDL_Rect rect, int* word_nb
|
|||||||
|
|
||||||
SDL_Rect** res = (SDL_Rect**)calloc(*word_nb, sizeof(SDL_Rect*));
|
SDL_Rect** res = (SDL_Rect**)calloc(*word_nb, sizeof(SDL_Rect*));
|
||||||
|
|
||||||
|
if (res == NULL)
|
||||||
|
errx(EXIT_FAILURE, "get_word_list_split: unable to calloc");
|
||||||
|
|
||||||
for (int y = 1; y < s_h; y+=2)
|
for (int y = 1; y < s_h; y+=2)
|
||||||
{
|
{
|
||||||
int nb_split;
|
int nb_split;
|
||||||
@ -358,6 +362,9 @@ SDL_Rect** get_word_list_split(SDL_Surface* surface, SDL_Rect rect, int* word_nb
|
|||||||
|
|
||||||
res[(y-1)/2] = (SDL_Rect*)calloc(word_len+1, sizeof(SDL_Rect));
|
res[(y-1)/2] = (SDL_Rect*)calloc(word_len+1, sizeof(SDL_Rect));
|
||||||
|
|
||||||
|
if (res[(y-1)/2] == NULL)
|
||||||
|
errx(EXIT_FAILURE, "get_word_list_split: unable to calloc");
|
||||||
|
|
||||||
for (int x = 1; x < nb_split; x+=2)
|
for (int x = 1; x < nb_split; x+=2)
|
||||||
{
|
{
|
||||||
SDL_Rect split = {
|
SDL_Rect split = {
|
||||||
@ -415,6 +422,9 @@ void export_split_grid(SDL_Surface* surface, SDL_Rect rect, const char* save_dir
|
|||||||
if (file_path == NULL || file_name == NULL)
|
if (file_path == NULL || file_name == NULL)
|
||||||
errx(EXIT_FAILURE, "unable to allocate memory");
|
errx(EXIT_FAILURE, "unable to allocate memory");
|
||||||
|
|
||||||
|
if (file_name == NULL)
|
||||||
|
errx(EXIT_FAILURE, "export_split_grid: unable to calloc");
|
||||||
|
|
||||||
strcpy(file_path, save_dir);
|
strcpy(file_path, save_dir);
|
||||||
|
|
||||||
sprintf(file_name, "letter_%i_%i.png", x, y);
|
sprintf(file_name, "letter_%i_%i.png", x, y);
|
||||||
@ -463,6 +473,11 @@ void export_split_word_list(SDL_Surface* surface, SDL_Rect rect, const char* sav
|
|||||||
char* file_path = (char*)calloc(strlen(save_dir)+40+1, sizeof(char));
|
char* file_path = (char*)calloc(strlen(save_dir)+40+1, sizeof(char));
|
||||||
char* file_name = (char*)calloc(40, sizeof(char));
|
char* file_name = (char*)calloc(40, sizeof(char));
|
||||||
|
|
||||||
|
if (file_path == NULL)
|
||||||
|
errx(EXIT_FAILURE, "export_split_word_list: unable to calloc");
|
||||||
|
if (file_name == NULL)
|
||||||
|
errx(EXIT_FAILURE, "export_split_word_list: unable to calloc");
|
||||||
|
|
||||||
if (file_path == NULL || file_name == NULL)
|
if (file_path == NULL || file_name == NULL)
|
||||||
errx(EXIT_FAILURE, "unable to allocate memory");
|
errx(EXIT_FAILURE, "unable to allocate memory");
|
||||||
|
|
||||||
@ -494,7 +509,7 @@ int get_bin_pixel(SDL_Surface* surface, int x, int y)
|
|||||||
return bright < 127;
|
return bright < 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_cluster_size(SDL_Surface* surface, int* x, int* y, int* w, int* h, int currx, int curry, int visited[surface->w][surface->h])
|
void get_cluster_size(SDL_Surface* surface, SDL_Rect rect, int* x, int* y, int* w, int* h, int currx, int curry, int visited[surface->w][surface->h])
|
||||||
{
|
{
|
||||||
visited[currx][curry] = 1;
|
visited[currx][curry] = 1;
|
||||||
|
|
||||||
@ -506,13 +521,13 @@ void get_cluster_size(SDL_Surface* surface, int* x, int* y, int* w, int* h, int
|
|||||||
int dx = (i%3) - 1;
|
int dx = (i%3) - 1;
|
||||||
int dy = (i/3) - 1;
|
int dy = (i/3) - 1;
|
||||||
|
|
||||||
if (dx < 0 && currx <= 0)
|
if (dx < 0 && currx <= rect.x)
|
||||||
continue;
|
continue;
|
||||||
if (dx > 0 && currx >= surface->w - 1)
|
if (dx > 0 && currx >= rect.x + rect.w - 1)
|
||||||
continue;
|
continue;
|
||||||
if (dy < 0 && curry <= 0)
|
if (dy < 0 && curry <= rect.y)
|
||||||
continue;
|
continue;
|
||||||
if (dy > 0 && curry >= surface->h - 1)
|
if (dy > 0 && curry >= rect. y + rect.h - 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (visited[currx + dx][curry + dy])
|
if (visited[currx + dx][curry + dy])
|
||||||
@ -535,7 +550,7 @@ void get_cluster_size(SDL_Surface* surface, int* x, int* y, int* w, int* h, int
|
|||||||
if (curry + dy >= (*y) + (*h))
|
if (curry + dy >= (*y) + (*h))
|
||||||
(*h)++;
|
(*h)++;
|
||||||
|
|
||||||
get_cluster_size(surface, x, y, w, h, currx + dx, curry + dy, visited);
|
get_cluster_size(surface, rect, x, y, w, h, currx + dx, curry + dy, visited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -596,7 +611,7 @@ SDL_Surface* copy_cluster(SDL_Surface* surface, pixel_cluster cluster_rect)
|
|||||||
return new_surface;
|
return new_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_cluster* get_clusters(SDL_Surface* surface, size_t* cluster_nb)
|
pixel_cluster* get_clusters(SDL_Surface* surface, SDL_Rect search_rect, size_t* cluster_nb)
|
||||||
{
|
{
|
||||||
*cluster_nb = 0;
|
*cluster_nb = 0;
|
||||||
|
|
||||||
@ -610,9 +625,9 @@ pixel_cluster* get_clusters(SDL_Surface* surface, size_t* cluster_nb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < surface->h; y++)
|
for (int y = search_rect.y; y < search_rect.y + search_rect.h; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < surface->w; x++)
|
for (int x = search_rect.x; x < search_rect.x + search_rect.w; x++)
|
||||||
{
|
{
|
||||||
if (visited[x][y])
|
if (visited[x][y])
|
||||||
continue;
|
continue;
|
||||||
@ -625,7 +640,7 @@ pixel_cluster* get_clusters(SDL_Surface* surface, size_t* cluster_nb)
|
|||||||
int w = 1;
|
int w = 1;
|
||||||
int h = 1;
|
int h = 1;
|
||||||
|
|
||||||
get_cluster_size(surface, &nx, &ny, &w, &h, nx, ny, visited);
|
get_cluster_size(surface, search_rect, &nx, &ny, &w, &h, nx, ny, visited);
|
||||||
|
|
||||||
(*cluster_nb)++;
|
(*cluster_nb)++;
|
||||||
}
|
}
|
||||||
@ -641,11 +656,14 @@ pixel_cluster* get_clusters(SDL_Surface* surface, size_t* cluster_nb)
|
|||||||
|
|
||||||
pixel_cluster* result = calloc(*cluster_nb, sizeof(pixel_cluster));
|
pixel_cluster* result = calloc(*cluster_nb, sizeof(pixel_cluster));
|
||||||
|
|
||||||
|
if (result == NULL)
|
||||||
|
errx(EXIT_FAILURE, "get_clusters: unable to calloc");
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
for (int y = 0; y < surface->h; y++)
|
for (int y = search_rect.y; y < search_rect.y + search_rect.h; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < surface->w; x++)
|
for (int x = search_rect.x; x < search_rect.x + search_rect.w; x++)
|
||||||
{
|
{
|
||||||
if (visited[x][y])
|
if (visited[x][y])
|
||||||
continue;
|
continue;
|
||||||
@ -658,7 +676,7 @@ pixel_cluster* get_clusters(SDL_Surface* surface, size_t* cluster_nb)
|
|||||||
int w = 1;
|
int w = 1;
|
||||||
int h = 1;
|
int h = 1;
|
||||||
|
|
||||||
get_cluster_size(surface, &nx, &ny, &w, &h, nx, ny, visited);
|
get_cluster_size(surface, search_rect, &nx, &ny, &w, &h, nx, ny, visited);
|
||||||
|
|
||||||
result[i] = (pixel_cluster){
|
result[i] = (pixel_cluster){
|
||||||
nx,
|
nx,
|
||||||
@ -666,7 +684,9 @@ pixel_cluster* get_clusters(SDL_Surface* surface, size_t* cluster_nb)
|
|||||||
w,
|
w,
|
||||||
h,
|
h,
|
||||||
x,
|
x,
|
||||||
y
|
y,
|
||||||
|
-1,
|
||||||
|
-1
|
||||||
};
|
};
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
@ -711,6 +731,9 @@ pixel_cluster* filter_primary_clusters(pixel_cluster* clusters, size_t nb_cluste
|
|||||||
|
|
||||||
pixel_cluster* filtered = calloc(*filtered_nb, sizeof(pixel_cluster));
|
pixel_cluster* filtered = calloc(*filtered_nb, sizeof(pixel_cluster));
|
||||||
|
|
||||||
|
if (filtered == NULL)
|
||||||
|
errx(EXIT_FAILURE, "filter_primary_clusters: unable to calloc");
|
||||||
|
|
||||||
size_t filtered_count = 0;
|
size_t filtered_count = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < nb_clusters; i++)
|
for (size_t i = 0; i < nb_clusters; i++)
|
||||||
@ -853,6 +876,9 @@ pixel_cluster* get_cluster_linkage(pixel_cluster* clusters, size_t start, size_t
|
|||||||
|
|
||||||
pixel_cluster* linkage = calloc(*linkage_nb, sizeof(pixel_cluster));
|
pixel_cluster* linkage = calloc(*linkage_nb, sizeof(pixel_cluster));
|
||||||
|
|
||||||
|
if (linkage == NULL)
|
||||||
|
errx(EXIT_FAILURE, "get_cluster_linkage: unable to calloc");
|
||||||
|
|
||||||
linkage[0] = clusters[start];
|
linkage[0] = clusters[start];
|
||||||
|
|
||||||
size_t linkage_count = 1;
|
size_t linkage_count = 1;
|
||||||
@ -892,6 +918,9 @@ pixel_cluster** get_clusters_linkages(pixel_cluster* clusters, size_t cluster_nb
|
|||||||
pixel_cluster** linkages = calloc(*nb_linkages, sizeof(pixel_cluster*));
|
pixel_cluster** linkages = calloc(*nb_linkages, sizeof(pixel_cluster*));
|
||||||
*linkage_len = calloc(*nb_linkages, sizeof(size_t));
|
*linkage_len = calloc(*nb_linkages, sizeof(size_t));
|
||||||
|
|
||||||
|
if (*linkage_len == NULL)
|
||||||
|
errx(EXIT_FAILURE, "get_clusters_linkages: unable to calloc");
|
||||||
|
|
||||||
size_t current_pos = 0;
|
size_t current_pos = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < cluster_nb; i++)
|
for (size_t i = 0; i < cluster_nb; i++)
|
||||||
@ -945,7 +974,6 @@ int same_pos(int pos1, int pos2, int margin)
|
|||||||
|
|
||||||
void export_grid_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t cluster_nb, char* grid_dir, int* sx, int* sy)
|
void export_grid_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t cluster_nb, char* grid_dir, int* sx, int* sy)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (size_t i = 0; i < cluster_nb; i++)
|
for (size_t i = 0; i < cluster_nb; i++)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -981,6 +1009,9 @@ void export_grid_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t c
|
|||||||
char* path;
|
char* path;
|
||||||
asprintf(&path, "%s/grid_%i_%i.png", grid_dir, x - 1, y - 1);
|
asprintf(&path, "%s/grid_%i_%i.png", grid_dir, x - 1, y - 1);
|
||||||
|
|
||||||
|
clusters[i].grid_x = x-1;
|
||||||
|
clusters[i].grid_y = y-1;
|
||||||
|
|
||||||
SDL_Surface* letter_surf = copy_cluster(surface, clusters[i]);
|
SDL_Surface* letter_surf = copy_cluster(surface, clusters[i]);
|
||||||
|
|
||||||
IMG_SavePNG(letter_surf, path);
|
IMG_SavePNG(letter_surf, path);
|
||||||
@ -989,11 +1020,74 @@ void export_grid_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel_cluster** get_main_linkages(SDL_Surface* surface, size_t* nb_linkages, size_t** linkages_len)
|
void export_main_grid_cluster(SDL_Surface* surface, pixel_cluster* grid_clusters, size_t grid_len, char* res_dir, int* sx, int* sy)
|
||||||
|
{
|
||||||
|
struct stat st = {0};
|
||||||
|
|
||||||
|
if (stat(res_dir, &st) == -1)
|
||||||
|
if (mkdir(res_dir, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create splitting directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
char* grid_path;
|
||||||
|
asprintf(&grid_path, "%s/grid", res_dir);
|
||||||
|
|
||||||
|
st = (struct stat){0};
|
||||||
|
|
||||||
|
if (stat(grid_path, &st) == -1)
|
||||||
|
if (mkdir(grid_path, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create grid directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
export_grid_cluster(surface, grid_clusters, grid_len, grid_path, sx, sy);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* export_prepare_words_dir(char* res_dir)
|
||||||
|
{
|
||||||
|
struct stat st = {0};
|
||||||
|
|
||||||
|
if (stat(res_dir, &st) == -1)
|
||||||
|
if (mkdir(res_dir, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create splitting directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
char* words_path;
|
||||||
|
asprintf(&words_path, "%s/words", res_dir);
|
||||||
|
|
||||||
|
st = (struct stat){0};
|
||||||
|
|
||||||
|
if (stat(words_path, &st) == -1)
|
||||||
|
if (mkdir(words_path, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create words directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
return words_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void export_main_words_cluster(SDL_Surface* surface, pixel_cluster** linkages, size_t nb_linkages, size_t* linkages_len, char* res_dir)
|
||||||
|
{
|
||||||
|
struct stat st = {0};
|
||||||
|
|
||||||
|
if (stat(res_dir, &st) == -1)
|
||||||
|
if (mkdir(res_dir, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create splitting directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
char* words_path;
|
||||||
|
asprintf(&words_path, "%s/words", res_dir);
|
||||||
|
|
||||||
|
st = (struct stat){0};
|
||||||
|
|
||||||
|
if (stat(words_path, &st) == -1)
|
||||||
|
if (mkdir(words_path, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create words directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < nb_linkages; i++)
|
||||||
|
{
|
||||||
|
export_word_cluster(surface, linkages[i], linkages_len[i], i, words_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel_cluster** get_main_linkages(SDL_Surface* surface, SDL_Rect search_rect, size_t* nb_linkages, size_t** linkages_len)
|
||||||
{
|
{
|
||||||
size_t nb_clusters;
|
size_t nb_clusters;
|
||||||
|
|
||||||
pixel_cluster* clusters = get_clusters(surface, &nb_clusters);
|
pixel_cluster* clusters = get_clusters(surface, search_rect, &nb_clusters);
|
||||||
|
|
||||||
size_t nb_filtered;
|
size_t nb_filtered;
|
||||||
|
|
||||||
@ -1008,19 +1102,39 @@ void export_main_linkages(SDL_Surface* surface, pixel_cluster** linkages, size_t
|
|||||||
{
|
{
|
||||||
size_t grid = get_grid_cluster(nb_linkages, linkages_len);
|
size_t grid = get_grid_cluster(nb_linkages, linkages_len);
|
||||||
|
|
||||||
|
struct stat st = {0};
|
||||||
|
|
||||||
|
if (stat(res_dir, &st) == -1)
|
||||||
|
if (mkdir(res_dir, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create splitting directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
char* grid_path;
|
||||||
|
asprintf(&grid_path, "%s/grid", res_dir);
|
||||||
|
|
||||||
|
st = (struct stat){0};
|
||||||
|
|
||||||
|
if (stat(grid_path, &st) == -1)
|
||||||
|
if (mkdir(grid_path, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create grid directory, %s", strerror(errno));
|
||||||
|
|
||||||
|
char* words_path;
|
||||||
|
asprintf(&words_path, "%s/words", res_dir);
|
||||||
|
|
||||||
|
st = (struct stat){0};
|
||||||
|
|
||||||
|
if (stat(words_path, &st) == -1)
|
||||||
|
if (mkdir(words_path, 0755) != 0)
|
||||||
|
errx(EXIT_FAILURE, "export_main_linkages: could not create words directory, %s", strerror(errno));
|
||||||
|
|
||||||
for (size_t i = 0; i < nb_linkages; i++)
|
for (size_t i = 0; i < nb_linkages; i++)
|
||||||
{
|
{
|
||||||
if (i == grid)
|
if (i == grid)
|
||||||
{
|
{
|
||||||
char* path;
|
export_grid_cluster(surface, linkages[i], linkages_len[i], grid_path, sx, sy);
|
||||||
asprintf(&path, "%s/grid", res_dir);
|
|
||||||
export_grid_cluster(surface, linkages[i], linkages_len[i], path, sx, sy);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* path;
|
export_word_cluster(surface, linkages[i], linkages_len[i], i - (i > grid ? 1 : 0), words_path);
|
||||||
asprintf(&path, "%s/words", res_dir);
|
|
||||||
export_word_cluster(surface, linkages[i], linkages_len[i], i - (i > grid ? 1 : 0), path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ typedef struct{
|
|||||||
int h;
|
int h;
|
||||||
int start_x;
|
int start_x;
|
||||||
int start_y;
|
int start_y;
|
||||||
|
int grid_x;
|
||||||
|
int grid_y;
|
||||||
}pixel_cluster;
|
}pixel_cluster;
|
||||||
|
|
||||||
void spilt_grid_vertical(SDL_Surface* surface, SDL_Rect rect);
|
void spilt_grid_vertical(SDL_Surface* surface, SDL_Rect rect);
|
||||||
@ -22,15 +24,21 @@ SDL_Rect** get_grid_split(SDL_Surface* surface, SDL_Rect rect, int* first_dim, i
|
|||||||
|
|
||||||
SDL_Rect** get_word_list_split(SDL_Surface* surface, SDL_Rect rect, int* word_nb);
|
SDL_Rect** get_word_list_split(SDL_Surface* surface, SDL_Rect rect, int* word_nb);
|
||||||
|
|
||||||
|
void get_cluster_center(pixel_cluster cluster, int* x, int* y);
|
||||||
|
|
||||||
void export_split_word_list(SDL_Surface* surface, SDL_Rect rect, const char* save_dir);
|
void export_split_word_list(SDL_Surface* surface, SDL_Rect rect, const char* save_dir);
|
||||||
|
|
||||||
void export_split_grid(SDL_Surface* surface, SDL_Rect rect, const char* save_dir);
|
void export_split_grid(SDL_Surface* surface, SDL_Rect rect, const char* save_dir);
|
||||||
|
|
||||||
|
char* export_prepare_words_dir(char* res_dir);
|
||||||
|
|
||||||
void export_word_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t cluster_nb, size_t word_nb, char* word_dir);
|
void export_word_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t cluster_nb, size_t word_nb, char* word_dir);
|
||||||
|
|
||||||
void export_grid_cluster(SDL_Surface* surface, pixel_cluster* clusters, size_t cluster_nb, char* grid_dir, int* sx, int* sy);
|
void export_main_grid_cluster(SDL_Surface* surface, pixel_cluster* grid_clusters, size_t grid_len, char* res_dir, int* sx, int* sy);
|
||||||
|
|
||||||
pixel_cluster** get_main_linkages(SDL_Surface* surface, size_t* nb_linkages, size_t** linkages_len);
|
void export_main_words_cluster(SDL_Surface* surface, pixel_cluster** linkages, size_t nb_linkages, size_t* linkages_len, char* res_dir);
|
||||||
|
|
||||||
|
pixel_cluster** get_main_linkages(SDL_Surface* surface, SDL_Rect search_rect, size_t* nb_linkages, size_t** linkages_len);
|
||||||
|
|
||||||
void export_main_linkages(SDL_Surface* surface, pixel_cluster** linkages, size_t nb_linkages, size_t* linkages_len, char* res_dir, int* sx, int* sy);
|
void export_main_linkages(SDL_Surface* surface, pixel_cluster** linkages, size_t nb_linkages, size_t* linkages_len, char* res_dir, int* sx, int* sy);
|
||||||
|
|
||||||
|