Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Codecs/H265/H265Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ void H265Encoder::Detach()
packet->data = static_cast<uint8_t*>( av_memdup( packetData.data(), packetData.size() ) );
packet->size = static_cast<int>( packetData.size() );
packet->stream_index = _params->pStream->index;
packet->pts = packet->dts = _params->pPicOut->pts;
packet->pts = _params->pPicOut->pts;
packet->dts = _params->pPicOut->dts;
packet->duration = 1;

AVRational encoderTimeBase{ 1, static_cast<int>( _frameRate ) };
Expand Down Expand Up @@ -197,6 +198,7 @@ void H265Encoder::WriteBitmap( std::shared_ptr<IBitmap> pBitmap )
{
_width = pBitmap->GetWidth();
_height = pBitmap->GetHeight();
_params->iFrame = 0;
_params->pParam->sourceWidth = _width;
_params->pParam->sourceHeight = _height;
_params->pParam->fpsNum = _frameRate;
Expand Down Expand Up @@ -315,7 +317,8 @@ void H265Encoder::WriteBitmap( std::shared_ptr<IBitmap> pBitmap )
packet->data = static_cast<uint8_t*>( av_memdup( packetData.data(), packetData.size() ) );
packet->size = static_cast<int>( packetData.size() );
packet->stream_index = _params->pStream->index;
packet->pts = packet->dts = _params->pPicOut->pts;
packet->pts = _params->pPicOut->pts;
packet->dts = _params->pPicOut->dts;
packet->duration = 1;

AVRational encoderTimeBase{ 1, static_cast<int>( _frameRate ) };
Expand Down
52 changes: 40 additions & 12 deletions GUI/CropWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,74 @@
#include "MainWindow.h"
#include "Serializer.h"
#include "ImGuiHelpers.h"
#include "./../Transforms/CropTransform.h"

#include "./../Transforms/ResizeTransform.h"

ACMB_GUI_NAMESPACE_BEGIN

CropWindow::CropWindow( const Point& gridPos )
: PipelineElementWindow( "Crop", gridPos, PEFlags_StrictlyOneInput | PEFlags_StrictlyOneOutput )
: PipelineElementWindow( "Crop", gridPos, PEFlags_StrictlyOneInput | PEFlags_StrictlyOneOutput )
, SettingsInterpolationUser<CropTransform>( this, { 0, 0, 10000, 10000 })
{
}

void CropWindow::DrawPipelineElementControls()
{
Size inputBitmapSize = { 65535, 65535 };
if ( auto pPrimaryInput = GetPrimaryInput() )
if ( auto pPrimaryInput = GetPrimaryInput(); pPrimaryInput && pPrimaryInput->GetPreviewedFrameNumber() >=0 )
if ( auto inputBitmapSizeExp = pPrimaryInput->GetBitmapSize() )
inputBitmapSize = inputBitmapSizeExp.value();
inputBitmapSize = inputBitmapSizeExp.value();

_dstRect.x = std::clamp(_dstRect.x, 0, inputBitmapSize.width - 1);
_dstRect.y = std::clamp( _dstRect.y, 0, inputBitmapSize.height - 1 );
_dstRect.width = std::clamp( _dstRect.width, 1, inputBitmapSize.width - _dstRect.x );
_dstRect.height = std::clamp( _dstRect.height, 1, inputBitmapSize.height - _dstRect.y );

ImGui::Text( "Crop area:" );
UI::DragInt( "Left", &_dstRect.x, 1.0f, 0, inputBitmapSize.width - 1, "Left boundary of the crop area", this );
UI::DragInt( "Top", &_dstRect.y, 1.0f, 0, inputBitmapSize.height - 1,"Top boundary of the crop area", this );
UI::DragInt( "Width", &_dstRect.width, 1.0f, 1, inputBitmapSize.width - _dstRect.x, "Width of the crop area", this );
UI::DragInt( "Height", &_dstRect.height, 1.0f, 1, inputBitmapSize.height - _dstRect.y, "Height of the crop area", this );

DrawFrameCounter();
}

void CropWindow::OnPreviewedFrameNumberChanged(int val)
{
PipelineElementWindow::OnPreviewedFrameNumberChanged(val);
_dstRect = GetInterpolatedSettings(_previewedFrameNumber);
}

IBitmapPtr CropWindow::ProcessBitmapFromPrimaryInput( IBitmapPtr pSource, size_t )
void CropWindow::OnKeyframeCommited()
{
return CropTransform::Crop( pSource, _dstRect );
AddSettings(_previewedFrameNumber, _dstRect );
}

IBitmapPtr CropWindow::ProcessBitmapFromPrimaryInput( IBitmapPtr pSource, size_t frameIndex )
{
auto interpolatedSettings = GetInterpolatedSettings( int( frameIndex ) );
return CropTransform::Crop( pSource, interpolatedSettings);
}

void CropWindow::Serialize( std::ostream& out ) const
{
PipelineElementWindow::Serialize( out );
gui::Serialize( _dstRect, out );
SettingsInterpolationUser<CropTransform>::Serialize( out );
}

bool CropWindow::Deserialize( std::istream& in )
{
if ( !PipelineElementWindow::Deserialize( in ) ) return false;
_dstRect = gui::Deserialize<Rect>( in, _remainingBytes );
SettingsInterpolationUser<CropTransform>::Deserialize( in, _remainingBytes );
return true;
}

int CropWindow::GetSerializedStringSize() const
{
return PipelineElementWindow::GetSerializedStringSize() + gui::GetSerializedStringSize( _dstRect );
return PipelineElementWindow::GetSerializedStringSize()
+ gui::GetSerializedStringSize( _dstRect )
+ SettingsInterpolationUser<CropTransform>::GetSerializedStringSize();
}

Expected<void, std::string> CropWindow::GeneratePreviewBitmap()
Expand All @@ -67,12 +91,16 @@ Expected<void, std::string> CropWindow::GeneratePreviewBitmap()

const Rect cropArea
{
.x = std::clamp( int( _dstRect.x * xFactor ), 0, inputPreviewSize.width - 1 ),
.y = std::clamp( int( _dstRect.y * yFactor ), 0, inputPreviewSize.height - 1 ),
.width = std::clamp( int( _dstRect.width * xFactor ), 1, inputPreviewSize.width - cropArea.x ),
.height = std::clamp( int( _dstRect.height * yFactor ), 1, inputPreviewSize.height - cropArea.y )
.x = std::clamp( int(_dstRect.x * xFactor ), 0, inputPreviewSize.width - 1 ),
.y = std::clamp( int(_dstRect.y * yFactor ), 0, inputPreviewSize.height - 1 ),
.width = std::clamp( int(_dstRect.width * xFactor ), 1, inputPreviewSize.width - cropArea.x ),
.height = std::clamp( int(_dstRect.height * yFactor ), 1, inputPreviewSize.height - cropArea.y )
};

_pPreviewBitmap = CropTransform::Crop(pInputBitmap, cropArea );
const Size finalSize = ResizeTransform::GetSizeWithPreservedRatio(Size{ cropArea.width, cropArea.height }, inputPreviewSize);
_pPreviewBitmap = ResizeTransform::Resize(_pPreviewBitmap, finalSize);

return {};
}

Expand Down
11 changes: 9 additions & 2 deletions GUI/CropWindow.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#pragma once
#include "PipelineElementWindow.h"
#include "SettingsInterpolationUser.h"

#include "./../Transforms/CropTransform.h"

ACMB_GUI_NAMESPACE_BEGIN

class CropWindow : public PipelineElementWindow
class CropWindow : public PipelineElementWindow, public SettingsInterpolationUser<CropTransform>
{
Rect _dstRect = { 0, 0, 1000, 1000 };
private:
CropTransform::Settings _dstRect = { 0, 0, 10000, 10000 };

virtual IBitmapPtr ProcessBitmapFromPrimaryInput( IBitmapPtr pSource, size_t taskNumber = 0 ) override;
virtual Expected<void, std::string> GeneratePreviewBitmap() override;
Expand All @@ -18,6 +22,9 @@ class CropWindow : public PipelineElementWindow
virtual bool Deserialize(std::istream& in) override;
virtual int GetSerializedStringSize() const override;

virtual void OnPreviewedFrameNumberChanged(int val) override;
virtual void OnKeyframeCommited() override;

SET_MENU_PARAMS( "\xef\x84\xa5", "Crop", "Crop image to an arbitrary rectangle", 7 );
};

Expand Down
24 changes: 12 additions & 12 deletions GUI/ImGuiHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ namespace UI

static void ResetParentWindow(PipelineElementWindow* parent)
{
parent->ResetPreview();
if ( !parent )
return;

parent->ResetPreview(PipelineElementWindow::PropagationDir::Forward );

if ( parent->GetInOutFlags() & PEFlags::PEFlags_NoInput )
parent->ResetProgress(PipelineElementWindow::PropagationDir::Forward);
Expand Down Expand Up @@ -143,8 +146,7 @@ namespace UI
if ( ImGui::Button( name.c_str(), size) && !isInterfaceLocked )
{
action();
if ( parent )
ResetParentWindow( parent );
ResetParentWindow( parent );

return true;
}
Expand All @@ -158,8 +160,7 @@ namespace UI
if ( ImGui::Button( name.c_str(), size ) )
{
action();
if ( parent )
ResetParentWindow(parent);
ResetParentWindow(parent);

return true;
}
Expand All @@ -174,8 +175,7 @@ namespace UI
if ( pressed )
{
*v = v_button;
if ( parent )
ResetParentWindow(parent);
ResetParentWindow(parent);

return true;
}
Expand All @@ -187,7 +187,7 @@ namespace UI
bool Checkbox( const std::string& label, bool* v, const std::string& tooltip, PipelineElementWindow* parent )
{
const bool isInterfaceLocked = MainWindow::GetInstance( FontRegistry::Instance() ).IsInterfaceLocked();
if ( ImGui::Checkbox( label.c_str(), v, isInterfaceLocked ) && parent )
if ( ImGui::Checkbox( label.c_str(), v, isInterfaceLocked ) )
{
ResetParentWindow(parent);
return true;
Expand All @@ -200,7 +200,7 @@ namespace UI
bool DragInt( const std::string& label, int* v, float v_speed, int v_min, int v_max, const std::string& tooltip, PipelineElementWindow* parent )
{
const bool isInterfaceLocked = MainWindow::GetInstance( FontRegistry::Instance() ).IsInterfaceLocked();
if ( ImGui::DragInt( label.c_str(), v, v_speed, v_min, v_max, "%d", isInterfaceLocked ? ImGuiSliderFlags_ReadOnly : ImGuiSliderFlags_AlwaysClamp ) && parent )
if ( ImGui::DragInt( label.c_str(), v, v_speed, v_min, v_max, "%d", isInterfaceLocked ? ImGuiSliderFlags_ReadOnly : ImGuiSliderFlags_AlwaysClamp ) )
{
ResetParentWindow(parent);
return true;
Expand All @@ -213,7 +213,7 @@ namespace UI
bool DragInt2( const std::string& label, int v[2], float v_speed, int v_min, int v_max, const std::string& tooltip, acmb::gui::PipelineElementWindow* parent )
{
const bool isInterfaceLocked = MainWindow::GetInstance( FontRegistry::Instance() ).IsInterfaceLocked();
if ( ImGui::DragInt2( label.c_str(), v, v_speed, v_min, v_max, "%d", isInterfaceLocked ? ImGuiSliderFlags_ReadOnly : ImGuiSliderFlags_AlwaysClamp ) && parent )
if ( ImGui::DragInt2( label.c_str(), v, v_speed, v_min, v_max, "%d", isInterfaceLocked ? ImGuiSliderFlags_ReadOnly : ImGuiSliderFlags_AlwaysClamp ) )
{
ResetParentWindow(parent);
return true;
Expand All @@ -226,7 +226,7 @@ namespace UI
bool DragFloat( const std::string& label, float* v, float v_speed, float v_min, float v_max, const std::string& tooltip, PipelineElementWindow* parent )
{
const bool isInterfaceLocked = MainWindow::GetInstance( FontRegistry::Instance() ).IsInterfaceLocked();
if ( ImGui::DragFloat( label.c_str(), v, v_speed, v_min, v_max, "%.4f", isInterfaceLocked ? ImGuiSliderFlags_ReadOnly : ImGuiSliderFlags_AlwaysClamp ) && parent )
if ( ImGui::DragFloat( label.c_str(), v, v_speed, v_min, v_max, "%.4f", isInterfaceLocked ? ImGuiSliderFlags_ReadOnly : ImGuiSliderFlags_AlwaysClamp ) )
{
ResetParentWindow(parent);
return true;
Expand All @@ -239,7 +239,7 @@ namespace UI
bool InputInt( const std::string& label, int* v, int step, int step_fast, int min, int max, const std::string& tooltip, acmb::gui::PipelineElementWindow* parent )
{
const bool isInterfaceLocked = MainWindow::GetInstance( FontRegistry::Instance() ).IsInterfaceLocked();
if ( ImGui::InputInt( label.c_str(), v, step, step_fast, isInterfaceLocked ? ImGuiInputTextFlags_ReadOnly : 0 ) && parent )
if ( ImGui::InputInt( label.c_str(), v, step, step_fast, isInterfaceLocked ? ImGuiInputTextFlags_ReadOnly : 0 ) )
{
ResetParentWindow(parent);
return true;
Expand Down
38 changes: 17 additions & 21 deletions GUI/ImageReaderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ void ImageReaderWindow::DrawPipelineElementControls()
{
for ( int i = 0; i < int( _fileNames.size() ); ++i )
{
const bool is_selected = (_selectedItemIdx == i);
const bool is_selected = (_previewedFrameNumber == i);
const std::string shortName = _fileNames[i].substr( _fileNames[i].find_last_of( "\\/" ) + 1 );
if ( ImGui::Selectable( shortName.c_str(), is_selected ) )
{
_selectedItemIdx = i;
ResetPreview();
OnPreviewedFrameNumberChanged( i );
}
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if ( is_selected )
Expand All @@ -51,7 +50,7 @@ void ImageReaderWindow::DrawPipelineElementControls()
ImGui::EndListBox();
}

ImGui::Text( "%d frames in %d files", int( _frameCount ), int( _fileNames.size() ) );
ImGui::Text( "%d frames in %d files", int( _taskCount ), int( _fileNames.size() ) );

auto fileDialog = FileDialog::Instance();
const auto openDialogName = "SelectImagesDialog##" + _name;
Expand All @@ -72,8 +71,8 @@ void ImageReaderWindow::DrawPipelineElementControls()
ImGui::CloseCurrentPopup();

_fileNames.clear();
_frameCount = 0;
_selectedItemIdx = 0;
_taskCount = 0;
_previewedFrameNumber = 0;
_taskNumberToFileIndex.clear();
ResetProgress( PropagationDir::Forward );
}, "Delete all images from the importing list", this );
Expand All @@ -95,8 +94,8 @@ void ImageReaderWindow::DrawPipelineElementControls()
{
auto pDecoder = ImageDecoder::Create( path );
_fileNames.push_back( path );
_frameCount += pDecoder->GetFrameCount();
_taskNumberToFileIndex[int( _frameCount - 1 )] = int( _fileNames.size() - 1 );
_taskCount += pDecoder->GetFrameCount();
_taskNumberToFileIndex[int( _taskCount - 1 )] = int( _fileNames.size() - 1 );
}
catch ( std::exception& e )
{
Expand All @@ -122,13 +121,13 @@ Expected<void, std::string> ImageReaderWindow::GeneratePreviewBitmap()
if ( _fileNames.empty() )
return unexpected( "No images in the list" );

if ( _selectedItemIdx >= int( _fileNames.size() ) )
if ( _previewedFrameNumber >= int( _fileNames.size() ) || _previewedFrameNumber < 0 )
return unexpected( "No image selected" );

if ( _fileNames[_selectedItemIdx].empty() )
if ( _fileNames[_previewedFrameNumber].empty() )
return unexpected( "Selected file name is empty" );

auto pDecoder = ImageDecoder::Create( _fileNames[_selectedItemIdx] );
auto pDecoder = ImageDecoder::Create( _fileNames[_previewedFrameNumber] );
const auto mainWindow = ImGui::FindWindowByName( "acmb" );
_pPreviewBitmap = pDecoder->ReadPreview( Size{ std::min( int( mainWindow->Size.x * 0.5f ), 1280 ), std::min( int( mainWindow->Size.y * 0.5f ), 720 ) } );
return {};
Expand Down Expand Up @@ -165,15 +164,15 @@ Expected<Size, std::string> ImageReaderWindow::GetBitmapSize()
if ( _fileNames.empty() )
return unexpected( "No images in the list" );

if ( _selectedItemIdx >= int( _fileNames.size() ) )
if ( _previewedFrameNumber >= int( _fileNames.size() ) )
return unexpected( "No image selected" );

if ( _fileNames[_selectedItemIdx].empty() )
if ( _fileNames[_previewedFrameNumber].empty() )
return unexpected( "Selected file name is empty" );

try
{
auto pDecoder = ImageDecoder::Create( _fileNames[_selectedItemIdx] );
auto pDecoder = ImageDecoder::Create( _fileNames[_previewedFrameNumber] );
const auto res = Size{ int( pDecoder->GetWidth() ), int( pDecoder->GetHeight() ) };
pDecoder->Detach();
return res;
Expand All @@ -188,8 +187,7 @@ void ImageReaderWindow::Serialize( std::ostream& out ) const
{
PipelineElementWindow::Serialize( out );
gui::Serialize( _workingDirectory, out );
gui::Serialize( _fileNames, out );
gui::Serialize( _selectedItemIdx, out );
gui::Serialize( _fileNames, out );
gui::Serialize( _invertOrder, out );
}

Expand All @@ -198,7 +196,6 @@ bool ImageReaderWindow::Deserialize( std::istream& in )
if ( !PipelineElementWindow::Deserialize( in ) ) return false;
_workingDirectory = gui::Deserialize<std::string>( in, _remainingBytes );
_fileNames = gui::Deserialize<std::vector<std::string>>( in, _remainingBytes );
_selectedItemIdx = gui::Deserialize<int>( in, _remainingBytes );
_invertOrder = gui::Deserialize<bool>( in, _remainingBytes );

for ( size_t i = 0; i < _fileNames.size(); ++i )
Expand All @@ -207,8 +204,8 @@ bool ImageReaderWindow::Deserialize( std::istream& in )
try
{
auto pDecoder = ImageDecoder::Create( fileName );
_frameCount += pDecoder->GetFrameCount();
_taskNumberToFileIndex[int( _frameCount - 1 )] = int( i );
_taskCount += pDecoder->GetFrameCount();
_taskNumberToFileIndex[int( _taskCount - 1 )] = int( i );
}
catch ( std::exception& e )
{
Expand All @@ -225,7 +222,6 @@ int ImageReaderWindow::GetSerializedStringSize() const
return PipelineElementWindow::GetSerializedStringSize()
+ gui::GetSerializedStringSize( _workingDirectory )
+ gui::GetSerializedStringSize( _fileNames )
+ gui::GetSerializedStringSize( _selectedItemIdx )
+ gui::GetSerializedStringSize( _invertOrder );
}

Expand All @@ -237,7 +233,7 @@ std::string ImageReaderWindow::GetTaskName( size_t taskNumber ) const

size_t ImageReaderWindow::GetTaskCount( bool )
{
return _frameCount;
return _taskCount;
}

REGISTER_TOOLS_ITEM( ImageReaderWindow )
Expand Down
3 changes: 0 additions & 3 deletions GUI/ImageReaderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class ImageReaderWindow : public PipelineElementWindow
std::vector<std::string> _fileNames;
std::map<int, int> _taskNumberToFileIndex;

int _selectedItemIdx = 0;
size_t _frameCount = 0;

bool _invertOrder = false;
virtual Expected<IBitmapPtr, std::string> RunTask( size_t i ) override;
virtual IBitmapPtr ProcessBitmapFromPrimaryInput( IBitmapPtr, size_t ) override { return nullptr; }
Expand Down
Loading