MCPcopy Create free account
hub / github.com/creatale/node-dv / selCreateFromSArray

Function selCreateFromSArray

deps/leptonica/src/sel1.c:1879–1939  ·  view source on GitHub ↗

! * \brief selCreateFromSArray() * * \param[in] sa * \param[in] first line of sarray where Sel begins * \param[in] last line of sarray where Sel ends * \return sela, or NULL on error * * * Notes: * (1) The Sel contains the following lines: * ~ The first line is the selname * ~ The remaining lines contain the Sel data. They must * be

Source from the content-addressed store, hash-verified

1877 * </pre>
1878 */
1879static SEL *
1880selCreateFromSArray(SARRAY *sa,
1881 l_int32 first,
1882 l_int32 last)
1883{
1884char ch;
1885char *name, *line;
1886l_int32 n, len, i, w, h, y, x;
1887SEL *sel;
1888
1889 PROCNAME("selCreateFromSArray");
1890
1891 if (!sa)
1892 return (SEL *)ERROR_PTR("sa not defined", procName, NULL);
1893 n = sarrayGetCount(sa);
1894 if (first < 0 || first >= n || last <= first || last >= n)
1895 return (SEL *)ERROR_PTR("invalid range", procName, NULL);
1896
1897 name = sarrayGetString(sa, first, L_NOCOPY);
1898 h = last - first;
1899 line = sarrayGetString(sa, first + 1, L_NOCOPY);
1900 len = strlen(line);
1901 if (line[0] != '"' || line[len - 1] != '"')
1902 return (SEL *)ERROR_PTR("invalid format", procName, NULL);
1903 w = len - 2;
1904 if ((sel = selCreate(h, w, name)) == NULL)
1905 return (SEL *)ERROR_PTR("sel not made", procName, NULL);
1906 for (i = first + 1; i <= last; i++) {
1907 line = sarrayGetString(sa, i, L_NOCOPY);
1908 y = i - first - 1;
1909 for (x = 0; x < w; ++x) {
1910 ch = line[x + 1]; /* skip the leading double-quote */
1911 switch (ch)
1912 {
1913 case 'X':
1914 selSetOrigin(sel, y, x); /* set origin and hit */
1915 case 'x':
1916 selSetElement(sel, y, x, SEL_HIT);
1917 break;
1918
1919 case 'O':
1920 selSetOrigin(sel, y, x); /* set origin and miss */
1921 case 'o':
1922 selSetElement(sel, y, x, SEL_MISS);
1923 break;
1924
1925 case 'C':
1926 selSetOrigin(sel, y, x); /* set origin and don't-care */
1927 case ' ':
1928 selSetElement(sel, y, x, SEL_DONT_CARE);
1929 break;
1930
1931 default:
1932 selDestroy(&sel);
1933 return (SEL *)ERROR_PTR("unknown char", procName, NULL);
1934 }
1935 }
1936 }

Callers 1

selaCreateFromFileFunction · 0.85

Calls 6

sarrayGetCountFunction · 0.85
sarrayGetStringFunction · 0.85
selCreateFunction · 0.85
selSetOriginFunction · 0.85
selSetElementFunction · 0.85
selDestroyFunction · 0.85

Tested by

no test coverage detected