libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moTexture.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moTexture.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andres Colubri
29 
30 *******************************************************************************/
31 
32 #include <moTexture.h>
33 #include <moTextureFilterIndex.h>
34 #include <FreeImage.h>
35 #include <moFileManager.h>
36 #include <moDataManager.h>
37 
38 #include "moArray.h"
39 moDefineDynamicArray(moTextureArray)
40 
41 //===========================================
42 //
43 // moTexture
44 //
45 //===========================================
46 
48 {
49  m_pFile = NULL;
50  m_bBuildedFromFile = false;
51  m_type = MO_TYPE_TEXTURE;
52  SetName(moText(""));
53  m_moid = -1;
54  m_glid = 0;
55 
56  m_width = 0;
57  m_height = 0;
58  m_bytespp = 0;
59  m_components = 0;
60  m_max_coord_s = 0.0;
61  m_max_coord_t = 0.0;
62 
63  m_pResourceManager = NULL;
64  m_gl = NULL;
65  m_pDataMan = NULL;
66  m_pFileMan = NULL;
67  m_fbo = NULL;
68  m_fbo_attach_point = MO_UNDEFINED;
69 
70  m_param = MODefTex2DParams;
71 
72  Luminance = -1;
73  Contrast = -1;
74  m_pBufferData = NULL;
75  m_buffer_width = 0;
76  m_buffer_height = 0;
77  m_buffer_bytespp = 0;
78 }
79 
81 {
82  Finish();
83 }
84 
86 {
87  m_pFile = NULL;
88  SetName(p_name);
89  m_moid = p_moid;
90  if (p_res) {
91  m_pResourceManager = p_res;
92  m_gl = p_res->GetGLMan();
93  m_pDataMan = p_res->GetDataMan();
94  m_pFileMan = p_res->GetFileMan();
95  }
96  m_param = p_param;
97  m_bInitialized = (m_gl!=NULL) && (m_pDataMan!=NULL) && (m_pFileMan!=NULL);
98  return m_bInitialized;
99 }
100 
102 {
103  if ((m_type != MO_TYPE_TEXTURE_MULTIPLE) && (0 < m_glid))
104  {
105  glDeleteTextures(1, &m_glid);
106  m_glid = 0;
107  }
108  m_bInitialized = false;
109  return true;
110 }
111 
112 
114 {
115  // int ii;
116  /*if ( 0 < m_glid ) {
117  //ii = m_glid;
118  glDeleteTextures(1, &m_glid);
119  m_glid = 0;
120  //m_glid = ii;
121  }*/
122 
123  if (m_glid<=0) {
124  glGenTextures(1, &m_glid);
125  }
126 
127 
128  CalculateSize(p_width, p_height);
129 /*
130  unsigned char* buffer = new unsigned char [m_width*m_height]();
131  SetBuffer(m_width, m_height, buffer );
132 */
133  return Build();
134 }
135 
136 MOboolean moTexture::BuildFromBuffer(MOuint p_width, MOuint p_height, const GLvoid* p_buffer, GLenum p_format, GLenum p_type)
137 {
138  BuildEmpty(p_width, p_height);
139  return SetBuffer(p_width, p_height, p_buffer, p_format, p_type);
140 }
141 
143 {
144  MOboolean res;
145  moFile* pFile = NULL;
146 
147  //check for file
148  if ( m_pFileMan->Load(p_filename)) {
149  pFile = m_pFileMan->GetFile(p_filename);
150  } else return false;
151  if ( pFile==NULL ) return false;
152  m_pFile = pFile;
153 
154  FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
155  FIBITMAP *m_pImage = NULL;
156 
158 
159  fif = FreeImage_GetFileType( m_pFile->GetCompletePath(), 0);
160 
161  if( fif == FIF_UNKNOWN ) {
162  // try to guess the file format from the file extension
163  fif = FreeImage_GetFIFFromFilename(m_pFile->GetCompletePath());
164  }
165 
166  if( (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif) ) {
167  // ok, let's load the file
168  m_pImage = FreeImage_Load( fif, m_pFile->GetCompletePath(), 0);
169  }
170  } else if ( m_pFile->IsRemote() ) {
171  //set an internal flag for texture to always check if file has finished downloading
172  //and build
174  //we check from filename
175  fif = FreeImage_GetFIFFromFilename(m_pFile->GetCompletePath());
176  if( (fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif) ) {
177  // ok, let's load the file
178  m_pImage = FreeImage_LoadFromMemory( fif, (FIMEMORY*)m_pFile->GetData(), 0);
179  }
180  }
181  }
182 
183  moMathd Mathd;
184 
185  if (m_pImage != NULL)
186  {
187  MOuint p_width;
188  MOuint p_height;
189  FIBITMAP* pImageScaled = NULL;
190 
191  p_width = FreeImage_GetWidth(m_pImage);
192  p_height = FreeImage_GetHeight(m_pImage);
193 
194  bool size_mult_4 = ( p_width % 4 ) != 0 || ( p_height % 4) == 0;
195  bool size_power_2 = ( !Mathd.IsPowerOfTwo( (int)p_width ) || !Mathd.IsPowerOfTwo( (int)p_height ) );
196  bool resize_image = false;
198 
199  if (size_power_2
200  &&
201  no_power ) {
202  if (!Mathd.IsPowerOfTwo(p_width)) p_width = NextPowerOf2( p_width );
203  if (!Mathd.IsPowerOfTwo(p_height)) p_height = NextPowerOf2( p_height );
204  resize_image = true;
205  }
206 
207  if ( size_mult_4 ) {
208 
209  p_width = p_width / 4;
210  p_width = p_width * 4;
211 
212  p_height = p_height / 4;
213  p_height = p_height* 4;
214  resize_image = true;
215  }
216 
217 
218  if (resize_image) {
219  pImageScaled = FreeImage_Rescale( m_pImage, p_width, p_height, FILTER_BICUBIC );
220  if (pImageScaled) {
221  FreeImage_Unload( m_pImage );
222  m_pImage = pImageScaled;
223  }
224  }
225 
226  MOuint bpp = FreeImage_GetBPP(m_pImage);
227  FREE_IMAGE_COLOR_TYPE colortype = FreeImage_GetColorType(m_pImage);
228  FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(m_pImage);
229  MOuint p_format;
230  MOuint red_mask = FreeImage_GetRedMask(m_pImage);
231  MOuint blue_mask = FreeImage_GetBlueMask(m_pImage);
232  MOuint green_mask = FreeImage_GetGreenMask(m_pImage);
233  MOuint pitch = FreeImage_GetPitch(m_pImage);
234  MODebug2->Message( GetName()+ " bpp: "+IntToStr(bpp)
235  +" colortype:"+IntToStr(colortype)
236  +" image_type:"+IntToStr(image_type)
237  +" pitch:"+IntToStr(pitch)
238  +" > blue_mask: " +IntToStr(blue_mask)
239  +" green_mask:"+IntToStr(green_mask)
240  +" red_mask:"+ IntToStr(red_mask) );
241 
242  m_param.target = GL_TEXTURE_2D;
243  switch (bpp)
244  {
245  case 8: // 8 bit, indexed or grayscale
246  m_param.internal_format = GL_RGB;
247  p_format = GL_LUMINANCE;
248  break;
249  case 16: // 16 bits
250  /*
251  if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
252  value->rgbBlue = (BYTE)((((*pixel & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F);
253  value->rgbGreen = (BYTE)((((*pixel & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F);
254  value->rgbRed = (BYTE)((((*pixel & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F);
255  value->rgbReserved = 0;
256  } else {
257  value->rgbBlue = (BYTE)((((*pixel & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F);
258  value->rgbGreen = (BYTE)((((*pixel & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F);
259  value->rgbRed = (BYTE)((((*pixel & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F);
260  value->rgbReserved = 0;
261  }
262  */
263  break;
264  case 24: // 24 bits
265  m_param.internal_format = GL_RGB;
266 /*
267 #ifndef OPENGLESV2
268  if ( red_mask == 0x0000FF || red_mask==0) p_format = GL_BGR;
269  else
270 #endif
271  p_format = GL_RGB;
272 #ifndef OPENGLESV2
273  if (fif==FIF_JPEG) p_format = GL_BGR;
274 #endif
275 */
276  p_format = GL_RGB;
277  if ( image_type==FIT_BITMAP && (fif==FIF_JPEG || fif==FIF_PNG) ) {
278  //BYTE* pbits = (BYTE*)FreeImage_GetBits(m_pImage);
279  for( int j = 0; j < (int)p_height; j++) {
280  //BYTE *pixel = (BYTE*)pbits;
281  BYTE *pixel = (BYTE *) FreeImage_GetScanLine( m_pImage, j );
282  for(int i = 0; i < (int)p_width; i++) {
283  BYTE tmp = pixel[FI_RGBA_RED];
284  pixel[FI_RGBA_RED] = pixel[FI_RGBA_BLUE];
285  //pixel[FI_RGBA_GREEN] = 128;
286  pixel[FI_RGBA_BLUE] = tmp;
287  pixel += 3;
288  }
289  // next line
290  //pbits += pitch;
291  }
292  }
293  break;
294  case 32: // 32 bits
295  {
296  m_param.internal_format = GL_RGBA;
297 #ifndef OPENGLESV2
298  //if ( blue_mask == 0xFF0000 || blue_mask==0 ) p_format = GL_BGRA_EXT;
299  //else
300 #endif
301  if ( image_type==FIT_BITMAP && fif==FIF_PNG ) {
302  //BYTE* pbits = (BYTE*)FreeImage_GetBits(m_pImage);
303  for( int j = 0; j < (int)p_height; j++) {
304  //BYTE *pixel = (BYTE*)pbits;
305  BYTE *pixel = (BYTE *) FreeImage_GetScanLine( m_pImage, j );
306  for(int i = 0; i < (int)p_width; i++) {
307  BYTE tmp = pixel[FI_RGBA_RED];
308  pixel[FI_RGBA_RED] = pixel[FI_RGBA_BLUE];
309  //pixel[FI_RGBA_GREEN] = 128;
310  pixel[FI_RGBA_BLUE] = tmp;
311  pixel += 4;
312  }
313  // next line
314  //pbits += pitch;
315  }
316  }
317  p_format = GL_RGBA;
318 #ifndef OPENGLESV2
319  //if (fif==FIF_PNG) p_format = GL_BGRA_EXT;
320 #else
321 
322 #endif
323  }
324  break;
325  default:
326  break;
327  }
328 
329  BuildEmpty(p_width, p_height);
330  FlipBufferVert((MOubyte *)FreeImage_GetBits(m_pImage), FreeImage_GetBPP(m_pImage) / 8 );
331  res = SetBuffer(p_width, p_height, FreeImage_GetBits(m_pImage), p_format);
332 
333  FreeImage_Unload(m_pImage);
334  }
335  else {
336  if (MODebug2 != NULL) MODebug2->Error(moText("Error at image load: ") + (moText)p_filename);
337  res = false;
338  }
339 
340  m_bBuildedFromFile = res;
341 
342  return res;
343 }
344 
346 {
347  moText extension = p_filename;
348  extension.Right(3);
349  return (!stricmp(extension,"tga") ||
350  !stricmp(extension,"jpg") ||
351  !stricmp(extension,"png") ||
352  !stricmp(extension,"gif") ||
353  !stricmp(extension,"bmp") ||
354  !stricmp(extension,"xpm") ||
355  !stricmp(extension,"ppm"));
356 }
357 
359 {
360  moValue* pValue = &p_param->GetValue();
361  return Load( pValue );
362 }
363 
365 {
366  SetName( p_value->GetSubValue(0).Text() );
367  moText namefull = m_pDataMan->GetDataPath() + moSlash + (moText)m_name;
368  return BuildFromFile(namefull);
369 }
370 
371 MOboolean moTexture::SetBuffer( const GLvoid* p_buffer, GLenum p_format, GLenum p_type)
372 {
373  return SetBuffer(m_width, m_height, p_buffer, p_format, p_type);
374 }
375 
376 MOboolean moTexture::SetBuffer(MOuint p_width, MOuint p_height, const GLvoid* p_buffer, GLenum p_format, GLenum p_type)
377 {
378  glBindTexture(m_param.target, m_glid);
379 
380  // Aqui hay que destruir la textura si los nuevos alto y anchos son diferentes de los actuales!!!!
381  moMathi mathi;
382 #ifndef OPENGLESV2
383  if ((m_gl != NULL) && m_gl->MipMapTexture(m_param.min_filter)
384  && ( mathi.IsPowerOfTwo( p_width ) )
385  && ( mathi.IsPowerOfTwo( p_height ) )
386  )
387  gluBuild2DMipmaps(m_param.target, m_param.internal_format, p_width, p_height, p_format, p_type, p_buffer);
388  else
389 #endif
390  glTexSubImage2D(m_param.target, 0, 0, 0, p_width, p_height, p_format, p_type, p_buffer);
391  glBindTexture(m_param.target, 0);
392 
393 #ifdef OPENGLESV2
394 //TODO: in OpenGL ES V2 GPU, we must save the last buffer data, so we dont need to use glGetTexImage, to fetch the texture pixels
395 if (m_pBufferData==NULL) {
396  ResetBufferData( true, 3 );
397 }
398 if (m_pBufferData) {
399  //copy buffer
400  memccpy( m_pBufferData, p_buffer, 1, p_width*p_height );
401 }
402 #endif
403  //if (m_gl != NULL) return !m_gl->CheckErrors("copying buffer to texture");
404  //else return true;
405 
406  return true;
407 }
408 
409 MOboolean moTexture::GetBuffer(GLvoid* p_buffer, GLenum p_format, GLenum p_type)
410 {
412  glBindTexture(m_param.target, this->m_glid);
414  if ( p_buffer == NULL ) {
415  MODebug2->Error("moTexture::GetBuffer > p_buffer: " + IntToStr((MOlong)p_buffer));
416  return false;
417  }
418  if (
419 #ifndef OPENGLESV2
420 p_format!=GL_BGR &&
421 p_format!=GL_BGRA &&
422 #endif
423 p_format!=GL_RGB && p_format!=GL_RGBA ) {
424  MODebug2->Error("moTexture::GetBuffer > p_format: " + IntToStr((int)p_format));
425  return false;
426  }
427  if ( p_type!=GL_UNSIGNED_BYTE && p_type!=GL_FLOAT && p_type!=GL_BYTE ) {
428  MODebug2->Error("moTexture::GetBuffer > p_type: " + IntToStr((int)p_type) );
429  return false;
430  }
431  try {
432 #ifndef OPENGLESV2
433  glGetTexImage( m_param.target, 0, p_format, p_type, p_buffer);
434 #else
435  return m_pBufferData;
436 #endif
437  } catch(...) {
438  MODebug2->Error("moTexture::GetBuffer > exception getting texture buffer. p_buffer: " + IntToStr((MOlong)p_buffer));
439  }
440  glBindTexture( m_param.target, 0);
441 
442  if (m_gl) {
443  if (m_gl->CheckErrors("copying texture to buffer")) {
444  //MODebug2->Error("moTexture::GetBuffer > GL ERROR: target: " + IntToStr((int)m_param.target) + " p_format: " + IntToStr((int)p_format) +" p_type:" + IntToStr((int)p_type) +" p_buffer:" + IntToStr((int)p_buffer) );
445  }
446  }
447  //else return true;
448  return true;
449 }
450 
451 bool moTexture::CalculateLuminanceAndConstrast( int x0, int y0, int x1, int y1 ) {
452 
453  //FREE_IMAGE_FORMAT fif;
454  FIBITMAP* fbitmap = NULL;
455  FIBITMAP* fbitmapcopy = NULL;
456  //configint options = 0;
457  BYTE* tempbuffer = NULL;
458 
459  if (GetHeight()==0 || GetWidth()==0) return false;
460 
461  if (x0 == 0 && y0 == 0 && x1 == 0 && y1 == 0) {
462 
463  tempbuffer = new BYTE [ GetHeight() * GetWidth() * 4 ];
464  if (tempbuffer==NULL) return false;
465  if (!GetBuffer( tempbuffer, GL_RGBA, GL_UNSIGNED_BYTE ) ) return false;
466  int bpp = 32;
467  int pitch = 4 * GetWidth();
468  fbitmap = FreeImage_ConvertFromRawBits( (BYTE*)tempbuffer, GetWidth(), GetHeight(), pitch, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, false );
469  if (tempbuffer)
470  delete [] tempbuffer;
471 
472  } else {
473 
474  int ww = (x1 - x0 - 1);
475  int hh = (y1 - y0 - 1);
476  if (ww>0 && hh>0) {
477  tempbuffer = new BYTE [ GetHeight() * GetWidth() * 4 ];
478  if (tempbuffer==NULL) return false;
479  //glReadPixels( x0, y0, ww, hh, GL_RGBA, GL_UNSIGNED_BYTE, tempbuffer);
480  if (!GetBuffer( tempbuffer, GL_RGBA, GL_UNSIGNED_BYTE ) ) return false;
481  int bpp = 32;
482  int pitch = 4 * GetWidth();
483  fbitmap = FreeImage_ConvertFromRawBits( (BYTE*)tempbuffer, GetWidth(), GetHeight(), pitch, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, false );
484  fbitmapcopy = FreeImage_Copy( fbitmap, x0, y0, x1, y1 );
485  FreeImage_Unload(fbitmap);
486  fbitmap = fbitmapcopy;
487  if (tempbuffer)
488  delete [] tempbuffer;
489 
490  } else {
491  MODebug2->Error(moText("moTexture::CalculateLuminanceAndConstrast ") + moText("freeimage problem"));
492  return false;
493  }
494 
495  }
496 
497  if (fbitmap && FreeImage_GetHistogram( (FIBITMAP *)fbitmap, (DWORD*)Histogram, FICC_BLACK )) {
498 
500  Luminance = 0;
501  long Total = 0;
502 
503  for(int ih=0; ih <256; ih++) {
504  Total+= Histogram[ih];
505  Luminance+= Histogram[ih]*ih;
506 
507  }
508 
509  Luminance = Luminance / Total;
510 
512  int Group[5];
513  int Totals[5];
514 
515  Group[0] = 0;
516  Group[1] = 0;
517  Group[2] = 0;
518  Group[3] = 0;
519  Group[4] = 0;
520 
521  Totals[0] = 0;
522  Totals[1] = 0;
523  Totals[2] = 0;
524  Totals[3] = 0;
525  Totals[4] = 0;
526 
527 
528  int zone = 0;
529  long dif = 0;
530  for(int ih=0; ih <256; ih++) {
531  zone = ih / 52;
532  dif = ( Histogram[ih]*(ih - Luminance)*(ih - Luminance));
533  Group[zone]+= dif;
534  Totals[zone]+= Histogram[ih];
535  }
536 
537  Contrast = 0;
538  for(int z=0;z<5;z++) {
539  if (Totals[z]>0) Contrast+= Group[z] / Totals[z];
540  }
541  Contrast = Contrast / 5;
542 
543  MODebug2->Push( moText("moTexture::CalculateLuminanceAndConstrast Histogram OK"));
544 
545  } else MODebug2->Error( moText("moTexture::CalculateLuminanceAndConstrast Histogram error"));
546 
547  if (fbitmap) FreeImage_Unload( fbitmap );
548  return true;
549 }
550 
552 {
553  MOuint AttachPt;
554  SetFBO(p_fbo);
555  p_fbo->AddTexture(GetWidth(), GetHeight(), GetTexParam(), GetGLId(), AttachPt);
556  SetFBOAttachPoint(AttachPt);
557  return AttachPt;
558 }
559 
561 {
562  if ((m_gl != NULL) && m_gl->RectTexture(m_param.target)) return m_width;
563  else return (MOuint)(m_max_coord_s * m_width);
564 }
565 
567 {
568  if ((m_gl != NULL) && m_gl->RectTexture(m_param.target)) return m_height;
569  else return (MOuint)(m_max_coord_t * m_height);
570 }
571 
574  if (p_src_mob==NULL) return GetGLId();
575  return 0;
576 }
577 
578 void moTexture::FlipBufferVert(MOubyte *pBuffer, MOint p_depth)
579 {
580  MOubyte *top;
581  MOubyte *bottom;
582  MOubyte *tmp_buffer;
583  int lineWidth = m_width * p_depth;
584 
585  tmp_buffer = new MOubyte[m_width * p_depth];
586 
587  top =(MOubyte*)pBuffer;
588  bottom =(MOubyte*)((BYTE*)pBuffer + lineWidth*(m_height - 1));
589  for(MOuint i = 0; i < (m_height >> 1); i++)
590  {
591  memcpy(tmp_buffer, top, lineWidth);
592  memcpy(top, bottom, lineWidth);
593  memcpy(bottom, tmp_buffer, lineWidth);
594 
595  top =(MOubyte*)((BYTE*) top + lineWidth);
596  bottom =(MOubyte*)((BYTE*) bottom - lineWidth);
597  }
598 }
599 
600 void moTexture::CopyFromTex(moTexture* p_src_tex, MOboolean p_copy_glid, MOboolean p_copy_moid, MOboolean p_copy_type, MOboolean p_copy_name)
601 {
602  if (p_src_tex != NULL)
603  {
604  m_gl = p_src_tex->m_gl;
605 
606  m_fbo = p_src_tex->m_fbo;
608 
609  if (p_copy_type) m_type = p_src_tex->m_type;
610  if (p_copy_moid) m_moid = p_src_tex->m_moid;
611  if (p_copy_glid) m_glid = p_src_tex->m_glid;
612  if (p_copy_name) m_name = p_src_tex->m_name;
613 
614  m_param = p_src_tex->m_param;
615  m_width = p_src_tex->m_width;
616  m_height = p_src_tex->m_height;
617  m_components = p_src_tex->m_components;
618  m_max_coord_s = p_src_tex->m_max_coord_s;
619  m_max_coord_t = p_src_tex->m_max_coord_t;
620  }
621 }
622 
624 {
625  m_gl = p_src_tex.m_gl;
626 
627  m_fbo = p_src_tex.m_fbo;
629 
630  m_type = p_src_tex.m_type;
631  m_moid = p_src_tex.m_moid;
632  m_glid = p_src_tex.m_glid;
633  m_name = p_src_tex.m_name;
634 
635  m_param = p_src_tex.m_param;
636  m_width = p_src_tex.m_width;
637  m_height = p_src_tex.m_height;
638  m_components = p_src_tex.m_components;
639  m_max_coord_s = p_src_tex.m_max_coord_s;
640  m_max_coord_t = p_src_tex.m_max_coord_t;
641 
642  return *this;
643 }
644 
646 {
647  glTexParameteri(m_param.target, GL_TEXTURE_MIN_FILTER, m_param.min_filter);
648  glTexParameteri(m_param.target, GL_TEXTURE_MAG_FILTER, m_param.mag_filter);
649  glTexParameteri(m_param.target, GL_TEXTURE_WRAP_S, m_param.wrap_s);
650  glTexParameteri(m_param.target, GL_TEXTURE_WRAP_T, m_param.wrap_t);
651  /*glTexParameteri(m_param.target, GL_GENERATE_MIPMAP, GL_TRUE );*/
652 }
653 
654 void moTexture::CalculateSize(MOuint p_width, MOuint p_height)
655 {
656 
657  p_width = ( p_width / 4 ) * 4;
658  p_height = ( p_height / 4 ) * 4;
659 
660  if ((m_gl != NULL) && m_gl->RectTexture(m_param.target))
661  {
662  m_width = p_width;
663  m_height = p_height;
664  m_max_coord_s = p_width;
665  m_max_coord_t = p_height;
666 
667 
668 
669 
670  }
671  /*
672  else
673  {
674  m_width = p_width;
675  m_height = p_height;
676  m_max_coord_s = 1.0;
677  m_max_coord_t = 1.0;
678  }*/
679  else if (RenderMan()->IsTextureNonPowerOf2Disabled())
680  {
681 
682  m_width = NextPowerOf2(p_width);
683  m_height = NextPowerOf2(p_height);
684 
685  m_max_coord_s = (float)p_width / (float)m_width;
686  m_max_coord_t = (float)p_height / (float)m_height;
687  moDebugManager::Message(" moTexture::CalculateSize of texture: " + GetName() + " from "
688  + IntToStr(p_width) + "x" + IntToStr(p_height)
689  + " to " + IntToStr(m_width) + "x" + IntToStr(m_height) );
690  }
691  else
692  {
693  m_width = p_width;
694  m_height = p_height;
695  m_max_coord_s = 1.0;
696  m_max_coord_t = 1.0;
697 
698  }
699 
700 }
701 
704 bool moTexture::ResetBufferData( bool force_creation, int bytes_per_pixel ) {
705 
706  bool resized = m_buffer_width!=m_width || m_buffer_height!=m_height;
707 
708  if (bytes_per_pixel>0) resized = resized || bytes_per_pixel!=(int)m_buffer_bytespp;
709  else resized = resized || m_buffer_bytespp!=m_bytespp;
710 
711  bool create_buffer = force_creation;
712 
713  if ( resized || force_creation ) {
714 
715  if (m_pBufferData && resized) {
717  delete [] m_pBufferData;
718  m_pBufferData = NULL;
719  create_buffer = true;
720  }
721 
722  if (create_buffer && m_pBufferData==NULL) {
728  if (bytes_per_pixel!=0) m_buffer_bytespp = bytes_per_pixel;
730 
731  if (bufsize>0) {
732  m_pBufferData = new BYTE [bufsize];
733  if (m_pBufferData) return true;
734  }
735  }
736  }
737 
738  return false;
739 }
740 
742 {
743  MOuint i;
744  for (i = 1; i < p_seed; i *= 2);
745  return i;
746 }
747 
749 {
750  glBindTexture(m_param.target, m_glid);
751  SetParam();
752 
753  GLenum pixel_format = GL_RGBA;
754  GLenum pixel_type_format = GL_UNSIGNED_BYTE;
755  void* blankdata = NULL;
756  MOubyte* ub_blankdata = NULL;
757  MOint* i_blankdata = NULL;
758  MOfloat* f_blankdata = NULL;
759 
760  switch(m_param.internal_format) {
761  case GL_RGBA:
762  pixel_format = GL_RGBA;
763  pixel_type_format = GL_UNSIGNED_BYTE;
764  m_bytespp = 4;
765  blankdata = new MOubyte [m_width*m_height*m_bytespp]();
766  ub_blankdata = (MOubyte*) blankdata;
767  break;
768  case GL_RGB:
769  pixel_format = GL_RGBA;
770  pixel_type_format = GL_UNSIGNED_BYTE;
771  m_bytespp = 4;
772  blankdata = new MOubyte [m_width*m_height*m_bytespp]();
773  ub_blankdata = (MOubyte*) blankdata;
774  break;
775 #ifndef OPENGLESV2
776  case GL_RGBA32I:
777  case GL_RGBA16I:
778  pixel_format = GL_RGBA_INTEGER;
779  pixel_type_format = GL_INT;
780  m_bytespp = 4;
781  blankdata = new MOint [m_width*m_height*m_bytespp]();
782  i_blankdata = (MOint*) blankdata;
783  break;
784  case GL_RGBA32F:
785  case GL_RGBA16F:
786  pixel_format = GL_RGBA;
787  pixel_type_format = GL_FLOAT;
788  m_bytespp = 4;
789  blankdata = new MOfloat [m_width*m_height*m_bytespp]();
790  f_blankdata = (MOfloat*) blankdata;
791  break;
792 #endif
793  default:
794  pixel_format = GL_RGBA;
795  pixel_type_format = GL_UNSIGNED_BYTE;
796  m_bytespp = 4;
797  blankdata = new MOint [m_width*m_height*m_bytespp]();
798  i_blankdata = (MOint*) blankdata;
799  break;
800  }
801 
802  glTexImage2D( m_param.target, 0,
804  m_width, m_height, 0,
805  pixel_format,
806  pixel_type_format,
807  blankdata );
808 
809  if (i_blankdata) delete [] i_blankdata;
810  if (ub_blankdata) delete [] ub_blankdata;
811  if (f_blankdata) delete [] f_blankdata;
812 #ifndef OPENGLESV2
813  glGetTexLevelParameteriv(m_param.target, 0, GL_TEXTURE_COMPONENTS, &m_components);
814 #else
815  //glGetTexParameteriv(m_param.target, GL_TEXTURE_COMPONENTS, &m_components);
816 #endif
817  ResetBufferData();
818  //if (m_gl != NULL) return !m_gl->CheckErrors("texture build");
819  if (m_gl != NULL) m_gl->CheckErrors("texture build");
820  return true;
821 }
822 
824  m_glid = 0;//reset gl texture id
825  moText namefull = m_pDataMan->GetDataPath() + moSlash + (moText)m_name;
826  return BuildFromFile( namefull );
827 }
828 
829 moText moTexture::CreateThumbnail( moText p_bufferformat, int w, int h, moText newfilename ) {
830 
831  moText thumbnailfilename;
832 
833  if ( newfilename==moText("") ) {
834 
835  //old version
836  //moThm
837  moFile SrcFile( m_name );
838  thumbnailfilename = (moText)m_pDataMan->GetDataPath() + moSlash + SrcFile.GetFileName();
839 
840  /*
841  // new version:
842  moFile SrcFile( m_name );
843  moDirectory Dir( (moText)m_pDataMan->GetDataPath() + moThm );
844  if ( ! Dir.Exists() ) {
845 
846  }
847  thumbnailfilename = (moText)m_pDataMan->GetDataPath() + moSlash + (moText)m_name + moText(".thm");
848  //thumbnailfilename = (moText)m_pDataMan->GetDataPath() + moThm + moSlash + SrcFile.GetFileName() + moText(".thm");
849  */
850 
851 
852  } else {
853  thumbnailfilename = newfilename;
854  }
855 
856  FREE_IMAGE_FORMAT fif;
857  FIBITMAP* fbitmap = NULL;
858  int options = 0;
859 
860  if (GetHeight()==0 || GetWidth()==0) {
861  MODebug2->Error("moTexture::CreateThumbnail > no width or height, texture surface is 0.");
862  return moText("");
863  }
864 
865  unsigned int bpp = 24;
866  unsigned int bytesperpixel = 3;
867  unsigned int pitch = bytesperpixel * GetWidth();
868 #ifndef OPENGLESV2
869  GLenum gbufferformat = GL_BGR;
870 #else
871  GLenum gbufferformat = GL_RGB;
872 #endif
873  GLenum gcomponenttype = GL_UNSIGNED_BYTE;
874 
875  if ( p_bufferformat == moText("PNGA")) {
876 
877  fif = FIF_PNG;
878  options = PNG_DEFAULT;
879  thumbnailfilename+= moText(".png");
880  bpp = 32;
881  bytesperpixel = 4;
882 #ifndef OPENGLESV2
883  gbufferformat = GL_BGRA;
884 #else
885  gbufferformat = GL_RGBA;
886 #endif
887  } else if ( p_bufferformat == moText("PNGF")) {
888 
889  fif = FIF_PNG;
890  options = PNG_DEFAULT;
891  thumbnailfilename+= moText(".png");
892  bpp = 32;
893  bytesperpixel = 4;
894 #ifndef OPENGLESV2
895  gbufferformat = GL_BGRA;
896 #else
897  gbufferformat = GL_RGBA;
898 #endif
899  gcomponenttype = GL_FLOAT;
900 
901  } else if ( p_bufferformat == moText("PNG")) {
902  fif = FIF_PNG;
903  options = PNG_DEFAULT;
904  thumbnailfilename+= moText(".png");
905  } else
906  if ( p_bufferformat == moText("JPG") || p_bufferformat == moText("JPGNORMAL")) {
907 
908  fif = FIF_JPEG;
909  options = JPEG_QUALITYNORMAL;
910  thumbnailfilename+= moText(".jpg");
911 
912  } else if ( p_bufferformat == moText("JPGSUPERB") ) {
913 
914  fif = FIF_JPEG;
915  options = JPEG_QUALITYSUPERB;
916  thumbnailfilename+= moText(".jpg");
917 
918  } else if ( p_bufferformat == moText("JPGBAD") ) {
919 
920  fif = FIF_JPEG;
921  options = JPEG_QUALITYBAD;
922  thumbnailfilename+= moText(".jpg");
923 
924  } else if ( p_bufferformat == moText("JPGAVERAGE") ) {
925 
926  fif = FIF_JPEG;
927  options = JPEG_QUALITYAVERAGE;
928  thumbnailfilename+= moText(".jpg");
929 
930  } else if ( p_bufferformat == moText("JPGGOOD") ) {
931 
932  fif = FIF_JPEG;
933  options = JPEG_QUALITYGOOD;
934  thumbnailfilename+= moText(".jpg");
935 
936  } else if ( p_bufferformat == moText("TGA") ) {
937 
938  fif = FIF_TARGA;
939  options = 0;
940  thumbnailfilename+= moText(".tga");
941  }
942 
943  pitch = bytesperpixel * GetWidth();
944  //pitch = ((GetWidth() * bpp + 31) /31 ) *4;
945 
946  if (gcomponenttype==GL_UNSIGNED_BYTE)
947  ResetBufferData( true, bytesperpixel );
948 /*
949  if (m_pBufferData==NULL) {
950  if (gcomponenttype==GL_UNSIGNED_BYTE) {
951  m_pBufferData = new BYTE [ pitch * GetHeight() ];
952  } else {
953  //CONVERT
954  }
955  }
956 */
957  if (m_pBufferData==NULL) {
958  MODebug2->Error("moTexture::CreateThumbnail > no memory for buffer data allocation or invalid component type.");
959  return moText("");
960  }
961 
962  if (!GetBuffer( m_pBufferData, gbufferformat, gcomponenttype ) ) {
963  MODebug2->Error("moTexture::CreateThumbnail > GetBuffer from texture " + GetName()+" failed.");
964  return moText("");
965  }
980  fbitmap = FreeImage_ConvertFromRawBits( (BYTE*)m_pBufferData,
981  GetWidth(),
982  GetHeight(),
983  pitch,
984  bpp,
985  0xFF0000,
986  0x00FF00,
987  0x0000FF,
988  true );
989 
990  //TODO: add alpha channel for RGBA: FreeImage_SetTransparent(fbitmap, image.flags & ImageData::ALPHA_BIT);
991 
992  if (!fbitmap) {
993 
994  MODebug2->Error("moTexture::CreateThumbnail > FreeImage_ConvertFromRawBits failed from: " + GetName() + " width:" + IntToStr(GetWidth())+" height:"+IntToStr(GetHeight()) );
995  return moText("");
996  }
997 
998  unsigned int fwidth = FreeImage_GetWidth(fbitmap);
999  unsigned int fheight = FreeImage_GetHeight(fbitmap);
1000  unsigned int fpitch = FreeImage_GetPitch(fbitmap);
1001  unsigned int fbpp = FreeImage_GetBPP(fbitmap);
1002  //FREE_IMAGE_TYPE image_type = FreeImage_GetImageType( fbitmap );
1003 
1004 
1005  if ((fwidth!=GetWidth() && fheight!=GetHeight()) ) {
1006 
1007  MODebug2->Error("moTexture::CreateThumbnail > freeimage width and height does not match texture wxh > fwidth:" + IntToStr(fwidth) + " fheight:" + IntToStr(fheight) );
1008  return moText("");
1009  }
1010 
1011  if ( fbpp!=bpp /*|| fpitch!=pitch*/ ) {
1012  MODebug2->Error("moTexture::CreateThumbnail > freeimage bpp and pitch does not match texture > fpitch:" + IntToStr(fpitch) +" vs pitch:" + IntToStr(pitch) + " fbpp (bits per pixel):" + IntToStr(bpp) +" vs bpp:" + IntToStr(bpp) );
1013  return moText("");
1014 
1015  }
1016 
1017 /*
1018  RGBQUAD colorv;
1019  if( FALSE==FreeImage_GetPixelColor( fbitmap, 0, 0, &colorv )) {
1020  MODebug2->Error("moTexture::CreateThumbnail > freeimage conversion failed somehow: no FreeImage_GetPixelColor!");
1021  return moText("");
1022  } else {
1023  MODebug2->Message("moTexture::CreateThumbnail > ");
1024  }
1025  */
1026 /*
1027  FILE* fp = fopen( thumbnailfilename ,"wb" );
1028  fwrite( FreeImage_, sizeof(BYTE), m_width * m_height * 3 , fp );
1029  fclose(fp);
1030  */
1031 
1032  FIBITMAP* fbitmap2 = NULL;
1034  //crop image...to match resolution
1035  if ( m_pResourceManager->GetRenderMan()->ScreenWidth() == w && w <= (int)GetWidth()
1036  && m_pResourceManager->GetRenderMan()->ScreenHeight() == h && h <= (int)GetHeight() ) {
1037  //MODebug2->Message("FreeImage_Copy");
1038  fbitmap2 = FreeImage_Copy( fbitmap, 0, 0, w, h);
1039  if (fbitmap2 && fbitmap) { FreeImage_Unload( fbitmap ); fbitmap=fbitmap2; }
1040  }
1041  } else {
1042  //MODebug2->Message("FreeImage_Rescale");
1043  w = (w / 4 ) * 4;
1044  h = (h / 4 ) * 4;
1045  if (w!=(int)GetWidth() || h!=(int)GetHeight()) fbitmap2 = FreeImage_Rescale( fbitmap, w, h, FILTER_BICUBIC );
1046  if (fbitmap2 && fbitmap) { FreeImage_Unload( fbitmap ); fbitmap=fbitmap2; }
1047  }
1048 
1049  //MODebug2->Message("FreeImage_FlipVertical");
1050  //MODebug2->Message("FreeImage_GetVersion:" + moText(FreeImage_GetVersion()));
1051  //FreeImage_FlipVertical( fbitmap );
1052 
1053 
1054  if (!FreeImage_Save( fif, fbitmap, thumbnailfilename, options )) {
1055  MODebug2->Error("moTexture::CreateThumbnail > not saved to disc. thumbnailfilename: " + thumbnailfilename);
1056  }
1057 
1058  if (fbitmap) { FreeImage_Unload( fbitmap ); }
1059 
1061  /*
1062  if (m_pBufferData)
1063  delete [] m_pBufferData;
1064  */
1065 
1066 
1067 
1068  //return ( moText("width:") + IntToStr(width) + moText("height:") + IntToStr(height) + moText("pitch") + IntToStr(ppitch) + moText("fif") + IntToStr(fif) + moText("oo") + IntToStr((int)fbitmap) );
1069 
1070  return thumbnailfilename;
1071 
1072 }
1073 
1074 
1075 //===========================================
1076 //
1077 // moTextureMemory
1078 //
1079 //===========================================
1080 
1082  reference_counter = 0;
1083  m_SizeInMemory = 0;
1084  m_bBitmapInMemory = false;
1085  hmem = NULL;
1086  fif = 0;
1087  m_BufferFormat = moText("JPG");
1088  Luminance = -1;
1089  Contrast = -1;
1090 
1091  int i = 0;
1092  for( i = 0; i<256; i++) Histogram[i] = 0;
1093 
1094 }
1095 
1097 
1098 }
1099 
1101 
1102  return moTexture::Init( p_name, p_moid, p_res, p_param );
1103 
1104 }
1105 
1106 MOboolean moTextureMemory::Init( moText p_name, MOuint p_moid, moResourceManager* p_res, moText bufferformat, moBitmap* pImageResult, moTexParam p_param ) {
1107 
1108  m_BufferFormat = bufferformat;
1109 
1110  if (pImageResult) LoadFromBitmap(pImageResult);
1111 
1112  return moTexture::Init( p_name, p_moid, p_res, p_param );
1113 }
1114 
1116 
1117  if ( m_bBitmapInMemory && hmem!=NULL ) {
1119  reference_counter = 1;
1120  ReleaseReference();
1122  FreeImage_CloseMemory((FIMEMORY*)hmem);
1123  hmem = NULL;
1124  }
1125 
1126  if (!hmem) {
1127  hmem = FreeImage_OpenMemory();
1128  }
1129  if (hmem) {
1130 
1131  if ( m_BufferFormat == moText("JPG")) {
1132  fif = FIF_JPEG;
1133  options = JPEG_QUALITYNORMAL;
1134  } else if ( m_BufferFormat == moText("JPGSUPERB") ) {
1135  fif = FIF_JPEG;
1136  options = JPEG_QUALITYSUPERB;
1137  } else if ( m_BufferFormat == moText("JPGBAD") ) {
1138  fif = FIF_JPEG;
1139  options = JPEG_QUALITYBAD;
1140  } else if ( m_BufferFormat == moText("JPGAVERAGE") ) {
1141  fif = FIF_JPEG;
1142  options = JPEG_QUALITYAVERAGE;
1143  } else if ( m_BufferFormat == moText("JPGGOOD") ) {
1144  fif = FIF_JPEG;
1145  options = JPEG_QUALITYGOOD;
1146  } else if ( m_BufferFormat == moText("TGA") ) {
1147  fif = FIF_TARGA;
1148  options = 0;
1149  } else if ( m_BufferFormat == moText("PNG") ) {
1150  fif = FIF_PNG;
1151  options = 0;
1152  } else if ( m_BufferFormat == moText("XPM") ) {
1153  fif = FIF_XPM;
1154  options = 0;
1155  } else if ( m_BufferFormat == moText("RAW") ) {
1156  fif = FIF_PPMRAW;
1157  options = 0;
1158  }
1159  //syntax: FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags FI_DEFAULT(0));
1160  if ( FreeImage_SaveToMemory( (FREE_IMAGE_FORMAT)fif, (FIBITMAP *)p_bitmap, (FIMEMORY*)hmem, options ) ) {
1161  m_SizeInMemory = FreeImage_TellMemory((FIMEMORY*)hmem);
1162  m_bBitmapInMemory = true;
1163 
1164  m_width = FreeImage_GetWidth((FIBITMAP *)p_bitmap);
1165  m_height = FreeImage_GetHeight((FIBITMAP *)p_bitmap);
1166 
1168 
1169  if (FreeImage_GetHistogram( (FIBITMAP *)p_bitmap, (DWORD*)Histogram, FICC_BLACK )) {
1170 
1172  Luminance = 0;
1173  long Total = 0;
1174 
1175  for(int ih=0; ih <256; ih++) {
1176  Total+= Histogram[ih];
1177  Luminance+= Histogram[ih]*ih;
1178 
1179  }
1180 
1181  Luminance = Luminance / Total;
1182 
1183 
1184 
1186  int Group[5];
1187  int Totals[5];
1188 
1189  Group[0] = 0;
1190  Group[1] = 0;
1191  Group[2] = 0;
1192  Group[3] = 0;
1193  Group[4] = 0;
1194 
1195  Totals[0] = 0;
1196  Totals[1] = 0;
1197  Totals[2] = 0;
1198  Totals[3] = 0;
1199  Totals[4] = 0;
1200 
1201 
1202  int zone = 0;
1203  long dif = 0;
1204  for(int ih=0; ih <256; ih++) {
1205  zone = ih / 52;
1206  dif = ( Histogram[ih]*(ih - Luminance)*(ih - Luminance));
1207  Group[zone]+= dif;
1208  Totals[zone]+= Histogram[ih];
1209  }
1210 
1211  Contrast = 0;
1212  for(int z=0;z<5;z++) {
1213  if (Totals[z]>0) Contrast+= Group[z] / Totals[z];
1214  }
1215  Contrast = Contrast / 5;
1216 
1217  } else MODebug2->Error( moText("moTextureMemory::LoadFromBitmap Histogram error"));
1218 
1219 
1220 
1221  //MODebug2->Push( moText("moTextureMemory::LoadFromBitmap success: hmem:") + IntToStr((int)hmem));
1222  //MODebug2->Push( moText("moTextureMemory::LoadFromBitmap luminance:") + IntToStr(Luminance) + moText(" contrast:") + IntToStr(Contrast) );
1223  } else m_bBitmapInMemory = false;
1224 
1225  }
1226 
1227  return m_bBitmapInMemory;
1228 
1229 }
1230 
1232 
1233  if (hmem!=NULL && m_glid>0) {
1234  FIBITMAP *pImage;
1235  //FIMEMORY *hmem;
1236 
1237  MOuint _format;
1238 
1239  //MOint FrameSize =
1240  FreeImage_TellMemory((FIMEMORY*)hmem);
1241  FreeImage_SeekMemory( (FIMEMORY*)hmem, 0L, SEEK_SET);
1242 
1243  //hmem = FreeImage_OpenMemory( pVideoFrame->hmem, pVideoFrame->m_FrameSize);
1244  //FreeImage_TellMemory(VideoFrame->hmem);
1245  // load an image from the memory stream
1246  pImage = FreeImage_LoadFromMemory( (FREE_IMAGE_FORMAT)fif, (FIMEMORY*)hmem, 0);
1247 
1248  switch (FreeImage_GetBPP(pImage))
1249  {
1250  case 8: // 8 bit, indexed or grayscale
1251  m_param.internal_format = GL_RGB;
1252  _format = GL_LUMINANCE;
1253  break;
1254  case 16: // 16 bits
1255  break;
1256  case 24: // 24 bits
1257  m_param.internal_format = GL_RGB;
1258 #ifndef OPENGLESV2
1259  if (FreeImage_GetBlueMask(pImage) == 0x000000FF) _format = GL_BGR;
1260  else
1261 #endif
1262  _format = GL_RGB;
1263 #ifndef OPENGLESV2
1264  #ifdef WIN32
1265  _format = GL_BGR;
1266  #endif // WIN32
1267 #endif
1268  break;
1269  case 32: // 32 bits
1270  m_param.internal_format = GL_RGBA;
1271 #ifndef OPENGLESV2
1272  if (FreeImage_GetBlueMask(pImage) == 0x000000FF) _format = GL_BGRA_EXT;
1273  else
1274 #endif
1275  _format = GL_RGBA;
1276  break;
1277  default:
1278  m_param.internal_format = GL_RGBA;
1279  _format = GL_RGBA;
1280  break;
1281  }
1283  Build();
1285  FlipBufferVert((MOubyte *)FreeImage_GetBits(pImage), FreeImage_GetBPP(pImage) / 8 );
1286  SetBuffer( m_width, m_height, FreeImage_GetBits(pImage), _format);
1287  FreeImage_Unload( pImage );
1288  //MODebug2->Push( moText("moTextureMemory::BuildFromMemory: success: hmem:") + IntToStr((int)hmem) + moText("glid:") + IntToStr(m_glid));
1289  return true;
1290  } else {
1291  //MODebug2->Error( moText("moTextureMemory::BuildFromMemory: Error GLID or Memory never assigned. hmem:") + IntToStr((int)hmem) + moText("glid:") + IntToStr(m_glid));
1292  return false;
1293  }
1294 }
1295 
1296 
1298 {
1299  MOboolean res = false;
1300 
1301  m_BufferFormat = p_bufferformat;
1302 
1303  if (p_bitmap != NULL)
1304  {
1306  res = LoadFromBitmap( p_bitmap );
1308 
1309  }
1310  else {
1311  if (MODebug2 != NULL) MODebug2->Error(moText("Error at image build from bitmap: [pointer is null] ") + (moText) this->GetName());
1312  res = false;
1313  }
1314 
1315  return res;
1316 }
1317 
1318 
1320 
1321 
1322  //si la referencia es 0:
1323  //asigna la textura
1324  if (this->Initialized()) {
1325 
1326  if (reference_counter==0) {
1327  if (m_bBitmapInMemory) {
1328  glGenTextures(1, &m_glid);
1330  if (BuildFromMemory()) {
1331  //MODebug2->Push( moText("moTextureMemory::GetReference success: glid: ") + IntToStr(m_glid) );
1332  reference_counter++;
1333  }
1334  } else MODebug2->Push( moText("moTextureMemory::GetReference no bitmap in memory ") );
1335  }
1336  } else MODebug2->Error( moText("moTextureMemory::GetReference Error: object not initialized") );
1337 
1338  return ((int)reference_counter);
1339 }
1340 
1342  if (reference_counter>0) {
1343  reference_counter--;
1344  if ( reference_counter==0 ) {
1346  if (m_glid>0) {
1347  glDeleteTextures(1,&m_glid);
1348  m_glid = 0;
1349  }
1350  }
1351  }
1352 }
1353 
1355 
1356  if (hmem) {
1357  FreeImage_CloseMemory( (FIMEMORY*)hmem );
1358  hmem = NULL;
1359  }
1360 
1361  m_SizeInMemory = 0;
1362  hmem = NULL;
1363  fif = (int)FIF_UNKNOWN;
1364 
1365  return moTexture::Finish();
1366 
1367 }
1368 
1369 //===========================================
1370 //
1371 // moTextureAnimated
1372 //
1373 //===========================================
1374 
1376 {
1377  m_FrameJump = 0;
1378  m_FrameNext = 0;
1379  m_FramePrevious = 0;
1380  m_FrameStart = 0;
1381  m_FrameEnd = 0;
1382  m_ActualFrame = 0;
1383  m_nFrames = 0;
1384  m_InterpolationTime = 0;
1385  m_bInterpolation = false;
1386  m_bInterpolating = false;
1387  m_pShaderCopy = NULL;
1388  m_pShaderInterpolate = NULL;
1389  m_pCopyStart = NULL;
1390  m_pCopyEnd = NULL;
1391  m_pInterpolator = NULL;
1393 }
1394 
1396 {
1397  Finish();
1398 }
1399 
1401 {
1402  m_FrameJump = 0;
1403  m_FrameNext = 0;
1404  m_FramePrevious = 0;
1405  m_FrameStart = 0;
1406  m_FrameEnd = 0;
1407  m_nFrames = 0;
1408  m_InterpolationTime = 0;
1409  m_bInterpolation = false;
1410  m_bInterpolating = false;
1411  m_pShaderCopy = NULL;
1412  m_pShaderInterpolate = NULL;
1413  m_pCopyStart = NULL;
1414  m_pCopyEnd = NULL;
1415  m_pInterpolator = NULL;
1417 
1418  return moTexture::Init(p_name, p_moid, p_res, p_param);
1419 }
1420 
1422 {
1437  return moTexture::Finish();
1438 }
1439 
1440 
1442  m_bIsPlaying = true;
1443 }
1444 
1445 
1447  m_bIsPlaying = false;
1448 }
1449 
1450 
1452  //m_bIsPlaying = true;
1453  return m_bIsPlaying;
1454 }
1455 
1456 void
1457 moTextureAnimated::SetInterpolation( MOuint p_FrameJump, MOuint p_InterpolationTime ) {
1458 
1459  m_FrameJump = p_FrameJump;
1460  m_InterpolationTime = p_InterpolationTime;
1478 
1481  if (!m_pCopyStart && this->GetWidth()>0 ) {
1482  moTextArray copy_filter_0;
1483  copy_filter_0.Add( moText( this->m_name+" shaders/Copy.cfg "+this->m_name+"copyStart") );
1484  int idx = SM->GetTextureFilterIndex()->LoadFilters( &copy_filter_0 );
1485  if (idx>-1) {
1486  m_pCopyStart = SM->GetTextureFilterIndex()->Get(idx-1);
1487  MODebug2->Message( moText("filter loaded m_pCopyStart") );
1488  }
1489  }
1490 
1491  if (!m_pCopyEnd && this->GetWidth()>0 ) {
1492  moTextArray copy_filter_0;
1493  copy_filter_0.Add( moText( this->m_name+" shaders/Copy.cfg "+this->m_name+"copyEnd") );
1494  int idx = SM->GetTextureFilterIndex()->LoadFilters( &copy_filter_0 );
1495  if (idx>-1) {
1496  m_pCopyEnd = SM->GetTextureFilterIndex()->Get(idx-1);
1497  MODebug2->Message( moText("filter loaded m_pCopyEnd") );
1498  }
1499  }
1500 
1501  if (!m_pInterpolator && this->GetWidth()>0 ) {
1502  moTextArray copy_filter_0;
1503  copy_filter_0.Add( moText( this->m_name+"copyStart "+this->m_name+"copyEnd shaders/TexInterpolator.cfg "+this->m_name+"") );
1504  int idx = SM->GetTextureFilterIndex()->LoadFilters( &copy_filter_0 );
1505  if (idx>-1) {
1506  m_pInterpolator = SM->GetTextureFilterIndex()->Get(idx-1);
1507  MODebug2->Message( moText("filter loaded m_pInterpolator") );
1508  }
1509  }
1549 }
1550 
1551 MOboolean
1553  return m_bInterpolating;
1554 }
1555 
1556 MOboolean
1558  return m_bInterpolation;
1559 }
1560 
1561 MOboolean
1563  if (m_pCopyStart && m_pCopyEnd && m_pInterpolator && activate) {
1564  m_bInterpolation = true;
1565  } else {
1566  m_bInterpolation = false;
1567  m_bInterpolating = false;
1568  }
1569  return m_bInterpolation;
1570 }
1571 
1572 
1573 //Cuando necesitamos interpolacion?
1574 //
1575 // Suavizado de saltos:
1576 // 1) se paso el intervalo maximo entre el cuadro actual y el siguiente
1577 // 2) todavia se esta en un ciclo de interpolacion
1578 //
1579 // Camara lenta: (a implementar)
1580 // 1) el tiempo maximo entre dos cuadros contiguos fue superado, entonces se generará un cuadro intermedio proporcional
1581 // 2) todavia se esta en un ciclo de interpolacion
1582 MOboolean
1584  // pasamos la barrera del m_FrameJump
1585  // !!!chequear que el next y el previous esten correctamente fijados
1586  //MODebug2->Push( moText("Pr:")+IntToStr(m_FramePrevious)+moText("Nxt:")+IntToStr(m_FrameNext) );
1587  //return false;
1588  if (!m_bInterpolation)
1589  return false;
1590 
1591  if (!m_bInterpolating) {
1592  if ( fabs( (double)((double)m_FrameNext - (double)m_FramePrevious) ) > (double)m_FrameJump ) {
1595  //desactivamos la interpolacion para poder acceder a los cuadros correspondientes libremente
1596  m_bInterpolating = false;
1597  ActivateInterpolation(false);
1598  //TODO: fix this
1599  moTextFilterParam DefParam;
1600  if (m_pCopyStart) m_pCopyStart->Apply( m_FrameStart, 1.0, DefParam );
1601  if (m_pCopyEnd) m_pCopyEnd->Apply( m_FrameEnd, 1.0, DefParam );
1602  //activamos nuevamente la interpolacion una vez copiados los cuadros
1603  ActivateInterpolation(true);
1604  m_bInterpolating = true;
1605  //fijamos nuevamente el previous y el next
1606  m_FramePrevious = m_FrameStart;
1608  m_StartTime = moGetTicks();
1609  return true;
1610  }
1611  } else {
1612  if ( m_InterpolationPosition >= 1.0 ) {
1613  m_StartTime = 0;
1614  m_bInterpolating = false;
1615  }
1616  }
1617  return m_bInterpolating;
1618 }
1619 
1620 
1621 MOint
1623  moTextFilterParam filterparam;
1624 
1626  if (m_bInterpolating) {
1627  MOuint m_ActualTime = moGetTicks();
1628  m_InterpolationPosition = (float)( m_ActualTime - m_StartTime ) / (m_InterpolationTime);
1631  filterparam = m_pInterpolator->GetTextFilterParam();
1632  filterparam.par_flt1 = m_InterpolationPosition;
1633  //TODO: fix this
1634  MODebug2->Message( moText("IP:")+FloatToStr(m_InterpolationPosition)+moText(" Param par_flt1:")+FloatToStr(filterparam.par_flt1)+moText(" Param UNIFORM ID:")+IntToStr(filterparam.m_par_flt1) );
1635 
1636  m_pInterpolator->Apply( m_InterpolationPosition, 1.0, filterparam );
1637 
1638  //MODebug2->Message( moText("IP:")+FloatToStr(m_InterpolationPosition) );
1639  return 1;
1640  }
1641  }
1642  return 0;
1643 }
1644 
1645 
1646 // NOTA: este algoritmo fija el cuadro next emparejando el moTempo con la cantidad de frames...
1647 MOint
1649  //segun el tempo elige el cuadro!
1650  int t;
1651  float ft,PeliV;
1652 
1653 
1654  if(p_tempo==NULL) {
1655  t = m_Time - moGetTicks();
1656  ft = (t / 1000) * m_fFramesPerSecond;//frames que deberian haber pasado en este lapso...
1657 
1658  if(ft >= 0.99) {
1659 
1660  m_FrameNext++;
1661 
1662  if( m_FrameNext >= m_nFrames ) {
1663  m_FrameNext = 0;
1664  }
1665 
1666  }
1667 
1668  } else {
1669  PeliV = fmod( p_tempo->ang*double(m_nFrames) / double(2*moMathf::PI) , double(m_nFrames) );
1670  m_FrameNext = min( int(ceilf(PeliV)), int(m_nFrames - 1) );
1671  //MODebug2->Push( "peliv:" + FloatToStr(PeliV) + " fnext: " + IntToStr(m_FrameNext));
1672  //PeliV = fmod( float( p_tempo->ang ), float(2*moMathf::PI)) /(2*moMathf::PI);
1673  //m_FrameNext = min(int(PeliV * m_nFrames), m_nFrames - 1);
1674  }
1675 
1676  if (NeedsInterpolation()) {
1677  Interpolate();
1678  } else {
1681  }
1682 
1683  return m_glid;
1684 }
1685 
1686 // NOTA: este devuelve simplemente el glid correspondiente al cuadro interno "i"
1687 //como en este caso no estan definidos las sub-texturas, ya q depende de cada implementaci�
1688 //devuelve el m_glid de moTexture
1689 MOint
1691 
1692  if (p_i>2000 || p_i>m_nFrames) {
1693  //TODO: WTF
1694  //p_i = 0;
1695  }
1696 
1697  m_FrameNext = p_i;
1698 
1699  if (NeedsInterpolation()) {
1700 
1701  MODebug2->Message( moText("moTextureAnimated::GetGLId( MOuint p_i ) > Interpolating image! ")+GetName()+
1702  " From m_FramePrevious: " + IntToStr( m_FramePrevious )+
1703  " To m_FrameNext: " + IntToStr( m_FrameNext )+
1704  " At m_InterpolationPosition: " + FloatToStr( m_InterpolationPosition, 2, 2 )+
1705  "From m_FrameStart: " + IntToStr( m_FrameStart )+
1706  " To m_FrameEnd: " + IntToStr( m_FrameEnd )
1707  );
1708  Interpolate();
1709  } else {
1710  if(m_FramePrevious!=p_i) this->GetFrame(p_i);
1711  m_FramePrevious = m_FrameNext = p_i;
1712  }
1713 
1714  return m_glid;
1715 }
1716 
1718 
1719  MOfloat PeliV;
1720 
1721  PeliV = fmod( (float)p_cycle, (float)1.0 );
1722  m_FrameNext = min(int(PeliV * m_nFrames), int(m_nFrames - 1));
1723 
1724  if (NeedsInterpolation()) {
1725  Interpolate();
1726  } else {
1729  }
1730  return m_glid;
1731 
1732 }
1733 
1734 void
1736 
1738  if (p_i>0) return;
1739  return;
1740 }
1741 
1742 MOuint
1744 
1745  return this->m_ActualFrame;
1746 }
1747 
1748 
1750  m_PlayMode = playmode;
1751 }
1752 
1754  return m_PlayMode;
1755 }
1756 
1757 
1758 //===========================================
1759 //
1760 // moTextureMultiple
1761 //
1762 //===========================================
1763 
1765 {
1767 }
1768 
1770 {
1771  Finish();
1772 }
1773 
1775 {
1776  moTextureAnimated::Init(p_name, p_moid, p_res, p_param);
1777 
1778  m_nFrames = 0;
1779  m_fFramesPerSecond = 24.0;
1780  m_textures_array.Init(0, NULL);
1781  return true;
1782 }
1783 
1785 {
1786  m_textures_array.Finish();
1788  return true;
1789 }
1790 
1792 {
1793  moText begin = p_filename;
1794  begin.Left(7);
1795  return !stricmp(begin,"multiple");
1796 }
1797 
1799 {
1800  moValue* pValue = &p_param->GetValue();
1801  return Load(pValue);
1802 }
1803 
1805 {
1806  SetName(p_value->GetSubValue(0).Text());
1807 
1808  int nframes = p_value->GetSubValueCount() - 1;
1809  moText fn;
1810  moTexture* newtex;
1811  for (int i = 0; i < nframes; i++)
1812  {
1813  fn = m_pDataMan->GetDataPath() + moSlash + p_value->GetSubValue(i + 1).Text();
1814  if (moTexture::SupportedFile(fn))
1815  {
1816  if (BuildFromFile(fn))
1817  {
1818  newtex = new moTexture;
1819  newtex->SetName(fn);
1820  newtex->CopyFromTex((moTexture*)this, true, false, false, false);
1821  m_textures_array.Add(newtex);
1822  }
1823  }
1824  }
1826 
1827  m_bBuildedFromFile = (0 < m_textures_array.Count());
1828 
1829  return 0 < m_textures_array.Count();
1830 }
1831 
1832 MOboolean moTextureMultiple::Load(moText p_name, moTextureArray &p_textures, MOuint p_id0, MOuint p_id1)
1833 {
1834  SetName(p_name);
1835  m_textures_array.Copy(p_textures, p_id0, p_id1);
1837  return 0 < m_textures_array.Count();
1838 }
1839 
1841 {
1842  m_textures_array.Init(p_tex_count, NULL);
1843  SetFrameCount(p_tex_count);
1844 }
1845 
1847 {
1848  if (ValidTexture(p_i)) {
1849  this->CopyFromTex(m_textures_array[p_i], true, false, false, false);
1850  this->m_ActualFrame = p_i;
1851  }
1852  else m_glid = 0;
1853 }
1854 
1856 {
1857  if (p_i < m_textures_array.Count() && p_texture) {
1858  if (ValidTexture(p_i)) {
1859  m_textures_array[p_i]->CopyFromTex(p_texture, true, true, true, true);
1860  }
1861  else
1862  {
1863  m_textures_array[p_i] = p_texture;
1864  }
1865  }
1866 }
1867 
1869 {
1870  m_textures_array.Add(p_texture);
1871  m_nFrames++;
1872 }
1873 
1875 {
1876  return ((p_i < (MOuint)m_textures_array.Count()) && (m_textures_array[p_i] != NULL));
1877 }
1878 
1879 //===========================================
1880 //
1881 // moMovie
1882 //
1883 //===========================================
1884 
1886 {
1888  m_pGraph = NULL;
1890  m_pFilename = "";
1891  m_bIsPlaying = false;
1892  m_bIsPaused = false;
1893 }
1894 
1896 {
1897  Finish();
1898 }
1899 
1901 {
1902  moTextureAnimated::Init(p_name, p_moid, p_res, p_param);
1903  if(!m_pGraph) {
1904 
1905  #ifdef MO_DIRECTSHOW
1906  m_pGraph = (moVideoGraph*) new moDsGraph();
1907  #endif
1908 
1909  #ifdef MO_GSTREAMER
1910  m_pGraph = (moVideoGraph*) new moGsGraph();
1911  #endif
1912  }
1913 
1915 
1916  return true;
1917 }
1918 
1920 {
1921  if (m_pGraph!=NULL)
1922  {
1923  delete m_pGraph;
1924  m_pGraph = NULL;
1925  }
1927  return true;
1928 }
1929 
1931  if (m_pGraph) {
1932  m_pGraph->Play();
1933  m_bIsPlaying = true;
1934  m_bIsPaused = false;
1935  }
1936 }
1937 
1939  if (m_pGraph) {
1940  m_pGraph->Pause();
1941  m_bIsPlaying = false;
1942  m_bIsPaused = true;
1943  }
1944 }
1945 
1947  if (m_pGraph) {
1948  m_pGraph->Play();
1949  m_bIsPlaying = true;
1950  m_bIsPaused = false;
1951  }
1952 }
1953 /*
1954 void BackToBlack( moTexture* pTex ) {
1955  if (pTex) {
1956  long size = pTex->GetWidth() * pTex->GetHeight() * 4;
1957  MOubyte* allblack = new MOubyte [size];
1958  memset( allblack, 0 , size);
1959  pTex->SetBuffer( allblack );
1960  }
1961 }
1962 */
1963 
1965  if (m_pGraph) {
1966  //if (GetPosition()==0 && m_pGraph->GetState()!=MO_STREAMSTATE_STOPPED) {
1967 
1968  m_pGraph->Stop();
1969  m_bIsPlaying = false;
1970  m_bIsPaused = false;
1971 
1972  //} else if ( GetPosition()!=0) {
1973  // m_pGraph->Pause();
1974  // m_pGraph->Seek(0);
1975  // m_bIsPlaying = true;
1976  //}
1977  }
1978 }
1979 
1980 void moMovie::Seek( long frame, float rate ) {
1981  if (m_pGraph) {
1982  m_pGraph->Seek( frame, rate );
1983  }
1984 }
1985 
1987  if (m_pGraph)
1988  return m_pGraph->GetPosition();
1989  return 0;
1990 }
1991 
1993 
1994  moStreamState stream_state = MO_STREAMSTATE_UNKNOWN;
1995 
1996  if (m_pGraph) {
1997 
1998  stream_state = m_pGraph->GetState();
1999 
2000  switch(stream_state) {
2002  m_bIsPlaying = true;
2003  m_bIsPaused = false;
2004  break;
2005  case MO_STREAMSTATE_PAUSED:
2006  m_bIsPlaying = false;
2007  m_bIsPaused = true;
2008  break;
2009  default:
2010  m_bIsPlaying = false;
2011  m_bIsPaused = false;
2012  break;
2013  }
2014 
2015  }
2016 
2017  return stream_state;
2018 }
2019 
2021 
2022  if (m_pGraph) {
2023  //MODebug2->Message("moMovie::IsPlaying > calling m_pGraph->GetState()");
2024  //m_pGraph->GetState();
2025  this->State();
2026  //MODebug2->Message("moMovie::IsPlaying > GetState returned");
2027  }
2028  return m_bIsPlaying;
2029 }
2030 
2032 
2033  if (m_pGraph) {
2034  //MODebug2->Message("moMovie::IsPlaying > calling m_pGraph->GetState()");
2035  //m_pGraph->GetState();
2036  this->State();
2037  //MODebug2->Message("moMovie::IsPlaying > GetState returned");
2038  }
2039  return m_bIsPaused;
2040 }
2041 
2042 
2043 void moMovie::SetBrightness( float brightness ) {
2044  if (m_pGraph) {
2045  m_pGraph->SetContrast( brightness );
2046  }
2047 }
2048 
2049 
2050 
2051 void moMovie::SetContrast( float contrast ) {
2052  if (m_pGraph) {
2053  m_pGraph->SetContrast( contrast );
2054  }
2055 }
2056 
2057 
2058 
2059 void moMovie::SetHue( float hue ) {
2060  if (m_pGraph) {
2061  m_pGraph->SetHue( hue );
2062  }
2063 }
2064 
2065 
2066 
2067 void moMovie::SetSaturation( float saturation ) {
2068  if (m_pGraph) {
2069  m_pGraph->SetSaturation( saturation);
2070  }
2071 }
2072 
2073 void moMovie::SetVolume( float volume ) {
2074 
2075  if ( HasAudio() && m_pGraph) {
2076  m_pGraph->SetVolume( volume);
2077  }
2078 }
2079 
2080 void moMovie::SetBalance( float balance ) {
2081  if ( HasAudio() && m_pGraph) {
2082  m_pGraph->SetBalance( balance);
2083  }
2084 }
2085 
2087  return true;
2088 }
2089 
2091  return true;
2092 }
2093 
2095 
2096  if (m_pGraph) {
2097  return m_pGraph->IsEOS();
2098  }
2099  return false;
2100 
2101 }
2102 
2104 {
2105 
2106  moFile FileName(p_filename);
2107  moText extension = FileName.GetExtension();
2108  return (!stricmp(extension,".avi") ||
2109  !stricmp(extension,".mov") ||
2110  !stricmp(extension,".mpg") ||
2111  !stricmp(extension,".mp4")||
2112  !stricmp(extension,".ogg") ||
2113  !stricmp(extension,".ogm") ||
2114  !stricmp(extension,".ogv") ||
2115  !stricmp(extension,".webm") ||
2116  !stricmp(extension,".web") ||
2117  !stricmp(extension,".mpv") ||
2118  !stricmp(extension,".mkv") ||
2119  !stricmp(extension,".m2v"));
2120 }
2121 
2123 {
2124  moText extension;
2125  MOboolean result = false;
2126  bool quicktime = false;
2127 
2128  extension = p_filename;
2129  extension.Right(3);
2130 
2131  if (extension==moText("mov")) quicktime = true;
2132 
2133  MOulong frames;
2134  MOboolean graphloaded = false;
2135  if (m_pGraph)
2136  {
2137  if (!m_pGraph->InitGraph())
2138  return false;
2139 
2140  if (quicktime)
2141  {
2143  graphloaded = m_pGraph->BuildLiveQTVideoGraph( p_filename, &m_BucketsPool);
2144  }
2145  else
2146  {
2148  graphloaded = m_pGraph->BuildLiveVideoGraph( p_filename, &m_BucketsPool);
2149  }
2150 
2151  if ( graphloaded )
2152  {
2153  m_pGraph->Pause();
2154 
2155  frames = m_pGraph->GetFramesLength();
2156  frameprevious = 0;
2157 
2158  SetFramesPerSecond(( (double) m_pGraph->GetVideoFormat().m_FrameRate ) / (double)( 100.0 ) );
2159 
2161 
2163 
2164  if (result)
2165  {
2166  lastframe = frames;
2167  SetFrameCount( frames );
2168  }
2169  }
2170  }
2171 
2172  if (result) {
2173  m_bBuildedFromFile = true;
2174  m_pFilename = p_filename;
2175  }
2176 
2177  return result;
2178 }
2179 
2181 {
2182  moValue* pValue = &p_param->GetValue();
2183  return Load( pValue );
2184 }
2185 
2187 {
2188  moText namefull;
2189 
2190  SetName( p_value->GetSubValue(0).Text());
2191 
2192  namefull = m_pDataMan->GetDataPath() + moSlash + (moText)m_name;
2193 
2194  return LoadMovieFile(namefull);
2195 }
2196 
2197 MOboolean moMovie::Reload( bool force_kill ) {
2198  if (force_kill) {
2199  //kill moGsGraph!!
2200  //check m_pFilename and reload!!
2201 
2202  }
2203  return true;
2204 }
2205 
2206 void moMovie::EnableVideo(int enable) {
2207  if (enable) return;
2208 }
2209 
2210 void moMovie::EnableAudio(int enable) {
2211  if (enable) return;
2212 }
2213 
2215 {
2216  if(m_pGraph)
2217  {
2218 
2219  //MODebug2->Message("moMovie::GetFrame > calling m_pGraph->GetState()");
2220  moStreamState state = m_pGraph->GetState();
2221  //MODebug2->Message("moMovie::GetFrame > returned m_pGraph->GetState()");
2222 
2225  if (state==MO_STREAMSTATE_PAUSED || state==MO_STREAMSTATE_STOPPED) {
2226  /*
2227 
2228  if (state==MO_STREAMSTATE_STOPPED)
2229  m_pGraph->Play();
2230 
2231  if (state==MO_STREAMSTATE_PAUSED)
2232  m_pGraph->Play();
2233  */
2234 
2235  //m_pGraph->Pause();
2236  MODebug2->Push( "moMovie::GetFrame > Going to p_i:"+IntToStr(p_i)+" Actual real timebase position:" + IntToStr(m_pGraph->GetPosition()) );
2237  }
2238  } else {
2239  m_pGraph->Seek( p_i );
2240  m_pGraph->Pause();
2241  }
2242 
2243 
2244  if (!m_BucketsPool.IsEmpty()) {
2245 
2246  moBucket* pbucket = NULL;
2247  MOubyte* pbuffer = NULL;
2248 
2249  pbucket = m_BucketsPool.RetreiveBucket();
2250 
2251  if (pbucket) {
2252  pbuffer = pbucket->GetBuffer();
2253  if (pbuffer) {
2254 
2256  pbucket->Lock();
2257 #ifndef OPENGLESV2
2258  SetBuffer(pbuffer, GL_BGR_EXT );
2259 #else
2260  SetBuffer(pbuffer, GL_RGB );
2261 #endif
2262 
2263  pbucket->Unlock();
2264 
2265  pbucket->EmptyBucket();
2266  }
2268  }
2269  }
2270  /*
2271  else {
2272 
2273  MODebug2->Error( moText("moMovie::GetFrame()")
2274  + moText(" m_BucketsPool is EMPTY !!!")
2275  + moText(" state:")
2276  + m_pGraph->StateToText(state) );
2277 
2278  }
2279  */
2280  } else {
2281  MODebug2->Error( moText("moMovie::GetFrame()") + moText(" m_pGraph is NULL !!!") );
2282  }
2283 }
2284 
bool HasAudio()
Definition: moTexture.cpp:2090
virtual moStreamState State()
Definition: moTexture.cpp:1992
void moBitmap
Definition: moTexture.h:44
virtual void Seek(long frame, float rate=1.0)
Definition: moTexture.cpp:1980
GLint mag_filter
Definition: moTypes.h:548
MOuint GetDataWidth() const
Definition: moTexture.cpp:560
Valor de un Parámetro.
Definition: moValue.h:501
MOboolean Initialized()
Pregunta si está inicializado.
Definition: moAbstract.cpp:153
moShader * m_pShaderCopy
Definition: moTexture.h:724
Parámetros internos de una textura.
Definition: moTypes.h:543
moFile * GetFile(moText p_FileName)
MOfloat m_max_coord_t
Definition: moTexture.h:410
MOuint m_FrameStart
Definition: moTexture.h:733
moFileType GetType()
Definition: moFile.cpp:442
virtual MOboolean LoadFromBitmap(moBitmap *p_bitmap)
Guarda el bitmap con el formato elegido en memoria.
Definition: moTexture.cpp:1115
virtual void SetInterpolation(MOuint p_FrameJump, MOuint p_InterpolationTime)
Definition: moTexture.cpp:1457
static void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
#define MOulong
Definition: moTypes.h:392
moVideoFormat GetVideoFormat()
Devuelve el formato de video.
MOboolean Refresh()
Definition: moTexture.cpp:823
void Error(moText p_text)
Anuncia y registra un error.
Definition: moAbstract.cpp:79
Tempo, beat, ritmo.
Definition: moTempo.h:44
virtual MOboolean Finish()
Definition: moTexture.cpp:1354
int Luminance
Definition: moTexture.h:416
GLint internal_format
Definition: moTypes.h:546
moText m_pFilename
Definition: moTexture.h:934
virtual MOulong GetPosition()
Definition: moTexture.cpp:1986
bool DestroyRetreivedBucket()
Definition: moBuckets.cpp:244
MOboolean m_bIsPaused
Definition: moTexture.h:699
MOboolean m_bBuildedFromFile
Definition: moTexture.h:388
MOuint SetFBOandAttachPoint(moFBO *p_fbo)
Definition: moTexture.cpp:551
virtual void GetFrame(MOuint p_i)
Definition: moTexture.cpp:1735
MOboolean Build()
Definition: moTexture.cpp:748
moValueBase & GetSubValue(MOint p_indexsubvalue=0)
Definition: moValue.h:539
moTextureFilter * m_pCopyStart
Definition: moTexture.h:714
void GetFrame(MOuint p_i)
Definition: moTexture.cpp:1846
virtual ~moTextureMemory()
Definition: moTexture.cpp:1096
void CalculateSize(MOuint p_width, MOuint p_height)
Definition: moTexture.cpp:654
MOboolean BuildFromBuffer(MOuint p_width, MOuint p_height, const GLvoid *p_buffer, GLenum p_format=GL_RGBA, GLenum p_type=GL_UNSIGNED_BYTE)
Definition: moTexture.cpp:136
virtual moPlayMode GetPlayMode()
Definition: moTexture.cpp:1753
virtual MOboolean Finish()
Definition: moTexture.cpp:1919
void GetFrame(MOuint p_i)
Definition: moTexture.cpp:2214
moTextureFilter * Get(MOuint p_idx)
virtual ~moMovie()
Definition: moTexture.cpp:1895
MOuint m_FramePrevious
Definition: moTexture.h:705
#define MO_UNDEFINED
Definition: moTypes.h:379
virtual ~moTextureAnimated()
Definition: moTexture.cpp:1395
moDefineDynamicArray(moTextureArray) moTexture
Definition: moTexture.cpp:39
virtual MOboolean Finish()
Definition: moTexture.cpp:1784
LIBMOLDEO_API moText0 FloatToStr(double a)
Definition: moText.cpp:1134
moRenderManager * GetRenderMan()
virtual void SetVolume(float volume)
Definition: moTexture.cpp:2073
moResourceManager * m_pResourceManager
Definition: moTexture.h:394
virtual MOboolean BuildFromMemory()
Construye la textura opengl desde el bitmap en memoria.
Definition: moTexture.cpp:1231
#define MOboolean
Definition: moTypes.h:385
MOuint m_buffer_height
Definition: moTexture.h:422
moVideoGraph * m_pGraph
Definition: moTexture.h:937
MOboolean Load(moParam *p_param)
Definition: moTexture.cpp:2180
MOboolean IsTextureNonPowerOf2Disabled() const
MOfloat m_fFramesPerSecond
Definition: moTexture.h:702
moText0 & Left(MOuint)
Definition: moText.cpp:484
bool Unlock()
Libera el acceso al buffer interno.
Definition: moBuckets.cpp:49
const moTexParam MODefTex2DParams
Parámetros internos predeterminados de una textura.
Definition: moTypes.h:562
virtual ~moTexture()
Definition: moTexture.cpp:80
textura múltiple
Definition: moTexture.h:55
MOboolean RectTexture(GLenum p_target) const
MOboolean BuildEmpty(MOuint p_width, MOuint p_height)
Definition: moTexture.cpp:113
void ReleaseReference()
Definition: moTexture.cpp:1341
bool IsEmpty()
Definition: moBuckets.cpp:138
moTextureFilterIndex * GetTextureFilterIndex()
MOboolean LoadMovieFile(moText p_filename)
Definition: moTexture.cpp:2122
virtual void SetContrast(float contrast)
Definition: moTexture.cpp:2051
MOboolean IsRemote()
Definition: moFile.cpp:458
bool Lock()
Paraliza el acceso al buffer interno.
Definition: moBuckets.cpp:45
MOuint m_FrameJump
Definition: moTexture.h:728
GLint wrap_t
Definition: moTypes.h:550
virtual MOboolean Init()
Inicializa el objeto.
Definition: moAbstract.cpp:141
MOboolean MipMapTexture(GLint p_min_filter)
virtual void SetSaturation(float saturation)
Definition: moTexture.cpp:2067
moText GetExtension()
Get absolute path and filename "/D/PP/myFileName.txt".
Definition: moFile.cpp:543
const moTextFilterParam & GetTextFilterParam()
MOuint m_glid
Definition: moTexture.h:401
MOboolean CheckErrors(moText p_location)
moFileManager * m_pFileMan
Definition: moTexture.h:392
void Apply(MOuint p_i, MOfloat p_fade, const moTextFilterParam &p_params)
virtual void SetBalance(float balance)
Definition: moTexture.cpp:2080
virtual void Continue()
Definition: moTexture.cpp:1946
moGLManager * GetGLMan()
virtual void SetVolume(float volume)=0
Fija el nivel de volumen.
MOuint m_buffer_width
Definition: moTexture.h:421
MOboolean Exists()
Definition: moFile.cpp:436
moShaderManager * GetShaderMan()
#define MOfloat
Definition: moTypes.h:403
void FlipBufferVert(MOubyte *pBuffer, MOint p_depth)
Definition: moTexture.cpp:578
moText GetFileName()
Definition: moFile.cpp:477
virtual void Pause()
Definition: moTexture.cpp:1938
MOint lastframe
Definition: moTexture.h:933
moDWord Histogram[256]
Definition: moTexture.h:419
Definition: moFBO.h:60
void SetTextureCount(MOuint p_tex_count)
Definition: moTexture.cpp:1840
moShader * m_pShaderInterpolate
Definition: moTexture.h:725
void AddFrame(moTexture *p_texture)
Definition: moTexture.cpp:1868
moText CreateThumbnail(moText p_bufferformat, int w, int h, moText newfilename=moText(""))
Definition: moTexture.cpp:829
MOboolean m_bInterpolating
Definition: moTexture.h:711
clase de para manejar textos
Definition: moText.h:75
void SetFBOAttachPoint(MOuint p_fbo_attach_point)
Definition: moTexture.h:203
virtual MOboolean ActivateInterpolation(MOboolean activate=true)
Definition: moTexture.cpp:1562
MOuint m_buffer_bytespp
Definition: moTexture.h:423
MOubyte * m_pBufferData
Definition: moTexture.h:420
#define MOlong
Definition: moTypes.h:391
virtual MOulong GetPosition()=0
La posición del stream en cuadros.
Grafo de reproducción de video.
Definition: moVideoGraph.h:584
void EnableAudio(int)
Definition: moTexture.cpp:2210
bool HasVideo()
Definition: moTexture.cpp:2086
MOuint m_StartTime
Definition: moTexture.h:732
moFBO * m_fbo
Definition: moTexture.h:396
int Contrast
Definition: moTexture.h:417
void SetFBO(moFBO *p_fbo)
Definition: moTexture.h:191
virtual MOboolean NeedsInterpolation()
Definition: moTexture.cpp:1583
moText GetName() const
Definition: moTexture.h:245
virtual void SetFrameCount(MOuint p_nframes)
Definition: moTexture.h:620
moText0 moText
Definition: moText.h:291
MOuint AddTexture(MOuint p_width, MOuint p_height, const moTexParam &p_param, MOuint p_glid, MOuint &p_attach_point)
Definition: moFBO.cpp:174
virtual MOulong GetFramesLength()=0
La cantidad de frames, el largo del stream.
moStreamState
Definition: moVideoGraph.h:140
MOboolean SupportedFile(moText p_filename)
Definition: moTexture.cpp:345
virtual moStreamState GetState()
Estado de la reproducción.
GStreamer Graph Class.
Definition: moGsGraph.h:151
virtual void SetSaturation(float saturation)=0
moText0 & Right(MOuint)
Definition: moText.cpp:491
#define MOint
Definition: moTypes.h:388
MOuint GetDataHeight() const
Definition: moTexture.cpp:566
virtual bool BuildLiveVideoGraph(moText filename, moBucketsPool *pBucketsPool)=0
Grafo de reproducción de video en modo vivo, asyncronicamente reproducido en función del clock...
MOboolean SupportedFile(moText p_filename)
Definition: moTexture.cpp:1791
virtual MOboolean Finish()
Definition: moTexture.cpp:101
MOboolean GetBuffer(GLvoid *p_buffer, GLenum p_format=GL_RGBA, GLenum p_type=GL_UNSIGNED_BYTE)
Definition: moTexture.cpp:409
moFileManager * GetFileMan()
void SetName(moText p_name)
Definition: moTexture.h:250
virtual MOint Interpolate()
Definition: moTexture.cpp:1622
virtual void Stop()
Definition: moTexture.cpp:1964
Clase Base para Objetos Moldeo ( moEffect, moIODevice, moResource, moConsole )
MOuint GetGLId() const
Definition: moTexture.h:224
static MOuint NextPowerOf2(MOuint p_seed)
Definition: moTexture.cpp:741
MOboolean ValidTexture(MOuint p_i)
Definition: moTexture.cpp:1874
MOint frameprevious
Definition: moTexture.h:932
clase base para el manejo de una textura
Definition: moTexture.h:78
moText GetCompletePath()
Get inmediate folder name: return "PP" for "PP/myFileName.txt".
Definition: moFile.cpp:538
Administrador de recursos.
virtual void SetPlayMode(moPlayMode playmode)
Definition: moTexture.cpp:1749
MOuint m_fbo_attach_point
Definition: moTexture.h:397
MOfloat m_InterpolationPosition
Definition: moTexture.h:735
void EmptyBucket()
Libera el espacio de memoria.
Definition: moBuckets.cpp:66
const MOlong PI
Definition: moMath.cpp:44
MOuint m_InterpolationTime
Definition: moTexture.h:729
virtual MOuint GetActualFrame()
Definition: moTexture.cpp:1743
bool CalculateLuminanceAndConstrast(int x0=0, int y0=0, int x1=0, int y1=0)
Definition: moTexture.cpp:451
virtual void Stop()=0
Detener la reproducción del video.
MOint ScreenHeight() const
GLint wrap_s
Definition: moTypes.h:549
MOubyte * GetData()
Definition: moFile.cpp:463
void SetFrame(MOuint p_i, moTexture *p_texture)
Definition: moTexture.cpp:1855
moText m_name
Definition: moTexture.h:402
virtual MOboolean IsInterpolating()
Definition: moTexture.cpp:1552
MOuint m_ActualFrame
Definition: moTexture.h:707
TEXTURA BASE.
Definition: moTexture.h:54
Clase que implementa un administrador de shaders.
MOuint m_width
Definition: moTexture.h:405
virtual void Play()=0
Reproducir el video.
static moDebug * MODebug2
Clase de impresión de errores para depuración
Definition: moAbstract.h:225
virtual void SetContrast(float contrast)=0
virtual bool BuildLiveQTVideoGraph(moText filename, moBucketsPool *pBucketsPool)=0
moTexture & operator=(const moTexture &p_src_tex)
Definition: moTexture.cpp:623
moDataManager * GetDataMan()
moText Text()
Definition: moValue.cpp:539
MOboolean Load(moText p_FileName, MOboolean bWaitForDownload=false)
moTextureFilter * m_pCopyEnd
Definition: moTexture.h:715
moGLManager * m_gl
Definition: moTexture.h:393
MOboolean BuildFromFile(moText p_filename)
Definition: moTexture.cpp:142
MOboolean m_bIsPlaying
Definition: moTexture.h:698
MOuint m_FrameNext
Definition: moTexture.h:704
virtual void SetHue(float hue)=0
moTextureType m_type
Definition: moTexture.h:399
Espacio en memoria para compartir datos entre objetos.
Definition: moBuckets.h:53
void Push(moText p_text)
Apila el mensaje dentro de la pila de mensajes.
Definition: moAbstract.h:115
virtual void SetHue(float hue)
Definition: moTexture.cpp:2059
MOuint GetHeight() const
Definition: moTexture.h:261
moValue & GetValue(MOint i=-1)
Definition: moParam.cpp:1204
MOuint LoadFilters(moParam *p_param)
MOboolean Load(moParam *p_param)
Definition: moTexture.cpp:358
bool IsEOS()
Definition: moTexture.cpp:2094
MOboolean Load(moParam *p_param)
Definition: moTexture.cpp:1798
moFile * m_pFile
Definition: moTexture.h:390
virtual void Play()
Definition: moTexture.cpp:1930
virtual void SetFramesPerSecond(MOfloat p_fps)
Definition: moTexture.h:632
#define RenderMan()
MOint m_components
Definition: moTexture.h:408
bool IsPowerOfTwo(int iValue)
Definition: moMath.h:297
MOboolean SupportedFile(moText p_filename)
Definition: moTexture.cpp:2103
virtual void SetBrightness(float brightness)
Definition: moTexture.cpp:2043
moTextureFilter * m_pInterpolator
Definition: moTexture.h:716
virtual bool IsPaused()
Definition: moTexture.cpp:2031
GLenum target
Definition: moTypes.h:545
GLint min_filter
Definition: moTypes.h:547
void SetParam()
Definition: moTexture.cpp:645
moFileStatus GetStatus()
Definition: moFile.cpp:453
moText GetDataPath()
virtual bool IsPlaying()
Definition: moTexture.cpp:2020
virtual bool IsEOS()=0
#define MOuint
Definition: moTypes.h:387
void CopyFromTex(moTexture *p_src_tex, MOboolean p_copy_glid, MOboolean p_copy_moid, MOboolean p_copy_type, MOboolean p_copy_name)
Definition: moTexture.cpp:600
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
MOboolean m_bInterpolation
Definition: moTexture.h:710
moTextureArray m_textures_array
Definition: moTexture.h:844
MOubyte * GetBuffer()
Devuelve el puntero al buffer de datos.
Definition: moBuckets.cpp:58
MOboolean Reload(bool force_kill=true)
Definition: moTexture.cpp:2197
moBucket * RetreiveBucket()
Definition: moBuckets.cpp:205
virtual bool InitGraph()=0
Inicialización del grafo.
void EnableVideo(int)
Definition: moTexture.cpp:2206
virtual void Play()
Definition: moTexture.cpp:1441
MOuint m_FrameRate
Definition: moVideoGraph.h:209
virtual MOboolean Finish()
Definition: moTexture.cpp:1421
MOuint m_height
Definition: moTexture.h:406
virtual MOboolean BuildFromBitmap(moBitmap *p_bitmap, moText p_bufferformat="JPG")
Guarda el bitmap con el formato elegido en memoria, luego construye la textura opengl.
Definition: moTexture.cpp:1297
virtual void SetBalance(float balance)=0
Fija el balance entre canal izquierdo y derecho en caso de haberlos.
MOuint GetSubValueCount()
Definition: moValue.h:545
MOint m_moid
Definition: moTexture.h:400
moBucketsPool m_BucketsPool
Definition: moTexture.h:935
una textura asociada a una animación de cuadros
Definition: moTexture.h:549
virtual bool IsPlaying()
Definition: moTexture.cpp:1451
MOboolean m_bInitialized
Valor de inicialización
Definition: moAbstract.h:223
virtual void Seek(MOuint frame, float rate=1.0)=0
Busca y posiciona.
MOdouble ang
Definition: moTempo.h:81
moPlayMode m_PlayMode
Definition: moTexture.h:697
bool ResetBufferData(bool force_creation=false, int bytes_per_pixel=0)
Definition: moTexture.cpp:704
MOuint GetWidth() const
Definition: moTexture.h:256
virtual void Stop()
Definition: moTexture.cpp:1446
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
Definition: moAbstract.cpp:114
MOint ScreenWidth() const
MOuint m_bytespp
Definition: moTexture.h:407
MOfloat m_max_coord_s
Definition: moTexture.h:409
#define MOubyte
Definition: moTypes.h:399
virtual void Pause()=0
Pausa la reproducción del video.
moDataManager * m_pDataMan
Definition: moTexture.h:391
virtual MOboolean IsInterpolationActive()
Definition: moTexture.cpp:1557
MOboolean SetBuffer(const GLvoid *p_buffer, GLenum p_format=GL_RGBA, GLenum p_type=GL_UNSIGNED_BYTE)
Definition: moTexture.cpp:371
MOulong moGetTicks()
Devuelve en milisegundos el valor del reloj de Moldeo.
Definition: moTimer.cpp:138
moTexParam m_param
Definition: moTexture.h:404
moTexParam GetTexParam() const
Definition: moTexture.h:307