Merge remote-tracking branch 'origin/fix/pict' into release/v9.1.0

This commit is contained in:
Oleg Korshul
2025-10-01 22:59:02 +03:00
10 changed files with 1869 additions and 3797 deletions

View File

@ -2338,7 +2338,8 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1,
for (size_t i = 0; i < paths2.size(); i++)
{
if (CBooleanOperations o; o.IsSelfInters(paths2[i]))
CBooleanOperations o;
if (o.IsSelfInters(paths2[i]))
{
CBooleanOperations operation(paths2[i], paths2[i], Intersection, fillType, isLuminosity);
CGraphicsPath p = std::move(operation.GetResult());
@ -2351,7 +2352,8 @@ CGraphicsPath CalcBooleanOperation(const CGraphicsPath& path1,
for (size_t j = 0; j < paths1.size(); j++)
{
if (CBooleanOperations o; o.IsSelfInters(paths1[j]))
CBooleanOperations o2;
if (o2.IsSelfInters(paths1[j]))
{
CBooleanOperations operation(paths1[j], paths1[j], Intersection, fillType, isLuminosity);
CGraphicsPath p = std::move(operation.GetResult());

View File

@ -262,6 +262,25 @@ namespace Aggplus
m_internal->m_agg_ps.line_to(x + width, y);
m_internal->m_agg_ps.line_to(x + width, y + height);
m_internal->m_agg_ps.line_to(x, y + height);
m_internal->m_agg_ps.line_to(x, y);
m_internal->m_agg_ps.close_polygon();
return Ok;
}
Status CGraphicsPath::AddRoundRectangle(double x, double y, double width, double height, double cx, double cy)
{
m_internal->m_agg_ps.move_to(x + cx, y);
m_internal->m_agg_ps.line_to(x + width - cx, y);
agg::bezier_arc arc1(x + width - cx, y + cy, cx, cy, -agg::pi / 2.0, agg::pi / 2.0);
m_internal->m_agg_ps.join_path(arc1, 0);
m_internal->m_agg_ps.line_to(x + width, y + height - cy);
agg::bezier_arc arc2(x + width - cx, y + height - cy, cx, cy, 0.0, agg::pi / 2.0);
m_internal->m_agg_ps.join_path(arc2, 0);
m_internal->m_agg_ps.line_to(x + cx, y + height);
agg::bezier_arc arc3(x + cx, y + height - cy, cx, cy, agg::pi / 2.0, agg::pi / 2.0);
m_internal->m_agg_ps.join_path(arc3, 0);
m_internal->m_agg_ps.line_to(x, y + cy);
agg::bezier_arc arc4(x + cx, y + cy, cx, cy, agg::pi, agg::pi / 2.0);
m_internal->m_agg_ps.join_path(arc4, 0);
m_internal->m_agg_ps.close_polygon();
return Ok;
}

View File

@ -72,6 +72,7 @@ namespace Aggplus
Status AddCurve(double* pPoints, int nCount);
Status AddEllipse(double x, double y, double width, double height);
Status AddRectangle(double x, double y, double width, double height);
Status AddRoundRectangle(double x, double y, double width, double height, double cx, double cy);
Status AddPolygon(double* pPoints, int nCount);
Status AddPath(const CGraphicsPath& oPath);
Status AddArc(double x, double y, double width, double height, double startAngle, double sweepAngle);

View File

@ -212,6 +212,8 @@ public:
void Offset(const PointF_T<T>& point) { Offset(point.X, point.Y); }
void Offset(T dx, T dy) { X += dx; Y += dy; }
inline bool IsPositive() { return X >= 0 && Y >= 0 && Width > 0 && Height > 0; }
public:
T X, Y, Width, Height;
};

View File

@ -282,8 +282,7 @@ SOURCES += \
$$LIB_GRAPHICS_PRI_PATH/raster/JBig2/source/JBig2File.cpp
SOURCES += \
$$LIB_GRAPHICS_PRI_PATH/raster/PICT/PICFile.cpp \
$$LIB_GRAPHICS_PRI_PATH/raster/PICT/pic.cpp
$$LIB_GRAPHICS_PRI_PATH/raster/PICT/PICFile.cpp
!build_xp {
CONFIG += support_heif

View File

@ -450,15 +450,15 @@ bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileTyp
#if CXIMAGE_SUPPORT_PIC
if (CXIMAGE_FORMAR_PIC == m_nFileType)
{
PICT::CPictFile PIC;
return PIC.Open(this, strFileName, !m_bIsRGBA);
CPictFile pict_file;
return pict_file.Open(this, strFileName, m_bIsRGBA);
}
#endif
#if CXIMAGE_SUPPORT_HEIF
if (CXIMAGE_FORMAT_HEIF == m_nFileType)
{
return NSHeif::CHeifFile::Open(this, strFileName, m_bIsRGBA);
return NSHeif::CHeifFile::Open(this, strFileName, m_bIsRGBA);
}
#endif
@ -540,8 +540,8 @@ bool CBgraFrame::Decode(BYTE* pBuffer, int nSize, unsigned int nFileType)
#if CXIMAGE_SUPPORT_PIC
if (CXIMAGE_FORMAR_PIC == m_nFileType)
{
PICT::CPictFile PIC;
return PIC.Open(this, pBuffer, nSize, !m_bIsRGBA);
CPictFile pict_file;
return pict_file.Open(this, pBuffer, nSize, m_bIsRGBA);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -32,14 +32,204 @@
#ifndef PICFILE_H
#define PICFILE_H
#include "../BgraFrame.h"
#include "../pro/Graphics.h"
namespace PICT {
class GRAPHICS_DECL CPictFile {
public:
bool Open(CBgraFrame* pFrame, const std::wstring& strFileName, bool isRGBA);
bool Open(CBgraFrame* pFrame, BYTE* pBuffer, int nSize, bool isRGBA);
};
}
enum PixelTrait
{
UndefinedPixelTrait = 0x000000,
CopyPixelTrait = 0x000001,
UpdatePixelTrait = 0x000002,
BlendPixelTrait = 0x000004
};
enum ClassType
{
UndefinedClass,
DirectClass,
PseudoClass
};
enum PixelChannel
{
UndefinedPixelChannel = 0,
RedPixelChannel = 0,
CyanPixelChannel = 0,
GrayPixelChannel = 0,
LPixelChannel = 0,
LabelPixelChannel = 0,
YPixelChannel = 0,
aPixelChannel = 1,
GreenPixelChannel = 1,
MagentaPixelChannel = 1,
CbPixelChannel = 1,
bPixelChannel = 2,
BluePixelChannel = 2,
YellowPixelChannel = 2,
CrPixelChannel = 2,
BlackPixelChannel = 3,
AlphaPixelChannel = 4,
IndexPixelChannel = 5,
ReadMaskPixelChannel = 6,
WriteMaskPixelChannel = 7,
MetaPixelChannel = 8, /* deprecated */
CompositeMaskPixelChannel = 9,
MetaPixelChannels = 10,
IntensityPixelChannel = 64, /* ???? */
CompositePixelChannel = 64, /* ???? */
SyncPixelChannel = 65 /* not a real channel */
};
struct PixelChannelMap
{
PixelChannel channel{UndefinedPixelChannel};
PixelTrait traits{UndefinedPixelTrait};
size_t offset{0};
};
struct PixelInfo
{
ClassType storage_class{DirectClass};
PixelTrait alpha_trait{UndefinedPixelTrait};
double red{0.0};
double green{0.0};
double blue{0.0};
double alpha{0.0};
double index{0.0};
};
struct Image
{
ClassType m_eStorageClass{DirectClass};
PixelTrait m_eAlphaTrait{UndefinedPixelTrait};
PixelInfo* m_pColormap{nullptr};
PixelChannelMap* m_pChannelMap{nullptr};
size_t m_nColors{0};
size_t m_nHeight{0};
size_t m_nWidth{0};
BYTE* m_pPixelData{nullptr};
Image()
{
m_pChannelMap = new PixelChannelMap[65];
for (size_t i=0; i <= 64; i++)
m_pChannelMap[i].channel=(PixelChannel) i;
m_pChannelMap[RedPixelChannel].offset = 0;
m_pChannelMap[GreenPixelChannel].offset = 1;
m_pChannelMap[BluePixelChannel].offset = 2;
m_pChannelMap[AlphaPixelChannel].offset = 3;
m_pChannelMap[IndexPixelChannel].offset = 5;
}
Image(const Image& other) : Image()
{
*this = other;
}
~Image()
{
if (m_pChannelMap)
delete[] m_pChannelMap;
if (m_pColormap)
delete[] m_pColormap;
if (m_pPixelData)
delete[] m_pPixelData;
}
Image& operator=(const Image& other)
{
if (this == &other)
return *this;
m_eStorageClass = other.m_eStorageClass;
m_eAlphaTrait = other.m_eAlphaTrait;
m_nColors = other.m_nColors;
m_nWidth = other.m_nWidth;
m_nHeight = other.m_nHeight;
if (other.m_pColormap)
{
m_pColormap = new PixelInfo[m_nColors + 1];
memcpy(m_pColormap, other.m_pColormap, m_nColors + 1);
}
memcpy(m_pChannelMap, other.m_pChannelMap, 65);
return *this;
}
};
class CPictFile
{
public:
CPictFile();
~CPictFile();
bool Open(CBgraFrame* frame, const std::wstring& fileName, bool isRGB);
bool Open(CBgraFrame* frame, BYTE* buffer, const size_t& size, bool isRGB);
private:
bool Decode();
bool DecodeHeader();
bool DecodeData();
size_t GetFileSize() const;
size_t Read(const size_t& length, void* data);
const void* ReadBlobStream(const size_t& length, void* data, size_t* count);
unsigned short ReadShortValue();
signed short ReadSignedShortValue();
unsigned int ReadLongValue();
bool ReadRectangle(Aggplus::Rect* rect);
void SetImageAlpha(Image* img, const BYTE alpha);
BYTE* DecodeImage(const Image& img, size_t bytesPerLine, size_t bitsPerPixel, size_t* extent);
const BYTE* UnpackScanline(const BYTE* pixels, const size_t& bitsPerPixel, BYTE* scanline, size_t* bytesPerLine);
void ReadPolygon();
Aggplus::Rect ContractRect(const Aggplus::Rect& rect, bool isFrame);
void DrawPolygon(bool isFrame);
void DrawLine(const Aggplus::Point& p1, const Aggplus::Point& p2);
void DrawRect(bool isFrame);
void DrawRoundRect(bool isFrame);
void DrawOval(bool isFrame);
void DrawArc();
void ReadAndDrawText(int x, int y);
void InitializeRenderer();
private:
int m_nVersion{0};
FILE* m_pFile{nullptr};
Image m_oImgData{};
CBgraFrame m_oFrame{};
BYTE* m_pFrameData{nullptr};
size_t m_nPenHeight{0};
size_t m_nPenWidth{0};
int m_nFontStyle{0};
int m_nFontSize{0};
std::wstring m_wsFontName{};
Aggplus::Point m_oPenPoint{};
Aggplus::Point m_oTextPoint{};
Aggplus::Rect m_oLastRect{};
Aggplus::Rect m_oLastRoundRect{};
Aggplus::Rect m_oLastOval{};
Aggplus::Rect m_oLastArc{};
std::vector<Aggplus::Point> m_arLastPolygon{};
NSGraphics::IGraphicsRenderer* m_pRenderer{nullptr};
NSFonts::IFontManager* m_pFontManager{nullptr};
};
#endif // PICFILE_H

File diff suppressed because it is too large Load Diff

View File

@ -1,391 +0,0 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef PIC_H
#define PIC_H
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cstddef>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <limits.h>
#include <sys/stat.h>
#include <stdarg.h>
typedef enum
{
UndefinedType,
BilevelType,
GrayscaleType,
GrayscaleAlphaType,
PaletteType,
PaletteAlphaType,
TrueColorType,
TrueColorAlphaType,
ColorSeparationType,
ColorSeparationAlphaType,
OptimizeType,
PaletteBilevelAlphaType
} ImageType;
typedef struct
{
char* path;
unsigned char* datum;
size_t length;
size_t signature;
char* name;
} StringInfo;
typedef struct _NodeInfo
{
void* key;
void* value;
struct _NodeInfo* left;
struct _NodeInfo* right;
} NodeInfo;
typedef struct
{
NodeInfo* root;
int (*compare)(const void*, const void*);
int balance;
void* key;
void* next;
size_t nodes;
size_t signature;
} SplayTreeInfo;
typedef struct _PrimaryInfo
{
double x;
double y;
double z;
} PrimaryInfo;
typedef struct _ChromaticityInfo
{
PrimaryInfo red_primary;
PrimaryInfo green_primary;
PrimaryInfo blue_primary;
PrimaryInfo white_point;
} ChromaticityInfo;
typedef struct _PICTCode
{
const char* name;
long long length;
const char* description;
} PICTCode;
typedef struct
{
short top;
short left;
short bottom;
short right;
} PICTrectangle;
typedef struct
{
short version;
short pack_type;
size_t pack_size;
size_t horizontal_resolution;
size_t vertical_resolution;
short pixel_type;
short bits_per_pixel;
short component_count;
short component_size;
size_t plane_bytes;
size_t table;
size_t reserved;
} PICTPixmap;
typedef struct
{
size_t width;
size_t height;
long long x;
long long y;
} RectangleInfo;
typedef struct _NexusInfo
{
RectangleInfo region;
size_t length;
unsigned char* pixels;
int authentic_pixel_cache;
size_t signature;
struct _NexusInfo* virtual_nexus;
} NexusInfo;
typedef struct _GeometryInfo
{
double rho;
double sigma;
double xi;
double psi;
double chi;
} GeometryInfo;
typedef enum
{
UndefinedChannel = 0x0000,
RedChannel = 0x0001,
GrayChannel = 0x0001,
CyanChannel = 0x0001,
LChannel = 0x0001,
GreenChannel = 0x0002,
MagentaChannel = 0x0002,
aChannel = 0x0002,
BlueChannel = 0x0004,
bChannel = 0x0002,
YellowChannel = 0x0004,
BlackChannel = 0x0008,
AlphaChannel = 0x0010,
OpacityChannel = 0x0010,
IndexChannel = 0x0020, /* Color Index Table? */
ReadMaskChannel = 0x0040, /* Pixel is Not Readable? */
WriteMaskChannel = 0x0080, /* Pixel is Write Protected? */
MetaChannel = 0x0100, /* not used */
CompositeMaskChannel = 0x0200, /* SVG mask */
CompositeChannels = 0x001F,
AllChannels = 0X7FFFFFF,
/*
Special purpose channel types.
FUTURE: are these needed any more - they are more like hacks
SyncChannels for example is NOT a real channel but a 'flag'
It really says -- "User has not defined channels"
Though it does have extra meaning in the "-auto-level" operator
*/
TrueAlphaChannel = 0x0100, /* extract actual alpha channel from opacity */
RGBChannels = 0x0200, /* set alpha from grayscale mask in RGB */
GrayChannels = 0x0400,
SyncChannels = 0x20000, /* channels modified as a single unit */
DefaultChannels = AllChannels
} ChannelType;
typedef enum
{
ReadMode,
WriteMode,
IOMode,
PersistMode
} MapMode;
typedef enum
{
UndefinedClass,
DirectClass,
PseudoClass
} ClassType;
typedef enum
{
UndefinedColorspace,
CMYColorspace, /* negated linear RGB colorspace */
CMYKColorspace, /* CMY with Black separation */
GRAYColorspace, /* Single Channel greyscale (non-linear) image */
HCLColorspace,
HCLpColorspace,
HSBColorspace,
HSIColorspace,
HSLColorspace,
HSVColorspace, /* alias for HSB */
HWBColorspace,
LabColorspace,
LCHColorspace, /* alias for LCHuv */
LCHabColorspace, /* Cylindrical (Polar) Lab */
LCHuvColorspace, /* Cylindrical (Polar) Luv */
LogColorspace,
LMSColorspace,
LuvColorspace,
OHTAColorspace,
Rec601YCbCrColorspace,
Rec709YCbCrColorspace,
RGBColorspace, /* Linear RGB colorspace */
scRGBColorspace, /* ??? */
sRGBColorspace, /* Default: non-linear sRGB colorspace */
TransparentColorspace,
xyYColorspace,
XYZColorspace, /* IEEE Color Reference colorspace */
YCbCrColorspace,
YCCColorspace,
YDbDrColorspace,
YIQColorspace,
YPbPrColorspace,
YUVColorspace,
LinearGRAYColorspace, /* Single Channel greyscale (linear) image */
JzazbzColorspace,
DisplayP3Colorspace,
Adobe98Colorspace,
ProPhotoColorspace,
OklabColorspace,
OklchColorspace
} ColorspaceType;
typedef enum
{
UndefinedPixelTrait = 0x000000,
CopyPixelTrait = 0x000001,
UpdatePixelTrait = 0x000002,
BlendPixelTrait = 0x000004
} PixelTrait;
typedef enum
{
UndefinedPixelChannel = 0,
RedPixelChannel = 0,
CyanPixelChannel = 0,
GrayPixelChannel = 0,
LPixelChannel = 0,
LabelPixelChannel = 0,
YPixelChannel = 0,
aPixelChannel = 1,
GreenPixelChannel = 1,
MagentaPixelChannel = 1,
CbPixelChannel = 1,
bPixelChannel = 2,
BluePixelChannel = 2,
YellowPixelChannel = 2,
CrPixelChannel = 2,
BlackPixelChannel = 3,
AlphaPixelChannel = 4,
IndexPixelChannel = 5,
ReadMaskPixelChannel = 6,
WriteMaskPixelChannel = 7,
MetaPixelChannel = 8, /* deprecated */
CompositeMaskPixelChannel = 9,
MetaPixelChannels = 10,
IntensityPixelChannel = 64, /* ???? */
CompositePixelChannel = 64, /* ???? */
SyncPixelChannel = 65 /* not a real channel */
} PixelChannel;
typedef struct
{
PixelChannel channel;
PixelTrait traits;
long long offset;
} PixelChannelMap;
typedef struct
{
ClassType storage_class;
ColorspaceType colorspace;
PixelTrait alpha_trait;
double fuzz;
size_t depth;
size_t count;
double red;
double green;
double blue;
double black;
double alpha;
double index;
} PixelInfo;
typedef struct
{
ClassType storage_class;
ColorspaceType colorspace;
ChromaticityInfo chromaticity;
int m_pctVersion;
size_t m_nHeight;
size_t m_nWidth;
size_t m_ndepth;
size_t m_nPixelsSize;
size_t colors;
SplayTreeInfo* profiles;
SplayTreeInfo* artifacts;
double fuzz;
unsigned char* ppixels;
double resolutionX;
double resolutionY;
double gamma;
ImageType type;
PixelInfo background_color;
PixelInfo* colormap;
PixelTrait alpha_trait;
PixelChannelMap* channel_map;
PixelTrait mask_trait;
int taint;
void* cache;
size_t number_channels;
char error[256];
}ImagePICT;
int DecodePICT(FILE* hFile, ImagePICT* image);
void AquireImage(ImagePICT* image);
ImagePICT* DestroyImage(ImagePICT* image);
#endif // PIC_H