OCRudoku  v1.0
Resolve word grid with ease
Loading...
Searching...
No Matches
Spliting.c File Reference
#include <err.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "Spliting.h"
#include "../Image/ImageUtils.h"
#include "../Application/ApplicationUtils.h"
Include dependency graph for Spliting.c:

Macros

#define _GNU_SOURCE
 

Functions

int get_grid_vertical_nb (SDL_Surface *surface, SDL_Rect rect)
 Calculates the number of vertical grid splits in a given SDL surface.
 
int * get_grid_vertical_split (SDL_Surface *surface, SDL_Rect rect, int *nb_splits)
 Calculates the vertical split positions in a given SDL surface.
 
int get_grid_horizontal_nb (SDL_Surface *surface, SDL_Rect rect)
 Calculates the number of horizontal grid splits in a given SDL surface.
 
int * get_grid_horizontal_split (SDL_Surface *surface, SDL_Rect rect, int *nb_splits)
 Calculates the horizontal split positions in a given SDL surface.
 
SDL_Rect ** get_grid_split (SDL_Surface *surface, SDL_Rect rect, int *first_dim, int *second_dim)
 Splits a given SDL surface into a grid of rectangles.
 
SDL_Rect ** get_word_list_split (SDL_Surface *surface, SDL_Rect rect, int *word_nb)
 Splits a given SDL surface into a list of words.
 
void export_split_grid (SDL_Surface *surface, SDL_Rect rect, const char *save_dir)
 Exports the split grid of a given SDL surface to a specified directory.
 
void export_split_word_list (SDL_Surface *surface, SDL_Rect rect, const char *save_dir)
 Exports the split word list of a given SDL surface to a specified directory.
 
int get_bin_pixel (SDL_Surface *surface, int x, int y)
 
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 copy_cluster_aux (SDL_Surface *surface, SDL_Surface *new_surface, int x, int y, int sx, int sy, int visited[])
 
SDL_Surface * copy_cluster (SDL_Surface *surface, pixel_cluster cluster_rect)
 
pixel_clusterget_clusters (SDL_Surface *surface, size_t *cluster_nb)
 
pixel_clusterfilter_primary_clusters (pixel_cluster *clusters, size_t nb_clusters, size_t *filtered_nb)
 
void get_cluster_center (pixel_cluster cluster, int *x, int *y)
 
double distance_between (int x1, int y1, int x2, int y2)
 
void get_cluster_linkage_count_aux (pixel_cluster *clusters, size_t start, size_t cluster_nb, size_t *linkage_nb, double distance, double margin, int visited[cluster_nb])
 
void get_cluster_linkage_aux (pixel_cluster *clusters, size_t start, size_t cluster_nb, size_t *current_linkage, pixel_cluster *arr, double distance, double margin, int visited[cluster_nb])
 
pixel_clusterget_cluster_linkage (pixel_cluster *clusters, size_t start, size_t cluster_nb, size_t *linkage_nb, int visited[cluster_nb])
 
pixel_cluster ** get_clusters_linkages (pixel_cluster *clusters, size_t cluster_nb, size_t *nb_linkages, size_t **linkage_len)
 
size_t get_grid_cluster (size_t nb_linkages, size_t *linkage_len)
 
void export_word_cluster (SDL_Surface *surface, pixel_cluster *clusters, size_t cluster_nb, size_t word_nb, char *word_dir)
 
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)
 
pixel_cluster ** get_main_linkages (SDL_Surface *surface, 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)
 
SDL_Rect get_grid_rect (pixel_cluster *linkages, size_t nb_linkages)
 

Variables

int split_margin = 0
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Function Documentation

◆ copy_cluster()

SDL_Surface * copy_cluster ( SDL_Surface * surface,
pixel_cluster cluster_rect )

◆ copy_cluster_aux()

void copy_cluster_aux ( SDL_Surface * surface,
SDL_Surface * new_surface,
int x,
int y,
int sx,
int sy,
int visited[] )

◆ distance_between()

double distance_between ( int x1,
int y1,
int x2,
int y2 )

◆ export_grid_cluster()

void export_grid_cluster ( SDL_Surface * surface,
pixel_cluster * clusters,
size_t cluster_nb,
char * grid_dir,
int * sx,
int * sy )

◆ export_main_linkages()

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 )

◆ export_split_grid()

void export_split_grid ( SDL_Surface * surface,
SDL_Rect rect,
const char * save_dir )

Exports the split grid of a given SDL surface to a specified directory.

This function splits the specified rectangular area of the SDL surface into a grid based on the brightness threshold defined by split_margin. It then exports each split area as a PNG image to the specified directory.

Parameters
surfaceThe SDL_Surface to analyze and split.
rectThe SDL_Rect defining the area of the surface to analyze and split.
save_dirThe directory where the split images will be saved.

◆ export_split_word_list()

void export_split_word_list ( SDL_Surface * surface,
SDL_Rect rect,
const char * save_dir )

Exports the split word list of a given SDL surface to a specified directory.

This function splits the specified rectangular area of the SDL surface into a list of words based on the brightness threshold defined by split_margin. It then exports each split word as a PNG image to the specified directory.

Parameters
surfaceThe SDL_Surface to analyze and split.
rectThe SDL_Rect defining the area of the surface to analyze and split.
save_dirThe directory where the split images will be saved.

◆ export_word_cluster()

void export_word_cluster ( SDL_Surface * surface,
pixel_cluster * clusters,
size_t cluster_nb,
size_t word_nb,
char * word_dir )

◆ filter_primary_clusters()

pixel_cluster * filter_primary_clusters ( pixel_cluster * clusters,
size_t nb_clusters,
size_t * filtered_nb )

◆ get_bin_pixel()

int get_bin_pixel ( SDL_Surface * surface,
int x,
int y )

◆ get_cluster_center()

void get_cluster_center ( pixel_cluster cluster,
int * x,
int * y )

◆ get_cluster_linkage()

pixel_cluster * get_cluster_linkage ( pixel_cluster * clusters,
size_t start,
size_t cluster_nb,
size_t * linkage_nb,
int visited[cluster_nb] )

◆ get_cluster_linkage_aux()

void get_cluster_linkage_aux ( pixel_cluster * clusters,
size_t start,
size_t cluster_nb,
size_t * current_linkage,
pixel_cluster * arr,
double distance,
double margin,
int visited[cluster_nb] )

◆ get_cluster_linkage_count_aux()

void get_cluster_linkage_count_aux ( pixel_cluster * clusters,
size_t start,
size_t cluster_nb,
size_t * linkage_nb,
double distance,
double margin,
int visited[cluster_nb] )

◆ get_cluster_size()

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] )

◆ get_clusters()

pixel_cluster * get_clusters ( SDL_Surface * surface,
size_t * cluster_nb )

◆ get_clusters_linkages()

pixel_cluster ** get_clusters_linkages ( pixel_cluster * clusters,
size_t cluster_nb,
size_t * nb_linkages,
size_t ** linkage_len )

◆ get_grid_cluster()

size_t get_grid_cluster ( size_t nb_linkages,
size_t * linkage_len )

◆ get_grid_horizontal_nb()

int get_grid_horizontal_nb ( SDL_Surface * surface,
SDL_Rect rect )

Calculates the number of horizontal grid splits in a given SDL surface.

This function analyzes the brightness of pixels in the specified rectangular area of the SDL surface and determines the number of horizontal splits based on the brightness threshold defined by split_margin.

Parameters
surfaceThe SDL_Surface to analyze.
rectThe SDL_Rect defining the area of the surface to analyze.
Returns
The number of horizontal grid splits found in the specified area.

◆ get_grid_horizontal_split()

int * get_grid_horizontal_split ( SDL_Surface * surface,
SDL_Rect rect,
int * nb_splits )

Calculates the horizontal split positions in a given SDL surface.

This function analyzes the brightness of pixels in the specified rectangular area of the SDL surface and determines the positions of horizontal splits based on the brightness threshold defined by split_margin.

Parameters
surfaceThe SDL_Surface to analyze.
rectThe SDL_Rect defining the area of the surface to analyze.
nb_splitsPointer to an integer where the number of splits will be stored.
Returns
An array of integers representing the horizontal split positions.

◆ get_grid_rect()

SDL_Rect get_grid_rect ( pixel_cluster * linkages,
size_t nb_linkages )

◆ get_grid_split()

SDL_Rect ** get_grid_split ( SDL_Surface * surface,
SDL_Rect rect,
int * first_dim,
int * second_dim )

Splits a given SDL surface into a grid of rectangles.

This function analyzes the brightness of pixels in the specified rectangular area of the SDL surface and determines the positions of vertical and horizontal splits based on the brightness threshold defined by split_margin. It then creates a grid of SDL_Rect structures representing the split areas.

Parameters
surfaceThe SDL_Surface to analyze.
rectThe SDL_Rect defining the area of the surface to analyze.
first_dimPointer to an integer where the number of horizontal splits will be stored.
second_dimPointer to an integer where the number of vertical splits will be stored.
Returns
A 2D array of SDL_Rect structures representing the split grid.

◆ get_grid_vertical_nb()

int get_grid_vertical_nb ( SDL_Surface * surface,
SDL_Rect rect )

Calculates the number of vertical grid splits in a given SDL surface.

This function analyzes the brightness of pixels in the specified rectangular area of the SDL surface and determines the number of vertical splits based on the brightness threshold defined by split_margin.

Parameters
surfaceThe SDL_Surface to analyze.
rectThe SDL_Rect defining the area of the surface to analyze.
Returns
The number of vertical grid splits found in the specified area.

◆ get_grid_vertical_split()

int * get_grid_vertical_split ( SDL_Surface * surface,
SDL_Rect rect,
int * nb_splits )

Calculates the vertical split positions in a given SDL surface.

This function analyzes the brightness of pixels in the specified rectangular area of the SDL surface and determines the positions of vertical splits based on the brightness threshold defined by split_margin.

Parameters
surfaceThe SDL_Surface to analyze.
rectThe SDL_Rect defining the area of the surface to analyze.
nb_splitsPointer to an integer where the number of splits will be stored.
Returns
An array of integers representing the vertical split positions.

◆ get_main_linkages()

pixel_cluster ** get_main_linkages ( SDL_Surface * surface,
size_t * nb_linkages,
size_t ** linkages_len )

◆ get_word_list_split()

SDL_Rect ** get_word_list_split ( SDL_Surface * surface,
SDL_Rect rect,
int * word_nb )

Splits a given SDL surface into a list of words.

This function analyzes the brightness of pixels in the specified rectangular area of the SDL surface and determines the positions of vertical splits based on the brightness threshold defined by split_margin. It then creates a list of SDL_Rect structures representing the split words.

Parameters
surfaceThe SDL_Surface to analyze.
rectThe SDL_Rect defining the area of the surface to analyze.
word_nbPointer to an integer where the number of words will be stored.
Returns
A 2D array of SDL_Rect structures representing the split words.

◆ same_pos()

int same_pos ( int pos1,
int pos2,
int margin )

Variable Documentation

◆ split_margin

int split_margin = 0