comparison libvo/gl_common.c @ 18961:9f1bbc70c773

Support for 16 bit ppms
author reimar
date Sat, 08 Jul 2006 19:23:26 +0000
parents 3bf0d70b4c7f
children a61ef37d3c71
comparison
equal deleted inserted replaced
18960:3aaed991e8cd 18961:9f1bbc70c773
65 65
66 //! \defgroup gltexture OpenGL texture handling helper functions 66 //! \defgroup gltexture OpenGL texture handling helper functions
67 67
68 //! \defgroup glconversion OpenGL conversion helper functions 68 //! \defgroup glconversion OpenGL conversion helper functions
69 69
70 static GLint hqtexfmt;
71
70 /** 72 /**
71 * \brief adjusts the GL_UNPACK_ALIGNMENT to fit the stride. 73 * \brief adjusts the GL_UNPACK_ALIGNMENT to fit the stride.
72 * \param stride number of bytes per line for which alignment should fit. 74 * \param stride number of bytes per line for which alignment should fit.
73 * \ingroup glgeneral 75 * \ingroup glgeneral
74 */ 76 */
312 for (i = 0; !ptr && dsc->funcnames[i]; i++) 314 for (i = 0; !ptr && dsc->funcnames[i]; i++)
313 ptr = getProcAddress((const GLubyte *)dsc->funcnames[i]); 315 ptr = getProcAddress((const GLubyte *)dsc->funcnames[i]);
314 } 316 }
315 *(dsc->funcptr) = ptr; 317 *(dsc->funcptr) = ptr;
316 } 318 }
319 if (strstr(allexts, "_texture_float"))
320 hqtexfmt = GL_RGB32F;
321 else if (strstr(allexts, "NV_float_buffer"))
322 hqtexfmt = GL_FLOAT_RGB32_NV;
323 else
324 hqtexfmt = GL_RGB16;
317 free(allexts); 325 free(allexts);
318 } 326 }
319 327
320 /** 328 /**
321 * \brief create a texture and set some defaults 329 * \brief create a texture and set some defaults
368 #define MAXDIM (16 * 1024) 376 #define MAXDIM (16 * 1024)
369 377
370 /** 378 /**
371 * \brief creates a texture from a PPM file 379 * \brief creates a texture from a PPM file
372 * \param target texture taget, usually GL_TEXTURE_2D 380 * \param target texture taget, usually GL_TEXTURE_2D
373 * \param fmt internal texture format 381 * \param fmt internal texture format, 0 for default
374 * \param filter filter used for scaling, e.g. GL_LINEAR 382 * \param filter filter used for scaling, e.g. GL_LINEAR
375 * \param f file to read PPM from 383 * \param f file to read PPM from
376 * \param width [out] width of texture 384 * \param width [out] width of texture
377 * \param height [out] height of texture 385 * \param height [out] height of texture
378 * \param maxval [out] maxval value from PPM file 386 * \param maxval [out] maxval value from PPM file
379 * \return 0 on error, 1 otherwise 387 * \return 0 on error, 1 otherwise
380 * \ingroup gltexture 388 * \ingroup gltexture
381 */ 389 */
382 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter, 390 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter,
383 FILE *f, int *width, int *height, int *maxval) { 391 FILE *f, int *width, int *height, int *maxval) {
384 unsigned w, h, m, val; 392 unsigned w, h, m, val, bpp;
385 char *data; 393 char *data;
386 ppm_skip(f); 394 ppm_skip(f);
387 if (fgetc(f) != 'P' || fgetc(f) != '6') 395 if (fgetc(f) != 'P' || fgetc(f) != '6')
388 return 0; 396 return 0;
389 ppm_skip(f); 397 ppm_skip(f);
398 val = fgetc(f); 406 val = fgetc(f);
399 if (!isspace(val)) 407 if (!isspace(val))
400 return 0; 408 return 0;
401 if (w > MAXDIM || h > MAXDIM) 409 if (w > MAXDIM || h > MAXDIM)
402 return 0; 410 return 0;
403 data = malloc(w * h * 3); 411 bpp = (m > 255) ? 6 : 3;
404 if (fread(data, w * 3, h, f) != h) 412 data = malloc(w * h * bpp);
413 if (fread(data, w * bpp, h, f) != h)
405 return 0; 414 return 0;
415 if (!fmt) {
416 fmt = (m > 255) ? hqtexfmt : 3;
417 if (fmt == GL_FLOAT_RGB32_NV && target != GL_TEXTURE_RECTANGLE)
418 fmt = GL_RGB16;
419 }
406 glCreateClearTex(target, fmt, filter, w, h, 0); 420 glCreateClearTex(target, fmt, filter, w, h, 0);
407 glUploadTex(target, GL_RGB, GL_UNSIGNED_BYTE, data, w * 3, 0, 0, w, h, 0); 421 glUploadTex(target, GL_RGB, (m > 255) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE,
422 data, w * bpp, 0, 0, w, h, 0);
408 free(data); 423 free(data);
409 if (width) *width = w; 424 if (width) *width = w;
410 if (height) *height = h; 425 if (height) *height = h;
411 if (maxval) *maxval = m; 426 if (maxval) *maxval = m;
412 return 1; 427 return 1;
420 * \ingroup glgeneral 435 * \ingroup glgeneral
421 * 436 *
422 * Does not handle all possible variants, just those used by MPlayer 437 * Does not handle all possible variants, just those used by MPlayer
423 */ 438 */
424 int glFmt2bpp(GLenum format, GLenum type) { 439 int glFmt2bpp(GLenum format, GLenum type) {
440 int component_size = 0;
425 switch (type) { 441 switch (type) {
426 case GL_UNSIGNED_BYTE_3_3_2: 442 case GL_UNSIGNED_BYTE_3_3_2:
427 case GL_UNSIGNED_BYTE_2_3_3_REV: 443 case GL_UNSIGNED_BYTE_2_3_3_REV:
428 return 1; 444 return 1;
429 case GL_UNSIGNED_SHORT_5_5_5_1: 445 case GL_UNSIGNED_SHORT_5_5_5_1:
430 case GL_UNSIGNED_SHORT_1_5_5_5_REV: 446 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
431 case GL_UNSIGNED_SHORT_5_6_5: 447 case GL_UNSIGNED_SHORT_5_6_5:
432 case GL_UNSIGNED_SHORT_5_6_5_REV: 448 case GL_UNSIGNED_SHORT_5_6_5_REV:
433 return 2; 449 return 2;
434 } 450 case GL_UNSIGNED_BYTE:
435 if (type != GL_UNSIGNED_BYTE) 451 component_size = 1;
436 return 0; //not implemented 452 break;
453 case GL_UNSIGNED_SHORT:
454 component_size = 2;
455 break;
456 }
437 switch (format) { 457 switch (format) {
438 case GL_LUMINANCE: 458 case GL_LUMINANCE:
439 case GL_ALPHA: 459 case GL_ALPHA:
440 return 1; 460 return component_size;
441 case GL_RGB: 461 case GL_RGB:
442 case GL_BGR: 462 case GL_BGR:
443 return 3; 463 return 3 * component_size;
444 case GL_RGBA: 464 case GL_RGBA:
445 case GL_BGRA: 465 case GL_BGRA:
446 return 4; 466 return 4 * component_size;
447 } 467 }
448 return 0; // unknown 468 return 0; // unknown
449 } 469 }
450 470
451 /** 471 /**