Exemplo n.º 1
0
void TProcess::run() {
       // QDataStream::setVersion(QDataStream::Qt_4_6);
    QNetworkAccessManager qnam;
    QNetworkRequest request = QNetworkRequest(QUrl(ImageInfo.ImageUrl));
    request.setRawHeader("User-Agent", "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1");
    QNetworkReply *reply = qnam.get(request);
    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    if (reply->error() == QNetworkReply::NoError) {
        ImageInfo.FetchedOk = true;
        QImageReader imageReader(reply);
        QImage pic = imageReader.read();
        QSize imgSize = pic.size();
        if (!imgSize.isNull()) {
            ImageInfo.ParsedOk = true;
            QImage thumb = pic.scaled(ThumbSize, ThumbSize, Qt::KeepAspectRatio);
            thumb = thumb.convertToFormat(QImage::Format_Indexed8);
            QByteArray imgData = GetPixelData(thumb);

            QCryptographicHash md5(QCryptographicHash::Md5);
            md5.addData(imgData);
            ImageInfo.Signature = md5.result().toHex().constData();
            ImageInfo.Size = imgSize;
        }
    }
}
Exemplo n.º 2
0
void RectCutCMPT::OnAutoCreateRects(wxCommandEvent& event)
{
	const ee::SprConstPtr& spr = m_stage->GetImage();
	const std::shared_ptr<ee::ImageSymbol>& sym = std::dynamic_pointer_cast<const ee::ImageSymbol>>(spr->GetSymbol());
	assert(sym);
	auto img = ee::ImageDataMgr::Instance()->GetItem(sym->GetFilepath());

	RectMgr& rects = std::dynamic_pointer_cast<RectCutOP>(m_editop)->GetRectMgr();

	m_part_rects.clear();
	std::vector<Rect> pre_rects;
	const std::vector<sm::rect*>& _rects = rects.GetAllRect();
	for (int i = 0, n = _rects.size(); i < n; ++i) {
		const sm::rect& src = *_rects[i];
		m_part_rects.push_back(src);
		Rect dst;
		dst.x = src.xmin;
		dst.y = src.ymin;
		dst.w = src.xmax - src.xmin;
		dst.h = src.ymax - src.ymin;
		dst.is_const = true;
		pre_rects.push_back(dst);
	}
	rects.Clear();

	RegularRectCut cut(img->GetPixelData(), img->GetWidth(), img->GetHeight(), pre_rects);
	cut.AutoCut();

	const std::vector<Rect>& result = cut.GetResult();
	for (int i = 0, n = result.size(); i < n; ++i) {
		int x = result[i].x,
			y = result[i].y,
			w = result[i].w,
			h = result[i].h;
		rects.Insert(sm::rect(sm::vec2(x, y), sm::vec2(x+w, y+h)));
	}

	ee::SetCanvasDirtySJ::Instance()->SetDirty();

	std::string msg = ee::StringHelper::Format("Left: %d, Used: %d", cut.GetLeftArea(), cut.GetUseArea());
	wxMessageBox(msg, wxT("Statics"), wxOK | wxICON_INFORMATION, this);
}
Exemplo n.º 3
0
void RectCutCMPT::OnOutputData(wxCommandEvent& event)
{
	auto op = std::dynamic_pointer_cast<RectCutOP>(m_editop);
	const std::vector<sm::rect*>& rects = op->GetRectMgr().GetAllRect();
	if (rects.empty()) {
		return;
	}

	const ee::SprConstPtr& spr = m_stage->GetImage();
	if (!spr) {
		return;
	}

	const std::shared_ptr<ee::ImageSymbol>& sym = std::dynamic_pointer_cast<const ee::ImageSymbol>>(spr->GetSymbol());
	if (!sym) {
		return;
	}

	ee::Image* image = sym->GetImage();

	std::string img_dir = m_imagePath->GetValue();
	std::string json_dir = m_jsonPath->GetValue();

	
	sm::vec2 center = op->GetCenter();
	if (center == sm::vec2(0, 0)) {
		center.x = image->GetClippedRegion().Width() * 0.5f;
		center.y = image->GetClippedRegion().Height() * 0.5f;
	}

	auto img_data = ee::ImageDataMgr::Instance()->GetItem(sym->GetFilepath());
	assert(img_data->GetFormat() == GPF_RGB || img_data->GetFormat() == GPF_RGBA8);
	int channels = img_data->GetFormat() == GPF_RGB ? 3 : 4;
	pimg::Cropping crop(img_data->GetPixelData(), img_data->GetWidth(), img_data->GetHeight(), channels);

	std::string img_name = ee::FileHelper::GetFilename(image->GetFilepath());
	ecomplex::Symbol* complex_all = new ecomplex::Symbol;
	ecomplex::Symbol* complex_part = new ecomplex::Symbol;
	for (int i = 0, n = rects.size(); i < n; ++i)
	{
		const sm::rect& r = *rects[i];
		if (r.Width() == 0 || r.Height() == 0) {
			continue;
		}

		uint8_t* pixels = crop.Crop(r.xmin, r.ymin, r.xmax, r.ymax);
		sm::vec2 sz = r.Size();

		std::string img_filename = img_dir + "\\" + img_name + "_" + ee::StringHelper::ToString(i) + ".png";
		gimg_export(img_filename.c_str(), pixels, sz.x, sz.y, GPF_RGBA8, true);

		auto& spr = new ee::DummySprite(new ee::DummySymbol(img_filename, sz.x, sz.y));
		sm::vec2 offset = r.Center() - center;
		spr->Translate(offset);
		complex_all->Add(spr);

		for (int j = 0, m = m_part_rects.size(); j < m; ++j) {
			if (m_part_rects[j] == r) {
				complex_part->Add(spr);
				break;
			}
		}
	}

	complex_all->name = img_name;
	complex_part->name = img_name + "_part";

	std::string tag = ee::SymbolFile::Instance()->Tag(s2::SYM_COMPLEX);

	std::string filename_all = json_dir + "\\" + img_name + "_" + tag + ".json";
	ecomplex::FileStorer::Store(filename_all.c_str(), complex_all, json_dir);
	delete complex_all;

	if (!complex_part->GetAllChildren().empty()) {
		std::string filename_part = json_dir + "\\" + img_name + "_part_" + tag + ".json";
		ecomplex::FileStorer::Store(filename_part.c_str(), complex_part, json_dir);
	}
	delete complex_part;

	ee::FinishDialog dlg(this);
	dlg.ShowModal();
}
Exemplo n.º 4
0
CRend_clp renderppmtocrend(CRendDisplay_clp display , int xpos, int ypos, FILE *f, int *sizex, int *sizey) {
    Rd_clp rd = f->rd;
    int sx,sy, depth;
    char buf[128];
    int16_t *ptr;
    int stride;
    int px,py;
    uint8_t *databuffer;
    CRend_clp crend;

    Rd$GetLine(rd, buf, 128);

    if (!strcmp(buf, "P6")) {
	fprintf(stderr,"Unknown image file format; first line is [%s]\n", buf);
	return NULL;
    }
    do Rd$GetLine(rd, buf, 128); while (buf[0] == '#');
    sscanf(buf, "%d %d", &sx, &sy);

    *sizex = sx;
    *sizey = sy;

    crend = CRendDisplay$CreateWindow(display,xpos,ypos,sx,sy);
    CRend$Map(crend);
 

    do Rd$GetLine(rd, buf, 128); while (buf[0] == '#');
    sscanf(buf, "%d", &depth);
	    
    ptr = CRend$GetPixelData(crend, &stride);
    databuffer = Heap$Malloc(Pvs(heap), sx*3);
    
    for (py = 0; py<sy; py++) {
	uint32_t *scrptr;
	uint32_t pack;
	char *bufptr;
	
	Rd$GetChars(rd, databuffer, sx*3);
		
	bufptr = databuffer;
	scrptr = (uint32_t *) (ptr + (stride * py));

	for (px = 0; px<sx; px+=2) {
	    pack = 0;
		    
	    pack = ((*(bufptr++) & 248))<<7; /* 10 - 3 */
	    pack += ((*(bufptr++) & 248))<<2; /* 5 - 3 */
	    pack += ((*(bufptr++) & 248))>>3; /* 0 - 3 */
	    pack += ((*(bufptr++) & 248))<<(23); /* 16 + 10 - 3 */
	    pack += ((*(bufptr++) & 248))<<(18); /* 16 + 5 - 3 */
	    pack += ((*(bufptr++) & 248))<<(13); /* 16 + 0 - 3 */
	    
	    *scrptr = pack;
		    
	    scrptr++;
	}
    }
    Heap$Free(Pvs(heap),databuffer);
    
    CRend$ExposeRectangle(crend,0,0,sx,sy);
    CRend$Flush(crend);
    return crend;

}