255 const char *filename)
258char *str_proto1, *str_proto2, *str_proto3;
259char *str_doc1, *str_doc2, *str_doc3, *str_doc4;
260char *str_def1, *str_def2, *str_proc1, *str_proc2;
261char *str_dwa1, *str_low_dt, *str_low_ds;
263l_int32 i, nsels, nbytes, actstart, end, newstart;
268 return ERROR_INT(
"sela not defined", __func__, 1);
271 if ((nsels = selaGetCount(sela)) == 0)
272 return ERROR_INT(
"no sels in sela", __func__, 1);
275 if ((filestr = (
char *)l_binaryRead(TEMPLATE1, &size)) == NULL)
276 return ERROR_INT(
"filestr not made", __func__, 1);
277 sa2 = sarrayCreateLinesFromString(filestr, 1);
280 return ERROR_INT(
"sa2 not made", __func__, 1);
283 sa1 = selaGetSelnames(sela);
286 sprintf(bigbuf,
"PIX *pixHMTDwa_%d(PIX *pixd, PIX *pixs, "
287 "const char *selname);", fileindex);
288 str_proto1 = stringNew(bigbuf);
289 sprintf(bigbuf,
"PIX *pixFHMTGen_%d(PIX *pixd, PIX *pixs, "
290 "const char *selname);", fileindex);
291 str_proto2 = stringNew(bigbuf);
292 sprintf(bigbuf,
"l_int32 fhmtgen_low_%d(l_uint32 *datad, l_int32 w,\n"
293 " l_int32 h, l_int32 wpld,\n"
294 " l_uint32 *datas, l_int32 wpls,\n"
295 " l_int32 index);", fileindex);
296 str_proto3 = stringNew(bigbuf);
297 sprintf(bigbuf,
" * PIX *pixHMTDwa_%d()", fileindex);
298 str_doc1 = stringNew(bigbuf);
299 sprintf(bigbuf,
" * PIX *pixFHMTGen_%d()", fileindex);
300 str_doc2 = stringNew(bigbuf);
301 sprintf(bigbuf,
" * \\brief pixHMTDwa_%d()", fileindex);
302 str_doc3 = stringNew(bigbuf);
303 sprintf(bigbuf,
" * \\brief pixFHMTGen_%d()", fileindex);
304 str_doc4 = stringNew(bigbuf);
305 sprintf(bigbuf,
"pixHMTDwa_%d(PIX *pixd,", fileindex);
306 str_def1 = stringNew(bigbuf);
307 sprintf(bigbuf,
"pixFHMTGen_%d(PIX *pixd,", fileindex);
308 str_def2 = stringNew(bigbuf);
309 sprintf(bigbuf,
" PROCNAME(\"pixHMTDwa_%d\");", fileindex);
310 str_proc1 = stringNew(bigbuf);
311 sprintf(bigbuf,
" PROCNAME(\"pixFHMTGen_%d\");", fileindex);
312 str_proc2 = stringNew(bigbuf);
313 sprintf(bigbuf,
" pixt2 = pixFHMTGen_%d(NULL, pixt1, selname);",
315 str_dwa1 = stringNew(bigbuf);
317 " fhmtgen_low_%d(datad, w, h, wpld, datat, wpls, index);",
319 str_low_dt = stringNew(bigbuf);
321 " fhmtgen_low_%d(datad, w, h, wpld, datas, wpls, index);",
323 str_low_ds = stringNew(bigbuf);
326 sa3 = sarrayCreate(0);
329 sarrayParseRange(sa2, 0, &actstart, &end, &newstart,
"--", 0);
330 sarrayAppendRange(sa3, sa2, actstart, end);
333 sarrayAddString(sa3, str_doc1,
L_INSERT);
334 sarrayAddString(sa3, str_doc2,
L_INSERT);
337 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
338 sarrayAppendRange(sa3, sa2, actstart, end);
341 sarrayAddString(sa3, str_proto1,
L_INSERT);
342 sarrayAddString(sa3, str_proto2,
L_INSERT);
343 sarrayAddString(sa3, str_proto3,
L_INSERT);
346 sprintf(bigbuf,
"\nstatic l_int32 NUM_SELS_GENERATED = %d;", nsels);
347 sarrayAddString(sa3, bigbuf,
L_COPY);
348 sprintf(bigbuf,
"static char SEL_NAMES[][80] = {");
349 sarrayAddString(sa3, bigbuf,
L_COPY);
350 for (i = 0; i < nsels - 1; i++) {
351 sprintf(bigbuf,
" \"%s\",",
353 sarrayAddString(sa3, bigbuf,
L_COPY);
355 sprintf(bigbuf,
" \"%s\"};",
357 sarrayAddString(sa3, bigbuf,
L_COPY);
360 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
361 sarrayAppendRange(sa3, sa2, actstart, end);
362 sarrayAddString(sa3, str_doc3,
L_INSERT);
363 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
364 sarrayAppendRange(sa3, sa2, actstart, end);
367 sarrayAddString(sa3, str_def1,
L_INSERT);
368 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
369 sarrayAppendRange(sa3, sa2, actstart, end);
370 sarrayAddString(sa3, str_proc1,
L_INSERT);
371 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
372 sarrayAppendRange(sa3, sa2, actstart, end);
373 sarrayAddString(sa3, str_dwa1,
L_INSERT);
374 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
375 sarrayAppendRange(sa3, sa2, actstart, end);
378 sarrayAddString(sa3, str_doc4,
L_INSERT);
379 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
380 sarrayAppendRange(sa3, sa2, actstart, end);
383 sarrayAddString(sa3, str_def2,
L_INSERT);
384 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
385 sarrayAppendRange(sa3, sa2, actstart, end);
386 sarrayAddString(sa3, str_proc2,
L_INSERT);
387 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
388 sarrayAppendRange(sa3, sa2, actstart, end);
389 sarrayAddString(sa3, str_low_dt,
L_INSERT);
390 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
391 sarrayAppendRange(sa3, sa2, actstart, end);
392 sarrayAddString(sa3, str_low_ds,
L_INSERT);
393 sarrayParseRange(sa2, newstart, &actstart, &end, &newstart,
"--", 0);
394 sarrayAppendRange(sa3, sa2, actstart, end);
396 filestr = sarrayToString(sa3, 1);
397 nbytes = strlen(filestr);
399 snprintf(bigbuf,
L_BUF_SIZE,
"%s.%d.c", filename, fileindex);
401 sprintf(bigbuf,
"%s.%d.c", OUTROOT, fileindex);
402 l_binaryWrite(bigbuf,
"w", filestr, nbytes);
435 const char *filename)
437char *filestr, *fname, *linestr;
438char *str_doc1, *str_doc2, *str_doc3, *str_def1;
440char breakstring[] =
" break;";
441char staticstring[] =
"static void";
442l_int32 i, k, l, nsels, nbytes, nhits, nmisses;
443l_int32 actstart, end, newstart;
444l_int32 argstart, argend, loopstart, loopend, finalstart, finalend;
446SARRAY *sa1, *sa2, *sa3, *sa4, *sa5, *sa6;
450 return ERROR_INT(
"sela not defined", __func__, 1);
453 if ((nsels = selaGetCount(sela)) == 0)
454 return ERROR_INT(
"no sels in sela", __func__, 1);
457 if ((filestr = (
char *)l_binaryRead(TEMPLATE2, &size)) == NULL)
458 return ERROR_INT(
"filestr not made", __func__, 1);
459 sa1 = sarrayCreateLinesFromString(filestr, 1);
462 return ERROR_INT(
"sa1 not made", __func__, 1);
465 if ((sa2 = sarrayCreate(nsels)) == NULL) {
467 return ERROR_INT(
"sa2 not made", __func__, 1);
469 for (i = 0; i < nsels; i++) {
470 sprintf(bigbuf,
"fhmt_%d_%d", fileindex, i);
471 sarrayAddString(sa2, bigbuf,
L_COPY);
475 sa3 = sarrayCreate(2 * nsels);
476 for (i = 0; i < nsels; i++) {
477 fname = sarrayGetString(sa2, i,
L_NOCOPY);
478 sprintf(bigbuf,
"static void %s%s", fname, PROTOARGS);
479 sarrayAddString(sa3, bigbuf,
L_COPY);
483 sprintf(bigbuf,
" * l_int32 fhmtgen_low_%d()",
485 str_doc1 = stringNew(bigbuf);
486 sprintf(bigbuf,
" * void fhmt_%d_*()", fileindex);
487 str_doc2 = stringNew(bigbuf);
490 sa4 = sarrayCreate(0);
493 sarrayParseRange(sa1, 0, &actstart, &end, &newstart,
"--", 0);
494 sarrayAppendRange(sa4, sa1, actstart, end);
497 sarrayAddString(sa4, str_doc1,
L_INSERT);
498 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart,
"--", 0);
499 sarrayAppendRange(sa4, sa1, actstart, end);
500 sarrayAddString(sa4, str_doc2,
L_INSERT);
501 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart,
"--", 0);
502 sarrayAppendRange(sa4, sa1, actstart, end);
505 for (i = 0; i < nsels; i++) {
506 if ((linestr = sarrayGetString(sa3, i,
L_COPY)) == NULL) {
511 return ERROR_INT(
"linestr not retrieved", __func__, 1);
513 sarrayAddString(sa4, linestr,
L_INSERT);
517 sprintf(bigbuf,
" * fhmtgen_low_%d()", fileindex);
518 str_doc3 = stringNew(bigbuf);
519 sprintf(bigbuf,
"fhmtgen_low_%d(l_uint32 *datad,", fileindex);
520 str_def1 = stringNew(bigbuf);
523 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart,
"--", 0);
524 sarrayAppendRange(sa4, sa1, actstart, end);
525 sarrayAddString(sa4, str_doc3,
L_INSERT);
526 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart,
"--", 0);
527 sarrayAppendRange(sa4, sa1, actstart, end);
528 sarrayAddString(sa4, str_def1,
L_INSERT);
529 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart,
"--", 0);
530 sarrayAppendRange(sa4, sa1, actstart, end);
533 for (i = 0; i < nsels; i++) {
534 sprintf(bigbuf,
" case %d:", i);
535 sarrayAddString(sa4, bigbuf,
L_COPY);
536 sprintf(bigbuf,
" %s(datad, w, h, wpld, datas, wpls);",
538 sarrayAddString(sa4, bigbuf,
L_COPY);
539 sarrayAddString(sa4, breakstring,
L_COPY);
543 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart,
"--", 0);
544 sarrayAppendRange(sa4, sa1, actstart, end);
547 sarrayParseRange(sa1, newstart, &argstart, &argend, &newstart,
"--", 0);
550 sarrayParseRange(sa1, newstart, &loopstart, &loopend, &newstart,
"--", 0);
553 sarrayParseRange(sa1, newstart, &finalstart, &finalend, &newstart,
"--", 0);
556 for (i = 0; i < nsels; i++) {
558 sarrayAddString(sa4, staticstring,
L_COPY);
559 fname = sarrayGetString(sa2, i,
L_NOCOPY);
560 sprintf(bigbuf,
"%s(l_uint32 *datad,", fname);
561 sarrayAddString(sa4, bigbuf,
L_COPY);
562 sarrayAppendRange(sa4, sa1, argstart, argend);
565 if ((sel = selaGetSel(sela, i)) == NULL) {
570 return ERROR_INT(
"sel not returned", __func__, 1);
573 sarrayJoin(sa4, sa5);
579 for (k = 0; k < sel->
sy; k++) {
580 for (l = 0; l < sel->
sx; l++) {
581 if (sel->
data[k][l] == 1)
583 else if (sel->
data[k][l] == 2)
588 linestr = stringNew(
" "
589 "lept_stderr(\"Error in HMT: no hits in sel!\\n\");\n}\n\n");
590 sarrayAddString(sa4, linestr,
L_INSERT);
595 sarrayAppendRange(sa4, sa1, loopstart, loopend);
603 return ERROR_INT(
"sa6 not made", __func__, 1);
605 sarrayJoin(sa4, sa6);
609 sarrayAppendRange(sa4, sa1, finalstart, finalend);
613 filestr = sarrayToString(sa4, 1);
614 nbytes = strlen(filestr);
616 snprintf(bigbuf,
L_BUF_SIZE,
"%slow.%d.c", filename, fileindex);
618 sprintf(bigbuf,
"%slow.%d.c", OUTROOT, fileindex);
619 l_binaryWrite(bigbuf,
"w", filestr, nbytes);
751 if (delx < -31 || delx > 31)
752 return (
char *)ERROR_PTR(
"delx out of bounds", __func__, NULL);
753 if (dely < -31 || dely > 31)
754 return (
char *)ERROR_PTR(
"dely out of bounds", __func__, NULL);
758 if (type == SEL_HIT) {
759 if ((delx == 0) && (dely == 0))
760 sprintf(bigbuf,
"(*sptr)");
761 else if ((delx == 0) && (dely < 0))
762 sprintf(bigbuf,
"(*(sptr %s))", wplstrm[absy - 1]);
763 else if ((delx == 0) && (dely > 0))
764 sprintf(bigbuf,
"(*(sptr %s))", wplstrp[absy - 1]);
765 else if ((delx < 0) && (dely == 0))
766 sprintf(bigbuf,
"((*(sptr) >> %d) | (*(sptr - 1) << %d))",
768 else if ((delx > 0) && (dely == 0))
769 sprintf(bigbuf,
"((*(sptr) << %d) | (*(sptr + 1) >> %d))",
771 else if ((delx < 0) && (dely < 0))
772 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
773 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
774 else if ((delx > 0) && (dely < 0))
775 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
776 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
777 else if ((delx < 0) && (dely > 0))
778 sprintf(bigbuf,
"((*(sptr %s) >> %d) | (*(sptr %s - 1) << %d))",
779 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
781 sprintf(bigbuf,
"((*(sptr %s) << %d) | (*(sptr %s + 1) >> %d))",
782 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
784 if ((delx == 0) && (dely == 0))
785 sprintf(bigbuf,
"(~*sptr)");
786 else if ((delx == 0) && (dely < 0))
787 sprintf(bigbuf,
"(~*(sptr %s))", wplstrm[absy - 1]);
788 else if ((delx == 0) && (dely > 0))
789 sprintf(bigbuf,
"(~*(sptr %s))", wplstrp[absy - 1]);
790 else if ((delx < 0) && (dely == 0))
791 sprintf(bigbuf,
"((~*(sptr) >> %d) | (~*(sptr - 1) << %d))",
793 else if ((delx > 0) && (dely == 0))
794 sprintf(bigbuf,
"((~*(sptr) << %d) | (~*(sptr + 1) >> %d))",
796 else if ((delx < 0) && (dely < 0))
797 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
798 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
799 else if ((delx > 0) && (dely < 0))
800 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
801 wplstrm[absy - 1], absx, wplstrm[absy - 1], 32 - absx);
802 else if ((delx < 0) && (dely > 0))
803 sprintf(bigbuf,
"((~*(sptr %s) >> %d) | (~*(sptr %s - 1) << %d))",
804 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
806 sprintf(bigbuf,
"((~*(sptr %s) << %d) | (~*(sptr %s + 1) >> %d))",
807 wplstrp[absy - 1], absx, wplstrp[absy - 1], 32 - absx);
810 return stringNew(bigbuf);