void BitmapImage::draw(GraphicsContext* gc, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp) { startAnimation(); SkBitmapRef* image = this->nativeImageForCurrentFrame(); if (!image) { // If it's too early we won't have an image yet. return; } // in case we get called with an incomplete bitmap const SkBitmap& bitmap = image->bitmap(); if (bitmap.getPixels() == NULL && bitmap.pixelRef() == NULL) { #ifdef TRACE_SKIPPED_BITMAPS SkDebugf("----- skip bitmapimage: [%d %d] pixels %p pixelref %p\n", bitmap.width(), bitmap.height(), bitmap.getPixels(), bitmap.pixelRef()); #endif return; } SkIRect srcR; SkRect dstR(dstRect); float invScaleX = (float)bitmap.width() / image->origWidth(); float invScaleY = (float)bitmap.height() / image->origHeight(); round_scaled(&srcR, srcRect, invScaleX, invScaleY); if (srcR.isEmpty() || dstR.isEmpty()) { #ifdef TRACE_SKIPPED_BITMAPS SkDebugf("----- skip bitmapimage: [%d %d] src-empty %d dst-empty %d\n", bitmap.width(), bitmap.height(), srcR.isEmpty(), dstR.isEmpty()); #endif return; } gc->platformContext()->drawBitmapRect(bitmap, &srcR, dstR, compositeOp); #ifdef TRACE_SUBSAMPLED_BITMAPS if (bitmap.width() != image->origWidth() || bitmap.height() != image->origHeight()) { SkDebugf("--- BitmapImage::draw [%d %d] orig [%d %d]\n", bitmap.width(), bitmap.height(), image->origWidth(), image->origHeight()); } #endif }
SDL_Surface * CMessage::drawDialogBox(int w, int h, PlayerColor playerColor) { //prepare surface SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); for (int i=0; i<w; i+=background->w)//background { for (int j=0; j<h; j+=background->h) { Rect srcR(0,0,background->w, background->h); Rect dstR(i,j,w,h); CSDL_Ext::blitSurface(background, &srcR, ret, &dstR); } } drawBorder(playerColor, ret, w, h); return ret; }
//-------------------------------------------------------------------- void InterView::Draw(BRect updateRect) { BRect visi(Bounds()); if (curPicture != NULL) { BRect picRect(curPicture->Bounds()); BRect viewRect(visi); if (autoScale) { viewRect.right -= B_V_SCROLL_BAR_WIDTH; viewRect.bottom -= B_H_SCROLL_BAR_HEIGHT; float dx = picRect.right / viewRect.right; float dy = picRect.bottom / viewRect.bottom; if (dx > dy) { float old_height = viewRect.bottom; viewRect.bottom = (picRect.bottom / picRect.right) * viewRect.right; viewRect.OffsetBy(0., old_height/2 - viewRect.bottom/2); FillRect(BRect(0., 0., viewRect.right, viewRect.top-1)); FillRect(BRect(0., viewRect.bottom, viewRect.right, visi.bottom)); zoomFactor = 1./dx; SendZoomFactorModified(); } else { float old_width = viewRect.right; viewRect.right = (picRect.right / picRect.bottom) * viewRect.bottom; viewRect.OffsetBy(old_width/2 - viewRect.right/2, 0.); FillRect(BRect(0., viewRect.top, viewRect.left-1, viewRect.bottom)); FillRect(BRect(viewRect.right+1, viewRect.top, visi.right, viewRect.bottom)); zoomFactor = 1./dy; SendZoomFactorModified(); } DrawBitmap(curPicture, viewRect); } else { if (zoomFactor == 1.) { BPoint pos(viewRect.right/2 - picRect.right/2 - B_V_SCROLL_BAR_WIDTH/2, viewRect.bottom/2 - picRect.bottom/2 - B_H_SCROLL_BAR_HEIGHT/2); if (pos.x < 0.) pos.x = -xOffs; else xOffs = 0.; // pos.x = 0; if (pos.y < 0.) pos.y = -yOffs; else yOffs = 0.; // pos.y = 0; DrawBitmap(curPicture, pos); FillRect(BRect(0., 0., visi.right, pos.y-1)); FillRect(BRect(0., visi.bottom - pos.y - B_H_SCROLL_BAR_HEIGHT + 1, visi.right, visi.bottom)); FillRect(BRect(0., pos.y, pos.x-1, visi.bottom-pos.y)); FillRect(BRect(visi.right-pos.x-B_V_SCROLL_BAR_WIDTH+1, pos.y, visi.right, visi.bottom-pos.y)); } else { picRect.right *= zoomFactor; picRect.bottom *= zoomFactor; BRect srcR(curPicture->Bounds()); BRect dstR(viewRect.right/2 - picRect.right/2 - B_V_SCROLL_BAR_WIDTH/2, viewRect.bottom/2 - picRect.bottom/2 - B_H_SCROLL_BAR_HEIGHT/2, viewRect.right/2 + picRect.right/2 + B_V_SCROLL_BAR_WIDTH/2, viewRect.bottom/2 + picRect.bottom/2 + B_H_SCROLL_BAR_HEIGHT/2); if (dstR.left < 0.) // pic wider than view { dstR.left = 0.; dstR.right = visi.right - B_V_SCROLL_BAR_WIDTH; srcR.left = picRect.left + xOffs/zoomFactor; srcR.right = picRect.left + xOffs/zoomFactor + (visi.right - B_V_SCROLL_BAR_WIDTH)/zoomFactor; } else xOffs = 0.; if (dstR.top < 0.) // pic higher than view { dstR.top = 0.; dstR.bottom = visi.bottom - B_H_SCROLL_BAR_HEIGHT; srcR.top = picRect.top + yOffs/zoomFactor; srcR.bottom = picRect.top + yOffs/zoomFactor + (visi.bottom - B_H_SCROLL_BAR_HEIGHT)/zoomFactor; } else yOffs = 0.; DrawBitmap(curPicture, srcR, dstR); FillRect(BRect(0., 0., visi.right, dstR.top-1)); // top FillRect(BRect(0., dstR.bottom+1, visi.right, visi.bottom)); // bottom FillRect(BRect(0., dstR.top, dstR.left-1, dstR.bottom)); // left FillRect(BRect(dstR.right+1, dstR.top, visi.right, dstR.bottom)); // right } } } else FillRect(Bounds()); }
int Test_Speed() { const int Loop = 100; //Frame IFrame = ImageReader("D:\\Test Images\\Haze\\20150202_132636.jpg"); Frame IFrame = ImageReader("D:\\Test Images\\BM3D\\_DSC8263.1noised.png"); Frame PFrame(IFrame, false); const Plane &srcR = IFrame.R(); Plane dstR(srcR, false); for (int l = 0; l < Loop; l++) { #if defined(Convolution_) Convolution3V(IFrame, 1, 2, 1); //Convolution3(IFrame, 1, 2, 1, 2, 4, 2, 1, 2, 1); #elif defined(EdgeDetect_) EdgeDetect(IFrame, EdgeKernel::Laplace2); #elif defined(Gaussian_) Gaussian2D filter; filter(IFrame); #elif defined(CUDA_Gaussian_) CUDA_Gaussian2D filter; filter(IFrame); #elif defined(Bilateral_) Bilateral2D_Para para; para.sigmaS = 3.0; para.sigmaR = 0.08; para.algorithm = 1; Bilateral2D_Data bldata(IFrame, para); Bilateral2D(IFrame, bldata); #elif defined(Transpose_) Transpose(PFrame, IFrame); #elif defined(CUDA_Transpose_) CUDA_Transpose(PFrame, IFrame); #elif defined(Specular_Highlight_Removal_) Specular_Highlight_Removal(IFrame); #elif defined(Retinex_MSRCP_) Retinex_MSRCP filter; filter(IFrame); #elif defined(Retinex_MSRCR_) Retinex_MSRCR filter; filter(IFrame); #elif defined(Retinex_MSRCR_GIMP_) Retinex_MSRCR_GIMP filter; filter(IFrame); #elif defined(Histogram_Equalization_) Histogram_Equalization(IFrame, 1.0, false); #elif defined(NLMeans_) NLMeans filter; filter(IFrame); #elif defined(BM3D_) BM3D filter; filter(IFrame); #elif defined(Haze_Removal_) Haze_Removal_Retinex filter; filter(IFrame); #elif defined(CUDA_Haze_Removal_) CUDA_Haze_Removal_Retinex filter; filter(IFrame); #else const PCType pzero = 0; const PCType pcount = dstR.PixelCount(); const PCType height = dstR.Height(); const PCType width = dstR.Width(); const PCType stride = dstR.Stride(); #endif } return 0; }
void CMessage::drawBorder(PlayerColor playerColor, SDL_Surface * ret, int w, int h, int x, int y) { std::vector<SDL_Surface *> &box = piecesOfBox[playerColor.getNum()]; // Note: this code assumes that the corner dimensions are all the same. // Horizontal borders int start_x = x + box[0]->w; const int stop_x = x + w - box[1]->w; const int bottom_y = y+h-box[7]->h+1; while (start_x < stop_x) { int cur_w = stop_x - start_x; if (cur_w > box[6]->w) cur_w = box[6]->w; // Top border Rect srcR(0, 0, cur_w, box[6]->h); Rect dstR(start_x, y, 0, 0); CSDL_Ext::blitSurface(box[6], &srcR, ret, &dstR); // Bottom border dstR.y = bottom_y; CSDL_Ext::blitSurface(box[7], &srcR, ret, &dstR); start_x += cur_w; } // Vertical borders int start_y = y + box[0]->h; const int stop_y = y + h - box[2]->h+1; const int right_x = x+w-box[5]->w; while (start_y < stop_y) { int cur_h = stop_y - start_y; if (cur_h > box[4]->h) cur_h = box[4]->h; // Left border Rect srcR(0, 0, box[4]->w, cur_h); Rect dstR(x, start_y, 0, 0); CSDL_Ext::blitSurface(box[4], &srcR, ret, &dstR); // Right border dstR.x = right_x; CSDL_Ext::blitSurface(box[5], &srcR, ret, &dstR); start_y += cur_h; } //corners Rect dstR(x, y, box[0]->w, box[0]->h); CSDL_Ext::blitSurface(box[0], nullptr, ret, &dstR); dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h); CSDL_Ext::blitSurface(box[1], nullptr, ret, &dstR); dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h); CSDL_Ext::blitSurface(box[2], nullptr, ret, &dstR); dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h); CSDL_Ext::blitSurface(box[3], nullptr, ret, &dstR); }