Beatmup
bitmap_from_chunk.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../parallelism.h"
21 #include "../bitmap/abstract_bitmap.h"
22 #include "../bitmap/content_lock.h"
23 #include "chunkfile.h"
24 
25 namespace Beatmup {
26 
27  /**
28  Loads a bitmap content from chunk.
29  The bitmap needs to be created in advance. The loaded chunk contains pixel data in binary form.
30  */
32  private:
33  virtual bool process(TaskThread& thread);
34  virtual void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline* gpu);
35  virtual void afterProcessing(ThreadIndex threadCount, GraphicPipeline* gpu, bool aborted);
38  std::string chunkId;
39  public:
40  inline BitmapFromChunk(): bitmap(nullptr), collection(nullptr) {}
43 
44  inline void setBitmap(AbstractBitmap* bitmap) { this->bitmap = bitmap; }
45 
46  inline void setCollection(ChunkCollection* collection) { this->collection = collection; }
47 
48  inline void setChunkId(const std::string& chunkId) { this->chunkId = chunkId; }
49 
50  /**
51  Loads a bitmap content from a given collection and chunk.
52  Launches a task in the main thread pool of the bitmap context.
53  \param[in,out] bitmap The bitmap to load
54  \param[in,out] collection The collection to load from
55  \param[in,out] chunkId Chunk ID containing the content to load
56  */
57  static void load(AbstractBitmap& bitmap, ChunkCollection& collection, const std::string& chunkId);
58  };
59 }
A very basic class for any image.
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Loads a bitmap content from chunk.
virtual void afterProcessing(ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
Instruction called after the task is executed.
static void load(AbstractBitmap &bitmap, ChunkCollection &collection, const std::string &chunkId)
Loads a bitmap content from a given collection and chunk.
void setChunkId(const std::string &chunkId)
void setCollection(ChunkCollection *collection)
void setBitmap(AbstractBitmap *bitmap)
BitmapFromChunk(AbstractBitmap &bitmap, ChunkCollection &collection, const std::string &chunkId)
ChunkCollection * collection
virtual bool process(TaskThread &thread)
Executes the task on CPU within a given thread.
virtual void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
Instruction called before the task is executed.
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
Definition: chunkfile.h:36
Internal low-level GPU control API.
Definition: pipeline.h:33
Thread executing tasks.
Definition: parallelism.h:154
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
ProcessingTarget
Definition: basic_types.h:55