Exemplo n.º 1
0
static gboolean buffer_probe_callback(
		GstElement *image_sink,
		GstBuffer *buffer, GstPad *pad)
{
	GstMessage *message;
	gchar *message_name;

	unsigned char *data_photo = (unsigned char *) GST_BUFFER_DATA(buffer);

	if(!create_jpeg(data_photo)) {
		message_name = "photo-failed";
		hildon_banner_show_information(GTK_WIDGET(cappdata->window),
				NULL, "Unable To Take Photo");
	} else {
		message_name = "photo-taken";
	}

	g_signal_handler_disconnect(G_OBJECT(image_sink),
			cappdata->buffer_cb_id);

	message = gst_message_new_application(GST_OBJECT(cappdata->pipeline),
			gst_structure_new(message_name, NULL));
	gst_element_post_message(cappdata->pipeline, message);

	return TRUE;
}
Exemplo n.º 2
0
    static Image* create_image(Stream& stream, TagHeader& header, uint16_t cid, uint32_t size)
    {
        auto start_pos = stream.get_position();
        auto byte1 = stream.read_uint8();
        if( byte1 == 0xFF )
        {
            auto byte2 = stream.read_uint8();

            // erroneous bytes before the jpeg soi marker for version before swf 8
            if( byte2 == 0xD9 )
            {
                assert( stream.read_uint8() == 0xFF && stream.read_uint8() == 0xD8 );
                start_pos = stream.get_position();
                assert( stream.read_uint8() == 0xFF && stream.read_uint8() == 0xD8 );
            }
            else
                assert( byte2 == 0xD8 );

            stream.set_position(start_pos);
            auto alpha = header.end_pos - start_pos - size;
            auto bitmap = create_jpeg(stream.get_current_ptr(), size, alpha);
            return Image::create(cid, std::move(bitmap));
        }
        else if( byte1 == 0x89 )
        {
            assert(
                stream.read_uint8() == 0x50 &&
                stream.read_uint8() == 0x4E &&
                stream.read_uint8() == 0x47 &&
                stream.read_uint8() == 0x0D &&
                stream.read_uint8() == 0x0A &&
                stream.read_uint8() == 0x1A &&
                stream.read_uint8() == 0x0A );
            // load png
        }
        else if( byte1 == 0x47 )
        {
            assert(
                stream.read_uint8() == 0x49 &&
                stream.read_uint8() == 0x46 &&
                stream.read_uint8() == 0x38 &&
                stream.read_uint8() == 0x39 &&
                stream.read_uint8() == 0x61 );
            // load non-animated GIF89a
        }

        return nullptr;
    }
Exemplo n.º 3
0
int grab_one(struct vd_video *vd) {
	char bufo[256];
	char xten[4][5] = {"-","raw", "pnm", "jpg"};
		
	
	#ifdef STAMP
	time_t t;
	struct tm *tm;
	char stringo[128];
	#endif
	
	/* gamma test */
	/* 
	   unsigned char g_table[256];
	   gamma_lookup(0.2, g_table);
	 
	*/
	
	
	
	if (-1 == ioctl(vd->grab_fd,VIDIOCMCAPTURE,&(vd->grab_buf))) {
			perror("ioctl VIDIOCMCAPTURE");
			exit(-1);
	} 
	if (-1 == ioctl(vd->grab_fd,VIDIOCSYNC,&(vd->grab_buf))) {
				perror("ioctl VIDIOCSYNC");
				exit(-1);
	}
 
	vd->image=vd->grab_data;

	if (vd->w == 3 && vd->grab_data  && (vd->img_format != VD_TGA_24)) {
			/* original or faster swap function */
			#ifdef BGR2RGB
			bgr2rgb(vd->grab_data, vd->grab_buf.width * vd->grab_buf.height);
			#else 
		 	
			swap_rgb24(vd->grab_data, vd->grab_buf.width * vd->grab_buf.height);
			#endif
	
		}


/* HOOK for effects */
	
	/* Uncomment and test the effects */
	/* try another order and parameters */
	/* effects test */
	/* threshold (vd, 30); */
	   //sobel(vd);   
	
	 /*gamma_apply(vd, g_table); */
	 /* laplace(vd); */ 
	/* noise (vd, 0.05); */
	 //negative(vd); 
	/* mirror(vd); */
	 /* lowpass(vd); */
	/* highpass(vd); */
	
	/* channel_threshold(vd); */
	/* predator(vd); */
	 /* posterize(vd, 3); */
	
	//threshold (vd, 200); 
	// sobel(vd);   
	//negative(vd);
	//mark_areas(vd);
	
	
	/* end test */
	#ifdef STAMP
	/* initial tests for the timestamp function */
	time (&t);
	tm = localtime (&t);
	if (vd->stamp) {	
		// validation
		if (vd->stamp_scale_w <= 0) vd->stamp_scale_w=1;
		if (vd->stamp_scale_h <= 0) vd->stamp_scale_h=1;
		strftime (stringo, sizeof (stringo), vd->stamp, tm);
		rgb24_printf(vd->stamp_pos_x, vd->stamp_pos_y, vd->stamp_scale_w, vd->stamp_scale_h, vd, "%s", stringo);
	}
	
	#endif
	/*
	 * timestamp
	 *
	 */
	 if (vd->tstampname) {
	 	sprintf(bufo, "%d-0.%s", (unsigned int)t,  xten[vd->img_format]);
 		#ifdef DEBUG
                fprintf (stderr,"filename: %s \n", bufo);
		#endif
		strncpy (vd->v_filename, bufo, strlen(bufo));
	 }
	vd->image=vd->grab_data; /* compatability */

	
		switch (vd->img_format) {
			case VD_RAW:
				create_raw(vd);
				break;
			case VD_PNM:
				create_pnm(vd);
				break;
			#ifdef HASJPEG
			case VD_JPG:
				create_jpeg(vd);
				break;
			#endif
			case VD_TGA_24:
				create_targa24(vd);
				break;
		}
	return 1;
}
Exemplo n.º 4
0
int do_RETR(ftp_session *s, char *param)
{
    int len;
    char arg[MAX_FTP_PATH], ftp_dir[MAX_FTP_PATH], buf[MAX_BUFFER];
    FILE *fp;
    size_t read, write;
    SOCKET sockfd;
    #ifdef USE_SPECIAL_FILE
    int type, start, size;
    char *mem;
    #endif

    MATCH_SP(param);

    len = get_string(param, arg, sizeof(arg));
    if (len == 0)
        return 501;
    param += len;

    MATCH_CRLF(param);

    if (!parse_dir(s->dir, arg, ftp_dir))
        return 550;
    #ifndef USE_SPECIAL_FILE
    if (!ftp_to_fs_read(ftp_dir, arg))
        return 550;
    #else
    type = get_special_file(ftp_dir);
    if (type == file_INVALID && !ftp_to_fs_read(ftp_dir, arg))
        return 550;

    if (type != file_INVALID)
    {
        start = 0;
        switch (type)
        {
            #ifdef USE_SCREEN_BMP
            case file_SCREEN_BMP:
                mem = create_snapshot(&size);
                if (mem == NULL)
                    return 450;
                break;
            #endif
            #ifdef USE_SCREEN_JPG
            case file_SCREEN_ZIP:
                {
                    mem = create_jpeg(&size);
                    if (mem == NULL)
                        return 450;
                    break;
                }
            #endif
            default:
                return 450;
        }
    }
    else
    #endif
    {
        fp = fopen(arg, "rb");
        if (fp == NULL)
            return 450;
    }

    if (s->prev_command == cmd_REST)
    {
        #ifdef USE_SPECIAL_FILE
        if (type != file_INVALID)
            start = s->restart;
        else
        #endif
            fseek(fp, s->restart, SEEK_SET);
    }

    ftp_printf(s->control, reply_150);

    sockfd = ftp_connect(s);
    if (sockfd == -1)
    {
        #ifdef USE_SPECIAL_FILE
        if (type != file_INVALID)
            free(mem);
        else
        #endif
            fclose(fp);
        return 425;
    }

    #ifdef USE_SPECIAL_FILE
    if (type != file_INVALID)
    {
        write = my_send(sockfd, &mem[start], size-start, 0);
        free(mem);
        if (write != size-start)
        {
            closesocket(sockfd);
            return 426;
        }
    }
    else
    #endif
    {
        while (!feof(fp))
        {
            s->tick = GetTickCount();
            read = fread(buf, 1, sizeof(buf), fp);
            if (ferror(fp))
            {
                closesocket(sockfd);
                fclose(fp);
                return 451;
            }
            write = my_send(sockfd, buf, read, 0);
            if (read != write)
            {
                closesocket(sockfd);
                fclose(fp);
                return 426;
            }
        }
        fclose(fp);
    }

    closesocket(sockfd);

    return 226;
}