示例#1
0
文件: image.c 项目: renmengye/darknet
void test_resize(char *filename)
{
    image im = load_image(filename, 0,0, 3);
    image gray = grayscale_image(im);

    image sat2 = copy_image(im);
    saturate_image(sat2, 2);

    image sat5 = copy_image(im);
    saturate_image(sat5, .5);

    image exp2 = copy_image(im);
    exposure_image(exp2, 2);

    image exp5 = copy_image(im);
    exposure_image(exp5, .5);

    show_image(im, "Original");
    show_image(gray, "Gray");
    show_image(sat2, "Saturation-2");
    show_image(sat5, "Saturation-.5");
    show_image(exp2, "Exposure-2");
    show_image(exp5, "Exposure-.5");
#ifdef OPENCV
    cvWaitKey(0);
#endif
}
示例#2
0
void test_resize(char *filename)
{
    image im = load_image(filename, 0,0, 3);
    float mag = mag_array(im.data, im.w*im.h*im.c);
    printf("L2 Norm: %f\n", mag);
    image gray = grayscale_image(im);

    image sat2 = copy_image(im);
    saturate_image(sat2, 2);

    image sat5 = copy_image(im);
    saturate_image(sat5, .5);

    image exp2 = copy_image(im);
    exposure_image(exp2, 2);

    image exp5 = copy_image(im);
    exposure_image(exp5, .5);

    #ifdef GPU
    image r = resize_image(im, im.w, im.h);
    image black = make_image(im.w*2 + 3, im.h*2 + 3, 9);
    image black2 = make_image(im.w, im.h, 3);

    float *r_gpu = cuda_make_array(r.data, r.w*r.h*r.c);
    float *black_gpu = cuda_make_array(black.data, black.w*black.h*black.c);
    float *black2_gpu = cuda_make_array(black2.data, black2.w*black2.h*black2.c);
    shortcut_gpu(3, r.w, r.h, 1, r_gpu, black.w, black.h, 3, black_gpu);
    //flip_image(r);
    //shortcut_gpu(3, r.w, r.h, 1, r.data, black.w, black.h, 3, black.data);

    shortcut_gpu(3, black.w, black.h, 3, black_gpu, black2.w, black2.h, 1, black2_gpu);
    cuda_pull_array(black_gpu, black.data, black.w*black.h*black.c);
    cuda_pull_array(black2_gpu, black2.data, black2.w*black2.h*black2.c);
    show_image_layers(black, "Black");
    show_image(black2, "Recreate");
    #endif

    show_image(im, "Original");
    show_image(gray, "Gray");
    show_image(sat2, "Saturation-2");
    show_image(sat5, "Saturation-.5");
    show_image(exp2, "Exposure-2");
    show_image(exp5, "Exposure-.5");
#ifdef OPENCV
    cvWaitKey(0);
#endif
}
示例#3
0
bool
ImageInput::read_native_tiles (int xbegin, int xend, int ybegin, int yend,
                               int zbegin, int zend, void *data)
{
    if (! m_spec.valid_tile_range (xbegin, xend, ybegin, yend, zbegin, zend))
        return false;

    // Base class implementation of read_native_tiles just repeatedly
    // calls read_native_tile, which is supplied by every plugin that
    // supports tiles.  Only the hardcore ones will overload
    // read_native_tiles with their own implementation.
    stride_t pixel_bytes = (stride_t) m_spec.pixel_bytes (true);
    stride_t tileystride = pixel_bytes * m_spec.tile_width;
    stride_t tilezstride = tileystride * m_spec.tile_height;
    stride_t ystride = (xend-xbegin) * pixel_bytes;
    stride_t zstride = (yend-ybegin) * ystride;
    std::vector<char> pels (m_spec.tile_bytes(true));
    for (int z = zbegin;  z < zend;  z += m_spec.tile_depth) {
        for (int y = ybegin;  y < yend;  y += m_spec.tile_height) {
            for (int x = xbegin;  x < xend;  x += m_spec.tile_width) {
                bool ok = read_native_tile (x, y, z, &pels[0]);
                if (! ok)
                    return false;
                copy_image (m_spec.nchannels, m_spec.tile_width,
                            m_spec.tile_height, m_spec.tile_depth,
                            &pels[0], size_t(pixel_bytes),
                            pixel_bytes, tileystride, tilezstride,
                            (char *)data+ (z-zbegin)*zstride + 
                                (y-ybegin)*ystride + (x-xbegin)*pixel_bytes,
                            pixel_bytes, ystride, zstride);
            }
        }
    }
    return true;
}
示例#4
0
文件: image.c 项目: bierdaci/egui
void egal_copy_image(GalImage *dst,
		eint dx, eint dy, eint w, eint h,
		GalImage *src, eint sx, eint sy)
{
	if (dx >= dst->w || dy >= dst->h)
		return;
    if (w == 0)
        w = src->w;
    if (h == 0)
        h = src->h;
    if (sx >= dst->w)
        return;
    if (sy >= dst->h)
        return;
    if (sx + w > src->w)
        w = src->w - sx;
    if (w > dst->w - dx)
        w = dst->w - dx;
    if (sy + h > src->h)
        h = src->h - sy;
    if (h > dst->h - dy)
        h = dst->h - dy;

	copy_image(dst, dx, dy, src, sx, sy, w, h);
}
示例#5
0
/* local tree then owns all compbufs */
static void localize(bNodeTree *UNUSED(localtree), bNodeTree *ntree)
{
	bNode *node;
	bNodeSocket *sock;
	
	for(node= ntree->nodes.first; node; node= node->next) {
		/* ensure new user input gets handled ok */
		node->need_exec= 0;
		
		/* move over the compbufs */
		/* right after ntreeCopyTree() oldsock pointers are valid */
		
		if(ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
			if(node->id) {
				if(node->flag & NODE_DO_OUTPUT)
					node->new_node->id= (ID *)copy_image((Image *)node->id);
				else
					node->new_node->id= NULL;
			}
		}
		
		for(sock= node->outputs.first; sock; sock= sock->next) {
			sock->new_sock->cache= sock->cache;
			compbuf_set_node(sock->new_sock->cache, node->new_node);
			
			sock->cache= NULL;
			sock->new_sock->new_sock= sock;
		}
	}
}
示例#6
0
文件: darknet.c 项目: kunle12/darknet
void mkimg(char *cfgfile, char *weightfile, int h, int w, int num, char *prefix)
{
    network *net = load_network(cfgfile, weightfile, 0);
    image *ims = get_weights(net->layers[0]);
    int n = net->layers[0].n;
    int z;
    for(z = 0; z < num; ++z){
        image im = make_image(h, w, 3);
        fill_image(im, .5);
        int i;
        for(i = 0; i < 100; ++i){
            image r = copy_image(ims[rand()%n]);
            rotate_image_cw(r, rand()%4);
            random_distort_image(r, 1, 1.5, 1.5);
            int dx = rand()%(w-r.w);
            int dy = rand()%(h-r.h);
            ghost_image(r, im, dx, dy);
            free_image(r);
        }
        char buff[256];
        sprintf(buff, "%s/gen_%d", prefix, z);
        save_image(im, buff);
        free_image(im);
    }
    free_network(net);
}
示例#7
0
void save_image_jpg(image p, char *name)
{
    image copy = copy_image(p);
    rgbgr_image(copy);
    int x,y,k;
    int params[3];

    char buff[256];
    sprintf(buff, "%s.jpg", name);

    params[0] = CV_IMWRITE_JPEG_QUALITY;
    params[1] = 75;
    params[2] = 0;

    IplImage *disp = cvCreateImage(cvSize(p.w,p.h), IPL_DEPTH_8U, p.c);
    int step = disp->widthStep;
    for(y = 0; y < p.h; ++y){
        for(x = 0; x < p.w; ++x){
            for(k= 0; k < p.c; ++k){
                disp->imageData[y*step + x*p.c + k] = (unsigned char)(get_pixel(copy,x,y,k)*255);
            }
        }
    }
    cvSaveImage(buff, disp, params);
    cvReleaseImage(&disp);
    free_image(copy);
}
示例#8
0
/**
 * gst_vaapi_image_update_from_buffer:
 * @image: a #GstVaapiImage
 * @buffer: a #GstBuffer
 * @rect: a #GstVaapiRectangle expressing a region, or %NULL for the
 *   whole image
 *
 * Transfers pixels data contained in the #GstBuffer into the
 * @image. Both image structures shall have the same format.
 *
 * Return value: %TRUE on success
 */
gboolean
gst_vaapi_image_update_from_buffer(
    GstVaapiImage     *image,
    GstBuffer         *buffer,
    GstVaapiRectangle *rect
)
{
    GstVaapiImagePrivate *priv;
    GstVaapiImageRaw dst_image, src_image;
    gboolean success;

    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);
    g_return_val_if_fail(GST_IS_BUFFER(buffer), FALSE);

    priv = image->priv;

    if (!init_image_from_buffer(&src_image, buffer))
        return FALSE;
    if (src_image.format != priv->format)
        return FALSE;
    if (src_image.width != priv->width || src_image.height != priv->height)
        return FALSE;

    if (!_gst_vaapi_image_map(image, &dst_image))
        return FALSE;

    success = copy_image(&dst_image, &src_image, rect);

    if (!_gst_vaapi_image_unmap(image))
        return FALSE;

    return success;
}
示例#9
0
文件: image.c 项目: renmengye/darknet
image collapse_images_horz(image *ims, int n)
{
    int color = 1;
    int border = 1;
    int h,w,c;
    int size = ims[0].h;
    h = size;
    w = (ims[0].w + border) * n - border;
    c = ims[0].c;
    if(c != 3 || !color){
        h = (h+border)*c - border;
        c = 1;
    }

    image filters = make_image(w, h, c);
    int i,j;
    for(i = 0; i < n; ++i){
        int w_offset = i*(size+border);
        image copy = copy_image(ims[i]);
        //normalize_image(copy);
        if(c == 3 && color){
            embed_image(copy, filters, w_offset, 0);
        }
        else{
            for(j = 0; j < copy.c; ++j){
                int h_offset = j*(size+border);
                image layer = get_image_layer(copy, j);
                embed_image(layer, filters, w_offset, h_offset);
                free_image(layer);
            }
        }
        free_image(copy);
    }
    return filters;
} 
示例#10
0
文件: t.c 项目: bhanderson/cpts460
int ufork(){
	PROC *p;
	int  i, child;
	u16  segment;

	/*** get a PROC for child process: **/
	if ( (p = get_proc(&freeList)) == NULL){
		printf("no more proc\n");
		return(-1);
	}
	printf("ufork\n");
	/* set procs values to running and ready so we can use it */
	p->status = READY;
	p->next = NULL;
	p->ppid = running->pid;
	p->parent = running;
	p->priority = running->priority;

	/* zero out kstack registers*/
	for (i = 1; i < 10; i++) {
		p->kstack[SSIZE -i] = 0;
	}
	// set address to resume to
	p->kstack[SSIZE -1] =(int)goUmode;
	p->ksp = &(p->kstack[SSIZE-9]);

	// set segment to processes data position
	segment = (p->pid + 1)*0x1000;
	// copy the segment
	copy_image(segment);
	printf("loaded at %u\n", segment);
	// clean the registers and set flag and uCs and uDs to runnings values
	for (i = 1; i < 13; i++) {
		child = 0x1000 - i*2;
		switch(i){
			case 1: put_word(segment, segment, child); break;
			case 2: put_word(segment, segment, child); break;
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
			case 10: put_word(0,segment, child); break;
			case 11:
			case 12: put_word(segment, segment, child); break;
		}
	}
	// same as kfork
	p->uss = segment;
	p->usp = 0x1000 - 24;
	put_word(0, segment, p->usp + 8*2);

	printf("Proc%d forked a child %d segment=%x\n", running->pid,p->pid,segment);
	enqueue(&readyQueue, p);
	nproc++;
	return(p->pid);
}
示例#11
0
void flip_image_with_mask(Image* image, const Mask* mask, FlipType flipType, int bgcolor)
{
  gfx::Rect bounds = mask->bounds();

  switch (flipType) {

    case FlipHorizontal: {
      base::UniquePtr<Image> originalRow(Image::create(image->pixelFormat(), bounds.w, 1));

      for (int y=bounds.y; y<bounds.y+bounds.h; ++y) {
        // Copy the current row.
        copy_image(originalRow, image, -bounds.x, -y);

        int u = bounds.x+bounds.w-1;
        for (int x=bounds.x; x<bounds.x+bounds.w; ++x, --u) {
          if (mask->containsPoint(x, y)) {
            put_pixel(image, u, y, get_pixel(originalRow, x-bounds.x, 0));
            if (!mask->containsPoint(u, y))
              put_pixel(image, x, y, bgcolor);
          }
        }
      }
      break;
    }

    case FlipVertical: {
      base::UniquePtr<Image> originalCol(Image::create(image->pixelFormat(), 1, bounds.h));

      for (int x=bounds.x; x<bounds.x+bounds.w; ++x) {
        // Copy the current column.
        copy_image(originalCol, image, -x, -bounds.y);

        int v = bounds.y+bounds.h-1;
        for (int y=bounds.y; y<bounds.y+bounds.h; ++y, --v) {
          if (mask->containsPoint(x, y)) {
            put_pixel(image, x, v, get_pixel(originalCol, 0, y-bounds.y));
            if (!mask->containsPoint(x, v))
              put_pixel(image, x, y, bgcolor);
          }
        }
      }
      break;
    }

  }
}
示例#12
0
文件: lsd.c 项目: kunle12/darknet
void inter_dcgan(char *cfgfile, char *weightfile)
{
    network *net = load_network(cfgfile, weightfile, 0);
    set_batch_network(net, 1);
    srand(2222222);

    clock_t time;
    char buff[256];
    char *input = buff;
    int i, imlayer = 0;

    for (i = 0; i < net->n; ++i) {
        if (net->layers[i].out_c == 3) {
            imlayer = i;
            printf("%d\n", i);
            break;
        }
    }
    image start = random_unit_vector_image(net->w, net->h, net->c);
    image end = random_unit_vector_image(net->w, net->h, net->c);
        image im = make_image(net->w, net->h, net->c);
        image orig = copy_image(start);

    int c = 0;
    int count = 0;
    int max_count = 15;
    while(1){
        ++c;

        if(count == max_count){
            count = 0;
            free_image(start);
            start = end;
            end = random_unit_vector_image(net->w, net->h, net->c);
            if(c > 300){
                end = orig;
            }
            if(c>300 + max_count) return;
        }
        ++count;

        slerp(start.data, end.data, (float)count / max_count, im.w*im.h*im.c, im.data);

        float *X = im.data;
        time=clock();
        network_predict(net, X);
        image out = get_network_image_layer(net, imlayer);
        //yuv_to_rgb(out);
        normalize_image(out);
        printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
        //char buff[256];
        sprintf(buff, "out%05d", c);
        save_image(out, "out");
        save_image(out, buff);
        show_image(out, "out", 0);
    }
}
示例#13
0
image *get_filters(convolutional_layer l)
{
    image *filters = calloc(l.n, sizeof(image));
    int i;
    for(i = 0; i < l.n; ++i){
        filters[i] = copy_image(get_convolutional_filter(l, i));
    }
    return filters;
}
示例#14
0
static int l_copy_image(lua_State * L)
{
    if (lua_gettop(L) != 1)
        luaL_error(L, "img.copy() needs exactly 1 argument");
    if (lua_istable(L, 1))
        (void) l_new_image(L);  /* image --- if everything worked well */
    else
        (void) copy_image(L, 1.0);      /* image */
    return 1;                   /* image */
}
示例#15
0
image *get_weights(convolutional_layer l)
{
    image *weights = calloc(l.n, sizeof(image));
    int i;
    for(i = 0; i < l.n; ++i){
        weights[i] = copy_image(get_convolutional_weight(l, i));
        //normalize_image(weights[i]);
    }
    return weights;
}
示例#16
0
Image ImageManager::processImage (const BeamImage& beamImage)
{
    const Image& srcImage = beamImage.image();

    Image process_src_image = preprocessOriginalImage(srcImage,
                                                      m_processSettings.cropHeader,
                                                      m_processSettings.cropFooter,
                                                      m_processSettings.autoCrop);

    QImage canvas = createNewCanvas (m_processSettings.newImageSize,
                                     m_processSettings.whiteBackground);

    int liedNrSize = 0;
    if (m_processSettings.addSongNumber)
        liedNrSize = 60;

    QSize target_frame_size = calculateTargetFrameSize( canvas.size(),
                                                        m_processSettings.borderSize,
                                                        liedNrSize );

    QSize scaled_image_size = calculateScaledImageSize( process_src_image.size(),
                                                        target_frame_size,
                                                        m_processSettings.zoom);


    QImage scaled_image = process_src_image.toQImage().scaled (scaled_image_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

    int x_offset = m_processSettings.borderSize;
    int y_offset = m_processSettings.borderSize + liedNrSize;

    QPoint offset ( x_offset + (target_frame_size.width() - scaled_image.size().width()) /2,
                   y_offset + (target_frame_size.height() - scaled_image.size().height()) /2);

    QPainter painter (&canvas);

    QFont font ("Arial");
    font.setPixelSize(40);
    painter.setFont(font);

    if (m_processSettings.addSongNumber)
        painter.drawText (QRect(10, 10, scaled_image.width(), 40), Qt::AlignHCenter, beamImage.liedNr());

    painter.drawImage(offset, scaled_image);

    Lut lut(8);
    ImageProcessing::generateLut(0,
                                 m_processSettings.brightness,
                                 m_processSettings.gamma, 1.0, 1.0, 1.0, lut);

    Image copy_image (canvas.size(), 4, 8);
    Image my_canvas = Image::fromQImage(canvas);
    ImageProcessing::applyLut(&my_canvas, &copy_image, lut);

    return copy_image;
}
示例#17
0
static int l_copy_image(lua_State * L)
{
    if (lua_gettop(L) != 1) {
        luaL_error(L, "img.copy needs an image as argument");
    } else if (lua_istable(L, 1)) {
        (void) l_new_image(L);
    } else {
        (void) copy_image(L, 1.0);
    }
    return 1;
}
示例#18
0
DARNIT_TILESHEET *detect_image(DARNIT_IMAGE_DATA img, int x, int y, int *piczels) {
	int minx, w, h;
	DARNIT_TILESHEET *ts;

	fill_image(img, x, y, PIXEL_SOLID, PIXEL_HIGHLIGHT);
	minx = geometrics_image(img, &w, &h);
	ts = copy_image(img, minx, y, w, h, piczels);
	fill_image(img, x, y, PIXEL_HIGHLIGHT, PIXEL_NONE);

	return ts;
}
示例#19
0
文件: t.c 项目: B-Rich/CptS460
int do_fork()
{
    
    PROC *p;
    int  i, child,j;
    u16  segment;

    /*** get a PROC for child process: ***/
    if ( (p = get_proc(&freeList)) == 0){
        printf("no more proc\n");
        return(-1);
    }

    /* initialize the new proc and its stack */
    p->status = READY;
    p->ppid = running->pid;
    p->parent = running;
    p->priority  = 1;                 // all of the same priority 1

    /******* write C code to to do THIS YOURSELF ********************
      Initialize p's kstack AS IF it had called tswitch() 
      from the entry address of body():

      HI   -1  -2    -3  -4   -5   -6   -7   -8    -9                LOW
      -------------------------------------------------------------
      |body| ax | bx | cx | dx | bp | si | di |flag|
      ------------------------------------------------------------
      ^
      PROC.ksp ---|

     ******************************************************************/
    for (j=1; j<10;j++)
        p->kstack[SSIZE-j];
    p->kstack[SSIZE-1]=(int)goUmode;
    p->ksp = &(p->kstack[SSIZE-9]);
    enqueue(&readyQueue, p);

    // make Umode image by copying the segment from the host process
    segment = (p->pid + 1)*0x1000;    
    copy_image(segment);
    //gotta fix that segment to make sure it doesnt reference wrong stuff
    p->uss = segment;
    p->usp = 0x1000 - 24;
    put_word(0x0200,segment,0x1000-2);
    put_word(segment,segment,0x1000-4);
    for (j=3;j<11;j++)
        put_word(0,segment,0x1000-2*j);
    put_word(segment,segment,0x1000-22);
    put_word(segment,segment,0x1000-24);


    return p->pid;
}
示例#20
0
bool
ImageInput::read_native_tiles (int xbegin, int xend, int ybegin, int yend,
                               int zbegin, int zend, 
                               int chbegin, int chend, void *data)
{
    chend = clamp (chend, chbegin+1, m_spec.nchannels);
    int nchans = chend - chbegin;

    // All-channel case just reduces to the simpler read_native_scanlines.
    if (chbegin == 0 && chend >= m_spec.nchannels)
        return read_native_tiles (xbegin, xend, ybegin, yend,
                                  zbegin, zend, data);

    if (! m_spec.valid_tile_range (xbegin, xend, ybegin, yend, zbegin, zend))
        return false;

    // Base class implementation of read_native_tiles just repeatedly
    // calls read_native_tile, which is supplied by every plugin that
    // supports tiles.  Only the hardcore ones will overload
    // read_native_tiles with their own implementation.

    stride_t native_pixel_bytes = (stride_t) m_spec.pixel_bytes (true);
    stride_t native_tileystride = native_pixel_bytes * m_spec.tile_width;
    stride_t native_tilezstride = native_tileystride * m_spec.tile_height;

    size_t prefix_bytes = m_spec.pixel_bytes (0,chbegin,true);
    size_t subset_bytes = m_spec.pixel_bytes (chbegin,chend,true);
    stride_t subset_ystride = (xend-xbegin) * subset_bytes;
    stride_t subset_zstride = (yend-ybegin) * subset_ystride;

    boost::scoped_array<char> pels (new char [m_spec.tile_bytes(true)]);
    for (int z = zbegin;  z < zend;  z += m_spec.tile_depth) {
        for (int y = ybegin;  y < yend;  y += m_spec.tile_height) {
            for (int x = xbegin;  x < xend;  x += m_spec.tile_width) {
                bool ok = read_native_tile (x, y, z, &pels[0]);
                if (! ok)
                    return false;
                copy_image (nchans, m_spec.tile_width,
                            m_spec.tile_height, m_spec.tile_depth,
                            &pels[prefix_bytes], subset_bytes,
                            native_pixel_bytes, native_tileystride,
                            native_tilezstride,
                            (char *)data+ (z-zbegin)*subset_zstride + 
                                (y-ybegin)*subset_ystride +
                                (x-xbegin)*subset_bytes,
                            subset_bytes, subset_ystride, subset_zstride);
            }
        }
    }
    return true;
}
示例#21
0
static int m_img_mul(lua_State * L)
{
    lua_Number scale;
    if (lua_isnumber(L, 1)) {   /* u? n */
        (void) luaL_checkudata(L, 2, TYPE_IMG); /* u n */
        lua_insert(L, -2);      /* n a */
    } else if (lua_isnumber(L, 2)) {    /* n u? */
        (void) luaL_checkudata(L, 1, TYPE_IMG); /* n a */
    }                           /* n a */
    scale = lua_tonumber(L, 2); /* n a */
    lua_pop(L, 1);              /* a */
    copy_image(L, scale);       /* b */
    return 1;
}
示例#22
0
image *get_weights(convolutional_layer l)
{
    image *weights = calloc(l.n, sizeof(image));
    int i;
    for(i = 0; i < l.n; ++i){
        weights[i] = copy_image(get_convolutional_weight(l, i));
        normalize_image(weights[i]);
        /*
           char buff[256];
           sprintf(buff, "filter%d", i);
           save_image(weights[i], buff);
         */
    }
    //error("hey");
    return weights;
}
int main(int argc, char *argv[])
{
    unsigned char* image;
    unsigned char header[54];
    unsigned char end[1024];
    unsigned char* final_image;
    float DesE = 20.0;
    int size;
    int window = 30;
    int TX,TY,p=4;
    double startT,stopT;
    int nt=4;

    if(isdigit(argv[1])){
       p = atoi(argv[1]);
    if(p<1 || p>20)
        printf("# of threads should be between 1 and 20 - it runs 4 threads -> default");
    else
        nt = p;
    }
    omp_set_num_threads(nt);

    startT = clock();
    double ss = omp_get_wtime();
    image = readBMP("lady1000.bmp",header,end,&size);

    //applying filter
    //extracting size
    TX = *(int*)&header[18];
    TY = *(int*)&header[22];

    final_image = (unsigned char*) malloc(size*sizeof(unsigned char));

    //copy image
    copy_image(image,final_image,size);
    //applying filter
    promediador(image,TX,TY,window,final_image,DesE);
    //write final result
    writeBMP("exit.bmp",final_image,header,end,size);

    stopT = clock();
    double ee = omp_get_wtime();
    printf("%d processors; %f secs\n",p,ee-ss);
}
示例#24
0
int do_fork(char *filename)
{
  int j;
  u16 size, segment;
  PROC *p = get_proc(&freeList);
  if (p)
  {
    p->status = READY;
    p->ppid = running->pid;
    p->priority = 1;
    p->next = 0;
    p->parent = running;
    
    // Initialize Stack
    for (j=1; j<10; ++j)
      p->kstack[SSIZE - j] = 0;          // all saved registers = 0
    p->kstack[SSIZE-1]=(int)goUmode;          // called tswitch() from body
    p->sp = &(p->kstack[SSIZE-9]);        // ksp -> kstack top
    
    // put in readyqueue
    enqueue( &readyQueue, p);
    ++nproc;
    
    // Initialize ustack
    size = 0x1000;		// size of one proc's space
    segment = ( p->pid +1 ) * 0x1000;	// proc 0 sits on 0x1000, proc 1 on 0x2000... 
    
    p->uss = segment;
    
    copy_image(segment);
    // for every 2 byte register put the right value
    reset_segment(segment);
    // 12 registers each 2 bytes
    p->usp = size - 12*2;
    
    return 0;
  }else
  {
    printf("No Mo Procs\n");
    return -1;
  }
}
示例#25
0
文件: image.c 项目: renmengye/darknet
void show_image_cv(image p, char *name)
{
    int x,y,k;
    image copy = copy_image(p);
    constrain_image(copy);
    if(p.c == 3) rgbgr_image(copy);
    //normalize_image(copy);

    char buff[256];
    //sprintf(buff, "%s (%d)", name, windows);
    sprintf(buff, "%s", name);

    IplImage *disp = cvCreateImage(cvSize(p.w,p.h), IPL_DEPTH_8U, p.c);
    int step = disp->widthStep;
    cvNamedWindow(buff, CV_WINDOW_AUTOSIZE); 
    //cvMoveWindow(buff, 100*(windows%10) + 200*(windows/10), 100*(windows%10));
    ++windows;
    for(y = 0; y < p.h; ++y){
        for(x = 0; x < p.w; ++x){
            for(k= 0; k < p.c; ++k){
                disp->imageData[y*step + x*p.c + k] = (unsigned char)(get_pixel(copy,x,y,k)*255);
            }
        }
    }
    free_image(copy);
    if(0){
        //if(disp->height < 448 || disp->width < 448 || disp->height > 1000){
        int w = 448;
        int h = w*p.h/p.w;
        if(h > 1000){
            h = 1000;
            w = h*p.w/p.h;
        }
        IplImage *buffer = disp;
        disp = cvCreateImage(cvSize(w, h), buffer->depth, buffer->nChannels);
        cvResize(buffer, disp, CV_INTER_LINEAR);
        cvReleaseImage(&buffer);
    }
    cvShowImage(buff, disp);
    cvReleaseImage(&disp);
}
示例#26
0
int main()
{
    PPM_IMG img_ibuf_c;

    printf("Running colour space converter .\n");
    img_ibuf_c = read_ppm("in.ppm");
    copy_image(img_ibuf_c);
    run_cpu_color_test(img_ibuf_c);
    run_gpu_color_test(img_ibuf_c);
    printf("GPU and CPU conversion on RGB to YUV: %s\n", confirm_gpu_rgb2yuv() ? "true" : "false");
    printf("GPU and CPU conversion on YUV to RGB: %s\n", confirm_gpu_yuv2rgb() ? "true" : "false");

    free_ppm(img_ibuf_c);

    free_ppm(img_obuf_rgb_cpu);
    free_yuv(img_obuf_yuv_cpu);
    free_ppm(img_obuf_rgb_gpu);
    free_yuv(img_obuf_yuv_gpu);

    return 0;
}
示例#27
0
/**
 * gst_vaapi_image_update_from_raw:
 * @image: a #GstVaapiImage
 * @src_image: a #GstVaapiImageRaw
 * @buffer: a #GstBuffer
 * @rect: a #GstVaapiRectangle expressing a region, or %NULL for the
 *   whole image
 *
 * Transfers pixels data contained in the #GstVaapiImageRaw into the
 * @image. Both image structures shall have the same format.
 *
 * Return value: %TRUE on success
 */
gboolean
gst_vaapi_image_update_from_raw(
    GstVaapiImage     *image,
    GstVaapiImageRaw  *src_image,
    GstVaapiRectangle *rect
)
{
    GstVaapiImageRaw dst_image;
    gboolean success;

    g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
    g_return_val_if_fail(image->priv->is_constructed, FALSE);

    if (!_gst_vaapi_image_map(image, &dst_image))
        return FALSE;

    success = copy_image(&dst_image, src_image, rect);

    if (!_gst_vaapi_image_unmap(image))
        return FALSE;

    return success;
}
示例#28
0
int id_copy(ID *id, ID **newid, int test)
{
	if(!test) *newid= NULL;

	/* conventions:
	 * - make shallow copy, only this ID block
	 * - id.us of the new ID is set to 1 */
	switch(GS(id->name)) {
		case ID_SCE:
			return 0; /* can't be copied from here */
		case ID_LI:
			return 0; /* can't be copied from here */
		case ID_OB:
			if(!test) *newid= (ID*)copy_object((Object*)id);
			return 1;
		case ID_ME:
			if(!test) *newid= (ID*)copy_mesh((Mesh*)id);
			return 1;
		case ID_CU:
			if(!test) *newid= (ID*)copy_curve((Curve*)id);
			return 1;
		case ID_MB:
			if(!test) *newid= (ID*)copy_mball((MetaBall*)id);
			return 1;
		case ID_MA:
			if(!test) *newid= (ID*)copy_material((Material*)id);
			return 1;
		case ID_TE:
			if(!test) *newid= (ID*)copy_texture((Tex*)id);
			return 1;
		case ID_IM:
			if(!test) *newid= (ID*)copy_image((Image*)id);
			return 1;
		case ID_LT:
			if(!test) *newid= (ID*)copy_lattice((Lattice*)id);
			return 1;
		case ID_LA:
			if(!test) *newid= (ID*)copy_lamp((Lamp*)id);
			return 1;
		case ID_SPK:
			if(!test) *newid= (ID*)copy_speaker((Speaker*)id);
			return 1;
		case ID_CA:
			if(!test) *newid= (ID*)copy_camera((Camera*)id);
			return 1;
		case ID_IP:
			return 0; /* deprecated */
		case ID_KE:
			if(!test) *newid= (ID*)copy_key((Key*)id);
			return 1;
		case ID_WO:
			if(!test) *newid= (ID*)copy_world((World*)id);
			return 1;
		case ID_SCR:
			return 0; /* can't be copied from here */
		case ID_VF:
			return 0; /* not implemented */
		case ID_TXT:
			if(!test) *newid= (ID*)copy_text((Text*)id);
			return 1;
		case ID_SCRIPT:
			return 0; /* deprecated */
		case ID_SO:
			return 0; /* not implemented */
		case ID_GR:
			if(!test) *newid= (ID*)copy_group((Group*)id);
			return 1;
		case ID_AR:
			if(!test) *newid= (ID*)copy_armature((bArmature*)id);
			return 1;
		case ID_AC:
			if(!test) *newid= (ID*)copy_action((bAction*)id);
			return 1;
		case ID_NT:
			if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id);
			return 1;
		case ID_BR:
			if(!test) *newid= (ID*)copy_brush((Brush*)id);
			return 1;
		case ID_PA:
			if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id);
			return 1;
		case ID_WM:
			return 0; /* can't be copied from here */
		case ID_GD:
			return 0; /* not implemented */
	}
	
	return 0;
}
示例#29
0
int fork()
{
	// kfork as BEFORE: pid = new PROC's pid
	PROC *p;
	PROC *temp;
	u16 tempWord;
	int i, j, segment, runningSegment;
	// (1). PROC *p = get_proc(); to get a FREE PROC from freeList;
	// if none, return 0 for FAIL;
	p = get_proc();

	if(p == 0)
	{
		printf("get_proc() failed, no more PROCs available\n");
		return 0;
	}

	// (2). Initialize the new PROC p with
	// --------------------------
	// status   = READY;
	// priority = 1;
	// ppid = running pid;
	// parent = running;
	// --------------------------
	p->status = READY;
	p->priority = 1;
	p->ppid = running->pid;
	p->parent = running;
	// *********** THIS IS THE MAIN PART OF THE ASSIGNMENT!!!***********
	// INITIALIZE p's kstack to make it start from body() when it runs.
	// To do this, PRETEND that the process called tswitch() from the 
	// the entry address of body() and executed the SAVE part of tswitch()
	// to give up CPU before. 
	// Initialize its kstack[ ] and ksp to comform to these.
	for(j = 1; j < 10; j++)
	{
		p->kstack[SSIZE - j] = 0;
	}
	p->kstack[SSIZE - 1] = (int)goUmode;
	p->ksp = &(p->kstack[SSIZE-9]);

	// enter p into readyQueue;
	enqueue(&readyQueue, p);


	// new PROC's segment = (pid+1)*0x1000;
	nproc++;

	segment = 0x1000*(p->pid+1);



	// ****** NEW WAY ******
	printf("About to fork() the NEW way\n");
	copy_image(segment);



	// we save the segment into the proc's slot
	// PROC.usp = TOP of ustack (per INT 80)
	
	// Set new PROC.uss = segment;
	p->uss = segment;
	// usp is the only thing that is copied over from parent
	p->usp = running->usp;

	// uDS 
	put_word(segment, segment, p->usp);
	// uES,
	put_word(segment, segment, p->usp+(2*1));
	// and uCS
	put_word(segment, segment, p->usp+(2*10));
	// the flag
	put_word(0x0200, segment, p->usp+(2*11));



	// return new proc's pid;
	return p->pid;
}
示例#30
0
文件: velfitpatch.c 项目: jobovy/nemo
nemo_main()
{
  bool Qsample, Qtab, Qout, Qxy;
  stream velstr, tabstr, outstr0, outstr1, outstr2;
  real scale;
  real *x, *y, *v, sol[3];
  int i, j, id, jd, nx, ny, nd, d, d2;
  string outmode = getparam("mode");
  string bname, oname;
  int mode = -1;
  int npt = 0;

  /* output mode */

  Qtab = hasvalue("tab");
  Qxy  = (*outmode == 'x' || *outmode == 'X');

  scale = getdparam("scale");

  /* read velocity field */

  velstr = stropen(getparam("in"),"r");
  read_image(velstr,&velptr);
  nx = Nx(velptr);
  ny = Ny(velptr);

  Qout = hasvalue("out");
  if (Qout) {
    copy_image(velptr, &outptr0);
    copy_image(velptr, &outptr1);
    copy_image(velptr, &outptr2);
    bname = getparam("out");
    oname = (string) allocate(strlen(bname) + 5);
    sprintf(oname,"%s.%s", bname, "vc");
    outstr0 = stropen(oname,"w");
    sprintf(oname,"%s.%s", bname, Qxy ? "ox" : "om");
    outstr1 = stropen(oname,"w");
    sprintf(oname,"%s.%s", bname, Qxy ? "oy" : "pa");
    outstr2 = stropen(oname,"w");
  }

  /* needed arrays */

  d = getiparam("patch");
  d2 = 2*d + 1;
  x = (real *) allocate(d2*d2*sizeof(real));
  y = (real *) allocate(d2*d2*sizeof(real));
  v = (real *) allocate(d2*d2*sizeof(real));

  for (i=d; i<nx-d; i++) {
    for (j=d; j<ny-d; j++) {
      nd = 0;
      for (id=-d; id<=d; id++) {
	for (jd=-d; jd<=d; jd++) {
	  x[nd] = id;
	  y[nd] = jd;
	  v[nd] = MapValue(velptr, i+id, j+jd);
	  if (v[nd] != 0.0) nd++;
	}
      }
      fit_patch(nd, x, y, v, sol, scale);
      if (!Qxy) xy2rt(sol);
      if (Qtab) printf("%d %d   %g %g %g\n",i,j,sol[0],sol[1],sol[2]);
      npt++;
      if (Qout) {
	MapValue(outptr0,i,j) = sol[0];
	MapValue(outptr1,i,j) = sol[1];
	MapValue(outptr2,i,j) = sol[2];
      }
    }
  }
  dprintf(0,"Processed %d points with patch area %d x %d\n",npt,d2,d2);
  if (Qout) {
    write_image(outstr0,outptr0);
    write_image(outstr1,outptr1);
    write_image(outstr2,outptr2);
  }
}