Skip to content

Commit

Permalink
Codable enum cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Nov 17, 2024
1 parent 9492065 commit 940d8a8
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 167 deletions.
89 changes: 0 additions & 89 deletions lib/PwgPgHdr.codable

This file was deleted.

55 changes: 0 additions & 55 deletions lib/UrfPgHdr.codable

This file was deleted.

46 changes: 28 additions & 18 deletions lib/ppm2pwg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "array.h"
#include "log.h"

#include "PwgPgHdr.h"
#include "UrfPgHdr.h"
#include "pwgpghdr.h"
#include "urfpghdr.h"

#include <iostream>
#include <map>
Expand Down Expand Up @@ -65,7 +65,7 @@ void bmp_to_pwg(Bytestream& bmpBts, Bytestream& outBts, size_t page, const Print
}

outBts << lineRepeat;
if(backside&&params.getBackHFlip())
if(backside && params.getBackHFlip())
{
// Flip line into tmp buffer
if(params.getBitsPerColor() == 1)
Expand Down Expand Up @@ -162,7 +162,7 @@ void compress_line(uint8_t* raw, size_t len, Bytestream& outBts, int colors)
}
}

static std::map<std::string, UrfPgHdr::MediaType_enum>
static const std::map<std::string, UrfPgHdr::MediaType_enum>
UrfMediaTypeMappings {{"auto", UrfPgHdr::AutomaticMediaType},
{"stationery", UrfPgHdr::Stationery},
{"transparency", UrfPgHdr::Transparency},
Expand All @@ -187,6 +187,14 @@ void make_pwg_hdr(Bytestream& outBts, const PrintParameters& params, bool backsi
{
PwgPgHdr outHdr;

static const std::map<PrintParameters::ColorMode, PwgPgHdr::ColorSpace_enum>
pwgColorSpaceMappings {{PrintParameters::sRGB24, PwgPgHdr::sRGB},
{PrintParameters::CMYK32, PwgPgHdr::CMYK},
{PrintParameters::Gray8, PwgPgHdr::sGray},
{PrintParameters::Black8, PwgPgHdr::Black},
{PrintParameters::Gray1, PwgPgHdr::sGray},
{PrintParameters::Black1, PwgPgHdr::Black}};

outHdr.MediaType = params.mediaType;
outHdr.Duplex = params.isTwoSided();
outHdr.HWResolutionX = params.hwResW;
Expand All @@ -201,14 +209,11 @@ void make_pwg_hdr(Bytestream& outBts, const PrintParameters& params, bool backsi
outHdr.BitsPerColor = params.getBitsPerColor();
outHdr.BitsPerPixel = params.getNumberOfColors() * outHdr.BitsPerColor;
outHdr.BytesPerLine = params.getPaperSizeWInBytes();
outHdr.ColorSpace = params.colorMode == PrintParameters::CMYK32 ? PwgPgHdr::CMYK
: params.colorMode == PrintParameters::sRGB24 ? PwgPgHdr::sRGB
: params.isBlack() ? PwgPgHdr::Black
: PwgPgHdr::sGray;
outHdr.ColorSpace = pwgColorSpaceMappings.at(params.colorMode);
outHdr.NumColors = params.getNumberOfColors();
outHdr.TotalPageCount = 0;
outHdr.CrossFeedTransform = backside&&params.getBackHFlip() ? -1 : 1;
outHdr.FeedTransform = backside&&params.getBackVFlip() ? -1 : 1;
outHdr.CrossFeedTransform = backside && params.getBackHFlip() ? -1 : 1;
outHdr.FeedTransform = backside && params.getBackVFlip() ? -1 : 1;
outHdr.AlternatePrimary = 0x00ffffff;
outHdr.setPrintQuality(params.quality);
outHdr.PageSizeName = params.paperSizeName;
Expand All @@ -222,19 +227,24 @@ void make_urf_hdr(Bytestream& outBts, const PrintParameters& params)
{
if(params.hwResW != params.hwResH)
{
exit(2);
throw std::logic_error("Asymmetric URF resolution");
}

UrfPgHdr outHdr;

static const std::map<PrintParameters::ColorMode, UrfPgHdr::ColorSpace_enum>
urfColorSpaceMappings {{PrintParameters::sRGB24, UrfPgHdr::sRGB},
{PrintParameters::CMYK32, UrfPgHdr::CMYK},
{PrintParameters::Gray8, UrfPgHdr::sGray}};

static const std::map<PrintParameters::DuplexMode, UrfPgHdr::Duplex_enum>
urfDuplexMappings {{PrintParameters::OneSided, UrfPgHdr::OneSided},
{PrintParameters::TwoSidedLongEdge, UrfPgHdr::TwoSidedLongEdge},
{PrintParameters::TwoSidedShortEdge, UrfPgHdr::TwoSidedShortEdge}};

outHdr.BitsPerPixel = 8*params.getNumberOfColors();
outHdr.ColorSpace = params.colorMode == PrintParameters::CMYK32 ? UrfPgHdr::CMYK
: params.colorMode == PrintParameters::sRGB24 ? UrfPgHdr::sRGB
: UrfPgHdr::sGray;
outHdr.Duplex = params.isTwoSided() ? (params.duplexMode == PrintParameters::TwoSidedShortEdge
? UrfPgHdr::ShortSide
: UrfPgHdr::LongSide)
: UrfPgHdr::NoDuplex;
outHdr.ColorSpace = urfColorSpaceMappings.at(params.colorMode);
outHdr.Duplex = urfDuplexMappings.at(params.duplexMode);
outHdr.setQuality(params.quality);
outHdr.MediaType = params.mediaType == "" ? UrfPgHdr::AutomaticMediaType
: UrfMediaTypeMappings.at(params.mediaType);
Expand Down
121 changes: 121 additions & 0 deletions lib/pwgpghdr.codable
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
CODABLE(PwgPgHdr)
DEFAULT_STRING(64, PwgRaster, "PwgRaster")
STRING(64, MediaColor)
STRING(64, MediaType)
STRING(64, PrintContentOptimize)
PADDING(12)
ENUM(uint32_t, CutMedia, ENUM_VALUE(CutNever, 0),
ENUM_LABEL(CutAfterDocument),
ENUM_LABEL(CutAfterJob),
ENUM_LABEL(CutAfterSet),
ENUM_LABEL(CutAfterPage))
FIELD(uint32_t, Duplex)
FIELD(uint32_t, HWResolutionX)
FIELD(uint32_t, HWResolutionY)
PADDING(16)
FIELD(uint32_t, InsertSheet)
ENUM(uint32_t, Jog, ENUM_VALUE(JogNever, 0),
ENUM_LABEL(JogAfterDocument),
ENUM_LABEL(JogAfterJob),
ENUM_LABEL(JogAfterSet),
ENUM_LABEL(JogAfterPage))
ENUM(uint32_t, LeadingEdge, ENUM_VALUE(ShortEdgeFirst, 0),
ENUM_LABEL(LongEdgeFirst))
PADDING(12)
ENUM(uint32_t, MediaPosition, ENUM_VALUE(AutomaticMediaPosition, 0),
ENUM_LABEL(Main),
ENUM_LABEL(Alternate),
ENUM_LABEL(LargeCapacity),
ENUM_LABEL(Manual),
ENUM_LABEL(EnvelopeMediaPosition),
ENUM_LABEL(DiscMediaPosition),
ENUM_LABEL(PhotoMediaPosition),
ENUM_LABEL(Hagaki),
ENUM_LABEL(MainRoll),
ENUM_LABEL(AlternateRoll),
ENUM_LABEL(Top),
ENUM_LABEL(Middle),
ENUM_LABEL(Bottom),
ENUM_LABEL(Side),
ENUM_LABEL(Left),
ENUM_LABEL(Right),
ENUM_LABEL(Center),
ENUM_LABEL(Rear),
ENUM_LABEL(ByPassTray),
ENUM_LABEL(Tray1),
ENUM_LABEL(Tray2),
ENUM_LABEL(Tray3),
ENUM_LABEL(Tray4),
ENUM_LABEL(Tray5),
ENUM_LABEL(Tray6),
ENUM_LABEL(Tray7),
ENUM_LABEL(Tray8),
ENUM_LABEL(Tray9),
ENUM_LABEL(Tray10),
ENUM_LABEL(Tray11),
ENUM_LABEL(Tray12),
ENUM_LABEL(Tray13),
ENUM_LABEL(Tray14),
ENUM_LABEL(Tray15),
ENUM_LABEL(Tray16),
ENUM_LABEL(Tray17),
ENUM_LABEL(Tray18),
ENUM_LABEL(Tray19),
ENUM_LABEL(Tray20),
ENUM_LABEL(Roll1),
ENUM_LABEL(Roll2),
ENUM_LABEL(Roll3),
ENUM_LABEL(Roll4),
ENUM_LABEL(Roll5),
ENUM_LABEL(Roll6),
ENUM_LABEL(Roll7),
ENUM_LABEL(Roll8),
ENUM_LABEL(Roll9),
ENUM_LABEL(Roll10))
FIELD(uint32_t, MediaWeightMetric)
PADDING(8)
FIELD(uint32_t, NumCopies)
ENUM(uint32_t, Orientation, ENUM_VALUE(Portrait, 0),
ENUM_LABEL(Landscape),
ENUM_LABEL(ReversePortrait),
ENUM_LABEL(ReverseLandscape))
PADDING(4)
FIELD(uint32_t, PageSizeX)
FIELD(uint32_t, PageSizeY)
PADDING(8)
FIELD(uint32_t, Tumble)
FIELD(uint32_t, Width)
FIELD(uint32_t, Height)
PADDING(4)
FIELD(uint32_t, BitsPerColor)
FIELD(uint32_t, BitsPerPixel)
FIELD(uint32_t, BytesPerLine)
ENUM(uint32_t, ColorOrder, ENUM_VALUE(Chunky, 0))
ENUM(uint32_t, ColorSpace, ENUM_VALUE(RGB, 1),
ENUM_VALUE(Black, 3),
ENUM_VALUE(CMYK, 6),
ENUM_VALUE(sGray, 18),
ENUM_VALUE(sRGB, 19),
ENUM_VALUE(AdobeRGB, 20))
PADDING(16)
FIELD(uint32_t, NumColors)
PADDING(28)
FIELD(uint32_t, TotalPageCount)
FIELD(int32_t, CrossFeedTransform)
FIELD(int32_t, FeedTransform)
FIELD(uint32_t, ImageBoxLeft)
FIELD(uint32_t, ImageBoxTop)
FIELD(uint32_t, ImageBoxRight)
FIELD(uint32_t, ImageBoxBottom)
FIELD(uint32_t, AlternatePrimary)
ENUM(uint32_t, PrintQuality, ENUM_VALUE(DefaultPrintQuality, 0),
ENUM_VALUE(Draft, 3),
ENUM_VALUE(Normal, 4),
ENUM_VALUE(High, 5))
PADDING(20)
FIELD(uint32_t, VendorIdentifier)
FIELD(uint32_t, VendorLength)
PADDING(1088)
PADDING(64)
STRING(64, RenderingIntent)
STRING(64, PageSizeName)
2 changes: 1 addition & 1 deletion lib/PwgPgHdr.h → lib/pwgpghdr.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PWGPGHDR_H
#define PWGPGHDR_H

#define CODABLE_FILE "PwgPgHdr.codable"
#define CODABLE_FILE "pwgpghdr.codable"
#include "codable.h"

#endif
Loading

0 comments on commit 940d8a8

Please sign in to comment.