void MapRect::ma_drawInactive(const GRect & pm_rect, const GP<GPixmap> & pm) // pm_rect is the rectangle of the pane in screen coordinates // where pm is supposed to go to { if (mapper && pm) { GRect border_rect=gmap_area->get_bound_rect(); mapper->map(border_rect); GRect irect; if (irect.intersect(border_rect, pm_rect)) { // Translate the intersection into the GPixmap's coordinate irect.translate(-pm_rect.xmin, -pm_rect.ymin); // Do hiliting first if (gmap_area->hilite_color!=0xffffffff) { if (gmap_area->hilite_color==0xff000000) { // Do XOR hiliting for(int y=irect.ymin;y<irect.ymax;y++) { GPixel * pix=(*pm)[pm->rows()-1-y]+irect.xmin; for(int x=irect.xmin;x<irect.xmax;x++, pix++) { pix->r^=0xff; pix->g^=0xff; pix->b^=0xff; } } } else { // Do COLOR hiliting int r=(gmap_area->hilite_color & 0xff0000) >> (16+2); int g=(gmap_area->hilite_color & 0xff00) >> (8+2); int b=(gmap_area->hilite_color & 0xff) >> 2; for(int y=irect.ymin;y<irect.ymax;y++) { GPixel * pix=(*pm)[pm->rows()-1-y]+irect.xmin; for(int x=irect.xmin;x<irect.xmax;x++, pix++) { pix->r=((((int) pix->r << 1)+(int) pix->r) >> 2)+r; pix->g=((((int) pix->g << 1)+(int) pix->g) >> 2)+g; pix->b=((((int) pix->b << 1)+(int) pix->b) >> 2)+b; } } } } }
void MapArea::draw(const GRect & bm_rect, const GP<GBitmap> & bm_in, GRect & pm_rect, GP<GPixmap> & pm_out, DRAW_MODE draw_mode) // Draws itself into the specified bitmap. The bm_rect should be // in the pane's coordinates. Since GBitmap may not contain color // information, we will create a color GPixmap patch (pm_out), where we // will actually be drawing. The pm_rect is a rectangle in // pane coordinates where this pm_out should go to. { DEBUG_MSG("MapArea::draw(): Highlighting " << gmap_area->url << ":" << gmap_area->target << "\n"); DEBUG_MAKE_INDENT(3); if (pane) { GRect brect=gmap_area->get_bound_rect(); mapper->map(brect); brect.inflate(3, 3); GRect irect; if (irect.intersect(bm_rect, brect)) { pm_rect=irect; irect.translate(-bm_rect.xmin, -bm_rect.ymin); pm_out=GPixmap::create(*bm_in, GRect(irect.xmin, bm_in->rows()-irect.ymax, irect.width(), irect.height())); if (!isInactiveOutlineMode()) if (draw_mode==DRAW_INACTIVE || draw_mode==DRAW_ACTIVE) ma_drawInactive(pm_rect, pm_out); if (!isActiveOutlineMode()) if (draw_mode==APPLY_ACTIVE || draw_mode==DRAW_ACTIVE) ma_applyActive(pm_rect, pm_out); } } }
void MapArea::updateCache(const GRect & pm_rect, const GP<GPixmap> & pm, GRectMapper * sdoc_mapper) // Takes the passed pixmap and updated the internal cache. // The pixmap should already contain the hyperlink draw in the // INACTIVE state. We will copy it and apply ACTIVE part here. // pm_rect is a rectangle in pane's coordinates where pm is supposed // to go to. sdoc_mapper maps screen coordinates to the coordinates // of the scaled document (see qd_base_paint.cpp) { DEBUG_MSG("MapArea::updateCache(): updating caches\n"); DEBUG_MAKE_INDENT(3); if (!isCacheUsed() || !pm || !pane) return; GRect brect=gmap_area->get_bound_rect(); mapper->map(brect); brect.inflate(3, 3); // To take into account edit controls GRect urect; if (urect.intersect(pm_rect, brect)) { for(GPosition pos=pieces;pos;++pos) { GP<MapPiece> piece=pieces[pos]; GRect prect=*piece; mapper->map(prect); GRect irect; if (irect.intersect(prect, urect)) { if (piece->getOnPixmap().isNull() || piece->getOffPixmap().isNull()) piece->createPixmaps(); QPixmap & on_pix=piece->getOnPixmap(); QPixmap & off_pix=piece->getOffPixmap(); // Now I need to make a copy of the area to be cached. // The problem is that I'll need to draw into the GPixmap // and I don't want to spoil the original. GP<GPixmap> ipix_off; GRect pix_rect=irect; pix_rect.translate(-pm_rect.xmin, -pm_rect.ymin); ipix_off=GPixmap::create(*pm, GRect(pix_rect.xmin, pm->rows()-pix_rect.ymax, pix_rect.width(), pix_rect.height())); GP<GPixmap> ipix_on=GPixmap::create(*ipix_off); // Now ipix_off and ipix_on contains the data, which can be modified. // Draw the map area into them draw(irect, ipix_on, APPLY_ACTIVE); // Dither pix_off and pix_on GRect drect=irect; sdoc_mapper->map(drect); if (qxImager) qxImager->dither(*ipix_on, drect.xmin, drect.ymin); if (qxImager) qxImager->dither(*ipix_off, drect.xmin, drect.ymin); // Now copy the GPixmaps into QPixmaps to be used for caching QDPainter p_off(&off_pix); p_off.drawPixmap(GRect(irect.xmin-prect.xmin, irect.ymin-prect.ymin, irect.width(), irect.height()), ipix_off); p_off.end(); QDPainter p_on(&on_pix); p_on.drawPixmap(GRect(irect.xmin-prect.xmin, irect.ymin-prect.ymin, irect.width(), irect.height()), ipix_on); p_on.end(); } } } }
void JB2Dict::JB2Codec::code_record( int &rectype, const GP<JB2Image> &gjim, JB2Shape *xjshp, JB2Blit *jblt) { GP<GBitmap> bm; GP<GBitmap> cbm; int shapeno = -1; int match; // Code record type code_record_type(rectype); // Pre-coding actions switch(rectype) { case NEW_MARK: case NEW_MARK_LIBRARY_ONLY: case NEW_MARK_IMAGE_ONLY: case MATCHED_REFINE: case MATCHED_REFINE_LIBRARY_ONLY: case MATCHED_REFINE_IMAGE_ONLY: case NON_MARK_DATA: { if(!xjshp) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Shape &jshp=*xjshp; if (!encoding) { jshp.bits = GBitmap::create(); jshp.parent = -1; if (rectype == NON_MARK_DATA) jshp.parent = -2; } bm = jshp.bits; break; } } // Coding actions switch (rectype) { case START_OF_DATA: { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; code_image_size (jim); code_eventual_lossless_refinement (); if (! encoding) init_library(jim); break; } case NEW_MARK: { code_absolute_mark_size (*bm, 4); code_bitmap_directly (*bm); code_relative_location (jblt, bm->rows(), bm->columns() ); break; } case NEW_MARK_LIBRARY_ONLY: { code_absolute_mark_size (*bm, 4); code_bitmap_directly (*bm); break; } case NEW_MARK_IMAGE_ONLY: { code_absolute_mark_size (*bm, 3); code_bitmap_directly (*bm); code_relative_location (jblt, bm->rows(), bm->columns() ); break; } case MATCHED_REFINE: { if(!xjshp || !gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Shape &jshp=*xjshp; JB2Image &jim=*gjim; match = code_match_index (jshp.parent, jim); cbm = jim.get_shape(jshp.parent).bits; LibRect &l = libinfo[match]; code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4); code_bitmap_by_cross_coding (*bm, cbm, match); code_relative_location (jblt, bm->rows(), bm->columns() ); break; } case MATCHED_REFINE_LIBRARY_ONLY: { if(!xjshp||!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; JB2Shape &jshp=*xjshp; match = code_match_index (jshp.parent, jim); cbm = jim.get_shape(jshp.parent).bits; LibRect &l = libinfo[match]; code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4); break; } case MATCHED_REFINE_IMAGE_ONLY: { if(!xjshp||!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; JB2Shape &jshp=*xjshp; match = code_match_index (jshp.parent, jim); cbm = jim.get_shape(jshp.parent).bits; LibRect &l = libinfo[match]; code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4); code_bitmap_by_cross_coding (*bm, cbm, match); code_relative_location (jblt, bm->rows(), bm->columns() ); break; } case MATCHED_COPY: { int temp; if (encoding) temp = jblt->shapeno; if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; match = code_match_index (temp, jim); if (!encoding) jblt->shapeno = temp; bm = jim.get_shape(jblt->shapeno).bits; LibRect &l = libinfo[match]; jblt->left += l.left; jblt->bottom += l.bottom; if (jim.reproduce_old_bug) code_relative_location (jblt, bm->rows(), bm->columns() ); else code_relative_location (jblt, l.top-l.bottom+1, l.right-l.left+1 ); jblt->left -= l.left; jblt->bottom -= l.bottom; break; } case NON_MARK_DATA: { code_absolute_mark_size (*bm, 3); code_bitmap_directly (*bm); code_absolute_location (jblt, bm->rows(), bm->columns() ); break; } case PRESERVED_COMMENT: { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; code_comment(jim.comment); break; } case REQUIRED_DICT_OR_RESET: { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; if (! gotstartrecordp) // Indicates need for a shape dictionary code_inherited_shape_count(jim); else // Reset all numerical contexts to zero reset_numcoder(); break; } case END_OF_DATA: { break; } default: { G_THROW( ERR_MSG("JB2Image.unknown_type") ); } } // Post-coding action if (!encoding) { // add shape to image switch(rectype) { case NEW_MARK: case NEW_MARK_LIBRARY_ONLY: case NEW_MARK_IMAGE_ONLY: case MATCHED_REFINE: case MATCHED_REFINE_LIBRARY_ONLY: case MATCHED_REFINE_IMAGE_ONLY: case NON_MARK_DATA: { if(!xjshp||!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Shape &jshp=*xjshp; shapeno = gjim->add_shape(jshp); shape2lib.touch(shapeno); shape2lib[shapeno] = -1; break; } } // add shape to library switch(rectype) { case NEW_MARK: case NEW_MARK_LIBRARY_ONLY: case MATCHED_REFINE: case MATCHED_REFINE_LIBRARY_ONLY: if(!xjshp) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } add_library(shapeno, *xjshp); break; } // make sure everything is compacted // decompaction will occur automatically on cross-coding bitmaps if (bm) bm->compress(); // add blit to image switch (rectype) { case NEW_MARK: case NEW_MARK_IMAGE_ONLY: case MATCHED_REFINE: case MATCHED_REFINE_IMAGE_ONLY: case NON_MARK_DATA: jblt->shapeno = shapeno; case MATCHED_COPY: if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } gjim->add_blit(* jblt); break; } } }