Skip to content
Draft
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
64 changes: 43 additions & 21 deletions RdlCri/BarCodeEAN13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,55 +127,77 @@ internal void DrawImage(Draw2.Bitmap bm, string upcode)
{
string barPattern = this.GetEncoding(upcode);
using Draw2.Graphics g = Draw2.Graphics.FromImage(bm);

// Set graphics quality for crisp bars
g.InterpolationMode = Draw2.Drawing2D.InterpolationMode.NearestNeighbor;
g.SmoothingMode = Draw2.Drawing2D.SmoothingMode.None;
g.PixelOffsetMode = Draw2.Drawing2D.PixelOffsetMode.Half;

float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

float barWidth = ModuleWidth * mag;
float barHeight = OptimalHeight * mag;
float fontHeight = FontHeight * mag;
float fontHeightMM = fontHeight / 72.27f * 25.4f;

g.PageUnit = Draw2.GraphicsUnit.Millimeter;

// Convert to pixel units for crisp rendering
g.PageUnit = Draw2.GraphicsUnit.Pixel;

// Calculate dimensions in pixels (not millimeters) for sharp rendering
float barWidthMM = ModuleWidth * mag;
float barHeightMM = OptimalHeight * mag;
float fontHeightMM = FontHeight * mag;

// Convert MM to pixels for precise rendering
float barWidthPixels = PixelConversions.PixelXFromMm(g, barWidthMM);
float barHeightPixels = PixelConversions.PixelYFromMm(g, barHeightMM);
float fontHeightPixels = PixelConversions.PixelYFromMm(g, fontHeightMM);

// Ensure minimum readable font size (at least 8 pixels)
fontHeightPixels = Math.Max(fontHeightPixels, 8.0f);

// Fill in the background with white
g.FillRectangle(Draw2.Brushes.White, 0, 0, bm.Width, bm.Height);

// Draw the bars
// Draw the bars - round positions to whole pixels for crisp edges
int barCount = LeftQuietZoneModules;
foreach (char bar in barPattern)
{
if (bar == '1')
{
float barHeightForDigits = barHeightPixels - fontHeightPixels;
float bh = ((barCount > ModulesToManufacturingStart && barCount < ModulesToManufacturingEnd) ||
(barCount > ModulesToProductStart && barCount < ModulesToProductEnd))
? barHeight - fontHeightMM
: barHeight;

g.FillRectangle(Draw2.Brushes.Black, barWidth * barCount, 0, barWidth, bh);
? barHeightForDigits
: barHeightPixels;

// Round to whole pixels for crisp bars
float x = (float)Math.Round(barWidthPixels * barCount);
float width = (float)Math.Round(barWidthPixels);

g.FillRectangle(Draw2.Brushes.Black, x, 0, width, bh);
}

barCount++;
}

// Draw the human readable portion of the barcode
using var f = new Draw2.Font("Arial", fontHeight);
// Draw the human readable portion of the barcode with anti-aliasing for text
g.TextRenderingHint = Draw2.Text.TextRenderingHint.AntiAlias;
using var f = new Draw2.Font("Arial", fontHeightPixels);

// Draw the left guard text (i.e. 2nd digit of the NumberSystem)
// Draw the left guard text (i.e. 1st digit of the NumberSystem)
string wc = upcode.Substring(0, 1);
float textY = barHeightPixels - fontHeightPixels;
g.DrawString(wc, f, Draw2.Brushes.Black,
new Draw2.PointF(barWidth * LeftQuietZoneModules - g.MeasureString(wc, f).Width,
barHeight - fontHeightMM));
new Draw2.PointF((float)Math.Round(barWidthPixels * LeftQuietZoneModules - g.MeasureString(wc, f).Width),
textY));

// Draw the manufacturing digits
wc = upcode.Substring(1, 6);
g.DrawString(wc, f, Draw2.Brushes.Black,
new Draw2.PointF(barWidth * ModulesToManufacturingEnd - g.MeasureString(wc, f).Width,
barHeight - fontHeightMM));
new Draw2.PointF((float)Math.Round(barWidthPixels * ModulesToManufacturingEnd - g.MeasureString(wc, f).Width),
textY));

// Draw the product code + the checksum digit
wc = upcode.Substring(7, 5) + CheckSum(upcode).ToString();
g.DrawString(wc, f, Draw2.Brushes.Black,
new Draw2.PointF(barWidth * ModulesToProductEnd - g.MeasureString(wc, f).Width,
barHeight - fontHeightMM));
new Draw2.PointF((float)Math.Round(barWidthPixels * ModulesToProductEnd - g.MeasureString(wc, f).Width),
textY));
}

/// <summary>
Expand Down
148 changes: 148 additions & 0 deletions ReportTests/BarCodeEAN13Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Majorsilence.Reporting.Cri;
using Majorsilence.Reporting.Rdl;
using NUnit.Framework;
using ReportTests.Utils;
using ZXing;
#if DRAWINGCOMPAT
using Majorsilence.Drawing;
using ZXing.SkiaSharp;
#else
using System.Drawing;
using ZXing.Windows.Compatibility;
#endif

namespace ReportTests
{
[TestFixture]
public class BarCodeEAN13Tests
{
private Uri _outputFolder = null;

[SetUp]
public void Prepare2Tests()
{
if (_outputFolder == null)
{
_outputFolder = GeneralUtils.OutputTestsFolder();
}

Directory.CreateDirectory(_outputFolder.LocalPath);

RdlEngineConfig.RdlEngineConfigInit();
}

[Test]
public void TestEAN13BarcodeGeneration()
{
// Create a barcode instance
var barcode = new BarCodeEAN13();

// Set properties
var props = new System.Collections.Generic.Dictionary<string, object>
{
{ "NumberSystem", "00" },
{ "ManufacturerCode", "12345" },
{ "ProductCode", "67890" }
};

barcode.SetProperties(props);

// Create bitmap (typical size for barcodes)
int width = 300;
int height = 200;
var bm = new Bitmap(width, height);

// Draw the barcode
barcode.DrawImage(ref bm);

// Save to file for visual inspection
string outputPath = Path.Combine(_outputFolder.LocalPath, "ean13_test.png");
bm.Save(outputPath, System.Drawing.Imaging.ImageFormat.Png);

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

Argument 2: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'Majorsilence.Drawing.Imaging.ImageFormat'

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

Argument 1: cannot convert from 'string' to 'System.IO.Stream'

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 63 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

// Try to decode the barcode using ZXing
var reader = new BarcodeReader();

Check failure on line 66 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'BarcodeReader' is an ambiguous reference between 'ZXing.Windows.Compatibility.BarcodeReader' and 'ZXing.BarcodeReader'

Check failure on line 66 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'BarcodeReader' is an ambiguous reference between 'ZXing.Windows.Compatibility.BarcodeReader' and 'ZXing.BarcodeReader'

Check failure on line 66 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

'BarcodeReader' is an ambiguous reference between 'ZXing.SkiaSharp.BarcodeReader' and 'ZXing.BarcodeReader'
var result = reader.Decode(bm);

Check failure on line 67 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The type 'BitmapSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Check failure on line 67 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The type 'BitmapSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Check failure on line 67 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type 'BitmapSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

// Assert that the barcode can be decoded
Assert.That(result, Is.Not.Null, "Barcode could not be decoded");
Assert.That(result.BarcodeFormat, Is.EqualTo(BarcodeFormat.EAN_13), "Wrong barcode format");

// The expected value is NumberSystem + ManufacturerCode + ProductCode + CheckDigit
// For "00" + "12345" + "67890", the check digit should be calculated
string expectedPrefix = "001234567890";
Assert.That(result.Text, Does.StartWith(expectedPrefix),
$"Barcode text '{result.Text}' does not start with expected prefix '{expectedPrefix}'");

Console.WriteLine($"Successfully decoded EAN-13 barcode: {result.Text}");

bm.Dispose();
}

[Test]
public void TestEAN13BarcodeWithDifferentSizes()
{
var barcode = new BarCodeEAN13();

var props = new System.Collections.Generic.Dictionary<string, object>
{
{ "NumberSystem", "50" },
{ "ManufacturerCode", "11111" },
{ "ProductCode", "22222" }
};

barcode.SetProperties(props);

// Test with different sizes
int[] widths = { 200, 300, 400 };
int[] heights = { 150, 200, 250 };

for (int i = 0; i < widths.Length; i++)
{
var bm = new Bitmap(widths[i], heights[i]);
barcode.DrawImage(ref bm);

string outputPath = Path.Combine(_outputFolder.LocalPath, $"ean13_test_{widths[i]}x{heights[i]}.png");
bm.Save(outputPath, System.Drawing.Imaging.ImageFormat.Png);

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 108 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

// Try to decode
var reader = new BarcodeReader();

Check failure on line 111 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'BarcodeReader' is an ambiguous reference between 'ZXing.Windows.Compatibility.BarcodeReader' and 'ZXing.BarcodeReader'

Check failure on line 111 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'BarcodeReader' is an ambiguous reference between 'ZXing.Windows.Compatibility.BarcodeReader' and 'ZXing.BarcodeReader'
var result = reader.Decode(bm);

Check failure on line 112 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The type 'BitmapSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Check failure on line 112 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The type 'BitmapSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Assert.That(result, Is.Not.Null,
$"Barcode at size {widths[i]}x{heights[i]} could not be decoded");
Assert.That(result.BarcodeFormat, Is.EqualTo(BarcodeFormat.EAN_13));

Console.WriteLine($"Size {widths[i]}x{heights[i]}: Successfully decoded EAN-13 barcode: {result.Text}");

bm.Dispose();
}
}

[Test]
public void TestEAN13DesignerImage()
{
var barcode = new BarCodeEAN13();

// Test the designer image (used at design time)
var bm = new Bitmap(300, 200);
barcode.DrawDesignerImage(ref bm);

string outputPath = Path.Combine(_outputFolder.LocalPath, "ean13_designer_test.png");
bm.Save(outputPath, System.Drawing.Imaging.ImageFormat.Png);

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / linux-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / windows-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

Check failure on line 134 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / mac-build

The type name 'ImageFormat' could not be found in the namespace 'System.Drawing.Imaging'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.

// Try to decode the designer barcode
var reader = new BarcodeReader();

Check failure on line 137 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'BarcodeReader' is an ambiguous reference between 'ZXing.Windows.Compatibility.BarcodeReader' and 'ZXing.BarcodeReader'
var result = reader.Decode(bm);

Check failure on line 138 in ReportTests/BarCodeEAN13Tests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The type 'BitmapSource' is defined in an assembly that is not referenced. You must add a reference to assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Assert.That(result, Is.Not.Null, "Designer barcode could not be decoded");
Assert.That(result.BarcodeFormat, Is.EqualTo(BarcodeFormat.EAN_13));

Console.WriteLine($"Successfully decoded designer EAN-13 barcode: {result.Text}");

bm.Dispose();
}
}
}
Loading