示例#1
0
		void Menu::drawMainMenu(Graphics2D& g, bool charSelect)
		{
			model::Project& proj = getOwner().getProject();
			model::SaveData& lsd = proj.getLSD();
			model::DataBase& ldb = proj.getLDB();
			std::ostringstream ss;
		// main menu
			g.drawWindow( Vector2D(0, 0), Size2D(88, 96) );
			// cursor
			if(charSelect) g.drawCursorPassive( Vector2D(4, cursor(0)*16 + 8), Size2D(80, CURSOR_H) );
			else g.drawCursor( Vector2D(4, cursor(0)*16 + 8) + cursorMove(), Size2D(80, CURSOR_H) );
			// command
			font::FontColor c = lsd.memberNum() != 0 ? font::FNT_ENABLE : font::FNT_DISABLE;
			g.drawString(command_[0], Vector2D(8, 10 + CURSOR_H*0), font::FNT_ENABLE);
			g.drawString(command_[1], Vector2D(8, 10 + CURSOR_H*1), c);
			g.drawString(command_[2], Vector2D(8, 10 + CURSOR_H*2), c);
			g.drawString(command_[3], Vector2D(8, 10 + CURSOR_H*3), proj.canSave() ? font::FNT_ENABLE : font::FNT_DISABLE);
			g.drawString(command_[4], Vector2D(8, 10 + CURSOR_H*4), font::FNT_ENABLE);
		// money
			g.drawMoneyWindow( Vector2D( 0, 208) );
		// char info
			g.drawWindow( Vector2D(88,   0), Size2D(232, 240) );
			// char cursor
			if(charSelect) g.drawCursor( Vector2D(92, cursor(1)*58 + 4) + cursorMove(), Size2D(224, 56) );
			std::vector< uint16_t >& mem = lsd.member();
			for(uint i = 0; i < mem.size(); i++) {
				uint charID = mem[i];

				Vector2D base(88 + 8, 8 + (FACE_SIZE[1] + 10)*i);
				g.drawFaceSet( proj.faceSet(charID), proj.faceSetPos(mem[i]), base );

				base += Vector2D(FACE_SIZE[0] + 8, 3);
				g.drawString( proj.name(charID), base);
				g.drawString( proj.title(charID), base + Vector2D(font::HALF_FONT_W*15, 0) );

				base += Vector2D(0, font::FONT_H + 3);
				// level
				g.drawString(ldb.vocabulary(128), base, font::FNT_STATUS);
				ss.str(""); ss << std::setw(2) << proj.level(charID);
				g.drawString( ss.str(), base + Vector2D(font::FULL_FONT_W, 0) );
				// condition
				g.drawString( proj.condition(charID), base + Vector2D(font::HALF_FONT_W*7, 0), proj.conditionColor(charID) );
				// HP
				g.drawString( ldb.vocabulary(129), base + Vector2D(font::HALF_FONT_W*18, 0), font::FNT_STATUS );
				ss.str(""); ss << std::setw(3) << proj.hp(charID) << "/" << std::setw(3) << proj.param(charID, Param::HP);
				g.drawString( ss.str(), base + Vector2D(font::HALF_FONT_W*20, 0) );

				base += Vector2D(0, font::FONT_H + 3);
				// experience
				g.drawString(ldb.vocabulary(127), base, font::FNT_STATUS);
				ss.str("");
				if( proj.level(charID) >= LV_MAX ) ss << RPG2kString(6, '-') << "/" << RPG2kString(6, '-');
				else ss << std::setw(6) << proj.exp(charID) << "/" << std::setw(6) << proj.nextLevelExp(charID);
				g.drawString( ss.str(), base + Vector2D(font::FULL_FONT_W, 0) );
				// MP
				g.drawString( ldb.vocabulary(130), base + Vector2D(font::HALF_FONT_W*18, 0), font::FNT_STATUS );
				ss.str(""); ss << std::setw(3) << proj.mp(charID) << "/" << std::setw(3) << proj.param(charID, Param::MP);
				g.drawString( ss.str(), base + Vector2D(font::HALF_FONT_W*20, 0) );
			}
		}
示例#2
0
		void Menu::draw(Graphics2D& g)
		{
			g.drawWallpaper( Vector2D(0, 0), SCREEN_SIZE );

			// model::Project& proj = getOwner().getProject();
			// model::DataBase& ldb = proj.getLDB();
			// model::SaveData& lsd = proj.getLSD();

			if( cursorNum() == 1 ) drawMainMenu(g);
			else switch( cursor(0) ) {
				case MENU_SKILL:
				case MENU_EQUIP:
					drawMainMenu(g, true);
					break;
				case MENU_QUIT:
					g.drawWindow( Vector2D( (SCREEN_SIZE[0]-quitMessageW_-16)/2, 72 ), Size2D(quitMessageW_+16, 32) );
					g.drawString(quitMessage_, Vector2D( (SCREEN_SIZE[0]-quitMessageW_)/2, 82 ), font::FNT_NORMAL);

					g.drawWindow( Vector2D( (SCREEN_SIZE[0]-yesNoW_-16)/2, 120 ), Size2D(yesNoW_+16, 48) );
					g.drawCursor(
						Vector2D( (SCREEN_SIZE[0]-yesNoW_-8)/2, cursor()*CURSOR_H + 128 ) + cursorMove(),
						Size2D(yesNoW_+8, 16)
					);
					g.drawString(yes_, Vector2D( (SCREEN_SIZE[0]-yesNoW_)/2, 130 ), font::FNT_NORMAL);
					g.drawString(no_ , Vector2D( (SCREEN_SIZE[0]-yesNoW_)/2, 146 ), font::FNT_NORMAL);
					break;
				default: break;
			}
		}
示例#3
0
文件: image.c 项目: evenex/hexgen2014
int ImageLoad(Image *i, const unsigned char *data, size_t size)
{
    if (!i)        { X2(bad_arg,    "NULL image pointer"); }
    if (!data)     { X2(bad_arg,     "NULL data pointer"); }
    if (size == 0) { X2(bad_arg, "size must be non-zero"); }
    
    if (size > INT_MAX) { X2(bad_size,
        "stb_image cannot load more than INT_MAX bytes in any one image"); }
    
    unsigned char *uc;
    int x, y, comp;
    
    uc = stbi_load_from_memory(data, (int) size, &x, &y, &comp, RGBA_CHANNELS);
    if (!uc) { X(stbi_load_from_memory); }
    
    i->size     = Size2D((size_t) x, (size_t) y);
    i->elements = i->size.x * i->size.y;
    i->bytes    = i->elements * RGBA_SIZE;
    
    i->pixels = uc;
    
    return 1;
    
    err_stbi_load_from_memory:
    err_bad_size:
    err_bad_arg:
        return 0;
}
示例#4
0
文件: font.cpp 项目: Luigi30/dosthing
//void putFontStringIntoFramebuffer(char *framebuffer, char *str, int len, int destX, int destY, int vga_color, unsigned char *font, int sizeX, int sizeY){
void fbPutString(char *framebuffer, const char *str, int len, Point destination, int vga_color, Font font){
    int sizeX = font.getSizeX();
    int sizeY = font.getSizeY();

    for(int i=0;i<len;i++){        
        fbPutGlyph(framebuffer, font.getGlyph(str[i]), Size2D(sizeX, sizeY), Point(destination.getX()+(sizeX * i), destination.getY()), vga_color);
    }
}
	void Graphics2D::drawWallpaper(Vector2D const& dstP, Size2D const& dstS)
	{
		Image const& sys = getSystemGraphic();
		Vector2D backP = Vector2D(0, 32) + 1;
		Size2D backS = Size2D(16, 16) - 1;

		switch( getOwner().getProject().wallpaperType() ) {
			case model::Wallpaper::TILE: {
				Size2D align = dstS / backS;
				Size2D remainS = dstS % backS;
				Vector2D remainP = align * backS;
				Size2D it;
				for(it[0] = 0; it[0] < align[0]; it[0]++) {
				for(it[1] = 0; it[1] < align[1]; it[1]++) {
					drawImage(sys, dstP + backS*it, backP, backS);
				}
				}
				// draw wallpaper unaligned space
				if(!remainS[0]) {
					for(it[1] = 0; it[1] < align[1]; it[1]++) {
						drawImage(sys,
							Vector2D(dstP[0] + remainP[0], dstP[1] + backS[1]*it[1]),
							backP, Size2D(remainS[0], backS[1])
						);
					}
				}
				if(!remainS[1]) {
					for(it[0] = 0; it[0] < align[0]; it[0]++) {
						drawImage(sys,
							Vector2D(dstP[0] + backS[0]*it[0], dstS[1] + remainP[1]),
							backP, Size2D(backS[0], remainS[1])
						);
					}
				}
				if( (!remainS[0]) && (!remainS[1]) ) {
					drawImage(sys, dstS + remainP, backP, remainS);
				}
			} break;
			case model::Wallpaper::ZOOM:
				drawImage(sys, dstP, dstS, backP, backS);
				break;
			default:
				break;
		}
	}
示例#6
0
UIWidget::UIWidget(std::weak_ptr<Window> parent_window)
  : window(parent_window)
{
  cache_texture = std::make_shared<SDLTexture>(parent_window, Size2D(0,0));
  on_display_mode_changed.SubscribeForever([this](){
    if(display_mode != DisplayMode::Invisible)
      SetNeedsRedrawing();
    auto p = parent.lock();
    if(p) p->OnChildVisibilityChanged();
  });
}
示例#7
0
		void Item::draw(Graphics2D& g)
		{
			model::Project& proj = getOwner().getProject();
			model::SaveData& lsd = proj.getLSD();
			model::DataBase& ldb = proj.getLDB();

			std::ostringstream ss;
			switch( cursorNum() ) {
				case 1: { // select item
					std::map< uint16_t, model::SaveData::Item >& itemList = lsd.item();
					structure::Array2D const& item = ldb[13];

					g.drawWindow( Vector2D(0,  0), Size2D(SCREEN_SIZE[0], 32) );

					g.drawWindow( Vector2D(0, 32), SCREEN_SIZE - Size2D(0, 32) );
					g.drawCursor(
						Vector2D(4, 42) + Vector2D( cursor() % 2 * 160,  cursor() / 2 * CURSOR_H ),
						Size2D(152, CURSOR_H)
					);
					int index = 0;
					for(std::map< uint16_t, model::SaveData::Item >::const_iterator it = itemList.begin(); it != itemList.end(); ++it) {
						Vector2D base = Vector2D(8, 42) + Vector2D( index % 2 * 160,  index / 2 * CURSOR_H );
						if( cursor() == index ) {
							g.drawString( item[it->first][2], Vector2D(8, 10) );
						}

						g.drawString(item[it->first][1], base);
						ss.str(""); ss << ":" << std::setw(2) << it->second.num;
						g.drawString( ss.str(), base + Vector2D( font::HALF_FONT_W*21, 0 ) );

						index++;
					}
				} break;
				case 2: // select char
					break;
			}
		}
示例#8
0
std::shared_ptr<SDLTextTexture> TextRenderer::Render(std::weak_ptr<Window> w,FontParams fp, std::string text){
  auto parent_window = w.lock();
  // Split the text into lines.
  std::vector<std::string> lines = Utilities::SplitString(text,"\n");
  // Buffers.
  std::vector<SDL_Surface*> surfaces;
  std::vector<std::shared_ptr<SDLTexture>> textures;
  // For each line of text
  for(auto& l : lines){
    // Workaround for rendering empty strings
    if(l == "") l = " ";
    // Ask SDL_TTF to render a line
    SDL_Surface* surf = TTF_RenderUTF8_Blended(GetFont(fp), l.c_str(), SDL_Color{255,255,255,255});
    if(!surf){
      std::cout << "Warning: TTF_RenderUTF8_Blended failed " << TTF_GetError() << std::endl;
      continue;
    }
    // Use SDLFix to premultiply alpha
    SDLFix::PremultiplySurface32RGBA(surf);
    // Store the surface in buffer.
    surfaces.push_back(surf);
  }
  int totalh = 0, maxw = 0;
  // When all surfaces are ready, for each surface
  for(auto& surf : surfaces){
    // create corresponding texture.
    textures.push_back(std::make_shared<SDLTextTexture>(w, surf));
    SDL_FreeSurface(surf);
    // Calculate total size
    Size2D size = textures.back()->GetSize();
    totalh += size.height;
    if(size.width >= maxw) maxw = size.width;
  }
  // Prepare the result texture
  auto res = std::make_shared<SDLTextTexture>(w,Size2D(maxw,totalh));
  // Create a helper drawcontext
  DrawContext dc(parent_window->GetWindow(), parent_window ->GetRenderer(), nullptr, 0,0,maxw,totalh);
  // We'll be drawing onto the result texture
  dc.Push(res,maxw,totalh);
  dc.Clear();
  int currenty = 0;
  for(auto& texture : textures){
    dc.DrawTexture(texture,Point2D(0,currenty));
    currenty += texture->GetSize().height;
  }
  dc.Pop();
  return res;
}
示例#9
0
void UIPathSelector::Init()
{
  child_button = UIButton::Create(window,"...");
  child_entry = UITextEntry::Create(window,path);
  Insert(child_entry, UIBox::PackMode::WIDE);
  Insert(child_button, UIBox::PackMode::TIGHT);
  
  child_button->SetBorder(false);
  child_button->SetCustomSize(Size2D(16,16));
  child_button->SetInnerMargin(0);
  
  subscriptions += child_button->on_clicked.Subscribe([this](){
    OpenDialog();
  });
  subscriptions += child_entry->on_edited.Subscribe([this](){
    path = child_entry->GetText();
  });
}
示例#10
0
int WindsimInit(Windsim *sim, World *w, size3D size)
{
    if (!sim)       { X2(bad_arg, "NULL sim pointer"); }
    if (!w)         { X2(bad_arg, "NULL world pointer"); }
    if (size.x < 1) { X2(bad_arg, "size.x must be > 0"); }
    if (size.y < 1) { X2(bad_arg, "size.y must be > 0"); }
    if (size.z < 1) { X2(bad_arg, "size.z must be > 0"); }
    
    size2D xy = Size2D(size.x, size.y);
    
    sim->world = w;
    sim->size = size;
    sim->elements = size.x * size.y * size.z;
    sim->height = WINDSIM_HEIGHT;
    
    /* a 3D grid of cells covering the map surface */
    sim->cell = malloc(sizeof(Windcell) * sim->elements);
    if (!sim->cell) { X(alloc_sim_cells); }
    
    /* a 1D grid of cells extending along the z axis away from the surface
     * of the planet, for graphing simulation state by altitude. */
    sim->graphAtmosphere1DCell = malloc(sizeof(GraphAtmosphere1DCell) * sim->size.z);
    if (!sim->graphAtmosphere1DCell) { X(alloc_graph_cells); }
    
    /* 2D buffers for sampling information from the world map at a lower
     * resolution */
    if (!Doubles2DInit(&sim->elevation, xy)) { X(Doubles2DInit_elevation); }
    if (!Doubles2DInit(&sim->sunlight,  xy)) { X(Doubles2DInit_sunlight);  }
    if (!Doubles2DInit(&sim->albedo,    xy)) { X(Doubles2DInit_albedo);    }
    
    return 1;
    
    err_Doubles2DInit_albedo:
        Doubles2DTeardown(&sim->sunlight);
    err_Doubles2DInit_sunlight:
        Doubles2DTeardown(&sim->elevation);
    err_Doubles2DInit_elevation:
        free(sim->graphAtmosphere1DCell);
    err_alloc_graph_cells:
        free(sim->cell);
    err_alloc_sim_cells:
    err_bad_arg:
        return 0;
}
示例#11
0
ResultsUI::ResultsUI(SpriteList *spriteList) : Screen(spriteList)
{
	mHeaderFont = FontManager::Load("definitionBody");
	mHeaderBar = new HeaderBar(mSpriteList, mHeaderFont);
	mLeaderboard = new Leaderboard(mSpriteList);
	mSummary = new Summary(mSpriteList);
	mSummary->mVisible = false;
	mSummary->mActive = false;
	mLeaderboard->mVisible = false;
	mLeaderboard->mActive = false;
	mSummary->mVisible = false;
	mSummary->mActive = false;
	mFillRectangle = new UI::Rectangle(Vec2(-2, -2), Vec2((float)::Screen::Width() + 4, 36), Color(0xff, 0x50, 0x50, 0x50), Color::Black, 2);
	mFillRectangle->mHitRect = Rect2D(Point2D(-1, -1), Size2D(0,0));

	mCloseTexture = Texture::Load("icon_close.png");
	mCloseButton = new UI::ImageButton(mCloseTexture, Vec2(::Screen::Width() - 48.0f,   0), Vec2(48, 48));

	AddUIItem(mFillRectangle);
	AddUIItem(mCloseButton);

	mHeaderBar->AddButton("High scores", mLeaderboard);
	mHeaderBar->AddButton("Summary", mSummary);

	mCloseButton->OnPress = [this] ()
	{
		Activate(false);
		if(OnClose != null)
		{
			OnClose();
		}
	};

	Activate(false);

	this->mZIndex = 2;
	mHeaderBar->mZIndex = 3;
	mLeaderboard->mZIndex = 0;
	mSummary->mZIndex = 0;
}
示例#12
0
	void Graphics2D::drawWindowType(Vector2D const& dstP, Size2D const& dstS, WindowType type)
	{
		Vector2D frontP(32*type, 0), backP;
		Vector2D backS; // background image size

		Image const& sys = getSystemGraphic();

		switch(type) {
			case WINDOW:
				backP(32*0, 0);
				backS = 32;
				break;
			case CURSOR_0: case CURSOR_1:
				backP(frontP[0] + CORNER, frontP[1] + CORNER);
				backS = NON_FRAME;
				break;
			default:
				return;
		}
		// draw wallpaper and side frame
		switch( getOwner().getProject().wallpaperType() ) {
			case model::Wallpaper::TILE: {
			// draw wallpaper
				// draw wallpaper aligned space
				Size2D align = dstS / backS;
				Size2D remainS = dstS % backS;
				Vector2D remainP = align * backS;
				Size2D it;
				for(it[0] = 0; it[0] < align[0]; it[0]++) {
				for(it[1] = 0; it[1] < align[1]; it[1]++) {
					drawImage(sys, dstP + backS*it, backP, backS);
				}
				}
				// draw wallpaper unaligned space
				if(!remainS[0]) {
					for(it[1] = 0; it[1] < align[1]; it[1]++) {
						drawImage(sys,
							Vector2D(dstP[0] + remainP[0], dstP[1] + backS[1]*it[1]),
							backP, Size2D(remainS[0], backS[1])
						);
					}
				}
				if(!remainS[1]) {
					for(it[0] = 0; it[0] < align[0]; it[0]++) {
						drawImage(sys,
							Vector2D(dstP[0] + backS[0]*it[0], dstS[1] + remainP[1]),
							backP, Size2D(backS[0], remainS[1])
						);
					}
				}
				if( (!remainS[0]) && (!remainS[1]) ) {
					drawImage(sys, dstS + remainP, backP, remainS);
				}
			// draw side frame
				// draw top and bottom frame aligned
				align( (dstS[0]-FRAME_W*2) / FRAME_L, (dstS[1]-FRAME_W*2) / FRAME_L);
				for(it[0] = 0; it[0] < align[0]; it[0]++) {
					// top frame
					drawImage(sys,
						Vector2D(dstP[0] + FRAME_W + FRAME_L * it[0], dstP[1]),
						Vector2D(frontP[0]+FRAME_W, frontP[1]),
						Size2D(FRAME_L, FRAME_W)
					);
					// bottom frame
					drawImage(sys,
						Vector2D(dstP[0] + FRAME_W + FRAME_L * it[0], dstP[1] + dstS[1]-FRAME_W),
						Vector2D(frontP[0]+FRAME_W, frontP[1]+C_AND_N),
						Size2D(FRAME_L, FRAME_W)
					);
				}
				// draw left and bottom frame aligned
				for(it[1] = 0; it[1] < align[1]; it[1]++) {
					// draw left
					drawImage(sys,
						Vector2D(dstP[0], dstP[1]+FRAME_W + FRAME_L*it[1]),
						Vector2D(frontP[0], frontP[1]+FRAME_W),
						Size2D(FRAME_W, FRAME_L)
					);
					// draw right
					drawImage(sys,
						Vector2D(dstP[0] + dstS[0]-FRAME_W, dstP[1]+FRAME_W + FRAME_L*it[1]),
						Vector2D(frontP[0]+C_AND_N, frontP[1]+FRAME_W),
						Size2D(FRAME_W, FRAME_L)
					);
				}
				// draw frame unaligned
				remainS( (dstS[0]-FRAME_W*2) % FRAME_L, (dstS[1]-FRAME_W*2) % FRAME_L );
				remainP(align[0] * FRAME_L + FRAME_W, align[1] * FRAME_L + FRAME_W);
				// top frame
				drawImage(sys,
					Vector2D(dstP[0]+remainP[0], dstP[1]),
					Vector2D(frontP[0]+FRAME_W, frontP[1]),
					Size2D(remainS[0], FRAME_W)
				);
				// bottom frame
				drawImage(sys,
					Vector2D(dstP[0]+remainP[0], dstP[1] + dstS[1]-FRAME_W),
					Vector2D(frontP[0]+FRAME_W, frontP[1]+C_AND_N),
					Size2D(remainS[0], FRAME_W)
				);
				// left frame
				drawImage(sys,
					Vector2D(dstP[0], dstP[1]+remainP[1]),
					Vector2D(frontP[0], frontP[1]+FRAME_W),
					Size2D(FRAME_W, remainS[1])
				);
				// right frame
				drawImage(sys,
					Vector2D(dstP[0] + dstS[0]-FRAME_W, dstP[1]+remainP[1]),
					Vector2D(frontP[0]+C_AND_N, frontP[1]+FRAME_W),
					Size2D(FRAME_W, remainS[1])
				);
			} break;
			case model::Wallpaper::ZOOM: {
				// draw wallpaper
				drawImage(sys, dstP, dstS, backP, backS);
				// draw top frame
				drawImage(sys,
					Vector2D(dstP[0]+FRAME_W, dstP[1]),
					Size2D(dstS[0]-FRAME_W, FRAME_W),
					Vector2D(frontP[0]+FRAME_W, frontP[1]),
					Size2D(FRAME_L, FRAME_W)
				);
				// draw left frame
				drawImage(sys,
					Vector2D(dstP[0], dstP[1]+FRAME_W),
					Size2D(FRAME_W, dstS[1]-FRAME_W),
					Vector2D(frontP[0], frontP[1]+FRAME_W),
					Size2D(FRAME_W, FRAME_L)
				);
				// draw right frame
				drawImage(sys,
					Vector2D(dstP[0] + dstS[0]-FRAME_W, dstP[1]+FRAME_W),
					Size2D(FRAME_W, dstS[1]-FRAME_W),
					Vector2D(frontP[0]+C_AND_N, frontP[1]+FRAME_W),
					Size2D(FRAME_W, FRAME_L)
				);
				// draw bottom frame
				drawImage(sys,
					Vector2D(dstP[0]+FRAME_W, dstP[1] + dstS[1]-FRAME_W),
					Size2D(dstS[0]-FRAME_W, FRAME_W),
					Vector2D(frontP[0]+FRAME_W, frontP[1]+C_AND_N),
					Size2D(FRAME_L, FRAME_W)
				);
			} break;
			default: rpg2k_assert(false);
		}

		Vector2D cornerSize(CORNER, CORNER);
		// draw corner frame
		drawImage(sys, dstP, frontP, cornerSize);
		drawImage(sys,
			Vector2D(dstP[0] + dstS[0] - CORNER, dstP[1]),
			Vector2D(frontP[0] + C_AND_N, frontP[1]), cornerSize
		);
		drawImage(sys,
			Vector2D(dstP[0], dstP[1] + dstS[1] - CORNER),
			Vector2D(frontP[0], frontP[1] + C_AND_N), cornerSize
		);
		drawImage(sys,
			Vector2D(dstP[0] + dstS[0] - CORNER, dstP[1] + dstS[1] -CORNER),
			Vector2D(frontP[0] + C_AND_N, frontP[1] + C_AND_N), cornerSize
		);
	}
示例#13
0
void UITextEntry::Init(){
  SetMinimalSize(Size2D(10, fontsize + 2));
  UpdateText();
}
示例#14
0
void UITextEntry::SetFontSize(int size){
  fontsize = size;
  SetMinimalSize(Size2D(10, fontsize + 2));
  UpdateText();
}
void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info)
{
    ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32);
    ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
    ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, weights);
    ARM_COMPUTE_ERROR_ON(!weights_info.are_reshaped() && weights->info()->dimension(2) != input->info()->dimension(2));
    ARM_COMPUTE_ERROR_ON(weights->info()->num_dimensions() > 4);

    if(biases != nullptr)
    {
        ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, biases);
        ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, biases);
        ARM_COMPUTE_ERROR_ON(!weights_info.are_reshaped() && biases->info()->dimension(0) != weights->info()->dimension(3));
        ARM_COMPUTE_ERROR_ON(biases->info()->num_dimensions() > 1);
    }

    const DataType dt                   = input->info()->data_type();
    const int      fixed_point_position = input->info()->fixed_point_position();

    _has_bias             = (biases != nullptr);
    _are_weights_reshaped = weights_info.are_reshaped();

    // Get parameters from conv_info
    unsigned int stride_x = 0;
    unsigned int stride_y = 0;
    std::tie(stride_x, stride_y) = conv_info.stride();

    // Get convolved dimensions
    unsigned int conv_w = 0;
    unsigned int conv_h = 0;

    const unsigned int kernel_width  = (_are_weights_reshaped) ? weights_info.kernel_size().first : weights->info()->dimension(0);
    const unsigned int kernel_height = (_are_weights_reshaped) ? weights_info.kernel_size().second : weights->info()->dimension(1);
    std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), kernel_width, kernel_height,
                                                 conv_info);

    // Check if its a "fully connected" convolution, i.e. the output size is 1x1xnum_kernels
    _is_fully_connected_convolution = ((conv_w == 1) && (conv_h == 1));

#if defined(__arm__)
    if(NEScheduler::get().cpu_info().CPU == CPUTarget::ARMV7 && dt == DataType::F32)
    {
        _mm_optimised_kernel = support::cpp14::make_unique<NEGEMMAArch32Kernel>();
    	std::cout << std::endl <<"line 157: _mm_optimised_kernel is NEGEMMAArch32Kernel" << std::endl;
    }
#elif defined(__aarch64__)
    if(NEScheduler::get().cpu_info().CPU >= CPUTarget::ARMV8 && dt == DataType::F32)
    {
        _mm_optimised_kernel = support::cpp14::make_unique<NEGEMMAArch64Kernel>();
        std::cout << std::endl <<"line 163: _mm_optimised_kernel is NEGEMMAArch64Kernel" << std::endl;
    }
#endif /* defined(__arm__) || defined(__aarch64__) */

    unsigned int mat_weights_cols = weights->info()->dimension(3);
    unsigned int mat_weights_rows = weights->info()->dimension(0) * weights->info()->dimension(1) * weights->info()->dimension(2) + (_has_bias ? 1 : 0);

    // Reshape weights if needed
    if(_mm_optimised_kernel != nullptr)
    {
        if(_are_weights_reshaped)
        {
            mat_weights_cols = weights_info.num_kernels();
            mat_weights_rows = weights->info()->dimension(1);
        }
        else
        {
            TensorShape reshaped_weights_shape{ mat_weights_cols, mat_weights_rows };

            // Create tensor to store the reshaped weights
            _weights_reshaped.allocator()->init(TensorInfo(reshaped_weights_shape, 1, dt, fixed_point_position));
            _reshape_weights.configure(weights, biases, &_weights_reshaped, false /* 1xW transpose */);
            weights = &_weights_reshaped;
        }
    }
    else
    {
        if(_are_weights_reshaped)
        {
            if(_is_fully_connected_convolution)
            {
                mat_weights_cols = weights_info.num_kernels();
                mat_weights_rows = weights->info()->dimension(1);
            }
            else
            {
                const unsigned int transpose_width = 16 / input->info()->element_size();
                mat_weights_cols                   = weights_info.num_kernels();
                mat_weights_rows                   = weights->info()->dimension(0) / transpose_width + (_has_bias ? 1 : 0);
            }
        }
        else
        {
            TensorShape reshaped_weights_shape;

            if(_is_fully_connected_convolution)
            {
                reshaped_weights_shape = TensorShape{ mat_weights_cols, mat_weights_rows };
            }
            else
            {
                // Create tensor to store transposed weights
                const float transpose_width = 16.0f / input->info()->element_size();
                reshaped_weights_shape      = TensorShape{ mat_weights_rows *static_cast<unsigned int>(transpose_width),
                                                           static_cast<unsigned int>(std::ceil(mat_weights_cols / transpose_width)) };
            }

            // Create tensor to store the reshaped weights
            _weights_reshaped.allocator()->init(TensorInfo(reshaped_weights_shape, 1, dt, fixed_point_position));
            _reshape_weights.configure(weights, biases, &_weights_reshaped, !_is_fully_connected_convolution /* 1xW transpose */);
            weights = &_weights_reshaped;
        }
    }

    // Create tensor to store im2col reshaped inputs
    const unsigned int mat_input_cols = mat_weights_rows;
    const unsigned int mat_input_rows = conv_w * conv_h;

    TensorShape shape_im2col(input->info()->tensor_shape());
    shape_im2col.set(0, mat_input_cols);
    shape_im2col.set(1, mat_input_rows);
    shape_im2col.set(2, 1);
    _input_im2col_reshaped.allocator()->init(TensorInfo(shape_im2col, 1, dt, fixed_point_position));
    _memory_group.manage(&_input_im2col_reshaped);

    // Create tensor (interleave) to prepare input tensor for GEMM
    if(!_is_fully_connected_convolution && _mm_optimised_kernel == nullptr)
    {
        TensorShape shape_interleaved(shape_im2col);
        shape_interleaved.set(0, shape_interleaved.x() * 4);
        shape_interleaved.set(1, std::ceil(shape_interleaved.y() / 4.f));
        _input_interleaved_reshaped.allocator()->init(TensorInfo(shape_interleaved, 1, dt, fixed_point_position));
        _memory_group.manage(&_input_interleaved_reshaped);
    }

    // Create GEMM output tensor
    TensorShape shape_gemm(_input_im2col_reshaped.info()->tensor_shape());
    shape_gemm.set(0, mat_weights_cols);
    shape_gemm.set(1, mat_input_rows);
    _gemm_output.allocator()->init(TensorInfo(shape_gemm, 1, dt, fixed_point_position));
    _memory_group.manage(&_gemm_output);

    // Configure kernels
    _input_im2col_kernel.configure(input, &_input_im2col_reshaped, Size2D(kernel_width, kernel_height), conv_info, _has_bias);

#if defined(__arm__) || defined(__aarch64__)
    if(_mm_optimised_kernel != nullptr)
    {
        struct CPUInfo ci = NEScheduler::get().cpu_info();

        const int M = _gemm_output.info()->tensor_shape().y();
        const int N = _gemm_output.info()->tensor_shape().x();
        const int K = _input_im2col_reshaped.info()->tensor_shape().x();

#if defined(__arm__)
        GemmInterleaved<sgemm_8x6, float, float> gemm(&ci, M, N, K, false, false);
#elif defined(__aarch64__)
        GemmInterleaved<sgemm_12x8, float, float> gemm(&ci, M, N, K, false, false);
#endif /* defined(__arm__) || defined(__aarch64__) */

        constexpr size_t alignment = 4096;
        _workspace.allocator()->init(TensorInfo(TensorShape{ (gemm.get_working_size() + alignment - 1) * NEScheduler::get().num_threads() }, 1, DataType::U8));
        _memory_group.manage(&_workspace);

        // Configure matrix multiplication kernel
        if(_is_fully_connected_convolution)
        {
            _mm_optimised_kernel->configure(&_input_im2col_reshaped, weights, &_gemm_output, &_workspace, 1.f, 0.f);
        }
        else
        {
            _mm_optimised_kernel->configure(&_input_im2col_reshaped, weights, &_gemm_output, &_workspace);
        }

        _workspace.allocator()->allocate();
    }
    else
#endif /* defined(__arm__) || defined(__aarch64__) */
    {
        if(_is_fully_connected_convolution)
        {
            _mm_kernel.configure(&_input_im2col_reshaped, weights, &_gemm_output, 1.0f);
        }
        else
        {
            _input_interleave_kernel.configure(&_input_im2col_reshaped, &_input_interleaved_reshaped);
            _mm_kernel.configure(&_input_interleaved_reshaped, weights, &_gemm_output, 1.0f);
            _input_interleaved_reshaped.allocator()->allocate();
        }
    }

    _input_im2col_reshaped.allocator()->allocate();
    _output_col2im_kernel.configure(&_gemm_output, output, Size2D(conv_w, conv_h));
    _gemm_output.allocator()->allocate();

    ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(0) != conv_w) || (output->info()->dimension(1) != conv_h), "Output shape does not match the expected one");

    // Allocate intermediate tensor
    if(!_are_weights_reshaped)
    {
        _weights_reshaped.allocator()->allocate();
    }
}
示例#16
0
		void Skill::draw(Graphics2D& g)
		{
			model::Project& proj = getOwner().getProject();
			// model::SaveData& lsd = proj.getLSD();
			model::DataBase& ldb = proj.getLDB();
			std::ostringstream ss;

			switch( cursorNum() ) {
				case 2: { // select skill
					structure::Array2D const& skill = ldb[12];

					g.drawWindow( Vector2D(0, 32*0), Size2D(SCREEN_SIZE[0], 32) );
					if( cursor() != (int)idList_.size() ) {
						g.drawString( skill[ idList_[ cursor() ] ][2], Vector2D(8, 10) );
					}

					g.drawWindow( Vector2D(0, 32*1), Size2D(SCREEN_SIZE[0], 32) );
					// name
					Vector2D base(8, 32 + 10);
					g.drawString( proj.name(curCharID_), base );
					// level
					base += Vector2D( font::HALF_FONT_W*14, 0 );
					g.drawString( ldb.vocabulary(128), base, font::FNT_STATUS );
					base += Vector2D( font::FULL_FONT_W*1, 0 );
					ss.str(""); ss << proj.level(curCharID_);
					g.drawString( ss.str(), base );
					// condition
					base += Vector2D( font::HALF_FONT_W*5, 0 );
					g.drawString( proj.condition(curCharID_), base, proj.conditionColor(curCharID_) );
					// HP
					base += Vector2D( font::HALF_FONT_W*10, 0 );
					g.drawString( ldb.vocabulary(129), base, font::FNT_STATUS );
					base += Vector2D( font::FULL_FONT_W*1, 0 );
					ss.str(""); ss << std::setw(3) << proj.hp(curCharID_) << "/" << std::setw(3) << proj.param(curCharID_, Param::HP);
					g.drawString( ss.str(), base );
					// MP
					base += Vector2D( font::HALF_FONT_W*9, 0 );
					g.drawString( ldb.vocabulary(130), base, font::FNT_STATUS );
					base += Vector2D( font::FULL_FONT_W*1, 0 );
					ss.str(""); ss << std::setw(3) << proj.mp(curCharID_) << "/" << std::setw(3) << proj.param(curCharID_, Param::MP);
					g.drawString( ss.str(), base );

					g.drawWindow( Vector2D(0, 32*2), SCREEN_SIZE - Size2D(0, 32*2) );
					g.drawCursor(
						Vector2D(4, 72) + Vector2D( cursor() % 2 * 160,  cursor() / 2 * CURSOR_H ),
						Size2D(152, CURSOR_H)
					);
					int index = 0;
					for(std::vector< uint16_t >::const_iterator it = idList_.begin(); it != idList_.end(); ++it) {
						if( *it == 0 ) break;

						base = Vector2D(8, 74) + Vector2D( index % 2 * 160, index / 2 * CURSOR_H );

						g.drawString(skill[*it][1], base);
						ss.str(""); ss << "-" << std::setw(3) << skill[*it][11].get<int>();
						g.drawString( ss.str(), base + Vector2D( font::HALF_FONT_W*20, 0 ) );

						index++;
					}
				} break;
				case 3: // select char
					break;
			}
		}