Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
tga.cpp File Reference
#include "tga.h"
#include "../../opengl2/glext.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+ Include dependency graph for tga.cpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RLEstate
 

Macros

#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define RLE_PACKETSIZE   0x80
 

Functions

static IGL_INLINE int std_fread (RLEstate *, unsigned char *buf, size_t datasize, size_t nelems, FILE *fp)
 
static IGL_INLINE int rle_fread (RLEstate *rleInfo, unsigned char *vbuf, size_t datasize, size_t nelems, FILE *fp)
 
IGL_INLINE void write16bit (int n, FILE *fp)
 

Variables

static char error [256]
 
static unsigned int _verbose = 0
 
static int totbytes = 0
 
unsigned char TGAHeaderColor [12]
 
unsigned char TGAHeaderBW [12]
 

Class Documentation

◆ RLEstate

struct RLEstate
Class Members
int laststate
unsigned char * statebuf
int statelen

Macro Definition Documentation

◆ MIN

#define MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

◆ RLE_PACKETSIZE

#define RLE_PACKETSIZE   0x80

Function Documentation

◆ rle_fread()

static IGL_INLINE int rle_fread ( RLEstate rleInfo,
unsigned char *  vbuf,
size_t  datasize,
size_t  nelems,
FILE *  fp 
)
static
78{
79
80 unsigned char *buf = vbuf;
81 int j, k;
82 int buflen, count, bytes, curbytes;
83 unsigned char *p;
84
85 /* Scale the buffer length. */
86 buflen = nelems * datasize;
87
88 j = 0;
89 curbytes = totbytes;
90 while (j < buflen) {
91 if (rleInfo->laststate < rleInfo->statelen) {
92 /* Copy bytes from our previously decoded buffer. */
93 bytes = MIN(buflen - j, rleInfo->statelen - rleInfo->laststate);
94 memcpy(buf + j, rleInfo->statebuf + rleInfo->laststate, bytes);
95 j += bytes;
96 rleInfo->laststate += bytes;
97
98 /* If we used up all of our state bytes, then reset them. */
99 if (rleInfo->laststate >= rleInfo->statelen) {
100 rleInfo->laststate = 0;
101 rleInfo->statelen = 0;
102 }
103
104 /* If we filled the buffer, then exit the loop. */
105 if (j >= buflen) break;
106 }
107
108 /* Decode the next packet. */
109 count = fgetc(fp);
110 if (count == EOF) {
111 if (_verbose) printf("TGA: hit EOF while looking for count\n");
112 return j / datasize;
113 }
114
115 /* Scale the byte length to the size of the data. */
116 bytes = ((count & ~RLE_PACKETSIZE) + 1) * datasize;
117
118 if (j + bytes <= buflen) {
119 /* We can copy directly into the image buffer. */
120 p = buf + j;
121 } else {
122#ifdef PROFILE
123 printf("TGA: needed to use statebuf for %d bytes\n", buflen - j);
124#endif
125 /* Allocate the state buffer if we haven't already. */
126 if (!rleInfo->statebuf) {
127 rleInfo->statebuf = (unsigned char *) malloc(RLE_PACKETSIZE * datasize);
128 }
129 p = rleInfo->statebuf;
130 }
131
132 if (count & RLE_PACKETSIZE) {
133 /* Fill the buffer with the next value. */
134 if (fread(p, datasize, 1, fp) != 1) {
135 if (_verbose) {
136 printf("TGA: EOF while reading %d/%d element RLE packet\n",
137 bytes, (int)datasize);
138 }
139 return j / datasize;
140 }
141
142 /* Optimized case for single-byte encoded data. */
143 if (datasize == 1) {
144 memset(p + 1, *p, bytes - 1);
145 } else {
146 for (k = datasize; k < bytes; k += datasize) {
147 memcpy(p + k, p, datasize);
148 }
149 }
150 } else {
151 /* Read in the buffer. */
152 if (fread(p, bytes, 1, fp) != 1) {
153 if (_verbose) {
154 printf("TGA: EOF while reading %d/%d element raw packet\n",
155 bytes, (int)datasize);
156 }
157 return j / datasize;
158 }
159 }
160
161 if (_verbose > 1) {
162 totbytes += bytes;
163 if (_verbose > 2) {
164 printf("TGA: %s packet %d/%d\n",
165 (count & RLE_PACKETSIZE) ? "RLE" : "raw",
166 bytes, totbytes);
167 }
168 }
169
170 /* We may need to copy bytes from the state buffer. */
171 if (p == rleInfo->statebuf) {
172 rleInfo->statelen = bytes;
173 } else {
174 j += bytes;
175 }
176 }
177
178 if (_verbose > 1) {
179 printf("TGA: rle_fread %d/%d (total %d)\n",
180 (int) ( nelems * datasize), totbytes - curbytes, totbytes);
181 }
182 return nelems;
183}
void * malloc(YYSIZE_T)
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12
#define MIN(a, b)
Definition tga.cpp:71
#define RLE_PACKETSIZE
Definition tga.cpp:73
static unsigned int _verbose
Definition tga.cpp:51
int statelen
Definition tga.cpp:56
int laststate
Definition tga.cpp:57
static int totbytes
Definition tga.cpp:52
unsigned char * statebuf
Definition tga.cpp:55

References _verbose, RLEstate::laststate, malloc(), MIN, RLE_PACKETSIZE, RLEstate::statebuf, RLEstate::statelen, and totbytes.

Referenced by igl::opengl::gliReadTGA().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ std_fread()

static IGL_INLINE int std_fread ( RLEstate ,
unsigned char *  buf,
size_t  datasize,
size_t  nelems,
FILE *  fp 
)
static
62{
63 if (_verbose > 1) {
64 totbytes += nelems * datasize;
65 printf("TGA: std_fread %d (total %d)\n",
66 (int)(nelems * datasize), totbytes);
67 }
68 return fread(buf, datasize, nelems, fp);
69}

References _verbose, and totbytes.

Referenced by igl::opengl::gliReadTGA().

+ Here is the caller graph for this function:

◆ write16bit()

IGL_INLINE void write16bit ( int  n,
FILE *  fp 
)
508 {
509 unsigned char bytes[] = { static_cast<unsigned char>(n % 256), static_cast<unsigned char>(n / 256) };
510 fwrite(bytes, 2, sizeof(unsigned char),fp);
511}

Referenced by igl::opengl::writeTGA().

+ Here is the caller graph for this function:

Variable Documentation

◆ _verbose

unsigned int _verbose = 0
static

◆ error

char error[256]
static

Referenced by Slic3r::CurlGlobalInit::CurlGlobalInit(), Slic3r::SupportSpotsGenerator::Params::Params(), Slic3r::GUI::BoostThreadWorker::~BoostThreadWorker(), Slic3r::GUI::CursorSetterRAII::~CursorSetterRAII(), Slic3r::Zipper::~Zipper(), Slic3r::Fill::_infill_direction(), Slic3r::GUI::GLCanvas3D::_init_main_toolbar(), Slic3r::GUI::GLCanvas3D::_init_undoredo_toolbar(), Slic3r::GUI::GLCanvas3D::_set_warning_notification(), Eigen::PardisoImpl< Derived >::_solve_impl(), Slic3r::sla::anonymous_namespace{Pad.cpp}::add_cavity(), Slic3r::_3MF_Base::add_error(), Slic3r::GUI::NotificationManager::UpdatedItemsInfoNotification::add_type(), Slic3r::Arachne::SkeletalTrapezoidation::addToolpathSegment(), Slic3r::Print::alert_when_supports_needed(), Slic3r::SeamPlacer::align_seam_points(), Eigen::PardisoImpl< Derived >::analyzePattern(), Slic3r::GUI::PrintHostQueueDialog::append_job(), Slic3r::UdpSocket::async_receive(), igl::bbw(), QuadricEdgeCollapse::calculate_3errors(), QuadricEdgeCollapse::calculate_error(), Slic3r::GUI::GUI_App::check_older_app_config(), Eigen::PardisoImpl< Derived >::compute(), Slic3r::GUI::Mouse3DController::connect_device(), Slic3r::Arachne::SkeletalTrapezoidation::constructFromPolygons(), Slic3r::copy_bed_model_and_texture_if_needed(), Slic3r::copy_dir(), Slic3r::anonymous_namespace{PresetUpdater.cpp}::copy_file_fix(), Slic3r::Emboss::create_font_file(), Slic3r::GUI::WxFontUtils::create_font_file(), Slic3r::FFFTreeSupport::create_layer_pathing(), Slic3r::FFFTreeSupport::create_nodes_from_area(), Slic3r::dda(), ImGui::DebugCheckVersionAndDataLayout(), Slic3r::instance_check_internal::delete_lockfile(), igl::xml::deserialize_xml(), Slic3r::AppUpdater::priv::download_file(), Slic3r::GUI::RemovableDriveManager::eject_drive(), Slic3r::PrintHostJobQueue::priv::emit_error(), Slic3r::PrintHostJobQueue::priv::error_fn(), Slic3r::AnycubicSLAArchive::export_print(), Slic3r::SL1Archive::export_print(), Slic3r::GUI::GCodeViewer::export_toolpaths_to_obj(), Slic3r::extract_model_from_archive(), Eigen::PardisoImpl< Derived >::factorize(), Slic3r::FillRectilinear::fill_surface(), Slic3r::FillMonotonic::fill_surface(), Slic3r::FillMonotonicLines::fill_surface(), Slic3r::FillGrid::fill_surface(), Slic3r::FillTriangles::fill_surface(), Slic3r::FillStars::fill_surface(), Slic3r::FillCubic::fill_surface(), Slic3r::BackgroundSlicingProcess::finalize_gcode(), Slic3r::PrintStatistics::finalize_output_path(), Slic3r::SLAPrintStatistics::finalize_output_path(), Slic3r::flatten_configbundle_hierarchy(), Slic3r::PrintHost::format_error(), Slic3r::SLAPrint::Steps::generate_preview(), Slic3r::GUI::generate_thumbnail_from_model(), Slic3r::Arachne::SkeletalTrapezoidation::generateTransitionMids(), Slic3r::GUI::generic_exception_handle(), Slic3r::Measure::get_center_and_radius(), Slic3r::PresetUpdater::priv::get_config_updates(), Slic3r::PresetUpdater::priv::get_file(), Slic3r::Repetier::get_groups(), Slic3r::GUI::HintDatabase::get_hint(), Slic3r::GUI::HintDatabase::get_next(), Slic3r::GUI::FileGet::priv::get_perform(), Slic3r::Repetier::get_printers(), Slic3r::PrusaLink::get_storage(), Slic3r::Arachne::SkeletalTrapezoidation::getOrCreateBeading(), Slic3r::Arachne::VoronoiUtils::getSourcePoint(), glAssertRecentCallImpl(), igl::opengl::gliReadTGA(), Slic3r::Utils::TCPConsole::handle_connect(), Slic3r::GUI::OtherInstanceMessageHandler::handle_message(), Slic3r::Utils::TCPConsole::handle_read(), Slic3r::LookupSession::handle_receive(), Slic3r::ResolveSession::handle_receive(), Slic3r::Utils::TCPConsole::handle_write(), Slic3r::AppUpdater::priv::http_get_file(), Slic3r::PresetBundle::import_newer_configs(), Slic3r::FFFTreeSupport::increase_single_area(), Slic3r::GLShadersManager::init(), Slic3r::GUI::IconManager::init(), Slic3r::GUI::GUI_App::init_app_config(), Slic3r::GUI::GLGizmoEmboss::init_create(), Slic3r::GLShaderProgram::init_from_files(), Slic3r::GLShaderProgram::init_from_texts(), Slic3r::GUI::OpenGLManager::init_gl(), Slic3r::GUI::OpenGLManager::init_glcontext(), Slic3r::GUI::MainFrame::init_tabpanel(), Slic3r::PresetUpdater::install_bundles_rsrc_or_cache_vendor(), Slic3r::instance_check(), Slic3r::GUI::FileGet::is_subdomain(), Slic3r::its_convex_hull(), Slic3r::its_quadric_edge_collapse(), its_write_obj(), its_write_obj(), its_write_off(), Slic3r::its_write_stl_ascii(), Slic3r::its_write_stl_binary(), its_write_vrml(), Slic3r::GUI::BundleMap::load(), Slic3r::AppConfig::load(), Slic3r::GUI::GLGizmoEmboss::load(), Slic3r::GUI::Bundle::load(), Slic3r::load_amf_archive(), Slic3r::load_amf_file(), Slic3r::PresetBundle::load_configbundle(), load_driver_functions(), load_func(), Slic3r::GUI::GCodeViewer::SequentialView::GCodeWindow::load_gcode(), Slic3r::GUI::HintDatabase::load_hints_from_file(), Slic3r::GUI::GUI_App::load_language(), Slic3r::load_obj(), Slic3r::PresetCollection::load_presets(), Slic3r::GUI::ConfigWizard::priv::load_vendors(), Slic3r::_3MF_Base::log_errors(), Slic3r::Bonjour::priv::lookup_perform(), main(), Slic3r::make_circle(), Eigen::PardisoImpl< Derived >::manageErrorCode(), net_open(), Slic3r::GUI::BitmapCache::nsvgGetDataFromFileWithReplace(), Slic3r::GUI::BitmapCache::nsvgParseFromFileWithReplace(), ObjParser::obj_parseline(), ObjParser::objparse(), ObjParser::objparse(), Slic3r::GUI::FileArchiveDialog::on_dpi_changed(), Slic3r::GUI::Downloader::on_error(), Slic3r::GUI::DataList< T, D >::on_mouse_move(), Slic3r::GUI::MainFrame::open_menubar_item(), Slic3r::CoolingBuffer::parse_layer_gcode(), Slic3r::AppUpdater::priv::parse_version_string(), Slic3r::PrintHostJobQueue::priv::perform_job(), Slic3r::GUI::DownloaderUtils::Worker::perform_register(), Slic3r::PresetUpdater::priv::perform_updates(), Slic3r::GUI::GUI_App::post_init(), Slic3r::PrusaLink::post_inner(), Slic3r::GCodeProcessor::post_process(), Slic3r::GUI::Plater::preview_zip_archive(), Slic3r::Print::process(), Slic3r::GCodeProcessor::process_ideamaker_tags(), Slic3r::GCodeProcessor::process_simplify3d_tags(), Slic3r::GCodeProcessor::process_T(), Slic3r::GCodeProcessor::process_tags(), Slic3r::PrusaLink::put_inner(), Slic3r::GUI::anonymous_namespace{HintNotification.cpp}::read_used_binary(), Slic3r::UdpSocket::receive_handler(), Slic3r::GUI::GCodeViewer::refresh_render_paths(), Slic3r::GUI::IconManager::release(), Slic3r::PrintHostJobQueue::priv::remove_source(), Slic3r::GUI::GCodeViewer::SequentialView::GCodeWindow::render(), Slic3r::Timing::TimeLimitAlarm::report_time_exceeded(), Slic3r::GUI::Plater::reslice(), Slic3r::Bonjour::priv::resolve_perform(), Slic3r::GUI::Mouse3DController::run(), Eigen::internal::pardiso_run_selector< IndexType >::run(), Eigen::internal::pardiso_run_selector< long long int >::run(), Eigen::internal::check_rows_cols_for_overflow< Dynamic >::run(), Slic3r::run_post_process_scripts(), Slic3r::Utils::TCPConsole::run_queue(), Slic3r::FFFTreeSupport::safe_offset_inc(), Slic3r::AppConfig::save(), Slic3r::GUI::search_for_drives_internal::search_path(), Slic3r::UdpSocket::send(), Slic3r::GUI::SendSystemInfoDialog::send_info(), igl::xml::serialize_xml(), Slic3r::WipingExtrusions::set_extruder_override(), Slic3r::GUI::NotificationManager::PrintHostUploadNotification::set_percentage(), Slic3r::FFFTreeSupport::set_points_on_areas(), Slic3r::GUI::Bed3D::set_shape(), Slic3r::GUI::Downloader::start_download(), Slic3r::GUI::GUI_App::start_download(), Slic3r::GUI::start_new_slicer_or_gcodeviewer(), Slic3r::Arachne::WallToolPaths::stitchToolPaths(), stl_open_count_facets(), stl_print_neighbors(), stl_read(), stl_write_ascii(), stl_write_binary(), stl_write_dxf(), stl_write_quad_object(), Slic3r::GUI::GLGizmoEmboss::store(), Slic3r::PresetUpdater::priv::sync_config(), Slic3r::GUI::anonymous_namespace{HintNotification.cpp}::tags_check(), Slic3r::GUI::Config::SnapshotDB::take_snapshot(), Slic3r::AstroBox::test(), Slic3r::FlashAir::test(), Slic3r::Moonraker::test(), Slic3r::OctoPrint::test(), Slic3r::PrusaLink::test(), Slic3r::Repetier::test(), Slic3r::PrusaLink::test_with_method_check(), Slic3r::Arachne::SkeletalTrapezoidation::transferEdge(), Slic3r::PresetCollection::update_map_system_profile_renamed(), Slic3r::AstroBox::upload(), Slic3r::FlashAir::upload(), Slic3r::MKS::upload(), Slic3r::Moonraker::upload(), Slic3r::OctoPrint::upload(), Slic3r::Repetier::upload(), Slic3r::OctoPrint::upload_inner_with_host(), Slic3r::AppUpdater::priv::version_check(), Slic3r::png::write_rgb_or_gray_to_file(), Slic3r::GUI::anonymous_namespace{HintNotification.cpp}::write_used_binary(), and igl::xml::writeDAE().

◆ TGAHeaderBW

unsigned char TGAHeaderBW[12]
Initial value:
=
{ 0,
0,
3,
0, 0, 0, 0, 0,
0, 0,
0, 0
}

Referenced by igl::opengl::writeTGA().

◆ TGAHeaderColor

unsigned char TGAHeaderColor[12]
Initial value:
=
{ 0,
0,
2,
0, 0, 0, 0, 0,
0, 0,
0, 0
}

Referenced by igl::opengl::writeTGA().

◆ totbytes

int totbytes = 0
static

Referenced by rle_fread(), and std_fread().