void upload_image_data_to_opengl(unsigned char* raw_image_data, CameraPixelCoding coding, int device_number) { unsigned char * gl_image_data; static unsigned char* show_pixels=NULL; GLuint textureId; GLubyte* ptr; textureId = textureId_all[device_number]; if (use_pbo) { #ifdef USE_GLEW glBindTexture(GL_TEXTURE_2D, textureId); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex_width, tex_height, gl_data_format, GL_UNSIGNED_BYTE, 0); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo); glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, PBO_stride*tex_height, 0, GL_STREAM_DRAW_ARB); ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB); if(ptr) { convert_pixels(raw_image_data, coding, PBO_stride, ptr, 1); glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer } glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); #endif /* ifdef USE_GLEW */ } else { if (show_pixels==NULL) { /* allocate memory */ show_pixels = (unsigned char *)malloc( PBO_stride*height ); if (show_pixels==NULL) { fprintf(stderr,"couldn't allocate memory in %s, line %d\n",__FILE__,__LINE__); exit(1); } } gl_image_data = convert_pixels(raw_image_data, coding, PBO_stride, show_pixels, 0); glBindTexture(GL_TEXTURE_2D, textureId); glTexSubImage2D(GL_TEXTURE_2D, /* target */ 0, /* mipmap level */ 0, /* x offset */ 0, /* y offset */ width, height, gl_data_format, /* data format */ GL_UNSIGNED_BYTE, /* data type */ gl_image_data); } }
int writeFITSline (void *fd, struct CCDexp *exposure, uint16 *lineBuffer) { convert_pixels((unsigned char *)lineBuffer, 2, exposure->rowBytes/2); return write((int)fd, lineBuffer, exposure->rowBytes) != exposure->rowBytes; }
int export_png_rgb_16(image *i, output *output) { const char *fn; int shouldclose; png_structp png_ptr; png_infop info_ptr; png_uint_32 n, x, y, pi; pixelref src; colour rgb; png_bytep pp; uint16_t *bp; FILE *fp; pixel_converter_fn converter; converter = convert_pixels(i->format, PF_RGB, 16); if(!converter) { fprintf(stderr, "cannot locate a suitable format converter for RGB-16\n"); return -1; } fn = output_filename(output, i, &shouldclose); fp = fopen(fn, "wb"); if(!fp) { return -1; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(!png_ptr) { return -1; } info_ptr = png_create_info_struct(png_ptr); if(!info_ptr) { return -1; } png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, i->width, i->height, 16, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); png_write_info(png_ptr, info_ptr); pp = (png_bytep) malloc(i->width * 3 * sizeof(uint16_t)); bp = (uint16_t *) pp; src.pixel[0] = i->pixels[0]; src.pixel[1] = i->pixels[1]; src.pixel[2] = i->pixels[2]; for(y = 0, pi = 0; y < i->height; y++) { for(n = 0, x = 0; x < i->width; x++, pi++) { converter(src, &rgb); src.pixel[0]++; src.pixel[1]++; src.pixel[2]++; bp[n] = htons(rgb.p.rgb.r); n++; bp[n] = htons(rgb.p.rgb.g); n++; bp[n] = htons(rgb.p.rgb.b); n++; } png_write_row(png_ptr, pp); } png_write_end(png_ptr, NULL); free(pp); fclose(fp); png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); png_destroy_write_struct(&png_ptr, NULL); return 0; }