void mos6530_base_t::device_reset() { m_pa_out = 0xff; m_pa_ddr = 0; m_pb_out = 0xff; // a7800 One-On-One Basketball (1on1u) needs this or you can't start a game, it doesn't initialize it. (see MT6060) m_pb_ddr = 0; m_ie_timer = false; m_irq_timer = false; m_ie_edge = false; m_irq_edge = false; m_pa7_dir = 0; update_pa(); update_pb(); update_irq(); edge_detect(); m_timer = 0xff; m_prescale = 1024; if (cur_live.state != IDLE) { live_abort(); } live_start(); live_run(); }
void mos6530_base_t::device_reset() { m_pa_out = 0; m_pa_ddr = 0; m_pb_out = 0; m_pb_ddr = 0; m_ie_timer = false; m_irq_timer = false; m_ie_edge = false; m_irq_edge = false; m_pa7_dir = 0; update_pa(); update_pb(); update_irq(); edge_detect(); m_timer = 0xff; m_prescale = 1024; if (cur_live.state != IDLE) { live_abort(); } live_start(); live_run(); }
QImage edge_detector::detectEdgeImage(const QImage image, int kernel) { QImage destImage = QImage( image); QRect rect = image.rect(); QColor qc; int H = rect.height(); int W = rect.width(); int **a; qreal gradient, gangle; int r, g, b; int maxg(0); for (int y=0; y<H; y++) // y=1; y<H-1; { for (int x=0; x<W; x++) // x=1; x<W-1; { a = get_neighbor_pixels(image, x, y, 1, true); edge_detect(a, kernel, &gradient, &gangle); deleteArray(a, 3); //size of array allocated by get_neighbor_pixels is 3x3, 3 = (range=1)*2+1 if ((gangle >= -22.5 && gangle < 22.5) || (gangle >= 157.5 || gangle < -157.5)) { r = 0; g = 0; b = 255; } else if ((gangle >= 22.5 && gangle < 67.5) || (gangle <= -112.5 && gangle > -157.5)) { r = 0; g = 255; b = 0; } else if ((gangle >= 67.5 && gangle < 112.5) || (gangle <= -67.5 && gangle > -112.5)) { r = 255; g = 255; b = 0; } else if ((gangle >= 112.5 && gangle < 157.5) || (gangle <= -22.5 && gangle > -67.5)) { r = 255; g = 0; b = 0; } if (gradient > maxg) maxg = gradient; qc.setRgb((int)gradient & r, (int)gradient & g, (int)gradient & b); destImage.setPixel( x, y, qc.rgba()); } } //printf("gangle = %f, maxg = %d\n", gangle, maxg); return destImage; }
int GP_FilterEdgePrewitt(const GP_Context *src, GP_Context **E, GP_Context **Phi, GP_ProgressCallback *callback) { GP_DEBUG(1, "Prewitt edge detection image %ux%u", src->w, src->h); return edge_detect(src, E, Phi, 1, callback); }
void roberts_cross(unsigned char dst[], unsigned char src[], int h, int s, int n_chans) { int kernel[] = {1, 0, 0, -1}; edge_detect(2, kernel, dst, src, h, s, n_chans); }
void sobel(unsigned char dst[], unsigned char src[], int h, int s, int n_chans) { int kernel[] = {-1, 0, 1, -2, 0, 2, -1, 0, 1}; edge_detect(3, kernel, dst, src, h, s, n_chans); }
void mos6530_base_t::pa_w(int bit, int state) { if (LOG) logerror("%s %s %s '%s' Port A Data Bit %u State %u\n", machine().time().as_string(), machine().describe_context(), name(), tag(), bit, state); m_pa_in &= ~(1 << bit); m_pa_in |= (state << bit); edge_detect(); }
void OFVideoGrabberApp::update(){ unsigned char *buffer = (unsigned char*)malloc(camWidth*camHeight); ofBackground(80, 80, 80); videoGrabber.grabFrame(); if(videoGrabber.isFrameNew()){ unsigned char* pixels = videoGrabber.getPixels(); convert_to_greyscale(pixels, camWidth, camHeight, buffer); edge_detect(buffer, camWidth, camHeight, filterBuffer); filteredTexture.loadData(filterBuffer, camWidth, camHeight, GL_LUMINANCE); } free(buffer); }
/* * Apply sobel operator. */ static int sobel(const GP_Context *src, GP_Context *dx, GP_Context *dy, GP_ProgressCallback *callback) { float dx_kern[] = { -1, 0, 1, -2, 0, 2, -1, 0, 1, }; GP_ConvolutionParams dx_conv = { .src = src, .x_src = 0, .y_src = 0, .w_src = src->w, .h_src = src->h, .dst = dx, .x_dst = 0, .y_dst = 0, .kernel = dx_kern, .kw = 3, .kh = 3, .kern_div = 1, .callback = callback, }; if (GP_FilterConvolution_Raw(&dx_conv)) return 1; float dy_kern[] = { -1, -2, -1, 0, 0, 0, 1, 2, 1, }; GP_ConvolutionParams dy_conv = { .src = src, .x_src = 0, .y_src = 0, .w_src = src->w, .h_src = src->h, .dst = dy, .x_dst = 0, .y_dst = 0, .kernel = dy_kern, .kw = 3, .kh = 3, .kern_div = 1, .callback = callback, }; if (GP_FilterConvolution_Raw(&dy_conv)) return 1; return 0; } static int edge_detect(const GP_Context *src, GP_Context **E, GP_Context **Phi, int type, GP_ProgressCallback *callback) { //TODO GP_ASSERT(src->pixel_type == GP_PIXEL_RGB888); GP_Context *dx, *dy; dx = GP_ContextCopy(src, 0); dy = GP_ContextCopy(src, 0); if (dx == NULL || dy == NULL) goto err0; switch (type) { case 0: if (sobel(src, dx, dy, callback)) goto err0; break; case 1: if (prewitt(src, dx, dy, callback)) goto err0; break; default: goto err0; } uint32_t i, j; for (i = 0; i < src->w; i++) { for (j = 0; j < src->h; j++) { GP_Pixel pix_x = GP_GetPixel_Raw_24BPP(dx, i, j); GP_Pixel pix_y = GP_GetPixel_Raw_24BPP(dy, i, j); int Rx, Gx, Bx; int Ry, Gy, By; int RE, GE, BE; int RPhi, GPhi, BPhi; Rx = GP_Pixel_GET_R_RGB888(pix_x); Gx = GP_Pixel_GET_G_RGB888(pix_x); Bx = GP_Pixel_GET_B_RGB888(pix_x); Ry = GP_Pixel_GET_R_RGB888(pix_y); Gy = GP_Pixel_GET_G_RGB888(pix_y); By = GP_Pixel_GET_B_RGB888(pix_y); RE = sqrt(Rx*Rx + Ry*Ry) + 0.5; GE = sqrt(Gx*Gx + Gy*Gy) + 0.5; BE = sqrt(Bx*Bx + By*By) + 0.5; GP_PutPixel_Raw_24BPP(dx, i, j, GP_Pixel_CREATE_RGB888(RE, GE, BE)); if (Rx != 0 && Ry != 0) RPhi = ((atan2(Rx, Ry) + M_PI) * 255)/(2*M_PI); else RPhi = 0; if (Gx != 0 && Gy != 0) GPhi = ((atan2(Gx, Gy) + M_PI) * 255)/(2*M_PI); else GPhi = 0; if (Bx != 0 && By != 0) BPhi = ((atan2(Bx, By) + M_PI) * 255)/(2*M_PI); else BPhi = 0; GP_PutPixel_Raw_24BPP(dy, i, j, GP_Pixel_CREATE_RGB888(RPhi, GPhi, BPhi)); } } if (Phi != NULL) *Phi = dy; else GP_ContextFree(dy); if (E != NULL) *E = dx; else GP_ContextFree(dx); return 0; err0: GP_ContextFree(dx); GP_ContextFree(dy); return 1; } int GP_FilterEdgeSobel(const GP_Context *src, GP_Context **E, GP_Context **Phi, GP_ProgressCallback *callback) { GP_DEBUG(1, "Sobel edge detection image %ux%u", src->w, src->h); return edge_detect(src, E, Phi, 0, callback); }
static void edge_preview_update (GimpPreview *preview) { /* drawable */ GimpDrawable *drawable; glong bytes; gint alpha; gboolean has_alpha; /* preview */ guchar *src = NULL; /* Buffer to hold source image */ guchar *render_buffer = NULL; /* Buffer to hold rendered image */ guchar *dest; gint width; /* Width of preview widget */ gint height; /* Height of preview widget */ gint x1; /* Upper-left X of preview */ gint y1; /* Upper-left Y of preview */ GimpPixelRgn srcPR; /* Pixel regions */ /* algorithm */ gint x, y; /* Get drawable info */ drawable = gimp_drawable_preview_get_drawable (GIMP_DRAWABLE_PREVIEW (preview)); bytes = gimp_drawable_bpp (drawable->drawable_id); alpha = bytes; has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); if (has_alpha) alpha--; /* * Setup for filter... */ gimp_preview_get_position (preview, &x1, &y1); gimp_preview_get_size (preview, &width, &height); /* initialize pixel regions */ gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, width, height, FALSE, FALSE); src = g_new (guchar, width * height * bytes); render_buffer = g_new (guchar, width * height * bytes); /* render image */ gimp_pixel_rgn_get_rect(&srcPR, src, x1, y1, width, height); dest = render_buffer; /* render algorithm */ for (y = 0 ; y < height ; y++) for (x = 0 ; x < width ; x++) { gint chan; for (chan = 0; chan < alpha; chan++) { guchar kernel[9]; #define SRC(X,Y) src[bytes * (CLAMP((X), 0, width-1) + \ width * CLAMP((Y), 0, height-1)) + chan] kernel[0] = SRC (x - 1, y - 1); kernel[1] = SRC (x - 1, y ); kernel[2] = SRC (x - 1, y + 1); kernel[3] = SRC (x , y - 1); kernel[4] = SRC (x , y ); kernel[5] = SRC (x , y + 1); kernel[6] = SRC (x + 1, y - 1); kernel[7] = SRC (x + 1, y ); kernel[8] = SRC (x + 1, y + 1); #undef SRC dest[chan] = edge_detect (kernel); } if (has_alpha) dest[alpha] = src[bytes * (x + width * y) + alpha]; dest += bytes; } /* * Draw the preview image on the screen... */ gimp_preview_draw_buffer (preview, render_buffer, width * bytes); g_free (render_buffer); g_free (src); }
static void edge (GimpDrawable *drawable) { GimpPixelRgn src_rgn, dest_rgn; gpointer pr; GimpPixelFetcher *pft; guchar *srcrow, *src; guchar *destrow, *dest; guchar pix00[4], pix01[4], pix02[4]; guchar pix10[4], pix11[4], pix12[4]; guchar pix20[4], pix21[4], pix22[4]; glong width, height; gint alpha; gboolean has_alpha; gint chan; gint x, y; gint x1, y1, x2, y2; gint maxval; gint cur_progress; gint max_progress; gdouble per_progress; if (evals.amount < 1.0) evals.amount = 1.0; pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_pixel_fetcher_set_edge_mode (pft, evals.wrapmode); gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); width = gimp_drawable_width (drawable->drawable_id); height = gimp_drawable_height (drawable->drawable_id); alpha = gimp_drawable_bpp (drawable->drawable_id); has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); if (has_alpha) alpha--; maxval = 255; cur_progress = 0; per_progress = 0.0; max_progress = (x2 - x1) * (y2 - y1) / 100; gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, x2-x1, y2-y1, FALSE, FALSE); gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, x2-x1, y2-y1, TRUE, TRUE); for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn); pr != NULL; pr = gimp_pixel_rgns_process (pr)) { srcrow = src_rgn.data; destrow = dest_rgn.data; for (y = dest_rgn.y; y < (dest_rgn.y + dest_rgn.h); y++, srcrow += src_rgn.rowstride, destrow += dest_rgn.rowstride) { src = srcrow; dest = destrow; for (x = dest_rgn.x; x < (dest_rgn.x + dest_rgn.w); x++, src += src_rgn.bpp, dest += dest_rgn.bpp) { if (dest_rgn.x < x && x < dest_rgn.x + dest_rgn.w - 2 && dest_rgn.y < y && y < dest_rgn.y + dest_rgn.h - 2) { /* * 3x3 kernel is inside of the tile -- do fast * version */ for (chan = 0; chan < alpha; chan++) { /* get the 3x3 kernel into a guchar array, * and send it to edge_detect */ guchar kernel[9]; gint i,j; #define PIX(X,Y) src[ (Y-1)*(int)src_rgn.rowstride + (X-1)*(int)src_rgn.bpp + chan ] /* make convolution */ for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) kernel[3*i + j] = PIX(i,j); #undef PIX dest[chan] = edge_detect (kernel); } } else { /* * The kernel is not inside of the tile -- do slow * version */ gimp_pixel_fetcher_get_pixel (pft, x-1, y-1, pix00); gimp_pixel_fetcher_get_pixel (pft, x , y-1, pix10); gimp_pixel_fetcher_get_pixel (pft, x+1, y-1, pix20); gimp_pixel_fetcher_get_pixel (pft, x-1, y , pix01); gimp_pixel_fetcher_get_pixel (pft, x , y , pix11); gimp_pixel_fetcher_get_pixel (pft, x+1, y , pix21); gimp_pixel_fetcher_get_pixel (pft, x-1, y+1, pix02); gimp_pixel_fetcher_get_pixel (pft, x , y+1, pix12); gimp_pixel_fetcher_get_pixel (pft, x+1, y+1, pix22); for (chan = 0; chan < alpha; chan++) { guchar kernel[9]; kernel[0] = pix00[chan]; kernel[1] = pix01[chan]; kernel[2] = pix02[chan]; kernel[3] = pix10[chan]; kernel[4] = pix11[chan]; kernel[5] = pix12[chan]; kernel[6] = pix20[chan]; kernel[7] = pix21[chan]; kernel[8] = pix22[chan]; dest[chan] = edge_detect (kernel); } } if (has_alpha) dest[alpha] = src[alpha]; } } cur_progress += dest_rgn.w * dest_rgn.h; if (cur_progress > max_progress) { cur_progress = cur_progress - max_progress; per_progress = per_progress + 0.01; gimp_progress_update (per_progress); } } gimp_progress_update (1.0); gimp_pixel_fetcher_destroy (pft); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1)); }
void EdgedetectDialog::log_thrChanged(int thr) { this->log_thr = thr * log_thr_step; edge_detect(); }
void EdgedetectDialog::log_deltaChanged(int delta) { this->log_delta = delta * log_delta_step; edge_detect(); }
void EdgedetectDialog::log_scaleChanged(int scale) { this->log_scale = scale * log_scale_step; edge_detect(); }
void EdgedetectDialog::log_ksizeChanged(int ksize) { this->log_ksize = 1 + ksize * log_ksize_step; edge_detect(); }
JNIEXPORT bool JNICALL Java_com_example_helloandroidcamera2_JNIUtils_edgeDetect( JNIEnv *env, jobject obj, jint srcWidth, jint srcHeight, jobject srcLumaByteBuffer, jint srcLumaRowStrideBytes, jobject dstSurface) { uint8_t *srcLumaPtr = reinterpret_cast<uint8_t *>( env->GetDirectBufferAddress(srcLumaByteBuffer)); if (srcLumaPtr == NULL) { return false; } ANativeWindow *win = ANativeWindow_fromSurface(env, dstSurface); ANativeWindow_acquire(win); ANativeWindow_Buffer buf; if (int err = ANativeWindow_lock(win, &buf, NULL)) { LOGE("ANativeWindow_lock failed with error code %d\n", err); ANativeWindow_release(win); return false; } ANativeWindow_setBuffersGeometry(win, srcWidth, srcHeight, 0 /*format unchanged*/); uint8_t *dstLumaPtr = reinterpret_cast<uint8_t *>(buf.bits); if (dstLumaPtr == NULL) { ANativeWindow_unlockAndPost(win); ANativeWindow_release(win); return false; } if (buf.format != IMAGE_FORMAT_YV12) { LOGE("ANativeWindow buffer locked but its format was not YV12."); ANativeWindow_unlockAndPost(win); ANativeWindow_release(win); return false; } if (!checkBufferSizesMatch(srcWidth, srcHeight, &buf)) { LOGE("ANativeWindow buffer locked but its size was %d x %d, expected " "%d x %d", buf.width, buf.height, srcWidth, srcHeight); ANativeWindow_unlockAndPost(win); ANativeWindow_release(win); return false; } uint32_t dstLumaSizeBytes = buf.stride * buf.height; uint32_t dstChromaRowStrideBytes = ALIGN(buf.stride / 2, 16); // Size of one chroma plane. uint32_t dstChromaSizeBytes = dstChromaRowStrideBytes * buf.height / 2; uint8_t *dstChromaVPtr = dstLumaPtr + dstLumaSizeBytes; uint8_t *dstChromaUPtr = dstLumaPtr + dstLumaSizeBytes + dstChromaSizeBytes; // Make these static so that we can reuse device allocations across frames. // It doesn't matter now, but useful for GPU backends. static buffer_t srcBuf = { 0 }; static buffer_t dstBuf = { 0 }; static buffer_t dstChromaBuf = { 0 }; srcBuf.host = srcLumaPtr; srcBuf.host_dirty = true; srcBuf.extent[0] = srcWidth; srcBuf.extent[1] = srcHeight; srcBuf.extent[2] = 0; srcBuf.extent[3] = 0; srcBuf.stride[0] = 1; srcBuf.stride[1] = srcLumaRowStrideBytes; srcBuf.min[0] = 0; srcBuf.min[1] = 0; srcBuf.elem_size = 1; dstBuf.host = dstLumaPtr; dstBuf.extent[0] = buf.width; // src and dst width/height actually match. dstBuf.extent[1] = buf.height; dstBuf.extent[2] = 0; dstBuf.extent[3] = 0; dstBuf.stride[0] = 1; dstBuf.stride[1] = buf.stride; // src and dst strides actually match. dstBuf.min[0] = 0; dstBuf.min[1] = 0; dstBuf.elem_size = 1; static bool first_call = true; static unsigned counter = 0; static unsigned times[16]; if (first_call) { LOGD("According to Halide, host system has %d cpus\n", halide_host_cpu_count()); first_call = false; for (int t = 0; t < 16; t++) { times[t] = 0; } } // Set chrominance to 128 to appear grayscale. // The dst chroma is guaranteed to be tightly packed since it's YV12. memset(dstChromaVPtr, 128, dstChromaSizeBytes * 2); int64_t t1 = halide_current_time_ns(); int err = edge_detect(&srcBuf, &dstBuf); if (err != halide_error_code_success) { LOGE("edge_detect failed with error code: %d", err); } int64_t t2 = halide_current_time_ns(); unsigned elapsed_us = (t2 - t1) / 1000; times[counter & 15] = elapsed_us; counter++; unsigned min = times[0]; for (int i = 1; i < 16; i++) { if (times[i] < min) { min = times[i]; } } LOGD("Time taken: %d us (minimum: %d us)", elapsed_us, min); ANativeWindow_unlockAndPost(win); ANativeWindow_release(win); return (err != halide_error_code_success); }