bool write_image(struct mp_image *image, const struct image_writer_opts *opts, const char *filename, struct mp_log *log) { struct image_writer_opts defs = image_writer_opts_defaults; if (!opts) opts = &defs; const struct img_writer *writer = get_writer(opts); struct image_writer_ctx ctx = { log, opts, writer, image->fmt }; int destfmt = get_target_format(&ctx, image->imgfmt); struct mp_image *dst = convert_image(image, destfmt, log); if (!dst) return false; FILE *fp = fopen(filename, "wb"); bool success = false; if (fp == NULL) { mp_err(log, "Error opening '%s' for writing!\n", filename); } else { success = writer->write(&ctx, dst, fp); success = !fclose(fp) && success; if (!success) mp_err(log, "Error writing file '%s'!\n", filename); } talloc_free(dst); return success; }
int write_image(struct mp_image *image, const struct image_writer_opts *opts, const char *filename) { struct mp_image *allocated_image = NULL; struct image_writer_opts defs = image_writer_opts_defaults; int d_w = image->display_w ? image->display_w : image->w; int d_h = image->display_h ? image->display_h : image->h; bool is_anamorphic = image->w != d_w || image->h != d_h; if (!opts) opts = &defs; const struct img_writer *writer = get_writer(opts); struct image_writer_ctx ctx = { opts, writer }; int destfmt = IMGFMT_RGB24; if (writer->pixfmts) { destfmt = writer->pixfmts[0]; // default to first pixel format for (int *fmt = writer->pixfmts; *fmt; fmt++) { if (*fmt == image->imgfmt) { destfmt = *fmt; break; } } } // Caveat: - no colorspace/levels conversion done if pixel formats equal // - RGB->YUV assumes BT.601 // - color levels broken in various ways thanks to libswscale if (image->imgfmt != destfmt || is_anamorphic) { struct mp_image *dst = alloc_mpi(d_w, d_h, destfmt); vf_clone_mpi_attributes(dst, image); int flags = SWS_LANCZOS | SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND | SWS_BITEXACT; mp_image_swscale(dst, image, flags); allocated_image = dst; image = dst; } FILE *fp = fopen(filename, "wb"); int success = 0; if (fp == NULL) { mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error opening '%s' for writing!\n", filename); } else { success = writer->write(&ctx, image, fp); success = !fclose(fp) && success; if (!success) mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error writing file '%s'!\n", filename); } free_mp_image(allocated_image); return success; }
const char *image_writer_file_ext(const struct image_writer_opts *opts) { struct image_writer_opts defs = image_writer_opts_defaults; if (!opts) opts = &defs; return get_writer(opts)->file_ext; }
int write_image(struct mp_image *image, const struct image_writer_opts *opts, const char *filename) { struct mp_image *allocated_image = NULL; struct image_writer_opts defs = image_writer_opts_defaults; int d_w = image->display_w ? image->display_w : image->w; int d_h = image->display_h ? image->display_h : image->h; bool is_anamorphic = image->w != d_w || image->h != d_h; if (!opts) opts = &defs; const struct img_writer *writer = get_writer(opts); struct image_writer_ctx ctx = { opts, writer }; int destfmt = IMGFMT_RGB24; if (writer->pixfmts) { destfmt = writer->pixfmts[0]; // default to first pixel format for (int *fmt = writer->pixfmts; *fmt; fmt++) { if (*fmt == image->imgfmt) { destfmt = *fmt; break; } } } // Caveat: no colorspace/levels conversion done if pixel formats equal // it's unclear what colorspace/levels the target wants if (image->imgfmt != destfmt || is_anamorphic) { struct mp_image *dst = mp_image_alloc(destfmt, d_w, d_h); mp_image_copy_attributes(dst, image); mp_image_swscale(dst, image, mp_sws_hq_flags); allocated_image = dst; image = dst; } FILE *fp = fopen(filename, "wb"); int success = 0; if (fp == NULL) { mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error opening '%s' for writing!\n", filename); } else { success = writer->write(&ctx, image, fp); success = !fclose(fp) && success; if (!success) mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error writing file '%s'!\n", filename); } talloc_free(allocated_image); return success; }
void * read_messages(){ int addr_len, numbytes; int status; char buf[BUFFER_LEN]; struct msg *last_message; struct sockaddr_in server_address; struct sockaddr_in client_addr; int sockfd; /* Inicializacion de servidor */ server_address.sin_family = AF_INET; server_address.sin_port = htons(listen_port); server_address.sin_addr.s_addr = INADDR_ANY; bzero(&(server_address.sin_zero), 8); /* Socket */ sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { perror("socket"); exit(1); } /* bind */ status = bind(sockfd ,(struct sockaddr *)&server_address ,sizeof(struct sockaddr)); if (status == -1) { perror("bind"); exit(2); } addr_len = sizeof(struct sockaddr); /* Ciclo indefinido de lectura de socket y escritura en buffer */ while(1) { numbytes = recvfrom(sockfd, buf, BUFFER_LEN, 0, (struct sockaddr *)&client_addr, (socklen_t *)&addr_len); if ( numbytes == -1 ) { perror("recvfrom"); exit(3); } buf[numbytes] = '\0'; /* Obtener posicion de escritura para el buffer circular */ last_message = (struct msg*) get_writer(cb); /* Modificar en memoria */ last_message->in_out = buf[0]; last_message->car_id = atoi(&buf[1]); /* Copiar direccion del cliente que envia */ memcpy(&last_message->client,&client_addr,sizeof(struct sockaddr_in)); advance_writer(&cb); } }
BOOL confirmFileWriter(char* deleteIndex, char* fileSubject){ BOOL flag; char* CurrentWriter = get_writer(); char fileWriter[80]; char* p; FILE* file = fopen(deleteIndex, "rt"); fgets(fileSubject, 160, file); fgets(fileWriter, 160, file); if((p = strchr(fileWriter, '\n'))!= NULL) *p = '\0'; if((p = strchr(fileSubject, '\n'))!= NULL) *p = '\0'; if(strcmp(fileWriter, CurrentWriter)==0) flag = TRUE; else flag = FALSE; fclose(file); return flag; }
int write_image(struct mp_image *image, const struct mp_csp_details *csp, const struct image_writer_opts *opts, const char *filename) { struct mp_image *allocated_image = NULL; struct image_writer_opts defs = image_writer_opts_defaults; bool is_anamorphic = image->w != image->width || image->h != image->height; if (!opts) opts = &defs; const struct img_writer *writer = get_writer(opts); struct image_writer_ctx ctx = { opts, writer }; int destfmt = IMGFMT_RGB24; if (writer->pixfmts) { destfmt = writer->pixfmts[0]; // default to first pixel format for (int *fmt = writer->pixfmts; *fmt; fmt++) { if (*fmt == image->imgfmt) { destfmt = *fmt; break; } } } if (image->imgfmt != destfmt || is_anamorphic) { struct mp_image *dst = alloc_mpi(image->w, image->h, destfmt); struct SwsContext *sws = sws_getContextFromCmdLine_hq(image->width, image->height, image->imgfmt, dst->width, dst->height, dst->imgfmt); struct mp_csp_details colorspace = MP_CSP_DETAILS_DEFAULTS; if (csp) colorspace = *csp; // This is a property of the output device; images always use // full-range RGB. colorspace.levels_out = MP_CSP_LEVELS_PC; mp_sws_set_colorspace(sws, &colorspace); sws_scale(sws, (const uint8_t **)image->planes, image->stride, 0, image->height, dst->planes, dst->stride); sws_freeContext(sws); allocated_image = dst; image = dst; } FILE *fp = fopen(filename, "wb"); int success = 0; if (fp == NULL) { mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error opening '%s' for writing!\n", filename); } else { success = writer->write(&ctx, image, fp); success = !fclose(fp) && success; if (!success) mp_msg(MSGT_CPLAYER, MSGL_ERR, "Error writing file '%s'!\n", filename); } free_mp_image(allocated_image); return success; }