예제 #1
0
void Segments::matchRunsToSegments(int x, int height, bool* lastBool, Segment** lastSegment,
                                   bool* currBool, Segment** currSegment, bool* nextBool, SegmentSettings seg,
                                   int* madeLines, int* foldedLines, int* shortLines)
{
    loadSegment(currSegment, height);

    int yStart = 0;
    bool inRun = false;
    for (int y = 0; y < height; y++)
    {
        if (!inRun && currBool [y])
        {
            inRun = true;
            yStart = y;
        }

        if ((y + 1 >= height) || !currBool [y + 1])
        {
            if (inRun)
                finishRun(lastBool, nextBool, lastSegment, currSegment, x, yStart, y, height, seg,
                          madeLines);

            inRun = false;
        }
    }

    removeUnneededLines(lastSegment, currSegment, height, foldedLines, shortLines, seg);
}
예제 #2
0
void Segments::makeSegments(QImage &imageProcessed, SegmentSettings seg)
{
    segments.clear(); // autoDelete is on

    // statistics that show up in debug spew
    int madeLines = 0;
    int shortLines = 0; // lines rejected since their segments are too short
    int foldedLines = 0; // lines rejected since they could be into other lines

    // debugging with modal progress dialog box is problematic so make switchable
    const bool useDlg = true;

    // for each new column of pixels, loop through the runs. a run is defined as
    // one or more colored pixels that are all touching, with one uncolored pixel or the
    // image boundary at each end of the set. for each set in the current column, count
    // the number of runs it touches in the adjacent (left and right) columns. here is
    // the pseudocode:
    //   if ((L > 1) || (R > 1))
    //     "this run is at a branch point so ignore the set"
    //   else
    //     if (L == 0)
    //       "this run is the start of a new segment"
    //     else
    //       "this run is appended to the segment on the left
    int width = imageProcessed.width();
    int height = imageProcessed.height();

    QProgressDialog* dlg;
    if (useDlg)
    {

        dlg = new QProgressDialog("Scanning segments in image", "Cancel", 0, width);
        CHECK_PTR_ENGAUGE(dlg);
        dlg->setCaption(QString("Progress"));
        dlg->show();
    }

    bool* lastBool = new bool [height];
    CHECK_PTR_ENGAUGE(lastBool);
    bool* currBool = new bool [height];
    CHECK_PTR_ENGAUGE(currBool);
    bool* nextBool = new bool [height];
    CHECK_PTR_ENGAUGE(nextBool);
    Segment** lastSegment = new Segment* [height];
    CHECK_PTR_ENGAUGE(lastSegment);
    Segment** currSegment = new Segment* [height];
    CHECK_PTR_ENGAUGE(currSegment);

    Discretize discretize;
    loadBool(&discretize, lastBool, &imageProcessed, -1);
    loadBool(&discretize, currBool, &imageProcessed, 0);
    loadBool(&discretize, nextBool, &imageProcessed, 1);
    loadSegment(lastSegment, height);

    for (int x = 0; x < width; x++)
    {
        if (useDlg)
        {
            // update progress bar
            dlg->setValue(x);
            qApp->processEvents();

            if (dlg->wasCanceled())
                // quit scanning. only existing segments will be available
                break;
        }

        matchRunsToSegments(x, height, lastBool, lastSegment, currBool, currSegment, nextBool, seg,
                            &madeLines, &foldedLines, &shortLines);

        // get ready for next column
        scrollBool(lastBool, currBool, height);
        scrollBool(currBool, nextBool, height);
        if (x + 1 < width)
            loadBool(&discretize, nextBool, &imageProcessed, x + 1);
        scrollSegment(lastSegment, currSegment, height);
    }

    if (useDlg)
    {
        dlg->setValue(width);
        delete dlg;
    }

    DigitDebug::scanning(QString("segment lines created ") + QString::number(madeLines) +
                         QString(", too short so removed ") + QString::number(shortLines) +
                         QString(", folded together ") + QString::number(foldedLines));

    delete[] lastBool;
    delete[] currBool;
    delete[] nextBool;
    delete[] lastSegment;
    delete[] currSegment;
}
예제 #3
0
/*---------------------------------------------------------------------------*
 * M A I N 
 *---------------------------------------------------------------------------*/
void	Main(void *arg)
{
  u8	draw_frame = 0;
  u32	objRM;
  Gfx	*gp, *gtop;
  OSTime rspstart;
  u32	 rsptime, rdptime;
  
  bg16seg = (u32)_codeSegmentEnd 
          + (u32)_staticSegmentEnd - (u32)_staticSegmentStart;
  bg8seg  = bg16seg + 
          + (u32)_bg_rgbaSegmentRomEnd - (u32)_bg_rgbaSegmentRomStart;
  
  loadSegment(bg16seg, bg8seg);
  menuInit();
  actionInit();
  rsptime = rdptime = 0;
  
  while(1){

    /*------ Start to read the controller. ------*/
    osContStartReadData(&siMessageQ);
    
    /*------ Wait for the retrace. ------*/
    osRecvMesg(&retraceMessageQ, NULL, OS_MESG_BLOCK);

    /*------ Setting the Bg structure. ------*/
    setBg();
    
    /*------ Setting the Object structure. ------*/
    setObject();
    
    /*------ Create the Gfx list. ------*/
    gtop = gp = glist[draw_frame];

    /*------ RSP initialization setting. ------*/
    gSPSegment(gp ++, 0, 0x0);
    gSPSegment(gp ++, STATIC_SEGMENT, _codeSegmentEnd);
    if (aMenu[MENU_BG_TX_FORMAT]){
      gSPSegment(gp ++, BG_SEGMENT, bg8seg);
    }
    gDPSetColorImage(gp ++, G_IM_FMT_RGBA,
		     G_IM_SIZ_16b, SCREEN_WD, system_cfb[draw_frame]);
    gSPDisplayList(gp ++, rdpInit_dl);
    gSPDisplayList(gp ++, clearCfb_dl);
    gSPDisplayList(gp ++, spriteInit_dl);

    /*------ Bg output. ------*/
    if (aMenu[MENU_BG_TX_FORMAT]){
      gDPSetTextureLUT(gp ++, G_TT_RGBA16);
      gSPObjLoadTxtr(gp ++, &objBgTLUT);
    }
    if (aMenu[MENU_BG_SCALABLE] == 0){

      /* Unscalable BG plane */
      gDPSetRenderMode(gp ++, G_RM_NOOP, G_RM_NOOP2);
      gDPSetCycleType(gp ++, G_CYC_COPY);
      gSPBgRectCopy(gp ++, &objBg);

    } else {
      /* Scalable BG plane */
      gDPSetRenderMode(gp ++, G_RM_SPRITE, G_RM_SPRITE2);
      gDPSetCycleType(gp ++, G_CYC_1CYCLE);
      gDPSetTextureFilter(gp ++,
			  RMmodeTable[aMenu[MENU_RENDERMODE]].txtrFilter);
      if (aMenu[MENU_BG_SCALABLE] == 1){
	/* Emulated by CPU */
	guS2DEmuSetScissor(0, 0, SCREEN_WD, SCREEN_HT, 
			   (RMmodeTable[aMenu[MENU_RENDERMODE]].txtrFilter
			    == G_TF_BILERP));
	guS2DEmuBgRect1Cyc(&gp, &objBg);
      } else {
	/* GBI command */
	gSPObjRenderMode(gp ++, RMmodeTable[aMenu[MENU_RENDERMODE]].objRMode);
	gSPBgRect1Cyc(gp ++, &objBg);
      }
    }
    gDPPipeSync(gp ++);

    /*------ Setting the Render Mode. ------*/
    objRM = RMmodeTable[aMenu[MENU_RENDERMODE]].objRMode;
    if (RMmodeTable[aMenu[MENU_RENDERMODE]].cycleType != G_CYC_COPY){
      if (!aMenu[MENU_RENDERMODE_2]){
	/* Opaque */
	if (RMmodeTable[aMenu[MENU_RENDERMODE]].antiAlias){
	  gDPSetRenderMode(gp ++, G_RM_AA_SPRITE, G_RM_AA_SPRITE2);
	} else {
	  gDPSetRenderMode(gp ++, G_RM_SPRITE, G_RM_SPRITE2);
	}
      } else {
	/* Translucent */
	if (RMmodeTable[aMenu[MENU_RENDERMODE]].antiAlias){
	  gDPSetRenderMode(gp ++, G_RM_AA_XLU_SPRITE, G_RM_AA_XLU_SPRITE2);
	} else {
	  gDPSetRenderMode(gp ++, G_RM_XLU_SPRITE, G_RM_XLU_SPRITE2);
	}
	gDPSetCombineMode(gp ++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
	gDPSetPrimColor(gp ++, 0, 0, 255, 255, 255, 128);
      }
    }
    
    /*------ Setting the Texture Filter and CycleType. ------*/
    gDPSetTextureFilter(gp ++, RMmodeTable[aMenu[MENU_RENDERMODE]].txtrFilter);
    gDPSetCycleType    (gp ++, RMmodeTable[aMenu[MENU_RENDERMODE]].cycleType );
    
    /*------ Setting the Texture Window. ------*/
    if (aMenu[MENU_OBJ_TX_WINDOW]) objRM |= G_OBJRM_NOTXCLAMP;

    /*------ Setting the Shrink. ------*/
    objRM |= ShrinkTable[aMenu[MENU_OBJ_SHRINK]];
    
    /*------ Setting the Object Render Mode. ------*/    
    gSPObjRenderMode(gp ++, objRM);
    
    /*------ Load setting of the Texture. -----*/
    if (!aMenu[MENU_OBJ_TX_TYPE]){
      gDPSetTextureLUT(gp ++, G_TT_NONE);
      gSPObjLoadTxtr(gp ++, (aMenu[MENU_OBJ_TX_LOAD_BY]
			     ? &objTxtrTile_RGBA16 : &objTxtrBlock_RGBA16));
    } else {
      gDPSetTextureLUT(gp ++, G_TT_RGBA16);
      gSPObjLoadTxtr(gp ++, (aMenu[MENU_OBJ_TX_LOAD_BY]
			     ? &objTxtrTile_CI4 : &objTxtrBlock_CI4));
      gSPObjLoadTxtr(gp ++, &objTLUT_CI4);
    }
    
    /*------ Output of Object:Rectangle1. ------*/
    gSPObjRectangle(gp ++, &(objRect[0]));

    if (RMmodeTable[aMenu[MENU_RENDERMODE]].cycleType != G_CYC_COPY){

      /*------ Output of Object:Rectangle2. ------*/
      gSPObjMatrix(gp ++, &(objMtx[0]));
      gSPObjSprite(gp ++, &(objRect[1]));

      /*------ Output of Object:Ball. ------*/      
      /* 
	 Ball is displayed by combining two sprite pieces.  Because of this, you need to change
	 the processing method by setting the Texture Filter.  

	 If the Texture Filter is PointSample, you don't have to specify SHRINKSIZE; but, If it
	 is Bilerp, it must be SHRINKSIZE_1.  When you specify SHRINKSIZE_1, the circumference
	 of Sprite for 0.5 texel is clamped.  The area excepted by this clamp becomes a part
	 that the Bilerp process gives no effect.     

	 Because you need to load the part of adjoining of Sprite twice in Bilerp, Ball draws
	 only for 64x63 texels.  It is important to understand the differences between
	 objBall[1] and objBall[2] well. 
      */
      if (!aMenu[MENU_RENDERMODE_2]){
	/* Draw one size larger to hide the joining part.  (Only opaque.)
	   It became unnecessary after S2DEX 1.05.   */
	/* objRM |= G_OBJRM_WIDEN; */
      }
      gDPPipeSync(gp ++);
      gDPSetTextureLUT(gp ++, G_TT_RGBA16);
      gSPObjLoadTxtr(gp ++, &objBallTLUT);
      if (RMmodeTable[aMenu[MENU_RENDERMODE]].txtrFilter == G_TF_POINT){
	gSPObjRenderMode(gp ++, objRM);
	gSPObjMatrix(gp ++, &(objMtx[2]));
	gSPObjLoadTxRectR(gp ++, &(objBall[0]));
	gSPObjLoadTxRectR(gp ++, &(objBall[1]));
	gSPObjMatrix(gp ++, &(objMtx[1]));
	gSPObjLoadTxSprite(gp ++, &(objBall[0]));
	gSPObjLoadTxSprite(gp ++, &(objBall[1]));
      } else {
	gSPObjRenderMode(gp ++, objRM|G_OBJRM_SHRINKSIZE_1);
	gSPObjMatrix(gp ++, &(objMtx[2]));
	gSPObjLoadTxRectR(gp ++, &(objBall[0]));
	gSPObjLoadTxRectR(gp ++, &(objBall[2]));
	gSPObjMatrix(gp ++, &(objMtx[1]));
	gSPObjLoadTxSprite(gp ++, &(objBall[0]));
	gSPObjLoadTxSprite(gp ++, &(objBall[2]));
      }
    }
    
    /*------ Output the processing meter. ------*/
    if (rsptime){
      gDPPipeSync(gp ++);
      gDPSetCycleType(gp ++, G_CYC_FILL);
      gDPSetRenderMode(gp ++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
      gDPSetFillColor(gp ++, (GPACK_RGBA5551(128,128,255,1) << 16 | 
			      GPACK_RGBA5551(128,128,255,1)));
      gDPFillRectangle(gp ++, 30, 201, 30+rsptime/100, 202);
      gDPFillRectangle(gp ++, 30, 205, 30+rdptime/100, 206);
      gDPSetFillColor(gp ++, (GPACK_RGBA5551(255,255,255,1) << 16 | 
			      GPACK_RGBA5551(255,255,255,1)));
      gDPFillRectangle(gp ++, 30,     200, 30,     207);
      gDPFillRectangle(gp ++, 30+166, 200, 30+166, 207);
    }
    gDPFullSync(gp ++);
    gSPEndDisplayList(gp ++);
    
    /*------ Execute the Gfx task. ------*/
    tlist.t.data_ptr = (u64 *)gtop;
    osWritebackDCache(gtop, ((u32)gp)-((u32)gtop));
    rspstart = osGetTime();
    osSpTaskStart(&tlist);
    
    /*------ Wait for the end. ------*/
    osRecvMesg(&rspMessageQ, NULL, OS_MESG_BLOCK);
    rsptime = OS_CYCLES_TO_NSEC(osGetTime() - rspstart) / 1000;

#ifdef	RSP_DEBUG
    /*------ The ASSERT process of the micro-code. ------*/
    if (ucCheckAssert()){
      ucDebugGfxLogPrint(&tlist);  	/* Output the process log of RSP, Gfx and DL. */
//	ucDebugRdpFifoPrint(&tlist); 	/* Output the RDP and fifo buffers.           */
//	ucDebugIMEMPrint(); 		/* Output IMEM.                     	      */
//      ucDebugDMEMPrint(); 		/* Output DMEM.                     	      */
      ucDebugAssertPrint();		/* Output Assert stop location, etc.          */
      ucDebugInfoPrint();		/* Output the work area for Debugging.        */
      while(1);
    }
#endif

#if 0
    /*------ Output the DEBUG information. ------*/
    if (Ac.pad[0].push & Z_TRIG){
      ucDebugRdpFifoPrint(&tlist); 	/* Output the RDP and fifo buffers.    */
      ucDebugInfoPrint();		/* Output the work area for Debugging. */
    }
#endif
    osRecvMesg(&rdpMessageQ, NULL, OS_MESG_BLOCK);
    rdptime = OS_CYCLES_TO_NSEC(osGetTime() - rspstart) / 1000;
    
    /* Switching the Frame. */
    osViSwapBuffer(system_cfb[draw_frame]);
    draw_frame ^= 1;

    /* Accept the controller data. */
    osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
    osContGetReadData(contPad);
    
    /* The input process. */
    actionUpdate();
  }
}