<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQImageToImageSource.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkQImageToImageSource.h"

#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnsignedCharArray.h"
#include "vtkPointData.h"

#include <QApplication>
#include <QImage>
#include <math.h>

#include "vtkSmartPointer.h"
#define VTK_CREATE(type, name) \
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()

vtkStandardNewMacro(vtkQImageToImageSource);

//----------------------------------------------------------------------------
vtkQImageToImageSource::vtkQImageToImageSource()
{
  this->QtImage = 0;
  this->SetNumberOfInputPorts(0);
  this->DataExtent[0] = 0;
  this->DataExtent[1] = 0;
  this->DataExtent[2] = 0;
  this->DataExtent[3] = 0;
  this->DataExtent[4] = 0;
  this->DataExtent[5] = 0;
}

//----------------------------------------------------------------------------
int vtkQImageToImageSource::RequestData( vtkInformation *vtkNotUsed(request),
                                         vtkInformationVector **vtkNotUsed(inputVector), 
                                         vtkInformationVector *outputVector)
{ 
  if(!QApplication::instance())
    {
    vtkErrorMacro("You must initialize QApplication before using this filter.");
    return 0;
    }

  // get the info objects
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
  vtkImageData *output = vtkImageData::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));
  
  if( this->QtImage == 0 )
    {
    vtkErrorMacro( "Qt Image was not set." );
    return 0;
    }

  this->QtImage->convertToFormat( QImage::Format_ARGB32 );
  QSize size = this->QtImage->size();
  int width = size.width();
  int height = size.height();
  const unsigned char* data2 = this->QtImage->bits();

  unsigned char* data = new unsigned char[4*width*height];
  memcpy( data, data2, 4*width*height );

  output->SetNumberOfScalarComponents( 4 );
  output->SetScalarTypeToUnsignedChar();
  output->SetExtent(this->DataExtent);
  output->AllocateScalars();
  
  vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast( output->GetPointData()->GetScalars() );
  
  int i, j;
  unsigned char temp[4];
  for( i = 0; i < height/2; i++ )
    {
    for( j = 0; j < width; j++ )
      {
      int bottom_address = ((((height-1)-i)*width)+j);
      int top_address = (i*width)+j;
      temp[0] = data[(4*bottom_address)+0];
      temp[1] = data[(4*bottom_address)+1];
      temp[2] = data[(4*bottom_address)+2];
      temp[3] = data[(4*bottom_address)+3];
<commit_msg>BUG: Converted QImage return object was ignored.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQImageToImageSource.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkQImageToImageSource.h"

#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUnsignedCharArray.h"
#include "vtkPointData.h"

#include <QApplication>
#include <QImage>
#include <math.h>

#include "vtkSmartPointer.h"
#define VTK_CREATE(type, name) \
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()

vtkStandardNewMacro(vtkQImageToImageSource);

//----------------------------------------------------------------------------
vtkQImageToImageSource::vtkQImageToImageSource()
{
  this->QtImage = 0;
  this->SetNumberOfInputPorts(0);
  this->DataExtent[0] = 0;
  this->DataExtent[1] = 0;
  this->DataExtent[2] = 0;
  this->DataExtent[3] = 0;
  this->DataExtent[4] = 0;
  this->DataExtent[5] = 0;
}

//----------------------------------------------------------------------------
int vtkQImageToImageSource::RequestData( vtkInformation *vtkNotUsed(request),
                                         vtkInformationVector **vtkNotUsed(inputVector), 
                                         vtkInformationVector *outputVector)
{ 
  if(!QApplication::instance())
    {
    vtkErrorMacro("You must initialize QApplication before using this filter.");
    return 0;
    }

  // get the info objects
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
  vtkImageData *output = vtkImageData::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));
  
  if( this->QtImage == 0 )
    {
    vtkErrorMacro( "Qt Image was not set." );
    return 0;
    }

  QImage newImage = this->QtImage->convertToFormat( QImage::Format_ARGB32 );
  QSize size = newImage.size();
  int width = size.width();
  int height = size.height();
  const unsigned char* data2 = newImage.bits();

  unsigned char* data = new unsigned char[4*width*height];
  memcpy( data, data2, 4*width*height );

  output->SetNumberOfScalarComponents( 4 );
  output->SetScalarTypeToUnsignedChar();
  output->SetExtent(this->DataExtent);
  output->AllocateScalars();
  
  vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast( output->GetPointData()->GetScalars() );
  
  int i, j;
  unsigned char temp[4];
  for( i = 0; i < height/2; i++ )
    {
    for( j = 0; j < width; j++ )
      {
      int bottom_address = ((((height-1)-i)*width)+j);
      int top_address = (i*width)+j;
      temp[0] = data[(4*bottom_address)+0];
      temp[1] = data[(4*bottom_address)+1];
      temp[2] = data[(4*bottom_address)+2];
      temp[3] = data[(4*bottom_address)+3];

{'fraction_non_alphanumeric': 0.21552668649240883, 'fraction_numerical': 0.01314759743308812, 'mean_word_length': 3.2458471760797343, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6595576', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1930, 'n_words': 414}