0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Graphic3d / Graphic3d_MediaTexture.cxx
CommitLineData
98e6c6d1 1// Created by: Kirill GAVRILOV
2// Copyright (c) 2019 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15// activate some C99 macros like UINT64_C in "stdint.h" which used by FFmpeg
16#ifndef __STDC_CONSTANT_MACROS
17 #define __STDC_CONSTANT_MACROS
18#endif
19
20#include <Graphic3d_MediaTexture.hxx>
21
22#include <Graphic3d_TextureParams.hxx>
23#include <Media_Frame.hxx>
24#include <Message.hxx>
25#include <Message_Messenger.hxx>
26
27#ifdef HAVE_FFMPEG
28#include <Standard_WarningsDisable.hxx>
29extern "C"
30{
31 #include <libavcodec/avcodec.h>
32 #include <libavutil/imgutils.h>
33};
34#include <Standard_WarningsRestore.hxx>
35#endif
36
37IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_MediaTexture, Graphic3d_Texture2D)
38
39// ================================================================
40// Function : Graphic3d_MediaTexture
41// Purpose :
42// ================================================================
000c21fa 43Graphic3d_MediaTexture::Graphic3d_MediaTexture (const Handle(Standard_HMutex)& theMutex,
98e6c6d1 44 Standard_Integer thePlane)
633084b8 45: Graphic3d_Texture2D ("", Graphic3d_TypeOfTexture_2D),
98e6c6d1 46 myMutex (theMutex),
47 myPlane (thePlane)
48{
49 myParams->SetModulate(false);
50 myParams->SetRepeat (false);
51 myParams->SetFilter (Graphic3d_TOTF_BILINEAR);
52 myParams->SetTextureUnit (Graphic3d_TextureUnit(int(Graphic3d_TextureUnit_0) + thePlane));
53}
54
55// ================================================================
56// Function : GetImage
57// Purpose :
58// ================================================================
faff3767 59Handle(Image_PixMap) Graphic3d_MediaTexture::GetImage (const Handle(Image_SupportedFormats)& )
98e6c6d1 60{
61 Standard_Mutex::Sentry aLock (myMutex.get());
62 if (myFrame.IsNull()
63 || myFrame->IsLocked()
64 || myFrame->IsEmpty()
65 || myFrame->SizeX() < 1
66 || myFrame->SizeY() < 1)
67 {
68 return Handle(Image_PixMap)();
69 }
70
71 if (myPixMapWrapper.IsNull())
72 {
73 myPixMapWrapper = new Image_PixMap();
74 }
75
76#ifdef HAVE_FFMPEG
77 const AVFrame* aFrame = myFrame->Frame();
78 const Image_Format anOcctFmt = Media_Frame::FormatFFmpeg2Occt (myFrame->Format());
79 if (anOcctFmt != Image_Format_UNKNOWN)
80 {
81 if (myPlane != 0
82 || !myPixMapWrapper->InitWrapper (anOcctFmt, aFrame->data[0], aFrame->width, aFrame->height, aFrame->linesize[0]))
83 {
84 return Handle(Image_PixMap)();
85 }
86 return myPixMapWrapper;
87 }
88 else if (myFrame->Format() == AV_PIX_FMT_YUV420P
89 || myFrame->Format() == AV_PIX_FMT_YUVJ420P)
90 {
91 const Graphic3d_Vec2i aSize = myPlane == 0 ? myFrame->Size() : myFrame->Size() / 2;
92 if (myPlane > 3
93 || !myPixMapWrapper->InitWrapper (Image_Format_Gray, aFrame->data[myPlane], aSize.x(), aSize.y(), aFrame->linesize[myPlane]))
94 {
95 return Handle(Image_PixMap)();
96 }
97 return myPixMapWrapper;
98 }
99#endif
100
101 return Handle(Image_PixMap)();
102}