TextureOpenGL* TextureOpenGL::Create( RenderOpenGL* parent,TextureFormat fmt,UInt32 w,UInt32 h, const Data* data) { if (fmt==TEXTURE_FORMAT_UNKNOWN) return 0; GLuint name = 0; glActiveTexture(GL_TEXTURE0); glGenTextures(1, &name); if (!name) return 0; glBindTexture(GL_TEXTURE_2D, name); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (format_compressed(fmt)) { if ( data ) glCompressedTexImage2D(GL_TEXTURE_2D, 0, convert_int_format(fmt), w, h, 0, data->GetSize(), data->GetData() ); else { glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &name); return 0; } } else { glTexImage2D(GL_TEXTURE_2D, 0, convert_int_format(fmt), w, h, 0, convert_format(fmt), convert_storage(fmt), data ? data->GetData() : 0); } return new TextureOpenGL( name, parent, fmt, w,h ); }
void Image::LoadPNG(const std::string &filename, Format format) { data_.reset(new std::vector<uint8_t>()); unsigned int error = lodepng::decode(*data_.get(), width_, height_, filename, convert_format(format)); if (error) throw LoadingException(lodepng_error_text(error)); format_ = format; }
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; SDL_Window *window = renderer->window; Uint32 temp_format = SDL_PIXELFORMAT_ARGB8888; void *temp_pixels; int temp_pitch; GLint internalFormat; GLenum format, type; Uint8 *src, *dst, *tmp; int w, h, length, rows; int status; GL_ActivateRenderer(renderer); temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { SDL_OutOfMemory(); return -1; } convert_format(data, temp_format, &internalFormat, &format, &type); SDL_GetWindowSize(window, &w, &h); data->glPixelStorei(GL_PACK_ALIGNMENT, 1); data->glPixelStorei(GL_PACK_ROW_LENGTH, (temp_pitch / SDL_BYTESPERPIXEL(temp_format))); data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h, format, type, temp_pixels); /* Flip the rows to be top-down */ length = rect->w * SDL_BYTESPERPIXEL(temp_format); src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch; dst = (Uint8*)temp_pixels; tmp = SDL_stack_alloc(Uint8, length); rows = rect->h / 2; while (rows--) { SDL_memcpy(tmp, dst, length); SDL_memcpy(dst, src, length); SDL_memcpy(src, tmp, length); dst += temp_pitch; src -= temp_pitch; } SDL_stack_free(tmp); status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch); SDL_free(temp_pixels); return status; }
static void print_union(struct mlist *mlp, struct tdesc *tdp, char *format, int level) { format = convert_format(format, ".x"); if (level != 0) printf("' noop ' %s", format); else { printf("' %s %x struct-field %s\n", format, mlp->offset / 8, mlp->name); } }
static void print_enum(struct mlist *mlp, struct tdesc *tdp, char *format, int level) { format = convert_format(format, ".d"); if (level != 0) printf("' l@ ' %s", format); else printf("' %s %x long-field %s\n", format, mlp->offset / 8, mlp->name); }
static void print_intrinsic(struct mlist *mlp, struct tdesc *tdp, char *format, int level) { format = convert_format(format, ".x"); if (level != 0) { switch (tdp->size) { case 1: printf("' c@ ' %s", format); break; case 2: printf("' w@ ' %s", format); break; case 4: printf("' l@ ' %s", format); break; case 8: printf("' x@ ' %s", format); break; } /* * Check for bit field. */ } else if (mlp->size != 0 && ((mlp->size % 8) != 0 || (mlp->offset % mlp->size) != 0)) { int offset, shift, mask; offset = (mlp->offset / 32) * 4; shift = 32 - ((mlp->offset % 32) + mlp->size); mask = ((int)pow(2, mlp->size) - 1) << shift; printf("' %s %x %x %x bits-field %s\n", format, shift, mask, offset, mlp->name); } else if (mlp->name != NULL) { switch (tdp->size) { case 1: printf("' %s %x byte-field %s\n", format, mlp->offset / 8, mlp->name); break; case 2: printf("' %s %x short-field %s\n", format, mlp->offset / 8, mlp->name); break; case 4: printf("' %s %x long-field %s\n", format, mlp->offset / 8, mlp->name); break; case 8: printf("' %s %x ext-field %s\n", format, mlp->offset / 8, mlp->name); break; } } }
bool platform_get_pixmap_info(EGLNativePixmapType pixmap, KHRN_IMAGE_WRAP_T *image) { image->format = convert_format(((uint32_t *)pixmap)[4]); image->width = ((uint32_t *)pixmap)[2]; image->height = ((uint32_t *)pixmap)[3]; /* can't actually access data */ image->stride = 0; image->aux = 0; image->storage = 0; return image->format != 0; }
int convert (MagickWand *input, MagickWand **output, convert_t *opts, unsigned char* data, size_t size) { if (convert_density(input, opts) != MagickPass) return -7; if (MagickReadImageBlob(input, data, size) != MagickPass) return -2; if (convert_adjoin(input, output, opts) != MagickPass) return -8; input = *output; MagickResetIterator(input); MagickNextImage(input); // Has to be called after MagickResetIterator to set the first picture as the current do { if (convert_format(input, opts) != MagickPass) return -3; if (convert_scale(input, opts) != MagickPass) return -4; if (convert_rotate(input, opts) != MagickPass) return -5; if (convert_crop(input, opts) != MagickPass) return -6; } while (MagickNextImage(input)); return 0; }
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; SDL_Window *window = renderer->window; GLint internalFormat; GLenum format, type; Uint8 *src, *dst, *tmp; int w, h, length, rows; GL_ActivateRenderer(renderer); if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) { /* FIXME: Do a temp copy to a format that is supported */ SDL_SetError("Unsupported pixel format"); return -1; } SDL_GetWindowSize(window, &w, &h); data->glPixelStorei(GL_PACK_ALIGNMENT, 1); data->glPixelStorei(GL_PACK_ROW_LENGTH, (pitch / SDL_BYTESPERPIXEL(pixel_format))); data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h, format, type, pixels); /* Flip the rows to be top-down */ length = rect->w * SDL_BYTESPERPIXEL(pixel_format); src = (Uint8*)pixels + (rect->h-1)*pitch; dst = (Uint8*)pixels; tmp = SDL_stack_alloc(Uint8, length); rows = rect->h / 2; while (rows--) { SDL_memcpy(tmp, dst, length); SDL_memcpy(dst, src, length); SDL_memcpy(src, tmp, length); dst += pitch; src -= pitch; } SDL_stack_free(tmp); return 0; }
texture_t gs_create_texture_from_file(const char *file) { struct ffmpeg_image image; texture_t tex = NULL; if (ffmpeg_image_init(&image, file)) { uint8_t *data = malloc(image.cx * image.cy * 4); if (ffmpeg_image_decode(&image, data, image.cx * 4)) { tex = gs_create_texture(image.cx, image.cy, convert_format(image.format), 1, (const uint8_t**)&data, 0); } ffmpeg_image_free(&image); free(data); } return tex; }
PUBLIC void put_scrap(int type, int srclen, char *src) { scrap_type format; int dstlen; char *dst; format = convert_format(type); dstlen = convert_data(type, NULL, src, srclen); #if defined(X11_SCRAP) /* * */ dst = (char *)alloca(dstlen); if ( dst != NULL ) { convert_data(type, dst, src, srclen); XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), XA_CUT_BUFFER0, format, 8, PropModeReplace, (unsigned char *) dst, dstlen); if ( we_lost_clipboard() ) XSetSelectionOwner(SDL_Display, XA_PRIMARY, SDL_Window, CurrentTime); } #elif defined(WIN_SCRAP) /* * */ if ( OpenClipboard(SDL_Window) ) { HANDLE hMem; hMem = GlobalAlloc((GMEM_MOVEABLE|GMEM_DDESHARE), dstlen); if ( hMem != NULL ) { dst = (char *)GlobalLock(hMem); convert_data(type, dst, src, srclen); GlobalUnlock(hMem); EmptyClipboard(); SetClipboardData(format, hMem); } CloseClipboard(); } #endif /* scrap type */ }
/// set texture pixels void GHL_CALL TextureOpenGL::SetData(UInt32 x,UInt32 y,UInt32 w,UInt32 h,const Data* data,UInt32 level) { glActiveTexture(GL_TEXTURE0); //glClientActiveTexture(GL_TEXTURE0); bind(); glPixelStorei(GL_UNPACK_ALIGNMENT,1); #ifndef GHL_OPENGLES glPixelStorei(GL_UNPACK_ROW_LENGTH,w); #endif if (format_compressed(m_fmt)) { glCompressedTexSubImage2D(GL_TEXTURE_2D, level, x, y, w, h, convert_int_format(m_fmt), data->GetSize(), data->GetData()); } else { glTexSubImage2D(GL_TEXTURE_2D, level, x, y, w, h, convert_format(m_fmt), convert_storage(m_fmt), data->GetData()); } glPixelStorei(GL_UNPACK_ALIGNMENT,4); #ifndef GHL_OPENGLES glPixelStorei(GL_UNPACK_ROW_LENGTH,0); #endif m_parent->RestoreTexture(); }
/*===============================================*/ int ReadHeaderSP20toMDB(T_MDB_data_header *old_header, FILE *fp) /*===============================================*/ { HD_DBP_SP20_RAW hd_raw; HD_DBP_SP20_DECOD hd_decod; BEAM_HD_SP20_INFO beam_info; int offset; if (fread(&hd_raw, sizeof(hd_raw), 1, fp) != 1) return NO_OK; decode_header_DBP_SP20 (&hd_raw, &hd_decod); //printf("------------\n read header \n"); // PrintHeaderDBP(&hd_decod); while(1){ if (fread(header_beam_spc_char, sizeof(header_beam_spc_char), 1, fp) != 1) return NO_OK; decode_header_sp20(header_beam_spc_char, &beam_info); //PrintHeader(&beam_info); offset=strlen(beam_info.quantities)*beam_info.cell_num; fseek(fp,offset,SEEK_CUR); if (beam_info.valid_data == 'V') { convert_format(&hd_decod, &beam_info, old_header); // PrintOldHeader (old_header); // printf ("%d -- %d \n",offset,sizeof(header_beam_spc_char)); fseek(fp, -(offset+sizeof(header_beam_spc_char)),SEEK_CUR); break; } } return OK; }
static void print_pointer(struct mlist *mlp, struct tdesc *tdp, char *format, int level) { format = convert_format(format, ".x"); if (level != 0) { switch (tdp->size) { case 1: printf("' c@ ' %s", format); break; case 2: printf("' w@ ' %s", format); break; case 4: printf("' l@ ' %s", format); break; case 8: printf("' x@ ' %s", format); break; } } else { printf("' %s %x ptr-field %s\n", format, mlp->offset / 8, mlp->name); } }
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; GL_TextureData *data; GLint internalFormat; GLenum format, type; int texture_w, texture_h; GLenum result; GL_ActivateRenderer(renderer); if (!convert_format(renderdata, texture->format, &internalFormat, &format, &type)) { SDL_SetError("Texture format %s not supported by OpenGL", SDL_GetPixelFormatName(texture->format)); return -1; } data = (GL_TextureData *) SDL_calloc(1, sizeof(*data)); if (!data) { SDL_OutOfMemory(); return -1; } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { size_t size; data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); size = texture->h * data->pitch; if (texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { /* Need to add size for the U and V planes */ size += (2 * (texture->h * data->pitch) / 4); } data->pixels = SDL_malloc(size); if (!data->pixels) { SDL_OutOfMemory(); SDL_free(data); return -1; } } texture->driverdata = data; renderdata->glGetError(); renderdata->glGenTextures(1, &data->texture); if (renderdata->GL_ARB_texture_rectangle_supported) { data->type = GL_TEXTURE_RECTANGLE_ARB; texture_w = texture->w; texture_h = texture->h; data->texw = (GLfloat) texture_w; data->texh = (GLfloat) texture_h; } else { data->type = GL_TEXTURE_2D; texture_w = power_of_2(texture->w); texture_h = power_of_2(texture->h); data->texw = (GLfloat) (texture->w) / texture_w; data->texh = (GLfloat) texture->h / texture_h; } data->format = format; data->formattype = type; data->scaleMode = GL_LINEAR; renderdata->glEnable(data->type); renderdata->glBindTexture(data->type, data->texture); renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #ifdef __MACOSX__ #ifndef GL_TEXTURE_STORAGE_HINT_APPLE #define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC #endif #ifndef STORAGE_CACHED_APPLE #define STORAGE_CACHED_APPLE 0x85BE #endif #ifndef STORAGE_SHARED_APPLE #define STORAGE_SHARED_APPLE 0x85BF #endif if (texture->access == SDL_TEXTUREACCESS_STREAMING) { renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_SHARED_APPLE); } else { renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE); } if (texture->access == SDL_TEXTUREACCESS_STREAMING && texture->format == SDL_PIXELFORMAT_ARGB8888) { renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, texture_h, 0, format, type, data->pixels); } else #endif { renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, texture_h, 0, format, type, NULL); } renderdata->glDisable(data->type); result = renderdata->glGetError(); if (result != GL_NO_ERROR) { GL_SetError("glTexImage2D()", result); return -1; } if (texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { data->yuv = SDL_TRUE; renderdata->glGenTextures(1, &data->utexture); renderdata->glGenTextures(1, &data->vtexture); renderdata->glEnable(data->type); renderdata->glBindTexture(data->type, data->utexture); renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2, texture_h/2, 0, format, type, NULL); renderdata->glBindTexture(data->type, data->vtexture); renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w/2, texture_h/2, 0, format, type, NULL); renderdata->glDisable(data->type); } return 0; }
int main (int argc, char *argv[]) { int i; FILE *f = stdin; char format = '\0'; int regex_file_specified = 0; setlocale (LC_TIME, "C"); determine_mode_from_name (argv[0]); while (1) { static struct option long_options[] = { {"help", 0, 0, 1000 + 'H'}, {"version", 0, 0, 1000 + 'V'}, {"verbose", 0, 0, 'v'}, {"list", 0, 0, 'l'}, {"filter", 0, 0, 1000 + 'f'}, {"grep", 0, 0, 'g'}, {"strip", 1, 0, 1000 + 'S'}, {"addprefix", 1, 0, 1000 + 'A'}, {"addoldprefix", 1, 0, 1000 + 'O'}, {"addnewprefix", 1, 0, 1000 + 'N'}, {"hunks", 1, 0, '#'}, {"lines", 1, 0, 1000 + ':'}, {"files", 1, 0, 'F'}, {"as-numbered-lines", 1, 0, 1000 + 'L'}, {"annotate", 0, 0, 1000 + 'a'}, {"format", 1, 0, 1000 + 'F'}, {"output-matching", 1, 0, 1000 + 'o'}, {"remove-timestamps", 0, 0, 1000 + 'r'}, {"with-filename", 0, 0, 'H'}, {"no-filename", 0, 0, 'h'}, {"empty-files-as-absent", 0, 0, 'E'}, {"number-files", 0, 0, 'N'}, {"clean", 0, 0, 1000 + 'c'}, {"strip-match", 1, 0, 'p'}, {"include", 1, 0, 'i'}, {"exclude", 1, 0, 'x'}, {"include-from-file", 1, 0, 'I'}, {"exclude-from-file", 1, 0, 'X'}, {"decompress", 0, 0, 'z'}, {"line-number", 0, 0, 'n'}, {"strip-match", 1, 0, 'p'}, {"status", 0, 0, 's'}, {"extended-regexp", 0, 0, 'E'}, {"empty-files-as-removed", 0, 0, 'E'}, {"file", 1, 0, 'f'}, {0, 0, 0, 0} }; char *end; int c = getopt_long (argc, argv, "vp:i:I:x:X:zns#:F:Ef:HhN", long_options, NULL); if (c == -1) break; switch (c) { case 'g': set_grep (); break; case 1000 + 'f': set_filter (); break; case 'l': set_list (); break; case 'E': if (mode == mode_grep) egrepping = REG_EXTENDED; else if (mode == mode_list) empty_files_as_absent = 1; else syntax (1); break; case 'f': if (mode == mode_grep) { regex_file_specified = 1; read_regex_file (optarg); } else syntax (1); break; case 1000 + 'V': printf("%s - patchutils version %s\n", progname, VERSION); exit(0); case 1000 + 'H': syntax (0); break; case 1000 + 'S': strip_components = strtoul (optarg, &end, 0); if (optarg == end) syntax (1); break; case 1000 + 'A': prefix_to_add = optarg; break; case 1000 + 'O': old_prefix_to_add = optarg; break; case 1000 + 'N': new_prefix_to_add = optarg; break; case 'p': ignore_components = strtoul (optarg, &end, 0); if (optarg == end) syntax (1); break; case 'x': patlist_add (&pat_exclude, optarg); break; case 'X': patlist_add_file (&pat_exclude, optarg); break; case 'i': patlist_add (&pat_include, optarg); break; case 'I': patlist_add_file (&pat_include, optarg); break; case 'z': unzip = 1; break; case 'n': numbering = 1; break; case 'N': number_files = 1; break; case 's': show_status = 1; break; case 'v': verbose++; if (numbering && verbose > 1) number_files = 1; break; case '#': if (hunks) syntax (1); if (*optarg == 'x') { hunks_exclude = 1; optarg = optarg + 1; } parse_range (&hunks, optarg); break; case 'H': if (mode == mode_list || mode == mode_grep) print_patchnames = 1; else syntax (1); break; case 'h': if (mode == mode_list || mode == mode_grep) print_patchnames = 0; else syntax (1); break; case 1000 + ':': if (lines) syntax (1); if (*optarg == 'x') { lines_exclude = 1; optarg = optarg + 1; } parse_range (&lines, optarg); break; case 'F': if (files) syntax (1); if (*optarg == 'x') { files_exclude = 1; optarg = optarg + 1; } parse_range (&files, optarg); break; case 1000 + 'L': if (!strcmp (optarg, "before")) number_lines = Before; else if (!strcmp (optarg, "after")) number_lines = After; else syntax (1); break; case 1000 + 'a': if (mode == mode_list) syntax (1); annotating = 1; break; case 1000 + 'F': if (!strcmp (optarg, "context") && !format) format = 'c'; else if (!strcmp (optarg, "unified") && !format) format = 'u'; else syntax (1); break; case 1000 + 'o': if (!strncmp (optarg, "hunk", 4)) output_matching = output_hunk; else if (!strncmp (optarg, "file", 4)) output_matching = output_file; else syntax (1); break; case 1000 + 'r': removing_timestamp = 1; break; case 1000 + 'c': clean_comments = 1; break; default: syntax(1); } } /* Preserve the old semantics of -p. */ if (mode != mode_filter && ignore_components && !strip_components && !pat_include && !pat_exclude) { fprintf (stderr, "-p given without -i or -x; guessing that you " "meant --strip instead.\n"); strip_components = ignore_components; ignore_components = 0; } if (mode != mode_grep && output_matching != output_none) error (EXIT_FAILURE, 0, "--output-matching only applies to " "grep mode"); if (numbering && !(mode == mode_list || (mode == mode_grep && output_matching == output_none))) error (EXIT_FAILURE, 0, "-n only applies to list mode"); if (mode != mode_filter && output_matching == output_none && number_lines != None) error (EXIT_FAILURE, 0, "--as-numbered-lines is " "inappropriate in this context"); if (mode == mode_filter && verbose && clean_comments) error (EXIT_FAILURE, 0, "can't use --verbose and " "--clean options simultaneously"); if (mode == mode_grep && !regex_file_specified) { int err; if (optind == argc) syntax (1); regex = xrealloc (regex, ++num_regex * sizeof (regex[0])); err = regcomp (®ex[num_regex - 1], argv[optind++], REG_NOSUB | egrepping); if (err) { char errstr[300]; regerror (err, ®ex[num_regex - 1], errstr, sizeof (errstr)); error (EXIT_FAILURE, 0, "%s", errstr); exit (1); } } if (number_lines != None || output_matching != output_none) { if (print_patchnames == 1) error (EXIT_FAILURE, 0, "-H is inappropriate in this context"); } else if (print_patchnames == -1) { if ((mode == mode_list || mode == mode_grep) && optind + 1 < argc) print_patchnames = 1; else print_patchnames = 0; } if (optind == argc) { f = convert_format (stdin, format); filterdiff (f, "(standard input)"); fclose (f); } else { for (i = optind; i < argc; i++) { if (unzip) { f = xopen_unzip (argv[i], "rb"); } else { f = xopen(argv[i], "rbm"); } f = convert_format (f, format); filterdiff (f, argv[i]); fclose (f); } } return 0; }
PUBLIC void get_scrap(int type, int *dstlen, char **dst) { scrap_type format; *dstlen = -1; format = convert_format(type); #if defined(X11_SCRAP) /* * */ { Window owner; Atom selection; Atom seln_type; int seln_format; unsigned long nbytes; unsigned long overflow; char *src; owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY); if ( (owner == None) || (owner == SDL_Window) ) { owner = DefaultRootWindow(SDL_Display); selection = XA_CUT_BUFFER0; } else { int selection_response = 0; SDL_Event event; owner = SDL_Window; selection = XInternAtom(SDL_Display, "SDL_SELECTION", False); XConvertSelection(SDL_Display, XA_PRIMARY, format, selection, owner, CurrentTime); while ( ! selection_response ) { SDL_WaitEvent(&event); if ( event.type == SDL_SYSWMEVENT ) { #if SDL_MAJOR_VERSION == 0 && SDL_MINOR_VERSION < 9 XEvent xevent = event.syswm.msg->xevent; #else XEvent xevent = event.syswm.msg->event.xevent; #endif if ( (xevent.type == SelectionNotify) && (xevent.xselection.requestor == owner) ) selection_response = 1; } else { /* FIXME: dropped event? */; } } } if ( XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, (unsigned char **)&src) == Success ) { if ( seln_type == format ) { char *mem; *dstlen = convert_scrap(type, NULL, src, nbytes); mem = sdl_ReallocHandle(dst, *dstlen); if ( mem == NULL ) *dstlen = -1; else convert_scrap(type, mem, src, nbytes); } XFree(src); } } #elif defined(WIN_SCRAP) /* * */ if ( IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window) ) { HANDLE hMem; char *src; hMem = GetClipboardData(format); if ( hMem != NULL ) { char *mem; src = (char *)GlobalLock(hMem); *dstlen = convert_scrap(type, NULL, src, 0); mem = sdl_ReallocHandle(dst, *dstlen); if ( mem == NULL ) *dstlen = -1; else convert_scrap(type, mem, src, 0); GlobalUnlock(hMem); } CloseClipboard(); } #endif /* scrap type */ }
void get_scrap(int type, int *dstlen, char **dst) { scrap_type format; *dstlen = 0; format = convert_format(type); #if defined(WZ_WS_X11) /* * */ { Window owner; Atom selection; Atom seln_type; int seln_format; unsigned long nbytes; unsigned long overflow; unsigned char * src; Lock_Display(); owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY); Unlock_Display(); if ( (owner == None) || (owner == SDL_Window) ) { owner = DefaultRootWindow(SDL_Display); selection = XA_CUT_BUFFER0; } else { int selection_response = 0; SDL_Event event; owner = SDL_Window; Lock_Display(); selection = XInternAtom(SDL_Display, "SDL_SELECTION", False); XConvertSelection(SDL_Display, XA_PRIMARY, format, selection, owner, CurrentTime); Unlock_Display(); while ( ! selection_response ) { SDL_WaitEvent(&event); if ( event.type == SDL_SYSWMEVENT ) { XEvent xevent = event.syswm.msg->event.xevent; if ( (xevent.type == SelectionNotify) && (xevent.xselection.requestor == owner) ) selection_response = 1; } } } Lock_Display(); if ( XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, &src) == Success ) { if ( seln_type == format ) { *dstlen = convert_scrap(type, NULL, (char*)src, nbytes); *dst = (char *)realloc(*dst, *dstlen); if ( *dst == NULL ) *dstlen = 0; else convert_scrap(type, *dst, (char*)src, nbytes); } XFree(src); } Unlock_Display(); } #elif defined(WZ_WS_WIN) /* * */ if ( IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window) ) { HANDLE hMem; char *src; hMem = GetClipboardData(format); if ( hMem != NULL ) { src = (char *)GlobalLock(hMem); *dstlen = convert_scrap(type, NULL, src, 0); *dst = (char *)realloc(*dst, *dstlen); if ( *dst == NULL ) *dstlen = 0; else convert_scrap(type, *dst, src, 0); GlobalUnlock(hMem); } CloseClipboard(); } #elif defined(WZ_WS_QNX) /* * */ #if (_NTO_VERSION < 620) /* before 6.2.0 releases */ { void* clhandle; PhClipHeader* clheader; int* cldata; clhandle=PhClipboardPasteStart(InputGroup); if (clhandle!=NULL) { clheader=PhClipboardPasteType(clhandle, Ph_CLIPBOARD_TYPE_TEXT); if (clheader!=NULL) { cldata=clheader->data; if ((clheader->length>4) && (*cldata==type)) { *dstlen = convert_scrap(type, NULL, (char*)clheader->data+4, clheader->length-4); *dst = (char *)realloc(*dst, *dstlen); if (*dst == NULL) { *dstlen = 0; } else { convert_scrap(type, *dst, (char*)clheader->data+4, clheader->length-4); } } } PhClipboardPasteFinish(clhandle); } } #else /* 6.2.0 and 6.2.1 and future releases */ { void* clhandle; PhClipboardHdr* clheader; int* cldata; clheader=PhClipboardRead(InputGroup, Ph_CLIPBOARD_TYPE_TEXT); if (clheader!=NULL) { cldata=clheader->data; if ((clheader->length>4) && (*cldata==type)) { *dstlen = convert_scrap(type, NULL, (char*)clheader->data+4, clheader->length-4); *dst = (char *)realloc(*dst, *dstlen); if (*dst == NULL) { *dstlen = 0; } else { convert_scrap(type, *dst, (char*)clheader->data+4, clheader->length-4); } } } } #endif #endif /* scrap type */ }
void put_scrap(int type, int srclen, char *src) { scrap_type format; int dstlen; #if (defined(WZ_WS_X11) || defined(WZ_WS_WIN) || defined(WZ_WS_QNX)) char *dst; #endif format = convert_format(type); dstlen = convert_data(type, NULL, src, srclen); #if defined(WZ_WS_X11) dst = (char *)malloc(dstlen); if ( dst != NULL ) { Lock_Display(); convert_data(type, dst, src, srclen); XChangeProperty(SDL_Display, DefaultRootWindow(SDL_Display), XA_CUT_BUFFER0, format, 8, PropModeReplace, (unsigned char *)dst, dstlen); free(dst); if ( lost_scrap() ) XSetSelectionOwner(SDL_Display, XA_PRIMARY, SDL_Window, CurrentTime); Unlock_Display(); } #elif defined(WZ_WS_WIN) /* * */ if ( OpenClipboard(SDL_Window) ) { HANDLE hMem; hMem = GlobalAlloc((GMEM_MOVEABLE|GMEM_DDESHARE), dstlen); if ( hMem != NULL ) { dst = (char *)GlobalLock(hMem); convert_data(type, dst, src, srclen); GlobalUnlock(hMem); EmptyClipboard(); SetClipboardData(format, hMem); } CloseClipboard(); } #elif defined(WZ_WS_QNX) /* * */ #if (_NTO_VERSION < 620) /* before 6.2.0 releases */ { PhClipHeader clheader= {Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; int* cldata; int status; dst = (char *)malloc(dstlen+4); if (dst != NULL) { cldata=(int*)dst; *cldata=type; convert_data(type, dst+4, src, srclen); clheader.data=dst; if (dstlen>65535) { clheader.length=65535; /* maximum photon clipboard size :( */ } else { clheader.length=dstlen+4; } status=PhClipboardCopy(InputGroup, 1, &clheader); if (status==-1) { fprintf(stderr, "Photon: copy to clipboard was failed !\n"); } free(dst); } } #else /* 6.2.0 and 6.2.1 and future releases */ { PhClipboardHdr clheader= {Ph_CLIPBOARD_TYPE_TEXT, 0, NULL}; int* cldata; int status; dst = (char *)malloc(dstlen+4); if (dst != NULL) { cldata=(int*)dst; *cldata=type; convert_data(type, dst+4, src, srclen); clheader.data=dst; clheader.length=dstlen+4; status=PhClipboardWrite(InputGroup, 1, &clheader); if (status==-1) { fprintf(stderr, "Photon: copy to clipboard was failed !\n"); } free(dst); } } #endif #endif /* scrap type */ }