const char *Circle::toXmlElement() { char *element = new char[MAX_SHAPE_LEN]; element[0] = '\0'; strcat(element, "<"); strcat(element, Circle::simpleClassName); strcat(element, " "); /* Write properties */ strcat(element, toPropertyValue("radius=\"", radius)); strcat(element, " "); strcat(element, toPropertyValue("cx=\"", cx)); strcat(element, " "); strcat(element, toPropertyValue("cy=\"", cy)); strcat(element, " "); strcat(element, toPropertyValue("stroke-width=\"", getStrokeWidth())); strcat(element, " "); strcat(element, toPropertyValue("stroke=\"", getStroke())); strcat(element, " "); strcat(element, toPropertyValue("fill=\"", getFill())); strcat(element, "/>"); return element; }
void Sketch::sortWithOrder(std::vector<int> sorted_stroke_ids) { std::vector<Stroke *> tmp; for (unsigned int i = 0; i <sorted_stroke_ids.size(); ++i) { tmp.push_back(getStroke(sorted_stroke_ids[i])); } strokes_ = tmp; }
double CQIllustratorShape:: getStrokeWidth() const { const CMatrix2D &m = getFlatMatrix(); double w = getStroke().getWidth(); CVector2D w1 = m*CVector2D(w, w); return w1.length(); }
int main() { const char *filename = "1.jpg"; IplImage *pStroke = getStroke(filename); IplImage *pTone = getTone(filename); Image stroke(pStroke); Image tone(pTone); cvShowImage("stroke", pStroke); cvShowImage("tone", pTone); //合并stroke与tone两张图 for (int i = 0; i < stroke.getH(); i++) for (int j = 0; j < stroke.getW(); j++) stroke[i][j] = (uchar) sqrt(stroke[i][j] * tone[i][j]); cvShowImage("result", pStroke); cvWaitKey(); cvDestroyAllWindows(); cvReleaseImage(&pStroke); cvReleaseImage(&pTone); }
/** ------------------------------------------------------------------------ ** * \brief Get an ISF structure from a stream * * * * \param pISF where we construct the ISF structure * * \param streamInfo data structure where informations about the stream are * * stored * * \param pGetUChar function used to get an unsigned char from a stream. * * * * \returns the error code given while processing * ** ------------------------------------------------------------------------ **/ int getISF ( ISF_t ** pISF, void * streamInfo, int (*pGetUChar) (void *, INT64 *, unsigned char*)) { int err = OK; /* the error code */ INT64 tag; /* number of the current tag */ decodeISF_t * pDecISF; /* we init the ISF structure */ *pISF = (ISF_t *) malloc (sizeof(ISF_t)); if (!*pISF) return OUT_OF_MEMORY; pDecISF = (decodeISF_t *) malloc(sizeof(decodeISF_t)); if (!pDecISF) { free(*pISF); pISF = NULL; return OUT_OF_MEMORY; } pDecISF->streamInfo = streamInfo; pDecISF->getUChar = pGetUChar; pDecISF->ISF = *pISF; pDecISF->lastStroke = pDecISF->lastHighlighterStroke = &((*pISF)->strokes); (*pISF)->strokes = NULL; pDecISF->gotStylusPressure = 0; /* Add default Transform */ err = createTransform(&pDecISF->transforms); if (err != OK) return err; pDecISF->curTransform = pDecISF->transforms; pDecISF->lastTransform = &pDecISF->transforms; /* Add default drawing attributes */ err = createDrawingAttrs(&(*pISF)->drawAttrs); if (err != OK) return err; pDecISF->curDrawAttrs = (*pISF)->drawAttrs; pDecISF->lastDrawAttrs = &(*pISF)->drawAttrs; (*pISF)->width = (*pISF)->height = 0; (*pISF)->xOrigin = (*pISF)->yOrigin = INT64_MAX; (*pISF)->xEnd = (*pISF)->yEnd = INT64_MIN; (*pISF)->penWidthMax = (*pISF)->penHeightMax = 0; /* Checking the header of that file */ err = checkHeader (pDecISF); while ( err == OK && pDecISF->bytesRead < pDecISF->fileSize ) { err = readMBUINT(pDecISF, &tag); switch (tag) { case INK_SPACE_RECT: LOG(stderr,"\nINK_SPACE_RECT\n"); /* TODO: nothing ?? */ break; case GUID_TABLE: LOG(stdout,"\nGUID_TABLE\n"); err = getGUIDTable (pDecISF); break; case DRAW_ATTRS_TABLE: LOG(stdout,"\nDRAW_ATTRS_TABLE\n"); err = getDrawAttrsTable (pDecISF); break; case DRAW_ATTRS_BLOCK: LOG(stdout,"\nDRAW_ATTRS_BLOCK\n"); err = getDrawAttrsBlock (pDecISF); break; case STROKE_DESC_TABLE: LOG(stderr,"\nSTROKE_DESC_TABLE\n"); /* TODO */ break; case STROKE_DESC_BLOCK: LOG(stdout,"\nSTROKE_DESC_BLOCK\n"); err = getStrokeDescBlock (pDecISF); break; case BUTTONS: LOG(stderr,"\nBUTTONS\n"); /* TODO */ break; case NO_X: LOG(stderr,"\nNO_X\n"); /* TODO */ break; case NO_Y: LOG(stderr,"\nNO_Y\n"); /* TODO */ break; case DIDX: LOG(stdout,"\nDIDX\n"); err = getDIDX (pDecISF); break; case STROKE: LOG(stdout,"\nSTROKE\n"); err = getStroke (pDecISF); break; case STROKE_PROPERTY_LIST: LOG(stderr,"\nSTROKE_PROPERTY_LIST\n"); /* TODO */ break; case POINT_PROPERTY: LOG(stderr,"\nPOINT_PROPERTY\n"); /* TODO */ break; case SIDX: LOG(stderr,"\nSIDX\n"); /* TODO */ break; case COMPRESSION_HEADER: LOG(stderr,"\nCOMPRESSION_HEADER\n"); /* TODO */ break; case TRANSFORM_TABLE: LOG(stdout,"\nTRANSFORM_TABLE\n"); err = getTransformTable (pDecISF); break; case TRANSFORM: LOG(stdout,"\nTRANSFORM\n"); err = getTransform (pDecISF); break; case TRANSFORM_ISOTROPIC_SCALE: LOG(stdout,"\nTRANSFORM_ISOTROPIC_SCALE\n"); err = getTransformIsotropicScale (pDecISF); break; case TRANSFORM_ANISOTROPIC_SCALE: LOG(stdout,"\nTRANSFORM_ANISOTROPIC_SCALE\n"); err = getTransformAnisotropicScale (pDecISF); break; case TRANSFORM_ROTATE: LOG(stdout,"\nTRANSFORM_ROTATE\n"); err = getTransformRotate (pDecISF); break; case TRANSFORM_TRANSLATE: LOG(stdout,"\nTRANSFORM_TRANSLATE\n"); err = getTransformTranslate (pDecISF); break; case TRANSFORM_SCALE_AND_TRANSLATE: LOG(stdout,"\nTRANSFORM_SCALE_AND_TRANSLATE\n"); err = getTransformScaleAndTranslate (pDecISF); break; case TRANSFORM_QUAD: LOG(stderr,"\nTRANSFORM_QUAD\n"); /* TODO */ break; case TIDX: LOG(stdout,"\nTIDX\n"); err = getTIDX (pDecISF); break; case METRIC_TABLE: LOG(stderr,"\nMETRIC_TABLE\n"); /* TODO */ break; case METRIC_BLOCK: LOG(stdout,"\nMETRIC_BLOCK\n"); err = getMetricBlock (pDecISF); break; case MIDX: LOG(stderr,"\nMIDX\n"); /* TODO */ break; case MANTISSA: LOG(stderr,"\nMANTISSA\n"); /* TODO */ break; case PERSISTENT_FORMAT: LOG(stdout,"\nPERSISTENT_FORMAT\n"); err = getPersistentFormat (pDecISF); break; case HIMETRIC_SIZE: LOG(stdout,"\nHIMETRIC_SIZE\n"); err = getHimetricSize (pDecISF); break; case STROKE_IDS: LOG(stdout,"\nSTROKE_IDS\n"); err = getStrokeIds (pDecISF); break; case 31: LOG(stdout,"\nTAG_31\n"); err = getUnknownTag (pDecISF); break; default: if (tag >= 100 && tag <= pDecISF->guidIdMax) { /* There's a GUID for that tag */ LOG(stdout,"\nGUID_%lld\n",tag); err = getProperty (pDecISF, tag); } else { LOG(stderr,"/!\\[MAIN] Oops, wrong flag found: %lld\n", tag); } } } /* pDecISF is no longer needed : decoding is finished */ freeDecodeISF(pDecISF); return err; }
void VectorBrushProp::draw(const TVectorRenderData &rd) { //Ensure that the stroke overlaps our clipping rect if (rd.m_clippingRect != TRect() && !rd.m_is3dView && !convert(rd.m_aff * m_stroke->getBBox()).overlaps(rd.m_clippingRect)) return; TPaletteP palette(m_brush->getPalette()); if (!palette) return; static TOutlineUtil::OutlineParameter param; //unused, but requested //Build a solid color style to draw each m_vi's stroke with. TSolidColorStyle colorStyle; //Push the specified rd affine before drawing glPushMatrix(); tglMultMatrix(rd.m_aff); //1. If necessary, build the outlines double currentPixelSize = sqrt(tglGetPixelSize2()); bool differentPixelSize = !isAlmostZero(currentPixelSize - m_pixelSize, 1e-5); m_pixelSize = currentPixelSize; int i, viRegionsCount = m_brush->getRegionCount(), viStrokesCount = m_brush->getStrokeCount(); if (differentPixelSize || m_strokeChanged) { m_strokeChanged = false; //1a. First, the regions m_regionOutlines.resize(viRegionsCount); for (i = 0; i < viRegionsCount; ++i) { TRegionOutline &outline = m_regionOutlines[i]; const TRegion *brushRegion = m_brush->getRegion(i); //Build the outline outline.clear(); TOutlineUtil::makeOutline(*getStroke(), *brushRegion, m_brushBox, outline); } //1b. Then, the strokes m_strokeOutlines.resize(viStrokesCount); for (i = 0; i < viStrokesCount; ++i) { TStrokeOutline &outline = m_strokeOutlines[i]; const TStroke *brushStroke = m_brush->getStroke(i); outline.getArray().clear(); TOutlineUtil::makeOutline(*getStroke(), *brushStroke, m_brushBox, outline, param); } } //2. Draw the outlines UINT s, t, r, strokesCount = m_brush->getStrokeCount(), regionCount = m_brush->getRegionCount(); for (s = 0; s < strokesCount; s = t) //Each cycle draws a group { //A vector image stores group strokes with consecutive indices. //2a. First, draw regions in the strokeIdx-th stroke's group for (r = 0; r < regionCount; ++r) { if (m_brush->sameGroupStrokeAndRegion(s, r)) { const TRegion *brushRegion = m_brush->getRegion(r); const TColorStyle *brushStyle = palette->getStyle(brushRegion->getStyle()); assert(brushStyle); //Draw the outline colorStyle.setMainColor(brushStyle->getMainColor()); colorStyle.drawRegion(0, false, m_regionOutlines[r]); } } //2b. Then, draw all strokes in strokeIdx-th stroke's group for (t = s; t < strokesCount && m_brush->sameGroup(s, t); ++t) { const TStroke *brushStroke = m_brush->getStroke(t); const TColorStyle *brushStyle = palette->getStyle(brushStroke->getStyle()); if (!brushStyle) continue; colorStyle.setMainColor(brushStyle->getMainColor()); colorStyle.drawStroke(0, &m_strokeOutlines[t], brushStroke); //brushStroke unused but requested } } glPopMatrix(); }
void TSimpleStrokeProp::draw(TFlash &flash) { getColorStyle()->drawStroke(flash, getStroke()); }
void OutlineStrokeProp::draw(TFlash &flash) { m_colorStyle->drawStroke(flash, getStroke()); }
void TVectorImagePatternStrokeProp::draw(TFlash &flash) { getColorStyle()->drawStroke(flash, getStroke()); }
std::string CQIllustratorShape:: getSVGStroke() const { std::string str = "style=\""; const CQIllustratorShapeStroke &stroke = getStroke(); const CRGBA &scolor = stroke.getColor(); double sopacity = stroke.getOpacity(); double width = getStrokeWidth(); const CLineDash &dash = stroke.getLineDash(); CLineCapType cap = stroke.getLineCap(); CLineJoinType join = stroke.getLineJoin(); if (sopacity > 0.0) { str += CStrUtil::strprintf("stroke: rgb(%d,%d,%d);", scolor.getRedI(), scolor.getGreenI(), scolor.getBlueI()); if (sopacity < 1.0) str += CStrUtil::strprintf(" stroke-opacity: %g;", sopacity); } else str += "stroke: none;"; if (width != 1.0) str += CStrUtil::strprintf(" stroke-width: %g;", width); if (! dash.isSolid()) str += CStrUtil::strprintf("stroke-dasharray: %s", dash.toString().c_str()); if (cap == LINE_CAP_TYPE_ROUND) str += CStrUtil::strprintf(" stroke-linecap: round;"); else if (cap == LINE_CAP_TYPE_SQUARE) str += CStrUtil::strprintf(" stroke-linecap: square;"); if (join == LINE_JOIN_TYPE_ROUND) str += CStrUtil::strprintf(" stroke-linejoin: round;"); else if (join == LINE_JOIN_TYPE_BEVEL) str += CStrUtil::strprintf(" stroke-linejoin: bevel;"); const CQIllustratorShapeFill &fill = getFill(); if (fill.hasGradient()) { // TODO } else { const CRGBA &fcolor = fill.getColor(); double fopacity = fill.getOpacity(); if (fopacity > 0.0) { str += CStrUtil::strprintf(" fill: rgb(%d,%d,%d);", fcolor.getRedI(), fcolor.getGreenI(), fcolor.getBlueI()); if (fopacity < 1.0) str += CStrUtil::strprintf(" fill-opacity: %g;", fopacity); } else str += "fill: none;"; } str += "\""; return str; }
void CQIllustratorShape:: setStrokeOpacity(double opacity) { getStroke().setOpacity(opacity); }
void CQIllustratorShape:: setStrokeColor(const CRGBA &rgba) { getStroke().setColor(rgba); }
void Circle::print() { std::cout << "circle " << cx << " " << cy << " " << getFill() << " " << getStroke() << " " << getStrokeWidth() << '\n'; }
Stroke* Sketch::getCurrentStroke() { return getStroke(cur_stroke_id_); }