예제 #1
0
LRESULT CALLBACK LocalEdit_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//	static int msgs[10] = { 0,0,0,0,0,0,0,0,0,0 };
//	static int wParams[10] = { 0,0,0,0,0,0,0,0,0,0 };
	short ret = 0;
	static int lastCharMsg = 0;

	if ( msg == 135 ) // spose to be WM_CHAR type of message, but for "return" chars etc...
	{
		if ( (TCHAR) wParam == '\r' ) // Return key pressed 
		{
			//OutDebug( "Return!!!" );
			//OutDebugs( "Msg = %d, Wparam = %d", msg, wParam );
			//for ( int i = 0; i < 10; i++ )
			//	OutDebugs( "Msg%d = %d, Wparam%d = %d", i, msgs[i], i, wParams[i] );
			pressedReturnInEdit = 1;
			// if we are currently in the "Find" edit box, then
			if ( hwnd == GetDlgItem( hDlg, IDC_LANGTOKEN_FINDTEXT ) )
			{
				SearchForText( LANG_NEXT );
				ret = 1;
			}
			else if ( hwnd == GetDlgItem( hDlg, IDC_LANGTOKEN_TEXT ) )
			{
				UpdateALanguageString();
				ret = 1;
			}
		}
		else if ( (TCHAR) wParam == VK_F3 && lastCharMsg != 82 )
		{
			//OutDebug( "F3" );
			//OutDebugs( "Msg = %d, Wparam = %d", msg, wParam );
			//for ( int i = 0; i < 10; i++ )
			//	OutDebugs( "Msg%d = %d, Wparam%d = %d", i, msgs[i], i, wParams[i] );
			SearchForText( LANG_NEXT );
			ret = 1;
		}
		else if ( (TCHAR) wParam == VK_F3 && lastCharMsg == 82 )
		{
			//OutDebug( "R!!!" );
			//OutDebugs( "Msg = %d, Wparam = %d", msg, wParam );
			//for ( int i = 0; i < 10; i++ )
			//	OutDebugs( "Msg%d = %d, Wparam%d = %d", i, msgs[i], i, wParams[i] );
			ret = 0;
		}
//		OutDebug( "" );
		lastCharMsg = wParam;
	}

/*	msgs[0] = msg;
	for ( int i = 8; i >= 0; i-- )
		msgs[i+1] = msgs[i];
	wParams[0] = wParam;
	for ( i = 8; i >= 0; i-- )
		wParams[i+1] = wParams[i];*/
	if ( ret )
		return ret;
	return CallWindowProc(lpfnEditClassProc, hwnd, msg, wParam, lParam);
}
예제 #2
0
/// Resegments the word to achieve the target_text from the classifier.
/// Returns false if the re-segmentation fails.
/// Uses brute-force combination of up to #kMaxGroupSize adjacent blobs, and
/// applies a full search on the classifier results to find the best classified
/// segmentation. As a compromise to obtain better recall, 1-1 ambiguity
/// substitutions ARE used.
bool Tesseract::FindSegmentation(const GenericVector<UNICHAR_ID>& target_text,
                                 WERD_RES* word_res) {
  // Classify all required combinations of blobs and save results in choices.
  int word_length = word_res->box_word->length();
  GenericVector<BLOB_CHOICE_LIST*>* choices =
      new GenericVector<BLOB_CHOICE_LIST*>[word_length];
  for (int i = 0; i < word_length; ++i) {
    for (int j = 1; j <= kMaxGroupSize && i + j <= word_length; ++j) {
      BLOB_CHOICE_LIST* match_result = classify_piece(
          word_res->seam_array, i, i + j - 1, "Applybox",
          word_res->chopped_word, word_res->blamer_bundle);
      if (applybox_debug > 2) {
        tprintf("%d+%d:", i, j);
        print_ratings_list("Segment:", match_result, unicharset);
      }
      choices[i].push_back(match_result);
    }
  }
  // Search the segmentation graph for the target text. Must be an exact
  // match. Using wildcards makes it difficult to find the correct
  // segmentation even when it is there.
  word_res->best_state.clear();
  GenericVector<int> search_segmentation;
  float best_rating = 0.0f;
  SearchForText(choices, 0, word_length, target_text, 0, 0.0f,
                &search_segmentation, &best_rating, &word_res->best_state);
  for (int i = 0; i < word_length; ++i)
    choices[i].delete_data_pointers();
  delete [] choices;
  if (word_res->best_state.empty()) {
    // Build the original segmentation and if it is the same length as the
    // truth, assume it will do.
    int blob_count = 1;
    for (int s = 0; s < word_res->seam_array.size(); ++s) {
      SEAM* seam = word_res->seam_array[s];
      if (!seam->HasAnySplits()) {
        word_res->best_state.push_back(blob_count);
        blob_count = 1;
      } else {
        ++blob_count;
      }
    }
    word_res->best_state.push_back(blob_count);
    if (word_res->best_state.size() != target_text.size()) {
      word_res->best_state.clear();  // No good. Original segmentation bad size.
      return false;
    }
  }
  word_res->correct_text.clear();
  for (int i = 0; i < target_text.size(); ++i) {
    word_res->correct_text.push_back(
        STRING(unicharset.id_to_unichar(target_text[i])));
  }
  return true;
}
예제 #3
0
LRESULT CALLBACK LangBuilderProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	hDlg = hWnd;

	static int show = 0;
	if ( show )
		OutDebugs( "LangBuilderProc: Message = %d, Wparam = %d, Lparam = %d", message, wParam, lParam );
	switch (message)
	{
        case WM_DESTROY:
			DestroyWindow( hWndLangBuilderListView );
            break;
        case WM_INITDIALOG:
			InitLanguageDialog();
			return 0;
		case WM_SETCURSOR:
			UpdateToolBar(hWnd, GetWindowLong((HWND)wParam, GWL_ID ));
			break;
		case WM_COMMAND:
			switch( LOWORD(wParam) ){
					break;
				case IDC_LANGTOKEN_UPDATE:
					UpdateALanguageString();
					break;
				case IDC_LANGTOKEN_FIND:
					SearchForText( LANG_NEXT );
					break;
				// Not working correctly, too hard to do... case IDC_LANGTOKEN_FINDPREV: 
				//	SearchForText( LANG_PREV );
				//	break;
				case IDC_LANGTOKEN_LANG:
					if ( HIWORD(wParam) == CBN_SELCHANGE )
						ChangeLanguageStringInComboBox();
					break;
				case IDC_LANGTOKEN_EXIT:
					ExitLanguageDialog();
					break;
				case IDC_LANGTOKEN_SAVEAS:
					char currLangName[64];
					if ( pressedReturnInEdit ) {
						pressedReturnInEdit = 0;
						return 1;
					}
					GetWindowText( GetDlgItem( hDlg, IDC_LANGTOKEN_LANG), currLangName, 64 );
					SaveLanguageToFile( currLangName );
					break;
			}
			break;

		case WM_NOTIFY:
			if ( LOWORD(wParam) == IDC_LANGTOKEN_LIST && ((LV_DISPINFO *)lParam)->hdr.code == LVN_ITEMCHANGING )
			{
				currItemSel = ((LV_DISPINFO *)lParam)->item.mask;
				DisplayCurrListItemInTextBox( currItemSel );
			}
			else if ( LOWORD(wParam) == IDC_LANGTOKEN_LIST && ((LV_DISPINFO *)lParam)->item.cchTextMax == VK_F3 )
				SearchForText( LANG_NEXT );
			break;
	}
    return 0;
}
예제 #4
0
/// Recursive helper to find a match to the target_text (from text_index
/// position) in the choices (from choices_pos position).
/// @param choices is an array of GenericVectors, of length choices_length,
/// with each element representing a starting position in the word, and the
/// #GenericVector holding classification results for a sequence of consecutive
/// blobs, with index 0 being a single blob, index 1 being 2 blobs etc.
/// @param choices_pos
/// @param choices_length
/// @param target_text
/// @param text_index
/// @param rating
/// @param segmentation
/// @param best_rating
/// @param best_segmentation
void Tesseract::SearchForText(const GenericVector<BLOB_CHOICE_LIST*>* choices,
                              int choices_pos, int choices_length,
                              const GenericVector<UNICHAR_ID>& target_text,
                              int text_index,
                              float rating, GenericVector<int>* segmentation,
                              float* best_rating,
                              GenericVector<int>* best_segmentation) {
  const UnicharAmbigsVector& table = getDict().getUnicharAmbigs().dang_ambigs();
  for (int length = 1; length <= choices[choices_pos].size(); ++length) {
    // Rating of matching choice or worst choice if no match.
    float choice_rating = 0.0f;
    // Find the corresponding best BLOB_CHOICE.
    BLOB_CHOICE_IT choice_it(choices[choices_pos][length - 1]);
    for (choice_it.mark_cycle_pt(); !choice_it.cycled_list();
         choice_it.forward()) {
      BLOB_CHOICE* choice = choice_it.data();
      choice_rating = choice->rating();
      UNICHAR_ID class_id = choice->unichar_id();
      if (class_id == target_text[text_index]) {
        break;
      }
      // Search ambigs table.
      if (class_id < table.size() && table[class_id] != NULL) {
        AmbigSpec_IT spec_it(table[class_id]);
        for (spec_it.mark_cycle_pt(); !spec_it.cycled_list();
             spec_it.forward()) {
          const AmbigSpec *ambig_spec = spec_it.data();
          // We'll only do 1-1.
          if (ambig_spec->wrong_ngram[1] == INVALID_UNICHAR_ID &&
              ambig_spec->correct_ngram_id == target_text[text_index])
            break;
        }
        if (!spec_it.cycled_list())
          break;  // Found an ambig.
      }
    }
    if (choice_it.cycled_list())
      continue;  // No match.
    segmentation->push_back(length);
    if (choices_pos + length == choices_length &&
        text_index + 1 == target_text.size()) {
      // This is a complete match. If the rating is good record a new best.
      if (applybox_debug > 2) {
        tprintf("Complete match, rating = %g, best=%g, seglength=%d, best=%d\n",
                rating + choice_rating, *best_rating, segmentation->size(),
                best_segmentation->size());
      }
      if (best_segmentation->empty() || rating + choice_rating < *best_rating) {
        *best_segmentation = *segmentation;
        *best_rating = rating + choice_rating;
      }
    } else if (choices_pos + length < choices_length &&
               text_index + 1 < target_text.size()) {
      if (applybox_debug > 3) {
        tprintf("Match found for %d=%s:%s, at %d+%d, recursing...\n",
                target_text[text_index],
                unicharset.id_to_unichar(target_text[text_index]),
                choice_it.data()->unichar_id() == target_text[text_index]
                     ? "Match" : "Ambig",
                choices_pos, length);
      }
      SearchForText(choices, choices_pos + length, choices_length, target_text,
                    text_index + 1, rating + choice_rating, segmentation,
                    best_rating, best_segmentation);
      if (applybox_debug > 3) {
        tprintf("End recursion for %d=%s\n", target_text[text_index],
                unicharset.id_to_unichar(target_text[text_index]));
      }
    }
    segmentation->truncate(segmentation->size() - 1);
  }
}
LRESULT	CDebugMemorySearch::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
{
    switch (wID)
    {
    case IDCANCEL:
        EndDialog(0);
        break;
    case IDC_BTN_RDRAM:
        m_PAddrStart.SetValue(0, true, true);
        m_SearchLen.SetValue(g_MMU->RdramSize(), true, true);
        break;
    case IDC_BTN_ROM:
        m_PAddrStart.SetValue(0x10000000, true, true);
        m_SearchLen.SetValue(g_Rom->GetRomSize(), true, true);
        break;
    case IDC_BTN_SPMEM:
        m_PAddrStart.SetValue(0x04000000, true, true);
        m_SearchLen.SetValue(0x2000, true, true);
        break;
    case IDC_SEARCH_HEX:
        {
            bool bChecked = (SendMessage(hWndCtl, BM_GETSTATE, 0, 0) & BST_CHECKED) != 0;
            m_SearchValue.SetDisplayType(bChecked ? CEditNumber::DisplayHex : CEditNumber::DisplayDec);
        }
        break;
    case ID_POPUP_SHOWINMEMORYVIEWER:
        {
            LONG iItem = m_SearchResults.GetNextItem(-1, LVNI_SELECTED);
            if (iItem == -1)
            {
                break;
            }

            int ItemId = m_SearchResults.GetItemData(iItem);
            SearchResultItem & Result = m_SearchResult[ItemId];
            m_Debugger->Debug_ShowMemoryLocation(Result.PAddr, false);
        }
        break;
    case IDC_RADIO_UNKNOWN:
        EnableUnknownOptions(true);
        EnableValueOptions(false);
        EnableTextOptions(false);
        EnableJalOptions(false);
        break;
    case IDC_RADIO_VALUE:
        EnableUnknownOptions(false);
        EnableValueOptions(true);
        EnableTextOptions(false);
        EnableJalOptions(false);
        break;
    case IDC_RADIO_TEXT:
        EnableUnknownOptions(false);
        EnableValueOptions(false);
        EnableTextOptions(true);
        EnableJalOptions(false);
        break;
    case IDC_RADIO_JAL:
        EnableUnknownOptions(false);
        EnableValueOptions(false);
        EnableTextOptions(false);
        EnableJalOptions(true);
        break;
    case IDC_BTN_SEARCH:
        if (SendMessage(GetDlgItem(IDC_RADIO_UNKNOWN), BM_GETSTATE, 0, 0) == BST_CHECKED)
        {
            g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_SearchMemory);
            SearchForUnknown();
            g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_SearchMemory);
            break;
        }
        if (SendMessage(GetDlgItem(IDC_RADIO_VALUE), BM_GETSTATE, 0, 0) == BST_CHECKED)
        {
            g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_SearchMemory);
            SearchForValue();
            g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_SearchMemory);
            break;
        }
        if (SendMessage(GetDlgItem(IDC_RADIO_TEXT), BM_GETSTATE, 0, 0) == BST_CHECKED)
        {
            g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_SearchMemory);
            SearchForText();
            g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_SearchMemory);
            break;
        }
    case IDC_RESET_BUTTON:
        Reset();
        break;
    }
    return FALSE;
}